|
| 1 | +import useConfigAccessSummaryQuery from "@flanksource-ui/api/query-hooks/useConfigAccessSummaryQuery"; |
| 2 | +import { ConfigAccessSummary } from "@flanksource-ui/api/types/configs"; |
| 3 | +import { ConfigDetailsTabs } from "@flanksource-ui/components/Configs/ConfigDetailsTabs"; |
| 4 | +import { Age } from "@flanksource-ui/ui/Age"; |
| 5 | +import { Badge } from "@flanksource-ui/ui/Badge/Badge"; |
| 6 | +import { MRTCellProps } from "@flanksource-ui/ui/MRTDataTable/MRTCellProps"; |
| 7 | +import MRTDataTable from "@flanksource-ui/ui/MRTDataTable/MRTDataTable"; |
| 8 | +import { MRT_ColumnDef } from "mantine-react-table"; |
| 9 | +import { useMemo } from "react"; |
| 10 | +import { useParams } from "react-router-dom"; |
| 11 | + |
| 12 | +const RoleCell = ({ cell }: MRTCellProps<ConfigAccessSummary>) => { |
| 13 | + const value = cell.getValue<string | null>(); |
| 14 | + return value ? ( |
| 15 | + <span>{value}</span> |
| 16 | + ) : ( |
| 17 | + <span className="text-gray-400">—</span> |
| 18 | + ); |
| 19 | +}; |
| 20 | + |
| 21 | +const LastSignedInCell = ({ cell }: MRTCellProps<ConfigAccessSummary>) => { |
| 22 | + const value = cell.getValue<string | null>(); |
| 23 | + if (!value) { |
| 24 | + return <span className="text-gray-400">Never</span>; |
| 25 | + } |
| 26 | + return <Age from={value} />; |
| 27 | +}; |
| 28 | + |
| 29 | +const OptionalDateCell = ({ cell }: MRTCellProps<ConfigAccessSummary>) => { |
| 30 | + const value = cell.getValue<string | null>(); |
| 31 | + if (!value) { |
| 32 | + return <span className="text-gray-400">—</span>; |
| 33 | + } |
| 34 | + return <Age from={value} />; |
| 35 | +}; |
| 36 | + |
| 37 | +const AccessTypeCell = ({ row }: MRTCellProps<ConfigAccessSummary>) => { |
| 38 | + const groupId = row.original.external_group_id; |
| 39 | + if (groupId) { |
| 40 | + return <Badge text="Group" color="yellow" title={`Group ID: ${groupId}`} />; |
| 41 | + } |
| 42 | + |
| 43 | + return <Badge text="Direct" color="gray" />; |
| 44 | +}; |
| 45 | + |
| 46 | +export function ConfigDetailsAccessPage() { |
| 47 | + const { id } = useParams(); |
| 48 | + const { |
| 49 | + data: accessSummary, |
| 50 | + isLoading, |
| 51 | + refetch |
| 52 | + } = useConfigAccessSummaryQuery(id); |
| 53 | + |
| 54 | + const columns = useMemo<MRT_ColumnDef<ConfigAccessSummary>[]>( |
| 55 | + () => [ |
| 56 | + { |
| 57 | + header: "User", |
| 58 | + accessorKey: "user", |
| 59 | + size: 160 |
| 60 | + }, |
| 61 | + { |
| 62 | + header: "Email", |
| 63 | + accessorKey: "email", |
| 64 | + size: 220 |
| 65 | + }, |
| 66 | + { |
| 67 | + header: "Role", |
| 68 | + accessorKey: "role", |
| 69 | + Cell: RoleCell, |
| 70 | + size: 120 |
| 71 | + }, |
| 72 | + { |
| 73 | + header: "Access", |
| 74 | + accessorKey: "external_group_id", |
| 75 | + Cell: AccessTypeCell, |
| 76 | + size: 120 |
| 77 | + }, |
| 78 | + { |
| 79 | + header: "Last Signed In", |
| 80 | + accessorKey: "last_signed_in_at", |
| 81 | + Cell: LastSignedInCell, |
| 82 | + sortingFn: "datetime", |
| 83 | + size: 160 |
| 84 | + }, |
| 85 | + { |
| 86 | + header: "Last Reviewed", |
| 87 | + accessorKey: "last_reviewed_at", |
| 88 | + Cell: OptionalDateCell, |
| 89 | + sortingFn: "datetime", |
| 90 | + size: 160 |
| 91 | + }, |
| 92 | + { |
| 93 | + header: "Granted", |
| 94 | + accessorKey: "created_at", |
| 95 | + Cell: OptionalDateCell, |
| 96 | + sortingFn: "datetime", |
| 97 | + size: 140 |
| 98 | + } |
| 99 | + ], |
| 100 | + [] |
| 101 | + ); |
| 102 | + |
| 103 | + const rows = accessSummary?.data ?? []; |
| 104 | + |
| 105 | + return ( |
| 106 | + <ConfigDetailsTabs |
| 107 | + pageTitlePrefix={"Catalog Access"} |
| 108 | + isLoading={isLoading} |
| 109 | + refetch={refetch} |
| 110 | + activeTabName="Access" |
| 111 | + > |
| 112 | + <div className="flex h-full flex-1 flex-col gap-2 overflow-y-auto"> |
| 113 | + <div className="flex flex-1 flex-col overflow-y-auto"> |
| 114 | + <MRTDataTable |
| 115 | + columns={columns} |
| 116 | + data={rows} |
| 117 | + isLoading={isLoading} |
| 118 | + disablePagination |
| 119 | + defaultSorting={[{ id: "user", desc: false }]} |
| 120 | + /> |
| 121 | + </div> |
| 122 | + </div> |
| 123 | + </ConfigDetailsTabs> |
| 124 | + ); |
| 125 | +} |
0 commit comments