fix: typo on parent check (#811)

This commit is contained in:
Laurent Senta
2022-01-17 13:59:31 +01:00
committed by GitHub
parent bd6b53f590
commit b0544dc2ef

View File

@@ -199,32 +199,33 @@ export class TagsState {
public async assignParent( public async assignParent(
tagUuid: string, tagUuid: string,
parentUuid: string | undefined futureParentUuid: string | undefined
): Promise<void> { ): Promise<void> {
const tag = this.application.findItem(tagUuid) as SNTag; const tag = this.application.findItem(tagUuid) as SNTag;
const currentParent = this.application.getTagParent(tag); const currentParent = this.application.getTagParent(tag);
const currentParentUuid = currentParent?.parentId; const currentParentUuid = currentParent?.uuid;
if (currentParentUuid === parentUuid) { if (currentParentUuid === futureParentUuid) {
return; return;
} }
const parent = const futureParent =
parentUuid && (this.application.findItem(parentUuid) as SNTag); futureParentUuid &&
(this.application.findItem(futureParentUuid) as SNTag);
if (!parent) { if (!futureParent) {
const futureSiblings = rootTags(this.application); const futureSiblings = rootTags(this.application);
if (!isValidFutureSiblings(this.application, futureSiblings, tag)) { if (!isValidFutureSiblings(this.application, futureSiblings, tag)) {
return; return;
} }
await this.application.unsetTagParent(tag); await this.application.unsetTagParent(tag);
} else { } else {
const futureSiblings = this.application.getTagChildren(parent); const futureSiblings = this.application.getTagChildren(futureParent);
if (!isValidFutureSiblings(this.application, futureSiblings, tag)) { if (!isValidFutureSiblings(this.application, futureSiblings, tag)) {
return; return;
} }
await this.application.setTagParent(parent, tag); await this.application.setTagParent(futureParent, tag);
} }
await this.application.sync(); await this.application.sync();