diff --git a/server/private/routers/auditLogs/queryAccessAuditLog.ts b/server/private/routers/auditLogs/queryAccessAuditLog.ts index 1ce03f716..5f7ca7d7e 100644 --- a/server/private/routers/auditLogs/queryAccessAuditLog.ts +++ b/server/private/routers/auditLogs/queryAccessAuditLog.ts @@ -93,6 +93,20 @@ export const queryAccessAuditLogsCombined = queryAccessAuditLogsQuery.merge( ); type Q = z.infer; +function sortNamedFilterOptions( + items: T[] +): T[] { + return [...items].sort((a, b) => { + const nameA = a.name ?? ""; + const nameB = b.name ?? ""; + + if (nameA < nameB) return -1; + if (nameA > nameB) return 1; + + return a.id - b.id; + }); +} + function getWhere(data: Q) { return and( gt(accessAuditLog.timestamp, data.timeStart), @@ -308,7 +322,7 @@ async function queryUniqueFilterAttributes( actors: uniqueActors .map((row) => row.actor) .filter((actor): actor is string => actor !== null), - resources: resourcesWithNames, + resources: sortNamedFilterOptions(resourcesWithNames), locations: uniqueLocations .map((row) => row.locations) .filter((location): location is string => location !== null) diff --git a/server/private/routers/auditLogs/queryConnectionAuditLog.ts b/server/private/routers/auditLogs/queryConnectionAuditLog.ts index 930ee6111..4af495463 100644 --- a/server/private/routers/auditLogs/queryConnectionAuditLog.ts +++ b/server/private/routers/auditLogs/queryConnectionAuditLog.ts @@ -107,6 +107,20 @@ export const queryConnectionAuditLogsCombined = queryConnectionAuditLogsQuery.merge(queryConnectionAuditLogsParams); type Q = z.infer; +function sortNamedFilterOptions( + items: T[] +): T[] { + return [...items].sort((a, b) => { + const nameA = a.name ?? ""; + const nameB = b.name ?? ""; + + if (nameA < nameB) return -1; + if (nameA > nameB) return 1; + + return a.id - b.id; + }); +} + function getWhere(data: Q) { return and( gt(connectionAuditLog.startedAt, data.timeStart), @@ -425,7 +439,7 @@ async function queryUniqueFilterAttributes( .map((row) => row.destAddr) .filter((addr): addr is string => addr !== null), clients: clientsWithNames, - resources: resourcesWithNames, + resources: sortNamedFilterOptions(resourcesWithNames), users: usersWithEmails }; } diff --git a/server/routers/auditLogs/queryRequestAuditLog.ts b/server/routers/auditLogs/queryRequestAuditLog.ts index 635683fe8..01126353e 100644 --- a/server/routers/auditLogs/queryRequestAuditLog.ts +++ b/server/routers/auditLogs/queryRequestAuditLog.ts @@ -86,6 +86,20 @@ export const queryRequestAuditLogsCombined = queryAccessAuditLogsQuery.merge( ); type Q = z.infer; +function sortNamedFilterOptions( + items: T[] +): T[] { + return [...items].sort((a, b) => { + const nameA = a.name ?? ""; + const nameB = b.name ?? ""; + + if (nameA < nameB) return -1; + if (nameA > nameB) return 1; + + return a.id - b.id; + }); +} + function getWhere(data: Q) { return and( gt(requestAuditLog.timestamp, data.timeStart), @@ -353,7 +367,7 @@ async function queryUniqueFilterAttributes( actors: uniqueActors .map((row) => row.actor) .filter((actor): actor is string => actor !== null), - resources: resourcesWithNames, + resources: sortNamedFilterOptions(resourcesWithNames), locations: uniqueLocations .map((row) => row.locations) .filter((location): location is string => location !== null),