From f8b24b2636fd906ed09817be47a72135f8218894 Mon Sep 17 00:00:00 2001 From: Faust1 <117363666+Faust1-2was-Aneo@users.noreply.github.com> Date: Wed, 18 Oct 2023 08:50:47 +0200 Subject: [PATCH] chore: fix sort unreliability (#715) Co-authored-by: yannick-aneo <136307285+yannick-aneo@users.noreply.github.com> --- src/app/components/columns-modify-dialog.component.ts | 4 ++-- src/app/components/show-card-content.component.ts | 2 +- .../components/view-tasks-by-status-dialog.component.spec.ts | 4 ++-- src/app/dashboard/services/dashboard-index.service.ts | 4 ++-- src/app/settings/index.component.ts | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/app/components/columns-modify-dialog.component.ts b/src/app/components/columns-modify-dialog.component.ts index d1ed92daa..fb7578994 100644 --- a/src/app/components/columns-modify-dialog.component.ts +++ b/src/app/components/columns-modify-dialog.component.ts @@ -86,13 +86,13 @@ export class ColumnsModifyDialogComponent imp * Sort the columns alphabetically */ availableColumns(): (keyof T | 'actions')[] { - const columns = this.data.availableColumns.filter(column => !column.toString().startsWith('options.')).sort() as (keyof T | 'actions')[]; + const columns = this.data.availableColumns.filter(column => !column.toString().startsWith('options.')).sort((a, b) => a.toString().localeCompare(b.toString())) as (keyof T | 'actions')[]; return columns; } availableOptionsColumns(): PrefixedOptions[] { - const columns = this.data.availableColumns.filter(column => column.toString().startsWith('options.')).sort() as PrefixedOptions[]; + const columns = this.data.availableColumns.filter(column => column.toString().startsWith('options.')).sort((a, b) => a.toString().localeCompare(b.toString())) as PrefixedOptions[]; return columns; } diff --git a/src/app/components/show-card-content.component.ts b/src/app/components/show-card-content.component.ts index cfa8d1679..b1e0f987c 100644 --- a/src/app/components/show-card-content.component.ts +++ b/src/app/components/show-card-content.component.ts @@ -87,7 +87,7 @@ export class ShowCardContentComponent implements OnChanges { ngOnChanges() { if (this.data) { - this.keys = Object.keys(this.data).sort(); + this.keys = Object.keys(this.data).sort((a, b) => a.toString().localeCompare(b.toString())); } } diff --git a/src/app/components/view-tasks-by-status-dialog.component.spec.ts b/src/app/components/view-tasks-by-status-dialog.component.spec.ts index 33b36a9f7..b934cf0b7 100644 --- a/src/app/components/view-tasks-by-status-dialog.component.spec.ts +++ b/src/app/components/view-tasks-by-status-dialog.component.spec.ts @@ -51,7 +51,7 @@ describe('ViewTasksByStatusDialogComponent', () => { }); it('should retrieve tasks keys with tasksStatuses', () => { - expect(component.tasksStatuses().sort()).toEqual([ + expect(component.tasksStatuses().sort((a, b) => a.toString().localeCompare(b.toString()))).toEqual([ TaskStatus.TASK_STATUS_UNSPECIFIED.toString(), TaskStatus.TASK_STATUS_DISPATCHED.toString(), TaskStatus.TASK_STATUS_CREATING.toString(), @@ -64,7 +64,7 @@ describe('ViewTasksByStatusDialogComponent', () => { TaskStatus.TASK_STATUS_ERROR.toString(), TaskStatus.TASK_STATUS_TIMEOUT.toString(), TaskStatus.TASK_STATUS_RETRIED.toString() - ].sort()); + ].sort((a, b) => a.toString().localeCompare(b.toString()))); }); it('should retrieve a label by its corresponding status', () => { diff --git a/src/app/dashboard/services/dashboard-index.service.ts b/src/app/dashboard/services/dashboard-index.service.ts index 9f684650a..4855f6abb 100644 --- a/src/app/dashboard/services/dashboard-index.service.ts +++ b/src/app/dashboard/services/dashboard-index.service.ts @@ -16,8 +16,8 @@ export class DashboardIndexService { // TODO: move to TasksStatusesService statuses(): { value: string, name: string }[] { - const values = Object.values(this.#tasksStatusesService.statuses).sort(); - const keys = Object.keys(this.#tasksStatusesService.statuses).sort(); + const values = Object.values(this.#tasksStatusesService.statuses).sort((a, b) => a.toString().localeCompare(b.toString())); + const keys = Object.keys(this.#tasksStatusesService.statuses).sort((a, b) => a.toString().localeCompare(b.toString())); const sortedKeys = values.map((value) => { return keys.find((key) => { return this.#tasksStatusesService.statuses[Number(key) as TaskStatus] === value; diff --git a/src/app/settings/index.component.ts b/src/app/settings/index.component.ts index 684cf6d02..a1f7261ab 100644 --- a/src/app/settings/index.component.ts +++ b/src/app/settings/index.component.ts @@ -455,6 +455,6 @@ export class IndexComponent implements OnInit { } #sortKeys(keys: Set): Set { - return new Set([...keys].sort()); + return new Set([...keys].sort((a, b) => a.localeCompare(b))); } }