fix(ui): gate audit retention, resolve export at click, merge live updates
This commit is contained in:
1 parent
1086511f1f
commit
a44a2f026e
4 files changed
+138
-114
No files matched your search
@@ -8,15 +8,18 @@ import {
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { api, type QueryParams } from "@/lib/api";
|
||||
import { api } from "@/lib/api";
|
||||
import { exportFilterParams, type AuditQuery } from "./audit";
|
||||
|
||||
/** Export is a navigation, not a fetch: the server owns the filename through
|
||||
* Content-Disposition. A new tab keeps a failed export's response visible
|
||||
* instead of saving the error text as a file. */
|
||||
const props = defineProps<{ params: QueryParams }>();
|
||||
* Content-Disposition. The window is resolved when the operator picks a
|
||||
* format, so the export covers everything visible now rather than at render.
|
||||
* A new tab keeps a failed export's response visible instead of saving the
|
||||
* error text as a file. */
|
||||
const props = defineProps<{ query: AuditQuery }>();
|
||||
|
||||
function url(format: "csv" | "json"): string {
|
||||
return api.auditExportURL(format, props.params);
|
||||
function open(format: "csv" | "json"): void {
|
||||
window.open(api.auditExportURL(format, exportFilterParams(props.query)), "_blank", "noopener");
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -26,12 +29,8 @@ function url(format: "csv" | "json"): string {
|
||||
<Button variant="outline" size="sm"><Download data-icon="inline-start" />Export</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem as-child>
|
||||
<a :href="url('csv')" target="_blank" rel="noopener" aria-label="Export as CSV">CSV</a>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem as-child>
|
||||
<a :href="url('json')" target="_blank" rel="noopener" aria-label="Export as JSON">JSON</a>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem @select="open('csv')">CSV</DropdownMenuItem>
|
||||
<DropdownMenuItem @select="open('json')">JSON</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</template>
|
||||
@@ -50,7 +50,6 @@ import {
|
||||
badgeFor,
|
||||
dedupeRecords,
|
||||
emptyMessage,
|
||||
exportFilterParams,
|
||||
hasFilters,
|
||||
hasTarget,
|
||||
queryFromRoute,
|
||||
@@ -76,7 +75,6 @@ const { records, facets, loading, loadingMore, error, moreError, hasMore } = sto
|
||||
|
||||
const query = computed(() => queryFromRoute(route.query));
|
||||
const queryKey = computed(() => JSON.stringify(query.value));
|
||||
const exportParams = computed(() => exportFilterParams(query.value));
|
||||
|
||||
const columns: DataTableColumn<AuditRecord>[] = [
|
||||
{ id: "event", label: "Event", fixed: true, class: "whitespace-normal" },
|
||||
@@ -323,6 +321,11 @@ const retentionHours = ref("0");
|
||||
const retentionError = ref("");
|
||||
const retentionSaving = ref(false);
|
||||
const retentionState = settings.stateFor(RETENTION_KIND);
|
||||
// The resource is instance-only; offering the item without it leaves a Save
|
||||
// that can only fail.
|
||||
const retentionAvailable = computed(() =>
|
||||
settings.catalog.some((resource) => resource.kind === RETENTION_KIND),
|
||||
);
|
||||
|
||||
function hoursFrom(value: unknown): number {
|
||||
if (typeof value === "number")
|
||||
@@ -383,12 +386,12 @@ async function saveRetention(): Promise<void> {
|
||||
<SelectItem v-for="view in views" :key="view.name" :value="view.name">{{ view.name }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<AuditExportMenu :params="exportParams" />
|
||||
<AuditExportMenu :query="query" />
|
||||
<MoreMenu label="Audit actions">
|
||||
<DropdownMenuItem :disabled="!identityId" @click="openSaveView">Save view…</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="activeView" variant="destructive" @click="deleteView">Delete view</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem @click="openRetention">Retention</DropdownMenuItem>
|
||||
<DropdownMenuSeparator v-if="retentionAvailable" />
|
||||
<DropdownMenuItem v-if="retentionAvailable" @click="openRetention">Retention</DropdownMenuItem>
|
||||
</MoreMenu>
|
||||
</PageHeader>
|
||||
|
||||
|
||||
+24
-2
@@ -102,6 +102,29 @@ export const useAuditStore = defineStore("audit", () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** Merges a fresh page one into the loaded feed: an id already on screen
|
||||
* keeps its place, replaced when the server now sends different content (a
|
||||
* coalesced denial count, say). An unseen id is returned so the page can
|
||||
* prepend it or hold it behind the new-events button. */
|
||||
function mergePageOne(incoming: AuditRecord[]): AuditRecord[] {
|
||||
const positions = new Map(records.value.map((record, index) => [recordKey(record), index]));
|
||||
const merged = records.value.slice();
|
||||
const added: AuditRecord[] = [];
|
||||
let replaced = false;
|
||||
for (const record of dedupeRecords(incoming)) {
|
||||
const at = positions.get(recordKey(record));
|
||||
if (at === undefined) {
|
||||
added.push(record);
|
||||
continue;
|
||||
}
|
||||
if (JSON.stringify(merged[at]) === JSON.stringify(record)) continue;
|
||||
merged[at] = record;
|
||||
replaced = true;
|
||||
}
|
||||
if (replaced) records.value = merged;
|
||||
return added;
|
||||
}
|
||||
|
||||
/** Re-reads page one after a live head. Returns the records this page did
|
||||
* not already hold; the page decides whether to prepend or hold them. */
|
||||
async function refresh(): Promise<AuditRecord[]> {
|
||||
@@ -116,8 +139,7 @@ export const useAuditStore = defineStore("audit", () => {
|
||||
nextCursor.value = response.next_cursor || null;
|
||||
hasMore.value = !!response.has_more;
|
||||
}
|
||||
const known = new Set(records.value.map(recordKey));
|
||||
return dedupeRecords(response.records ?? []).filter((record) => !known.has(recordKey(record)));
|
||||
return mergePageOne(response.records ?? []);
|
||||
}
|
||||
|
||||
function prepend(incoming: AuditRecord[]): void {
|
||||
|
||||
Reference in new issue
Block a user