-
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
92d4146
commit 019abc1
Showing
7 changed files
with
273 additions
and
7 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
107 changes: 105 additions & 2 deletions
107
assets/src/components/kubernetes/access/RoleBinding.tsx
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,108 @@ | ||
import { ReactElement } from 'react' | ||
import { ReactElement, useMemo } from 'react' | ||
import { Link, Outlet, useOutletContext, useParams } from 'react-router-dom' | ||
import { SidecarItem, useSetBreadcrumbs } from '@pluralsh/design-system' | ||
import { A } from 'honorable' | ||
|
||
import { | ||
RoleBindingQueryVariables, | ||
Rolebinding_RoleBindingDetail as RoleBindingT, | ||
useRoleBindingQuery, | ||
} from '../../../generated/graphql-kubernetes' | ||
import { KubernetesClient } from '../../../helpers/kubernetes.client' | ||
import { MetadataSidecar, useKubernetesCluster } from '../utils' | ||
import ResourceDetails, { TabEntry } from '../ResourceDetails' | ||
import { | ||
ROLES_REL_PATH, | ||
getAccessAbsPath, | ||
getResourceDetailsAbsPath, | ||
} from '../../../routes/kubernetesRoutesConsts' | ||
import { NAMESPACE_PARAM } from '../Kubernetes' | ||
import LoadingIndicator from '../../utils/LoadingIndicator' | ||
import { FullHeightTableWrap } from '../../utils/layout/FullHeightTableWrap' | ||
import Subjects from '../common/Subjects' | ||
|
||
import { getBreadcrumbs } from './Roles' | ||
|
||
const directory: Array<TabEntry> = [ | ||
{ path: '', label: 'Subjects' }, | ||
{ path: 'raw', label: 'Raw' }, | ||
] as const | ||
|
||
export default function RoleBinding(): ReactElement { | ||
return <div>RoleBinding details</div> | ||
const cluster = useKubernetesCluster() | ||
const { clusterId, name = '', namespace = '' } = useParams() | ||
const { data, loading } = useRoleBindingQuery({ | ||
client: KubernetesClient(clusterId ?? ''), | ||
skip: !clusterId, | ||
pollInterval: 30_000, | ||
variables: { | ||
name, | ||
namespace, | ||
} as RoleBindingQueryVariables, | ||
}) | ||
|
||
const rb = data?.handleGetRoleBindingDetail | ||
|
||
useSetBreadcrumbs( | ||
useMemo( | ||
() => [ | ||
...getBreadcrumbs(cluster), | ||
{ | ||
label: namespace ?? '', | ||
url: `${getAccessAbsPath( | ||
cluster?.id | ||
)}/${ROLES_REL_PATH}?${NAMESPACE_PARAM}=${namespace}`, | ||
}, | ||
{ | ||
label: name ?? '', | ||
url: getResourceDetailsAbsPath( | ||
clusterId, | ||
'rolebinding', | ||
name, | ||
namespace | ||
), | ||
}, | ||
], | ||
[cluster, clusterId, name, namespace] | ||
) | ||
) | ||
|
||
if (loading) return <LoadingIndicator /> | ||
|
||
return ( | ||
<ResourceDetails | ||
tabs={directory} | ||
sidecar={ | ||
<MetadataSidecar objectMeta={rb?.objectMeta}> | ||
<SidecarItem heading="Role"> | ||
<A | ||
as={Link} | ||
to={getResourceDetailsAbsPath( | ||
clusterId, | ||
'role', | ||
rb?.roleRef.name ?? '', | ||
namespace | ||
)} | ||
inline | ||
> | ||
{rb?.roleRef.name} | ||
</A> | ||
</SidecarItem> | ||
</MetadataSidecar> | ||
} | ||
> | ||
<Outlet context={rb} /> | ||
</ResourceDetails> | ||
) | ||
} | ||
|
||
// TODO: Add links. | ||
export function RoleBindingSubjects(): ReactElement { | ||
const rb = useOutletContext() as RoleBindingT | ||
|
||
return ( | ||
<FullHeightTableWrap> | ||
<Subjects subjects={rb?.subjects} /> | ||
</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,50 @@ | ||
import { ReactElement } from 'react' | ||
import { Table } from '@pluralsh/design-system' | ||
import { createColumnHelper } from '@tanstack/react-table' | ||
|
||
import { | ||
Maybe, | ||
V1_Subject as SubjectT, | ||
} from '../../../generated/graphql-kubernetes' | ||
|
||
const columnHelper = createColumnHelper<SubjectT>() | ||
|
||
const columns = [ | ||
columnHelper.accessor((subject) => subject?.name, { | ||
id: 'name', | ||
header: 'Name', | ||
cell: ({ getValue }) => getValue(), | ||
}), | ||
columnHelper.accessor((subject) => subject?.namespace, { | ||
id: 'namespace', | ||
header: 'Namespace', | ||
cell: ({ getValue }) => getValue(), | ||
}), | ||
columnHelper.accessor((subject) => subject?.kind, { | ||
id: 'kind', | ||
header: 'Kind', | ||
cell: ({ getValue }) => getValue(), | ||
}), | ||
columnHelper.accessor((subject) => subject?.apiGroup, { | ||
id: 'apiGroup', | ||
header: 'API group', | ||
cell: ({ getValue }) => getValue(), | ||
}), | ||
] | ||
|
||
export default function Subjects({ | ||
subjects, | ||
}: { | ||
subjects?: Maybe<Array<Maybe<SubjectT>>> | ||
}): ReactElement { | ||
return ( | ||
<Table | ||
data={subjects || []} | ||
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
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