|
| 1 | +import { PermissionAPIResponse } from "@flanksource-ui/api/types/permissions"; |
| 2 | +import { Avatar } from "@flanksource-ui/ui/Avatar"; |
| 3 | +import { Badge } from "@flanksource-ui/ui/Badge/Badge"; |
| 4 | +import { MRTDateCell } from "@flanksource-ui/ui/MRTDataTable/Cells/MRTDateCells"; |
| 5 | +import MRTDataTable from "@flanksource-ui/ui/MRTDataTable/MRTDataTable"; |
| 6 | +import { MRT_ColumnDef } from "mantine-react-table"; |
| 7 | +import CanaryLink from "../Canary/CanaryLink"; |
| 8 | +import { CheckLink } from "../Canary/HealthChecks/CheckLink"; |
| 9 | +import ConfigLink from "../Configs/ConfigLink/ConfigLink"; |
| 10 | +import PlaybookSpecIcon from "../Playbooks/Settings/PlaybookSpecIcon"; |
| 11 | +import { TopologyLink } from "../Topology/TopologyLink"; |
| 12 | + |
| 13 | +const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [ |
| 14 | + { |
| 15 | + id: "Resource", |
| 16 | + header: "Resource", |
| 17 | + Cell: ({ row }) => { |
| 18 | + const config = row.original.catalog; |
| 19 | + const check = row.original.checks; |
| 20 | + const playbook = row.original.playbook; |
| 21 | + const canary = row.original.canary; |
| 22 | + const component = row.original.component; |
| 23 | + |
| 24 | + return ( |
| 25 | + <div className="flex flex-col"> |
| 26 | + {config && <ConfigLink config={config} />} |
| 27 | + {check && <CheckLink check={check} />} |
| 28 | + {playbook && <PlaybookSpecIcon playbook={playbook} showLabel />} |
| 29 | + {canary && <CanaryLink canary={canary} />} |
| 30 | + {component && <TopologyLink topology={component} />} |
| 31 | + </div> |
| 32 | + ); |
| 33 | + } |
| 34 | + }, |
| 35 | + { |
| 36 | + id: "action", |
| 37 | + header: "Action", |
| 38 | + Cell: ({ row }) => { |
| 39 | + const action = row.original.action; |
| 40 | + const deny = row.original.deny; |
| 41 | + |
| 42 | + return ( |
| 43 | + <div> |
| 44 | + <span>{action}</span> |
| 45 | + {deny && <Badge text="deny" />} |
| 46 | + </div> |
| 47 | + ); |
| 48 | + } |
| 49 | + }, |
| 50 | + { |
| 51 | + id: "updated", |
| 52 | + header: "Updated", |
| 53 | + accessorFn: (row) => row.updated_at, |
| 54 | + Cell: MRTDateCell |
| 55 | + }, |
| 56 | + { |
| 57 | + id: "created", |
| 58 | + header: "Created", |
| 59 | + accessorFn: (row) => row.created_at |
| 60 | + }, |
| 61 | + { |
| 62 | + id: "createdBy", |
| 63 | + header: "Created By", |
| 64 | + Cell: ({ row }) => { |
| 65 | + const createdBy = row.original.createdBy; |
| 66 | + return <Avatar user={createdBy} />; |
| 67 | + } |
| 68 | + } |
| 69 | +]; |
| 70 | + |
| 71 | +type PermissionsTableProps = { |
| 72 | + permissions: PermissionAPIResponse[]; |
| 73 | + isLoading: boolean; |
| 74 | + pageCount: number; |
| 75 | + totalEntries: number; |
| 76 | +}; |
| 77 | + |
| 78 | +export default function PermissionsTable({ |
| 79 | + permissions, |
| 80 | + isLoading, |
| 81 | + pageCount, |
| 82 | + totalEntries |
| 83 | +}: PermissionsTableProps) { |
| 84 | + return ( |
| 85 | + <MRTDataTable<PermissionAPIResponse> |
| 86 | + columns={permissionsTableColumns} |
| 87 | + data={permissions} |
| 88 | + isLoading={isLoading} |
| 89 | + manualPageCount={pageCount} |
| 90 | + totalRowCount={totalEntries} |
| 91 | + enableServerSidePagination |
| 92 | + /> |
| 93 | + ); |
| 94 | +} |
0 commit comments