mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-31 04:56:43 +00:00
Sort resource filter options in audit logs
This commit is contained in:
@@ -93,6 +93,20 @@ export const queryAccessAuditLogsCombined = queryAccessAuditLogsQuery.merge(
|
|||||||
);
|
);
|
||||||
type Q = z.infer<typeof queryAccessAuditLogsCombined>;
|
type Q = z.infer<typeof queryAccessAuditLogsCombined>;
|
||||||
|
|
||||||
|
function sortNamedFilterOptions<T extends { id: number; name: string | null }>(
|
||||||
|
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) {
|
function getWhere(data: Q) {
|
||||||
return and(
|
return and(
|
||||||
gt(accessAuditLog.timestamp, data.timeStart),
|
gt(accessAuditLog.timestamp, data.timeStart),
|
||||||
@@ -308,7 +322,7 @@ async function queryUniqueFilterAttributes(
|
|||||||
actors: uniqueActors
|
actors: uniqueActors
|
||||||
.map((row) => row.actor)
|
.map((row) => row.actor)
|
||||||
.filter((actor): actor is string => actor !== null),
|
.filter((actor): actor is string => actor !== null),
|
||||||
resources: resourcesWithNames,
|
resources: sortNamedFilterOptions(resourcesWithNames),
|
||||||
locations: uniqueLocations
|
locations: uniqueLocations
|
||||||
.map((row) => row.locations)
|
.map((row) => row.locations)
|
||||||
.filter((location): location is string => location !== null)
|
.filter((location): location is string => location !== null)
|
||||||
|
|||||||
@@ -107,6 +107,20 @@ export const queryConnectionAuditLogsCombined =
|
|||||||
queryConnectionAuditLogsQuery.merge(queryConnectionAuditLogsParams);
|
queryConnectionAuditLogsQuery.merge(queryConnectionAuditLogsParams);
|
||||||
type Q = z.infer<typeof queryConnectionAuditLogsCombined>;
|
type Q = z.infer<typeof queryConnectionAuditLogsCombined>;
|
||||||
|
|
||||||
|
function sortNamedFilterOptions<T extends { id: number; name: string | null }>(
|
||||||
|
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) {
|
function getWhere(data: Q) {
|
||||||
return and(
|
return and(
|
||||||
gt(connectionAuditLog.startedAt, data.timeStart),
|
gt(connectionAuditLog.startedAt, data.timeStart),
|
||||||
@@ -425,7 +439,7 @@ async function queryUniqueFilterAttributes(
|
|||||||
.map((row) => row.destAddr)
|
.map((row) => row.destAddr)
|
||||||
.filter((addr): addr is string => addr !== null),
|
.filter((addr): addr is string => addr !== null),
|
||||||
clients: clientsWithNames,
|
clients: clientsWithNames,
|
||||||
resources: resourcesWithNames,
|
resources: sortNamedFilterOptions(resourcesWithNames),
|
||||||
users: usersWithEmails
|
users: usersWithEmails
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,20 @@ export const queryRequestAuditLogsCombined = queryAccessAuditLogsQuery.merge(
|
|||||||
);
|
);
|
||||||
type Q = z.infer<typeof queryRequestAuditLogsCombined>;
|
type Q = z.infer<typeof queryRequestAuditLogsCombined>;
|
||||||
|
|
||||||
|
function sortNamedFilterOptions<T extends { id: number; name: string | null }>(
|
||||||
|
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) {
|
function getWhere(data: Q) {
|
||||||
return and(
|
return and(
|
||||||
gt(requestAuditLog.timestamp, data.timeStart),
|
gt(requestAuditLog.timestamp, data.timeStart),
|
||||||
@@ -353,7 +367,7 @@ async function queryUniqueFilterAttributes(
|
|||||||
actors: uniqueActors
|
actors: uniqueActors
|
||||||
.map((row) => row.actor)
|
.map((row) => row.actor)
|
||||||
.filter((actor): actor is string => actor !== null),
|
.filter((actor): actor is string => actor !== null),
|
||||||
resources: resourcesWithNames,
|
resources: sortNamedFilterOptions(resourcesWithNames),
|
||||||
locations: uniqueLocations
|
locations: uniqueLocations
|
||||||
.map((row) => row.locations)
|
.map((row) => row.locations)
|
||||||
.filter((location): location is string => location !== null),
|
.filter((location): location is string => location !== null),
|
||||||
|
|||||||
Reference in New Issue
Block a user