-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): users table in settings (#4221)
- Loading branch information
1 parent
e535e75
commit 803399f
Showing
3 changed files
with
256 additions
and
4 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,132 @@ | ||
import React, { useMemo } from "react"; | ||
import { graphql, useLazyLoadQuery } from "react-relay"; | ||
import { | ||
flexRender, | ||
getCoreRowModel, | ||
useReactTable, | ||
} from "@tanstack/react-table"; | ||
|
||
import { Icon, Icons } from "@arizeai/components"; | ||
|
||
import { tableCSS } from "@phoenix/components/table/styles"; | ||
import { TableEmpty } from "@phoenix/components/table/TableEmpty"; | ||
import { TimestampCell } from "@phoenix/components/table/TimestampCell"; | ||
|
||
import { UsersTableQuery } from "./__generated__/UsersTableQuery.graphql"; | ||
|
||
export function UsersTable() { | ||
const data = useLazyLoadQuery<UsersTableQuery>( | ||
graphql` | ||
query UsersTableQuery { | ||
users { | ||
edges { | ||
user: node { | ||
username | ||
createdAt | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
{} | ||
); | ||
|
||
const tableData = useMemo(() => { | ||
return data.users.edges.map(({ user }) => ({ | ||
email: user.email, | ||
username: user.username, | ||
createdAt: user.createdAt, | ||
})); | ||
}, [data]); | ||
|
||
type TableRow = (typeof tableData)[number]; | ||
const table = useReactTable<TableRow>({ | ||
columns: [ | ||
{ | ||
header: "email", | ||
accessorKey: "email", | ||
}, | ||
{ | ||
header: "username", | ||
accessorKey: "username", | ||
}, | ||
{ | ||
header: "created at", | ||
accessorKey: "createdAt", | ||
cell: TimestampCell, | ||
}, | ||
], | ||
data: tableData, | ||
getCoreRowModel: getCoreRowModel(), | ||
}); | ||
const rows = table.getRowModel().rows; | ||
const isEmpty = table.getRowModel().rows.length === 0; | ||
return ( | ||
<table css={tableCSS}> | ||
<thead> | ||
{table.getHeaderGroups().map((headerGroup) => ( | ||
<tr key={headerGroup.id}> | ||
{headerGroup.headers.map((header) => ( | ||
<th colSpan={header.colSpan} key={header.id}> | ||
{header.isPlaceholder ? null : ( | ||
<div | ||
{...{ | ||
className: header.column.getCanSort() | ||
? "cursor-pointer" | ||
: "", | ||
onClick: header.column.getToggleSortingHandler(), | ||
style: { | ||
left: header.getStart(), | ||
width: header.getSize(), | ||
}, | ||
}} | ||
> | ||
{flexRender( | ||
header.column.columnDef.header, | ||
header.getContext() | ||
)} | ||
{header.column.getIsSorted() ? ( | ||
<Icon | ||
className="sort-icon" | ||
svg={ | ||
header.column.getIsSorted() === "asc" ? ( | ||
<Icons.ArrowUpFilled /> | ||
) : ( | ||
<Icons.ArrowDownFilled /> | ||
) | ||
} | ||
/> | ||
) : null} | ||
</div> | ||
)} | ||
</th> | ||
))} | ||
</tr> | ||
))} | ||
</thead> | ||
{isEmpty ? ( | ||
<TableEmpty /> | ||
) : ( | ||
<tbody> | ||
{rows.map((row) => { | ||
return ( | ||
<tr key={row.id}> | ||
{row.getVisibleCells().map((cell) => { | ||
return ( | ||
<td key={cell.id}> | ||
{flexRender( | ||
cell.column.columnDef.cell, | ||
cell.getContext() | ||
)} | ||
</td> | ||
); | ||
})} | ||
</tr> | ||
); | ||
})} | ||
</tbody> | ||
)} | ||
</table> | ||
); | ||
} |
116 changes: 116 additions & 0 deletions
116
app/src/pages/settings/__generated__/UsersTableQuery.graphql.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.