-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
156 additions
and
42 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
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,120 @@ | ||
import { | ||
type ColumnDef, | ||
getCoreRowModel, | ||
useReactTable, | ||
type Cell, | ||
} from "@tanstack/react-table"; | ||
import { type RouterOutputs } from "@tableland/studio-api"; | ||
import { useEffect, useState } from "react"; | ||
import { Check } from "lucide-react"; | ||
import Link from "next/link"; | ||
import { DataTable } from "./data-table"; | ||
import HashDisplay from "./hash-display"; | ||
import { type ACLItem } from "@/lib/validator-queries"; | ||
|
||
type TableRowData = ACLItem & { | ||
isOwner: boolean; | ||
} & RouterOutputs["users"]["usersForAddresses"][string]; | ||
|
||
interface Props { | ||
acl: ACLItem[]; | ||
authorizedStudioUsers: RouterOutputs["users"]["usersForAddresses"]; | ||
owner: string; | ||
} | ||
|
||
export default function ACL({ acl, authorizedStudioUsers, owner }: Props) { | ||
const data: TableRowData[] = acl.map((item) => { | ||
const studioUser = authorizedStudioUsers[item.controller]; | ||
const isOwner = item.controller === owner; | ||
return { | ||
...item, | ||
...studioUser, | ||
isOwner, | ||
}; | ||
}); | ||
|
||
const columns: Array<ColumnDef<TableRowData>> = [ | ||
{ | ||
accessorKey: "controller", | ||
header: "Address", | ||
cell: AddressCell, | ||
}, | ||
{ | ||
accessorKey: "team.name", | ||
header: "Studio User", | ||
cell: UserCell, | ||
}, | ||
{ | ||
accessorKey: "isOwner", | ||
header: "Table Owner", | ||
cell: BoolCell, | ||
}, | ||
{ | ||
accessorKey: "privileges.insert", | ||
header: "Insert", | ||
cell: BoolCell, | ||
}, | ||
{ | ||
accessorKey: "privileges.update", | ||
header: "Update", | ||
cell: BoolCell, | ||
}, | ||
{ | ||
accessorKey: "privileges.delete", | ||
header: "Delete", | ||
cell: BoolCell, | ||
}, | ||
]; | ||
|
||
const table = useReactTable({ | ||
data, | ||
columns, | ||
getCoreRowModel: getCoreRowModel(), | ||
}); | ||
return <DataTable table={table} />; | ||
} | ||
|
||
function AddressCell({ | ||
getValue, | ||
}: ReturnType<Cell<TableRowData, unknown>["getContext"]>) { | ||
const initialValue = getValue<string>(); | ||
|
||
const [value, setValue] = useState(initialValue); | ||
|
||
useEffect(() => { | ||
setValue(initialValue); | ||
}, [initialValue]); | ||
|
||
return ( | ||
<HashDisplay hash={value} copy className="justify-start text-foreground" /> | ||
); | ||
} | ||
|
||
function BoolCell({ | ||
getValue, | ||
}: ReturnType<Cell<TableRowData, unknown>["getContext"]>) { | ||
const initialValue = getValue<boolean>(); | ||
|
||
const [value, setValue] = useState(initialValue); | ||
|
||
useEffect(() => { | ||
setValue(initialValue); | ||
}, [initialValue]); | ||
|
||
return value ? <Check /> : null; | ||
} | ||
|
||
function UserCell({ | ||
getValue, | ||
row, | ||
}: ReturnType<Cell<TableRowData, unknown>["getContext"]>) { | ||
const initialValue = getValue<string>(); | ||
|
||
const [value, setValue] = useState(initialValue); | ||
|
||
useEffect(() => { | ||
setValue(initialValue); | ||
}, [initialValue]); | ||
|
||
return <Link href={`/${row.original.team.slug}`}>{value}</Link>; | ||
} |
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
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