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)
This commit is contained in:
Lisbet Alvarez authored and GitHub committed 2025-06-05 11:00:25 -07:00
1 parent 4c959ab297
commit 738fa1f15f
27 files changed
+331 -41

No files matched your search

@@ -0,0 +1,12 @@
/**
* 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));
}