Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apikey: Fix timestamp displays #3415

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion web/src/app/admin/AdminAPIKeys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export default function AdminAPIKeys(): JSX.Element {
<Time
prefix={hasExpired ? 'Expired ' : 'Expires '}
time={key.expiresAt}
format='relative'
/>
</Typography>
<Typography variant='subtitle2' component='div' color='textSecondary'>
Expand All @@ -145,7 +146,12 @@ export default function AdminAPIKeys(): JSX.Element {
component='div'
color='textSecondary'
>
<Time prefix='Last Used: ' time={key.expiresAt} />
Last Used:&nbsp;
{key.lastUsed ? (
<Time format='relative' time={key.lastUsed.time} />
) : (
`Never`
)}
</Typography>
</Grid>
<Grid
Expand Down
72 changes: 45 additions & 27 deletions web/src/app/admin/admin-api-keys/AdminAPIKeyDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ const useStyles = makeStyles(() => ({
},
}))

function ActionBy(props: {
label: string
time?: string
name?: string
}): React.ReactNode {
let record: React.ReactNode = 'Never'
if (props.time && props.name) {
record = (
<React.Fragment>
<Time format='relative' time={props.time} /> by {props.name}
</React.Fragment>
)
} else if (props.time) {
record = <Time format='relative' time={props.time} />
}

return (
<ListItem divider>
<ListItemText primary={props.label} secondary={record} />
</ListItem>
)
}

export default function AdminAPIKeyDrawer(props: Props): JSX.Element {
const { onClose, apiKeyID } = props
const classes = useStyles()
Expand All @@ -81,6 +104,8 @@ export default function AdminAPIKeyDrawer(props: Props): JSX.Element {
return d.id === apiKeyID
}) || ({} as GQLAPIKey)

const lastUsed = apiKey?.lastUsed || null

if (error) {
return <GenericError error={error.message} />
}
Expand Down Expand Up @@ -137,6 +162,9 @@ export default function AdminAPIKeyDrawer(props: Props): JSX.Element {
secondary={apiKey?.description}
/>
</ListItem>
<ListItem divider>
<ListItemText primary='Role' secondary={apiKey?.role} />
</ListItem>
<ListItem divider>
<ListItemText
primary='Query'
Expand All @@ -147,33 +175,23 @@ export default function AdminAPIKeyDrawer(props: Props): JSX.Element {
}
/>
</ListItem>
<ListItem divider>
<ListItemText
primary='Creation Time'
secondary={<Time prefix='' time={apiKey?.createdAt} />}
/>
</ListItem>
<ListItem divider>
<ListItemText
primary='Created By'
secondary={apiKey?.createdBy?.name}
/>
</ListItem>
<ListItem divider>
<ListItemText
primary='Expires At'
secondary={<Time prefix='' time={apiKey?.expiresAt} />}
/>
</ListItem>
<ListItem divider>
<ListItemText
primary='Updated By'
secondary={apiKey?.updatedBy?.name}
/>
</ListItem>
<ListItem divider>
<ListItemText primary='Role' secondary={apiKey?.role} />
</ListItem>
<ActionBy
label='Created'
time={apiKey?.createdAt}
name={apiKey?.createdBy?.name}
/>
<ActionBy
label='Updated'
time={apiKey?.updatedAt}
name={apiKey?.updatedBy?.name}
/>
<ActionBy label='Expires' time={apiKey?.expiresAt} />

<ActionBy
label='Last Used'
time={lastUsed?.time}
name={lastUsed ? lastUsed.ua + ' from ' + lastUsed.ip : ''}
/>
</List>
<Grid className={classes.buttons}>
<ButtonGroup variant='contained'>
Expand Down