| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import dayjs from 'dayjs'
- import { Input, SidePanel, TextArea } from 'ui'
- import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
- import {
- FormSection,
- FormSectionContent,
- FormSectionLabel,
- } from '@/components/ui/Forms/FormSection'
- import {
- TIMESTAMP_MICROS_PER_MS,
- type AuditLog,
- } from '@/data/organizations/organization-audit-logs-query'
- interface LogDetailsPanelProps {
- selectedLog?: AuditLog
- onClose: () => void
- }
- export const LogDetailsPanel = ({ selectedLog, onClose }: LogDetailsPanelProps) => {
- const timestamp = selectedLog
- ? dayjs(selectedLog.timestamp / TIMESTAMP_MICROS_PER_MS).format('DD MMM YYYY, HH:mm:ss')
- : ''
- const timestampWithTz = selectedLog
- ? dayjs(selectedLog.timestamp / TIMESTAMP_MICROS_PER_MS).format('DD MMM YYYY, HH:mm:ss (ZZ)')
- : ''
- return (
- <SidePanel
- size="large"
- header={selectedLog ? `"${selectedLog.action.name}" on ${timestamp}` : ''}
- visible={selectedLog !== undefined}
- onCancel={onClose}
- cancelText="Close"
- >
- <FormSection header={<FormSectionLabel>General</FormSectionLabel>}>
- <FormSectionContent loading={false}>
- <FormItemLayout label="Occurred at" description={timestampWithTz} isReactForm={false}>
- <Input
- readOnly
- size="small"
- value={
- selectedLog
- ? dayjs(selectedLog.timestamp / TIMESTAMP_MICROS_PER_MS).toISOString()
- : ''
- }
- />
- </FormItemLayout>
- <FormItemLayout label="Request ID" isReactForm={false}>
- <Input readOnly size="small" value={selectedLog?.request_id ?? ''} />
- </FormItemLayout>
- {selectedLog?.organization_slug && (
- <FormItemLayout label="Organization" isReactForm={false}>
- <Input readOnly size="small" value={selectedLog.organization_slug} />
- </FormItemLayout>
- )}
- {selectedLog?.project_ref && (
- <FormItemLayout label="Project ref" isReactForm={false}>
- <Input readOnly size="small" value={selectedLog.project_ref} />
- </FormItemLayout>
- )}
- </FormSectionContent>
- </FormSection>
- <SidePanel.Separator />
- <FormSection header={<FormSectionLabel>Actor</FormSectionLabel>}>
- <FormSectionContent loading={false}>
- <FormItemLayout label="Token type" isReactForm={false}>
- <Input readOnly size="small" value={selectedLog?.actor.token_type ?? ''} />
- </FormItemLayout>
- {selectedLog?.actor.email && (
- <FormItemLayout label="Email" isReactForm={false}>
- <Input readOnly size="small" value={selectedLog?.actor.email ?? ''} />
- </FormItemLayout>
- )}
- {selectedLog?.actor.user_id && (
- <FormItemLayout label="User ID" isReactForm={false}>
- <Input readOnly size="small" value={selectedLog?.actor.user_id ?? ''} />
- </FormItemLayout>
- )}
- {selectedLog?.actor.ip && (
- <FormItemLayout label="IP address" isReactForm={false}>
- <Input readOnly size="small" value={selectedLog?.actor.ip ?? ''} />
- </FormItemLayout>
- )}
- {selectedLog?.actor.oauth_app_name && (
- <FormItemLayout label="OAuth app" isReactForm={false}>
- <Input readOnly size="small" value={selectedLog?.actor.oauth_app_name ?? ''} />
- </FormItemLayout>
- )}
- {selectedLog?.actor.app_name && (
- <FormItemLayout label="App" isReactForm={false}>
- <Input readOnly size="small" value={selectedLog?.actor.app_name ?? ''} />
- </FormItemLayout>
- )}
- </FormSectionContent>
- </FormSection>
- <SidePanel.Separator />
- <FormSection header={<FormSectionLabel>Action</FormSectionLabel>}>
- <FormSectionContent loading={false}>
- <FormItemLayout label="Name" isReactForm={false}>
- <Input readOnly size="small" value={selectedLog?.action.name ?? ''} />
- </FormItemLayout>
- <FormItemLayout label="Method" isReactForm={false}>
- <Input readOnly size="small" value={selectedLog?.action.method ?? ''} />
- </FormItemLayout>
- <FormItemLayout label="Route" isReactForm={false}>
- <Input readOnly size="small" value={selectedLog?.action.route ?? ''} />
- </FormItemLayout>
- <FormItemLayout label="Status" isReactForm={false}>
- <Input readOnly size="small" value={String(selectedLog?.action.status ?? '')} />
- </FormItemLayout>
- {selectedLog?.action.metadata && (
- <FormItemLayout label="Metadata" isReactForm={false}>
- <TextArea
- readOnly
- rows={5}
- className="font-mono input-xs"
- value={JSON.stringify(selectedLog.action.metadata, null, 2)}
- />
- </FormItemLayout>
- )}
- </FormSectionContent>
- </FormSection>
- </SidePanel>
- )
- }
|