Files
Joshen Lim c9a25cf11f Joshenlim/fe 5172 deprecate old table component (#53728)
## Context

More housekeeping - deprecates the old Table component in favor of the
Table component under `ui`

JFYI also realised as part of this that the following 2 routes are
unreachable from the dashboard and hence am opting to deprecate them
with a redirect
- /logs/explorer/recent
- /logs/explorer/saved

## Areas affected to check
- [ ] Integrations -> Webhooks
<img width="600" alt="image"
src="https://github.com/user-attachments/assets/58523cdb-6219-49be-9d2f-5bc26ae03d7f"
/>
- [ ] Database -> Column Privileges
<img width="600" alt="image"
src="https://github.com/user-attachments/assets/98bea654-24ac-4646-9c65-5bc4f18565e9"
/>
- [ ] Observability -> API  
<img width="600" alt="image"
src="https://github.com/user-attachments/assets/a6512c6f-bd04-4d25-8e3c-99c85883434a"
/>
- [ ] Observability -> Storage
  - Its a table under "Request caching" which I don't have data for 😅 🙏 
- [ ] Observability -> Database
<img width="600" alt="image"
src="https://github.com/user-attachments/assets/4f0ba203-64b3-41f7-971e-974e232bdedd"
/>
- [ ] Table Editor -> Project API Docs -> Column list
<img width="600" alt="image"
src="https://github.com/user-attachments/assets/6358e7a8-5770-46f9-a5a2-4851855ae97f"
/>
- [ ] Table Editor -> Project API Docs -> RPC parameters list
<img width="600" alt="image"
src="https://github.com/user-attachments/assets/5e45a1d6-cd29-451c-bf00-5d806ef37cec"
/>
2026-11-23 10:59:28 +07:00

133 lines
4.2 KiB
TypeScript

import {
Card,
Label,
Switch,
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from 'ui'
import {
ALL_PRIVILEGE_TYPES,
COLUMN_PRIVILEGE_TYPES,
TABLE_PRIVILEGE_TYPES,
} from './Privileges.constants'
import { usePrivilegesState } from './Privileges.utils'
import type { ColumnPrivilege } from '@/data/privileges/column-privileges-query'
export interface PrivilegesTableProps extends Pick<
ReturnType<typeof usePrivilegesState>,
'tableCheckedStates' | 'columnCheckedStates' | 'toggleTablePrivilege' | 'toggleColumnPrivilege'
> {
columnPrivileges: ColumnPrivilege[]
disabled: boolean
isApplyingChanges?: boolean
}
export const PrivilegesTable = ({
columnPrivileges,
tableCheckedStates,
columnCheckedStates,
toggleTablePrivilege,
toggleColumnPrivilege,
disabled,
isApplyingChanges = false,
}: PrivilegesTableProps) => {
const handleClickColumnName = (columnId: string) => {
const hasAllPrivileges = COLUMN_PRIVILEGE_TYPES.every(
(privilege) => columnCheckedStates[columnId][privilege]
)
const privilegesToToggle = COLUMN_PRIVILEGE_TYPES.filter((privilege) =>
hasAllPrivileges
? columnCheckedStates[columnId][privilege]
: !columnCheckedStates[columnId][privilege]
)
privilegesToToggle.forEach((privilege) => {
toggleColumnPrivilege(columnId, privilege)
})
}
return (
<Card className="mb-4">
<Table className="table-fixed">
<TableHeader>
<TableRow>
<TableHead key="header-column">
<span>Column</span>
</TableHead>
{ALL_PRIVILEGE_TYPES.map((privilege) => {
const checked = tableCheckedStates[privilege]
const switchThId = `privilege-th-${privilege}`
return (
<TableHead key={`header-${privilege}`}>
<div className="inline-flex items-center gap-2">
<Label htmlFor={switchThId} className="text-xs">
{privilege.charAt(0) + privilege.slice(1).toLowerCase()}
</Label>
<Switch
id={switchThId}
checked={checked}
onCheckedChange={() => {
toggleTablePrivilege(privilege)
}}
disabled={disabled || isApplyingChanges}
/>
</div>
</TableHead>
)
})}
</TableRow>
</TableHeader>
<TableBody>
{columnPrivileges.map((column) => (
<TableRow key={column.column_id}>
<TableCell>
<button
tabIndex={0}
onClick={() => handleClickColumnName(column.column_id)}
className="block w-full truncate text-left text-foreground"
>
{column.column_name}
</button>
</TableCell>
{COLUMN_PRIVILEGE_TYPES.map((privilege) => {
const checked = columnCheckedStates[column.column_id][privilege]
return (
<TableCell key={privilege}>
{COLUMN_PRIVILEGE_TYPES.includes(privilege) && (
<div className="ml-5 inline-flex">
<Switch
aria-label={`${privilege} privilege for ${column.column_name}`}
checked={checked}
onCheckedChange={() => {
toggleColumnPrivilege(column.column_id, privilege)
}}
disabled={disabled || isApplyingChanges}
/>
</div>
)}
</TableCell>
)
})}
{TABLE_PRIVILEGE_TYPES.map((privilege) => {
return (
<TableCell key={privilege}>
<span className="ml-5 text-xs text-foreground-lighter">N/A</span>
</TableCell>
)
})}
</TableRow>
))}
</TableBody>
</Table>
</Card>
)
}