Skip to content

Commit

Permalink
finish secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Mar 26, 2024
1 parent e656039 commit 677e86b
Showing 1 changed file with 78 additions and 6 deletions.
84 changes: 78 additions & 6 deletions assets/src/components/kubernetes/configuration/Secret.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { ReactElement, useMemo } from 'react'
import { Card, Prop, useSetBreadcrumbs } from '@pluralsh/design-system'
import { ReactElement, useMemo, useState } from 'react'
import {
Card,
EyeClosedIcon,
EyeIcon,
IconFrame,
Prop,
Table,
useSetBreadcrumbs,
} from '@pluralsh/design-system'
import { useParams } from 'react-router-dom'
import { useTheme } from 'styled-components'

import { createColumnHelper } from '@tanstack/react-table'

import {
SecretQueryVariables,
useSecretQuery,
Expand All @@ -21,6 +31,53 @@ import {

import { getBreadcrumbs } from './Secrets'

type SecretDataEntry = {
key: string
value: any
}

function SecretDataValue({ value }: { value: any }) {
const theme = useTheme()
const [reveal, setReveal] = useState(false)

return (
<div
css={{
display: 'flex',
alignItems: 'center',
gap: theme.spacing.xxsmall,
}}
>
<IconFrame
size="medium"
clickable
tooltip={reveal ? 'Hide value' : 'Reveal value'}
icon={reveal ? <EyeIcon /> : <EyeClosedIcon />}
onClick={() => setReveal(() => !reveal)}
/>
<div css={{ wordBreak: 'break-word' }}>
{reveal ? atob(value) : value}
</div>
</div>
)
}

const columnHelper = createColumnHelper<SecretDataEntry>()

const columns = [
columnHelper.accessor((row) => row.key, {
id: 'key',
header: 'Key',
meta: { gridTemplate: `fit-content(200px)` },
cell: ({ getValue }) => getValue(),
}),
columnHelper.accessor((row) => row.value, {
id: 'value',
header: 'Value',
cell: ({ getValue }) => <SecretDataValue value={getValue()} />,
}),
]

export default function Secret(): ReactElement {
const theme = useTheme()
const cluster = useKubernetesCluster()
Expand Down Expand Up @@ -56,6 +113,15 @@ export default function Secret(): ReactElement {
)
)

const secretData: SecretDataEntry[] = useMemo(
() =>
Object.entries(secret?.data ?? {}).map(([key, value]) => ({
key,
value,
})),
[secret?.data]
)

if (loading) return <LoadingIndicator />

return (
Expand Down Expand Up @@ -84,15 +150,21 @@ export default function Secret(): ReactElement {
</section>
<section>
<SubTitle>Data</SubTitle>
{/* TODO: Reveal all button. */}
<Card
css={{
display: 'flex',
flexDirection: 'row',
flexDirection: 'column',
}}
>
{Object.entries(secret?.data)?.map(([key, value]) => (
<Prop title={key}>{value}</Prop>
))}
<Table
data={secretData || []}
columns={columns}
css={{
maxHeight: 'unset',
height: '100%',
}}
/>
</Card>
</section>
</div>
Expand Down

0 comments on commit 677e86b

Please sign in to comment.