Skip to content

Commit

Permalink
chore: fix sort unreliability (#715)
Browse files Browse the repository at this point in the history
Co-authored-by: yannick-aneo <[email protected]>
  • Loading branch information
fdewas-aneo and yannick-aneo authored Oct 18, 2023
1 parent 8ff7645 commit f8b24b2
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/app/components/columns-modify-dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ export class ColumnsModifyDialogComponent<T extends object,O extends object> 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<O>[] {
const columns = this.data.availableColumns.filter(column => column.toString().startsWith('options.')).sort() as PrefixedOptions<O>[];
const columns = this.data.availableColumns.filter(column => column.toString().startsWith('options.')).sort((a, b) => a.toString().localeCompare(b.toString())) as PrefixedOptions<O>[];

return columns;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/show-card-content.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class ShowCardContentComponent<T extends object> 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()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/app/dashboard/services/dashboard-index.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/app/settings/index.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,6 @@ export class IndexComponent implements OnInit {
}

#sortKeys(keys: Set<Key>): Set<Key> {
return new Set([...keys].sort());
return new Set([...keys].sort((a, b) => a.localeCompare(b)));
}
}

1 comment on commit f8b24b2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 88%
88.7% (1414/1594) 79.7% (271/340) 79.62% (336/422)

JUnit

Tests Skipped Failures Errors Time
473 0 💤 0 ❌ 0 🔥 1m 34s ⏱️
Files coverage (88%)
File% Stmts% Branch% Funcs% LinesUncovered Line #s
All files88.779.779.6288.87 
applications/services100100100100 
   applications-filters.service.ts100100100100 
components91.9394.1181.2593.51 
   actions-toolbar-group.component.ts100100100100 
   actions-toolbar.component.ts100100100100 
   auto-refresh-button.component.ts100100100100 
   auto-refresh-dialog.component.ts100100100100 
   columns-button.component.ts100100100100 
   columns-modify-dialog.component.ts26.660033.3365–123
   count-tasks-by-status.component.ts1005010010048
   page-header.component.ts8010008039
   page-section-header.component.ts8010008031
   page-section.component.ts100100100100 
   refresh-button.component.ts100100100100 
   share-url.component.ts92.851007592.337
   show-card-content.component.ts100100100100 
   spinner.component.ts100100100100 
   table-actions-toolbar.component.ts100100100100 
   view-tasks-by-status-dialog.component.ts100100100100 
   view-tasks-by-status.component.ts100100100100 
components/filters9578.9495.7494.89 
   filters-chips.component.ts100100100100 
   filters-dialog-and.component.ts100100100100 
   filters-dialog-filter-field.component.ts86.275.7592.385.9699–100, 132, 174, 198–202
   filters-dialog-input.component.ts92.8563.6387.592.5973–74
   filters-dialog-or.component.ts100100100100 
   filters-dialog.component.ts100100100100 
   filters-toolbar.component.ts100100100100 
components/navigation99.4410097.3699.42 
   add-external-service-dialog.component.ts100100100100 
   edit-external-service-dialog.component.ts100100100100 
   form-external-service.component.ts100100100100 
   manage-external-services-dialog.component.ts100100100100 
   navigation.component.ts98.1410088.8898.11215
   theme-selector.component.ts100100100100 
dashboard100100100100 
   index.component.ts100100100100 
dashboard/components68.138.8845.6768.24 
   add-line-dialog.component.ts55.55100055.5527–38
   add-statuses-group-dialog.component.ts45.45100045.4529–45
   edit-name-line-dialog.component.ts5010005031–46
   edit-status-group-dialog.component.ts41.66100041.6630–47
   form-name-line.component.ts47.360047.3657–88
   form-statuses-group.component.ts22.50022.582–159
   line.component.ts100100100100 
   manage-groups-dialog.component.ts100100100100 
   reorganize-lines-dialog.component.ts32.430034.28104–160
   split-lines-dialog.component.ts42.850042.8538–61
   statuses-group-card.component.ts100100100100 
dashboard/services52.533.3326.6652.77 
   dashboard-index.service.ts240022.7210–49
   dashboard-storage.service.ts100100100100 
services98.3695.4195.698.23 
   auto-refresh.service.ts100100100100 
   date-handler.service.ts100100100100 
   default-config.service.ts100100100100 
   environment.service.ts80100507519
   filters.service.ts100100100100 
   icons.service.ts100100100100 
   navigation.service.ts10080100100109
   notification.service.ts100100100100 
   query-params.service.ts100100100100 
   share-url.service.ts100100100100 
   storage.service.ts98.0310010097.9595
   table-storage.service.ts500042.8511–31
   table-url.service.ts100100100100 
   table.service.ts100100100100 
   tasks-by-status.service.ts100100100100 
   user-grpc.service.ts100100100100 
   user.service.ts100100100100 
   utils.service.ts100100100100 
   versions-grpc.service.ts100100100100 
   versions.service.ts1007010010014, 25, 32
tasks/services76.7647.7282.8575.78 
   tasks-filters.service.ts100100100100 
   tasks-grpc.service.ts23.330020.6813–151
   tasks-index.service.ts100100100100 
   tasks-statuses.service.ts100100100100 
tokens100100100100 
   filters.token.ts100100100100 

Please sign in to comment.