Skip to content

Commit

Permalink
Enable automatic exclusion of non-required dependencies in the Publis…
Browse files Browse the repository at this point in the history
…hing Wizard #6415
  • Loading branch information
edloidas committed Jun 19, 2023
1 parent 03518a8 commit 98d90e3
Showing 1 changed file with 112 additions and 70 deletions.
182 changes: 112 additions & 70 deletions modules/lib/src/main/resources/assets/js/app/publish/PublishProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ interface ReloadDependenciesParams {
silent?: boolean;
}

interface LoadDependenciesParams
extends ReloadDependenciesParams {
ids: ContentId[];
}

export type LoadingStartedListener = (checking: boolean) => void;

export class PublishProcessor {
Expand Down Expand Up @@ -156,7 +161,7 @@ export class PublishProcessor {
}

reloadPublishDependencies(params: ReloadDependenciesParams): void {
const {resetDependantItems, resetExclusions = false, silent} = params;
const {resetDependantItems, resetExclusions, silent} = params;
const excludeNonRequired = CONFIG.isTrue('excludeDependencies');

if (!silent) {
Expand All @@ -165,33 +170,20 @@ export class PublishProcessor {

const ids = this.getContentToPublishIds();
const isNoItemsToPublish = ids.length === 0;
const instanceId = this.instanceId;
const needExcludeNonRequired = excludeNonRequired && (this.cleanLoad || resetExclusions) && !isNoItemsToPublish;
const isNothingToExclude = !resetExclusions && this.isSomeOrNoneExcluded();

Q().then(() => {
if (resetExclusions) {
this.resetExcludedIds();
} else if (this.isSomeOrNoneExcluded()) {
return;
}
if (resetExclusions) {
this.resetExcludedIds();
}

if (needExcludeNonRequired) {
return this.findExcludedDependenciesWithoutChildren(ids).then(excludedIds => {
this.setExcludedIds(excludedIds);
});
}
}).then(() => {
if (isNoItemsToPublish) {
this.handleNoPublishItemsToLoad(resetDependantItems, silent);
} else {
this.loadPublishDependencies(ids, resetDependantItems, silent);
}
}).catch(reason => {
if (instanceId === this.instanceId) {
this.notifyLoadingFailed();
DefaultErrorHandler.handle(reason);
}
});
if (isNoItemsToPublish) {
this.handleNoPublishItemsToLoad(resetDependantItems, silent);
} else if (needExcludeNonRequired && !isNothingToExclude) {
this.cleanLoadPublishDependencies({...params, ids});
} else {
this.loadPublishDependencies({...params, ids});
}
}

private handleNoPublishItemsToLoad(resetDependantItems?: boolean, silent?: boolean): void {
Expand All @@ -216,7 +208,8 @@ export class PublishProcessor {
console.debug('PublishProcessor.reloadPublishDependencies: resolved dependants = ', dependants);
}

if (resetDependantItems) { // just opened or first time loading children
// just opened or first time loading children
if (resetDependantItems) {
this.dependantList.setItems(dependants);
} else {
this.filterDependantItems(dependants);
Expand All @@ -225,37 +218,89 @@ export class PublishProcessor {
this.dependantList.refresh();
}

private loadPublishDependencies(ids: ContentId[], resetDependantItems?: boolean, silent?: boolean): Q.Promise<void> {
private async cleanLoadPublishDependencies({ids, resetDependantItems, silent}: LoadDependenciesParams): Promise<void> {
const instanceId = this.instanceId;
const cleanLoad = this.cleanLoad;
this.cleanLoad = false;

return this.createResolveDependenciesRequest(ids, cleanLoad ? [] : this.getExcludedIds()).sendAndParse()
.then((result: ResolvePublishDependenciesResult) => {
this.processResolveDependenciesResult(result);
this.handleExclusionResult();
}).then(() => {
const hasExcluded = this.getExcludedIds().length > 0;
if (hasExcluded) {
return this.createResolveDependenciesRequest(ids, []).sendAndParse().then(
(result: ResolvePublishDependenciesResult) => {
if (instanceId === this.instanceId) {
this.allDependantIds = [...result.getDependants()];
}
});
} else if (instanceId === this.instanceId) {
this.allDependantIds = [...this.dependantIds];
}
}).then(() => {
return this.loadDescendants(cleanLoad).then((descendants: ContentSummaryAndCompareStatus[]) => {
if (instanceId === this.instanceId) {
this.processResolveDescendantsResult(descendants, resetDependantItems);
if (!silent) {
this.notifyLoadingFinished();
}
}
});
});

try {
const [maxResult, childrenIds] = await Q.all([
this.createResolveDependenciesRequest(ids).sendAndParse(),
this.findIncludedChildrenIds(),
]);

const potentialExcludedIds = maxResult.getDependants().filter(id => !this.itemsIncludeId(childrenIds, id));

const minResult = await this.createResolveDependenciesRequest(ids, potentialExcludedIds).sendAndParse();

const excludedIds = potentialExcludedIds.filter(id => !this.itemsIncludeId(minResult.getRequired(), id));

if (instanceId !== this.instanceId) {
return;
}

this.setExcludedIds(excludedIds);

this.processResolveDependenciesResult(minResult);
this.handleExclusionResult();

this.allDependantIds = maxResult.getDependants();

const descendants = await this.loadDescendants();

if (instanceId !== this.instanceId) {
return;
}

this.processResolveDescendantsResult(descendants, resetDependantItems);
if (!silent) {
this.notifyLoadingFinished();
}
} catch (reason) {
if (instanceId === this.instanceId) {
this.notifyLoadingFailed();
DefaultErrorHandler.handle(reason);
}
}
}

private async loadPublishDependencies({ids, resetDependantItems, silent}: LoadDependenciesParams): Promise<void> {
const instanceId = this.instanceId;

try {
const result = await this.createResolveDependenciesRequest(ids, this.getExcludedIds()).sendAndParse();

if (instanceId !== this.instanceId) {
return;
}

this.processResolveDependenciesResult(result);
this.handleExclusionResult();

const hasExcluded = this.getExcludedIds().length > 0;
const allDependantIds = hasExcluded ? await this.createResolveDependenciesRequest(ids).sendAndParse().then(
r => r.getDependants()) : this.dependantIds;

if (instanceId !== this.instanceId) {
return;
}

this.allDependantIds = [...allDependantIds];

const descendants = await this.loadDescendants();

if (instanceId !== this.instanceId) {
return;
}

this.processResolveDescendantsResult(descendants, resetDependantItems);
if (!silent) {
this.notifyLoadingFinished();
}
} catch (reason) {
if (instanceId === this.instanceId) {
this.notifyLoadingFailed();
DefaultErrorHandler.handle(reason);
}
}
}

updateLoadExcluded(loadExcluded: boolean): void {
Expand All @@ -282,7 +327,7 @@ export class PublishProcessor {
const instanceId = this.instanceId;
this.notifyLoadingStarted(false);

this.createResolveDependenciesRequest(ids, []).sendAndParse().then((result: ResolvePublishDependenciesResult) => {
this.createResolveDependenciesRequest(ids).sendAndParse().then((result: ResolvePublishDependenciesResult) => {
if (this.instanceId === instanceId) {
this.allDependantIds = [...result.getDependants()];

Expand All @@ -306,25 +351,16 @@ export class PublishProcessor {
return parentIds.length === 0 ? Q([]) : new FindIdsByParentsRequest(parentIds).sendAndParse();
}

private findExcludedDependenciesWithoutChildren(ids: ContentId[]): Q.Promise<ContentId[]> {
return Q.all([
this.findIncludedChildrenIds(),
this.createResolveDependenciesRequest(ids, this.excludedIds, []).sendAndParse(),
]).then(([childrenIds, result]) => {
return result.getDependants().filter(id => !this.itemsIncludeId(childrenIds, id));
});
}

private createResolveDependenciesRequest(
ids: ContentId[],
excludedIds: ContentId[],
excludedIds: ContentId[] = [],
excludedChildrenIds?: ContentId[],
): ResolvePublishDependenciesRequest {

return ResolvePublishDependenciesRequest.create()
.setIds(ids)
.setExcludedIds(excludedIds)
.setExcludeChildrenIds(excludedChildrenIds ?? this.itemList.getExcludeChildrenIds())
.setExcludeChildrenIds(excludedChildrenIds ?? this.getExcludeChildrenIds())
.build();
}

Expand All @@ -338,8 +374,8 @@ export class PublishProcessor {
this.allPendingDelete = result.isAllPendingDelete();
}

private loadDescendants(cleanLoad?: boolean): Q.Promise<ContentSummaryAndCompareStatus[]> {
const dependantsIds = this.getDependantIds(this.loadExcluded || cleanLoad);
private loadDescendants(): Q.Promise<ContentSummaryAndCompareStatus[]> {
const dependantsIds = this.getDependantIds(this.loadExcluded);
const noDependantItems = dependantsIds.length === 0;

if (noDependantItems) {
Expand All @@ -356,6 +392,12 @@ export class PublishProcessor {
if (this.isAnyExcluded(inProgressIds) || this.isAnyExcluded(invalidIds)) {
NotifyManager.get().showFeedback(i18n('dialog.publish.notAllExcluded'));
}

const missingExcludedIds = this.dependantList.getItemsIds().filter(
id => !this.itemsIncludeId(this.dependantIds, id) && !this.itemsIncludeId(this.excludedIds, id));
if (missingExcludedIds.length > 0) {
this.setExcludedIds([...this.excludedIds, ...missingExcludedIds]);
}
}

private itemsIncludeId(sourceIds: ContentId[], targetId: ContentId): boolean {
Expand Down

0 comments on commit 98d90e3

Please sign in to comment.