Skip to content

Commit

Permalink
Revert action sorting to the previous variant. Treat visibleIndex und…
Browse files Browse the repository at this point in the history
…efined as 0.
  • Loading branch information
andrewtelnov committed Nov 18, 2024
1 parent 11ddcc9 commit 9db181b
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/survey-core/src/actions/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class ActionContainer<T extends BaseAction = Action> extends Base impleme
const res: T = this.createAction(val);
if(sortByVisibleIndex && !this.isActionVisible(res)) return res;
const items = [].concat(this.actions, res);
items.sort(this.compareByVisibleIndex);
this.sortItems(items);
this.actions = items;
return res;
}
Expand All @@ -143,13 +143,23 @@ export class ActionContainer<T extends BaseAction = Action> extends Base impleme
}
});
if (sortByVisibleIndex) {
newActions.sort(this.compareByVisibleIndex);
this.sortItems(newActions);
}
this.actions = newActions;
}
private compareByVisibleIndex(first: T, second: T): number {
if(first.visibleIndex === undefined) return 1;
if(second.visibleIndex === undefined) return -1;
private sortItems(items: Array<IAction>): void {
if(this.hasSetVisibleIndex(items)) {
items.sort(this.compareByVisibleIndex);
}
}
private hasSetVisibleIndex(items: Array<IAction>): boolean {
for(let i = 0; i < items.length; i ++) {
const index = items[i].visibleIndex;
if(index !== undefined && index >= 0) return true;
}
return false;
}
private compareByVisibleIndex(first: IAction, second: IAction): number {
return first.visibleIndex - second.visibleIndex;
}
private isActionVisible(item: IAction): boolean {
Expand Down

0 comments on commit 9db181b

Please sign in to comment.