Skip to content

Commit 778571c

Browse files
authored
ISS-1928: sorted trust center controls (#1670)
1 parent 24def49 commit 778571c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

apps/console/src/lib/graphql-hooks/control.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,24 @@ export function useAllControlsGroupedWithListFields({ where, enabled = true }: {
383383
}, [data?.pages])
384384

385385
const groupedControls = useMemo(() => {
386-
return allControls.reduce<Record<string, ControlListStandardFieldsFragment[]>>((acc, control) => {
386+
const groups = allControls.reduce<Record<string, ControlListStandardFieldsFragment[]>>((acc, control) => {
387387
const category = control.category || 'Uncategorized'
388388
if (!acc[category]) acc[category] = []
389389
acc[category].push(control)
390390
return acc
391391
}, {})
392+
393+
for (const controls of Object.values(groups)) {
394+
controls.sort((a, b) => a.refCode.localeCompare(b.refCode, undefined, { numeric: true }))
395+
}
396+
397+
const sortedEntries = Object.entries(groups).sort(([, controlsA], [, controlsB]) => {
398+
const minA = controlsA[0]?.refCode ?? ''
399+
const minB = controlsB[0]?.refCode ?? ''
400+
return minA.localeCompare(minB, undefined, { numeric: true })
401+
})
402+
403+
return Object.fromEntries(sortedEntries)
392404
}, [allControls])
393405

394406
const isLoadingAll = isLoading || isFetchingNextPage || hasNextPage || isFetching

0 commit comments

Comments
 (0)