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: allow copy as JSON and fix query formatting #3434

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion web/src/app/admin/admin-api-keys/AdminAPIKeyDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ export default function AdminAPIKeyDrawer(props: Props): JSX.Element {
<ListItemText
primary='Query'
secondary={
<Button variant='text' onClick={() => setShowQuery(true)}>
<Button
variant='outlined'
onClick={() => setShowQuery(true)}
sx={{ mt: 0.5 }}
>
Show Query
</Button>
}
Expand Down
42 changes: 32 additions & 10 deletions web/src/app/admin/admin-api-keys/AdminAPIKeyShowQueryDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { gql, useQuery } from 'urql'
import { GenericError } from '../../error-pages'
import Spinner from '../../loading/components/Spinner'
import { GQLAPIKey } from '../../../schema'
import { Grid, Typography } from '@mui/material'
import { Grid, useTheme } from '@mui/material'
import CopyText from '../../util/CopyText'

// query for getting existing API Keys
Expand All @@ -22,6 +22,7 @@ export default function AdminAPIKeyShowQueryDialog(props: {
apiKeyID: string
onClose: (yes: boolean) => void
}): JSX.Element {
const theme = useTheme()
const [{ fetching, data, error }] = useQuery({
query,
})
Expand All @@ -44,16 +45,37 @@ export default function AdminAPIKeyShowQueryDialog(props: {
}
loading={fetching}
form={
<Grid item xs={12}>
<Typography sx={{ mb: 3 }}>
<code>
<CopyText
title={key.query}
value={key.query}
placement='bottom'
/>
<Grid container spacing={2}>
<Grid item xs={12}>
<code
style={{
fontSize: 'large',
color: theme.palette.getContrastText(
theme.palette.secondary.main,
),
}}
>
<pre
style={{
backgroundColor: theme.palette.secondary.main,
padding: 12,
borderRadius: 6,
}}
>
{key.query}
</pre>
</code>
</Typography>
</Grid>
<Grid item xs={12}>
<CopyText title='Copy Query' value={key.query} placement='bottom' />
</Grid>
<Grid item xs={12}>
<CopyText
title='Copy Query (as JSON)'
value={JSON.stringify(key.query)}
placement='bottom'
/>
</Grid>
</Grid>
}
onClose={onClose}
Expand Down
6 changes: 3 additions & 3 deletions web/src/app/util/CopyText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import makeStyles from '@mui/styles/makeStyles'
import copyToClipboard from './copyToClipboard'
import ContentCopy from 'mdi-material-ui/ContentCopy'
import AppLink from './AppLink'
import Tooltip, { TooltipProps } from '@mui/material/Tooltip'
import { Typography, Tooltip, TooltipProps } from '@mui/material'

const useStyles = makeStyles({
copyContainer: {
Expand Down Expand Up @@ -52,7 +52,7 @@ export default function CopyText(props: CopyTextProps): JSX.Element {
)
} else {
content = (
<span
<Typography
className={classes.copyContainer}
role='button'
tabIndex={0}
Expand All @@ -75,7 +75,7 @@ export default function CopyText(props: CopyTextProps): JSX.Element {
fontSize='small'
/>
{props.title}
</span>
</Typography>
)
}

Expand Down