-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f164f00
commit 92d4146
Showing
10 changed files
with
424 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,75 @@ | ||
import { ReactElement } from 'react' | ||
import { ReactElement, useMemo } from 'react' | ||
import { Outlet, useOutletContext, useParams } from 'react-router-dom' | ||
import { useSetBreadcrumbs } from '@pluralsh/design-system' | ||
|
||
import { KubernetesClient } from '../../../helpers/kubernetes.client' | ||
import { | ||
ClusterRoleQueryVariables, | ||
Clusterrole_ClusterRoleDetail as ClusterRoleT, | ||
useClusterRoleQuery, | ||
} from '../../../generated/graphql-kubernetes' | ||
import { MetadataSidecar, useKubernetesCluster } from '../utils' | ||
|
||
import { getResourceDetailsAbsPath } from '../../../routes/kubernetesRoutesConsts' | ||
import LoadingIndicator from '../../utils/LoadingIndicator' | ||
import ResourceDetails, { TabEntry } from '../ResourceDetails' | ||
import PolicyRules from '../common/PolicyRules' | ||
|
||
import { FullHeightTableWrap } from '../../utils/layout/FullHeightTableWrap' | ||
|
||
import { getBreadcrumbs } from './ClusterRoles' | ||
|
||
const directory: Array<TabEntry> = [ | ||
{ path: '', label: 'Policy rules' }, | ||
{ path: 'raw', label: 'Raw' }, | ||
] as const | ||
|
||
export default function ClusterRole(): ReactElement { | ||
return <div>ClusterRole details</div> | ||
const cluster = useKubernetesCluster() | ||
const { clusterId, name = '' } = useParams() | ||
const { data, loading } = useClusterRoleQuery({ | ||
client: KubernetesClient(clusterId ?? ''), | ||
skip: !clusterId, | ||
pollInterval: 30_000, | ||
variables: { | ||
name, | ||
} as ClusterRoleQueryVariables, | ||
}) | ||
|
||
const cr = data?.handleGetClusterRoleDetail | ||
|
||
useSetBreadcrumbs( | ||
useMemo( | ||
() => [ | ||
...getBreadcrumbs(cluster), | ||
|
||
{ | ||
label: name ?? '', | ||
url: getResourceDetailsAbsPath(clusterId, 'clusterrole', name), | ||
}, | ||
], | ||
[cluster, clusterId, name] | ||
) | ||
) | ||
|
||
if (loading) return <LoadingIndicator /> | ||
|
||
return ( | ||
<ResourceDetails | ||
tabs={directory} | ||
sidecar={<MetadataSidecar objectMeta={cr?.objectMeta} />} | ||
> | ||
<Outlet context={cr} /> | ||
</ResourceDetails> | ||
) | ||
} | ||
|
||
export function RolePolicyRules(): ReactElement { | ||
const cr = useOutletContext() as ClusterRoleT | ||
|
||
return ( | ||
<FullHeightTableWrap> | ||
<PolicyRules rules={cr.rules} /> | ||
</FullHeightTableWrap> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,89 @@ | ||
import { ReactElement } from 'react' | ||
import { ReactElement, useMemo } from 'react' | ||
import { Outlet, useOutletContext, useParams } from 'react-router-dom' | ||
import { useSetBreadcrumbs } from '@pluralsh/design-system' | ||
|
||
import { MetadataSidecar, useKubernetesCluster } from '../utils' | ||
import { | ||
RoleQueryVariables, | ||
Role_RoleDetail as RoleT, | ||
useRoleQuery, | ||
} from '../../../generated/graphql-kubernetes' | ||
import { KubernetesClient } from '../../../helpers/kubernetes.client' | ||
|
||
import { | ||
ROLES_REL_PATH, | ||
getAccessAbsPath, | ||
getResourceDetailsAbsPath, | ||
} from '../../../routes/kubernetesRoutesConsts' | ||
import { NAMESPACE_PARAM } from '../Kubernetes' | ||
import LoadingIndicator from '../../utils/LoadingIndicator' | ||
import ResourceDetails, { TabEntry } from '../ResourceDetails' | ||
|
||
import { SubTitle } from '../../cluster/nodes/SubTitle' | ||
|
||
import PolicyRules from '../common/PolicyRules' | ||
|
||
import { FullHeightTableWrap } from '../../utils/layout/FullHeightTableWrap' | ||
|
||
import { getBreadcrumbs } from './Roles' | ||
|
||
const directory: Array<TabEntry> = [ | ||
{ path: '', label: 'Policy rules' }, | ||
{ path: 'raw', label: 'Raw' }, | ||
] as const | ||
|
||
export default function Role(): ReactElement { | ||
return <div>Role details</div> | ||
const cluster = useKubernetesCluster() | ||
const { clusterId, name = '', namespace = '' } = useParams() | ||
const { data, loading } = useRoleQuery({ | ||
client: KubernetesClient(clusterId ?? ''), | ||
skip: !clusterId, | ||
pollInterval: 30_000, | ||
variables: { | ||
name, | ||
namespace, | ||
} as RoleQueryVariables, | ||
}) | ||
|
||
const role = data?.handleGetRoleDetail | ||
|
||
useSetBreadcrumbs( | ||
useMemo( | ||
() => [ | ||
...getBreadcrumbs(cluster), | ||
{ | ||
label: namespace ?? '', | ||
url: `${getAccessAbsPath( | ||
cluster?.id | ||
)}/${ROLES_REL_PATH}?${NAMESPACE_PARAM}=${namespace}`, | ||
}, | ||
{ | ||
label: name ?? '', | ||
url: getResourceDetailsAbsPath(clusterId, 'role', name, namespace), | ||
}, | ||
], | ||
[cluster, clusterId, name, namespace] | ||
) | ||
) | ||
|
||
if (loading) return <LoadingIndicator /> | ||
|
||
return ( | ||
<ResourceDetails | ||
tabs={directory} | ||
sidecar={<MetadataSidecar objectMeta={role?.objectMeta} />} | ||
> | ||
<Outlet context={role} /> | ||
</ResourceDetails> | ||
) | ||
} | ||
|
||
export function RolePolicyRules(): ReactElement { | ||
const role = useOutletContext() as RoleT | ||
|
||
return ( | ||
<FullHeightTableWrap> | ||
<PolicyRules rules={role.rules} /> | ||
</FullHeightTableWrap> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { ReactElement } from 'react' | ||
import { Table } from '@pluralsh/design-system' | ||
import { createColumnHelper } from '@tanstack/react-table' | ||
|
||
import { | ||
Maybe, | ||
V1_PolicyRule as PolicyRuleT, | ||
} from '../../../generated/graphql-kubernetes' | ||
|
||
const columnHelper = createColumnHelper<PolicyRuleT>() | ||
|
||
const columns = [ | ||
columnHelper.accessor((rule) => rule?.resources, { | ||
id: 'resources', | ||
header: 'Resources', | ||
cell: ({ getValue }) => | ||
getValue()?.map((resource) => <div>{resource}</div>), | ||
}), | ||
columnHelper.accessor((rule) => rule?.nonResourceURLs, { | ||
id: 'nonResourceURLs', | ||
header: 'Non-resource URL', | ||
cell: ({ getValue }) => | ||
getValue()?.map((nonResourceURL) => <div>{nonResourceURL}</div>), | ||
}), | ||
columnHelper.accessor((rule) => rule?.resourceNames, { | ||
id: 'resourceNames', | ||
header: 'Resource names', | ||
cell: ({ getValue }) => | ||
getValue()?.map((resourceName) => <div>{resourceName}</div>), | ||
}), | ||
columnHelper.accessor((rule) => rule?.verbs, { | ||
id: 'verbs', | ||
header: 'Verbs', | ||
cell: ({ getValue }) => getValue()?.map((verb) => <div>{verb}</div>), | ||
}), | ||
columnHelper.accessor((rule) => rule?.apiGroups, { | ||
id: 'apiGroups', | ||
header: 'API groups', | ||
cell: ({ getValue }) => | ||
getValue()?.map((apiGroup) => <div>{apiGroup}</div>), | ||
}), | ||
] | ||
|
||
export default function PolicyRules({ | ||
rules, | ||
}: { | ||
rules: Array<Maybe<PolicyRuleT>> | ||
}): ReactElement { | ||
return ( | ||
<Table | ||
data={rules} | ||
columns={columns} | ||
css={{ | ||
maxHeight: 'unset', | ||
height: '100%', | ||
}} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.