Skip to content

Commit f0ab97b

Browse files
committed
show user and silo IDs with middle truncation
1 parent 28e9807 commit f0ab97b

File tree

1 file changed

+46
-17
lines changed

1 file changed

+46
-17
lines changed

app/pages/system/AuditLog.tsx

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ import { useVirtualizer } from '@tanstack/react-virtual'
1111
import cn from 'classnames'
1212
import { differenceInMilliseconds } from 'date-fns'
1313
import { useMemo, useRef } from 'react'
14+
import { match } from 'ts-pattern'
1415

1516
import { api } from '@oxide/api'
1617
import { Logs16Icon, Logs24Icon } from '@oxide/design-system/icons/react'
1718

1819
import { DocsPopover } from '~/components/DocsPopover'
1920
import { useDateTimeRangePicker } from '~/components/form/fields/DateTimeRangePicker'
2021
import { useIntervalPicker } from '~/components/RefetchIntervalPicker'
22+
import { EmptyCell } from '~/table/cells/EmptyCell'
2123
import { Badge } from '~/ui/lib/Badge'
2224
import { Button } from '~/ui/lib/Button'
2325
import { PageHeader, PageTitle } from '~/ui/lib/PageHeader'
2426
import { Spinner } from '~/ui/lib/Spinner'
27+
import { Truncate } from '~/ui/lib/Truncate'
2528
import { classed } from '~/util/classed'
2629
import { toSyslogDateString, toSyslogTimeString } from '~/util/date'
2730
import { docLinks } from '~/util/links'
@@ -39,6 +42,10 @@ const LoadingState = () => {
3942
return <div>Loading State</div>
4043
}
4144

45+
const colWidths = {
46+
gridTemplateColumns: '7rem 4.25rem 180px 140px 120px 140px 300px 300px',
47+
}
48+
4249
const HeaderCell = classed.div`text-mono-sm text-tertiary`
4350

4451
// for virtualizer
@@ -112,6 +119,12 @@ export default function SiloAuditLogsPage() {
112119
{rowVirtualizer.getVirtualItems().map((virtualRow) => {
113120
const log = allItems[virtualRow.index]
114121

122+
const [userId, siloId] = match(log.actor)
123+
.with({ kind: 'silo_user' }, (actor) => [actor.siloUserId, actor.siloId])
124+
.with({ kind: 'user_builtin' }, (actor) => [actor.userBuiltinId, undefined])
125+
.with({ kind: 'unauthenticated' }, () => [undefined, undefined])
126+
.exhaustive()
127+
115128
return (
116129
<div
117130
key={virtualRow.index}
@@ -126,10 +139,9 @@ export default function SiloAuditLogsPage() {
126139
'grid h-9 w-full items-center gap-8 px-[var(--content-gutter)] text-left text-sans-md border-secondary',
127140
virtualRow.index !== 0 && 'border-t'
128141
)}
129-
style={{
130-
gridTemplateColumns: '7rem 4.25rem 180px 120px 120px 120px 300px 300px',
131-
}}
142+
style={colWidths}
132143
>
144+
{/* TODO: might be especially useful here to get the original UTC timestamp in a tooltip */}
133145
<div className="overflow-hidden whitespace-nowrap text-mono-sm">
134146
<span className="text-tertiary">
135147
{toSyslogDateString(log.timeCompleted)}
@@ -141,19 +153,37 @@ export default function SiloAuditLogsPage() {
141153
<Badge>200</Badge>
142154
</div>
143155
<div>
144-
<Badge color="neutral" className="text-tertiary">
145-
{log.operationId.split('_').join(' ')}
146-
</Badge>
156+
<Badge color="neutral">{log.operationId.split('_').join(' ')}</Badge>
157+
</div>
158+
<div className="text-secondary">
159+
{userId ? (
160+
<Truncate
161+
maxLength={12}
162+
text={userId}
163+
position="middle"
164+
hasCopyButton
165+
/>
166+
) : (
167+
<EmptyCell />
168+
)}
147169
</div>
148-
<div className="text-secondary">hannah.arendt</div>
149170
<div>
150-
{!!log.accessMethod && (
151-
<Badge color="neutral" className="text-tertiary">
152-
{log.accessMethod.split('_').join(' ')}
153-
</Badge>
171+
<Badge color="neutral">
172+
{log.accessMethod?.split('_').join(' ') || 'Unknown'}
173+
</Badge>
174+
</div>
175+
<div className="text-secondary">
176+
{siloId ? (
177+
<Truncate
178+
maxLength={12}
179+
text={siloId}
180+
position="middle"
181+
hasCopyButton
182+
/>
183+
) : (
184+
<EmptyCell />
154185
)}
155186
</div>
156-
<div className="text-secondary">maze-war</div>
157187
<div className="text-secondary">
158188
{differenceInMilliseconds(new Date(log.timeCompleted), log.timeStarted)}
159189
ms
@@ -204,16 +234,15 @@ export default function SiloAuditLogsPage() {
204234

205235
<div
206236
className="sticky top-0 z-10 !mx-0 grid !w-full items-center gap-8 border-b px-[var(--content-gutter)] pb-2 pt-4 bg-default border-secondary"
207-
style={{
208-
gridTemplateColumns: '7rem 4.25rem 180px 120px 120px 120px 300px 300px',
209-
}}
237+
style={colWidths}
210238
>
239+
{/* TODO: explain that this is time completed, not time started as you might expect */}
211240
<HeaderCell>Time</HeaderCell>
212241
<HeaderCell>Status</HeaderCell>
213242
<HeaderCell>Operation</HeaderCell>
214-
<HeaderCell>Actor</HeaderCell>
243+
<HeaderCell>Actor ID</HeaderCell>
215244
<HeaderCell>Access Method</HeaderCell>
216-
<HeaderCell>Silo</HeaderCell>
245+
<HeaderCell>Silo ID</HeaderCell>
217246
<HeaderCell>Duration</HeaderCell>
218247
</div>
219248

0 commit comments

Comments
 (0)