Files
threshold-ui/ui/admin/app/utils/sort-name-with-id-fallback.js
T
Lisbet Alvarez 738fa1f15f refactor: 💡 add custom sort to resources (#2860)
* refactor: 💡 add custom sort

* test: 💍 fix tests

* test: 💍 fix more tests

* refactor: 💡 use reusable sort function for name

* refactor: 💡 use sort util in all resources w/ optional name

* Add missing copyright headers

* test: 💍 fix broken tests & add tests for new util

* refactor: 💡 add name custom sort to users

* test: 💍 fix import in tests

* refactor: 💡 add custom name sort to scopes

* test: 💍 pr feedback on util test cases

* refactor: 💡 move sort function into object (pr feedback)
2025-06-05 11:00:25 -07:00

13 lines
307 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
export function sortNameWithIdFallback(recordA, recordB) {
let a = recordA.attributes.name;
let b = recordB.attributes.name;
a = a ? a : recordA.id;
b = b ? b : recordB.id;
return String(a).localeCompare(String(b));
}