@alepha/ui 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -1
- package/dist/account/AccountBrand.d.ts +10 -3
- package/dist/account/AccountBrand.d.ts.map +1 -1
- package/dist/account/AccountBrand.js +12 -6
- package/dist/account/AccountBrand.js.map +1 -1
- package/dist/account/AccountLayout.d.ts.map +1 -1
- package/dist/account/AccountLayout.js +1 -1
- package/dist/account/AccountLayout.js.map +1 -1
- package/dist/admin/AdminUserDetail.d.ts +3 -3
- package/dist/admin/AdminUserDetail.js +3 -3
- package/dist/admin/AdminUserDetail.js.map +1 -1
- package/dist/ai/AiChat.d.ts +36 -6
- package/dist/ai/AiChat.d.ts.map +1 -1
- package/dist/ai/AiChat.js +101 -63
- package/dist/ai/AiChat.js.map +1 -1
- package/dist/ai/AiChatComposer.d.ts +22 -0
- package/dist/ai/AiChatComposer.d.ts.map +1 -0
- package/dist/ai/AiChatComposer.js +75 -0
- package/dist/ai/AiChatComposer.js.map +1 -0
- package/dist/ai/AiChatConfirmCard.d.ts +5 -2
- package/dist/ai/AiChatConfirmCard.d.ts.map +1 -1
- package/dist/ai/AiChatConfirmCard.js +7 -6
- package/dist/ai/AiChatConfirmCard.js.map +1 -1
- package/dist/ai/AiChatConfirmFields.d.ts +9 -0
- package/dist/ai/AiChatConfirmFields.d.ts.map +1 -0
- package/dist/ai/AiChatConfirmFields.js +45 -0
- package/dist/ai/AiChatConfirmFields.js.map +1 -0
- package/dist/ai/AiChatEmpty.d.ts +26 -0
- package/dist/ai/AiChatEmpty.d.ts.map +1 -0
- package/dist/ai/AiChatEmpty.js +47 -0
- package/dist/ai/AiChatEmpty.js.map +1 -0
- package/dist/ai/AiChatHistory.d.ts +3 -2
- package/dist/ai/AiChatHistory.d.ts.map +1 -1
- package/dist/ai/AiChatHistory.js +51 -22
- package/dist/ai/AiChatHistory.js.map +1 -1
- package/dist/ai/AiChatMessage.d.ts +14 -0
- package/dist/ai/AiChatMessage.d.ts.map +1 -1
- package/dist/ai/AiChatMessage.js +20 -12
- package/dist/ai/AiChatMessage.js.map +1 -1
- package/dist/ai/index.d.ts +3 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +4 -1
- package/dist/ai/useAiChat.d.ts +4 -0
- package/dist/ai/useAiChat.d.ts.map +1 -1
- package/dist/ai/useAiChat.js +15 -1
- package/dist/ai/useAiChat.js.map +1 -1
- package/dist/core/Sidebar.js +2 -2
- package/dist/core/Sidebar.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/useToast.d.ts +22 -1
- package/dist/core/useToast.d.ts.map +1 -1
- package/dist/core/useToast.js +4 -1
- package/dist/core/useToast.js.map +1 -1
- package/dist/core/useUndoable.d.ts +93 -0
- package/dist/core/useUndoable.d.ts.map +1 -0
- package/dist/core/useUndoable.js +172 -0
- package/dist/core/useUndoable.js.map +1 -0
- package/dist/i18n/fr/uiFr.d.ts.map +1 -1
- package/dist/i18n/fr/uiFr.js +50 -1
- package/dist/i18n/fr/uiFr.js.map +1 -1
- package/dist/markdown/MarkdownView.d.ts +15 -0
- package/dist/markdown/MarkdownView.d.ts.map +1 -1
- package/dist/markdown/MarkdownView.js +4 -1
- package/dist/markdown/MarkdownView.js.map +1 -1
- package/dist/organizations/useInviteOrganizationMember.d.ts +2 -2
- package/dist/organizations/useInviteOrganizationMember.js.map +1 -1
- package/dist/shell/AppShellSidebarNavItem.d.ts.map +1 -1
- package/dist/shell/AppShellSidebarNavItem.js +25 -2
- package/dist/shell/AppShellSidebarNavItem.js.map +1 -1
- package/dist/shell/PlateTabBar.d.ts.map +1 -1
- package/dist/shell/PlateTabBar.js +2 -2
- package/dist/shell/PlateTabBar.js.map +1 -1
- package/dist/shell/SidebarBackHeader.d.ts +35 -0
- package/dist/shell/SidebarBackHeader.d.ts.map +1 -0
- package/dist/shell/SidebarBackHeader.js +34 -0
- package/dist/shell/SidebarBackHeader.js.map +1 -0
- package/dist/shell/appShellNav.d.ts +30 -0
- package/dist/shell/appShellNav.d.ts.map +1 -1
- package/dist/shell/appShellNav.js.map +1 -1
- package/dist/shell/index.d.ts +2 -1
- package/dist/shell/index.d.ts.map +1 -1
- package/dist/shell/index.js +2 -1
- package/dist/swagger/$uiSwagger.d.ts +75 -0
- package/dist/swagger/$uiSwagger.d.ts.map +1 -0
- package/dist/swagger/$uiSwagger.js +51 -0
- package/dist/swagger/$uiSwagger.js.map +1 -0
- package/dist/swagger/OpenApiSpec.d.ts +113 -0
- package/dist/swagger/OpenApiSpec.d.ts.map +1 -0
- package/dist/swagger/OpenApiSpec.js +186 -0
- package/dist/swagger/OpenApiSpec.js.map +1 -0
- package/dist/swagger/SwaggerAccessBadge.d.ts +16 -0
- package/dist/swagger/SwaggerAccessBadge.d.ts.map +1 -0
- package/dist/swagger/SwaggerAccessBadge.js +40 -0
- package/dist/swagger/SwaggerAccessBadge.js.map +1 -0
- package/dist/swagger/SwaggerAlephaMeta.d.ts +11 -0
- package/dist/swagger/SwaggerAlephaMeta.d.ts.map +1 -0
- package/dist/swagger/SwaggerAlephaMeta.js +103 -0
- package/dist/swagger/SwaggerAlephaMeta.js.map +1 -0
- package/dist/swagger/SwaggerCredentials.d.ts +11 -0
- package/dist/swagger/SwaggerCredentials.d.ts.map +1 -0
- package/dist/swagger/SwaggerCredentials.js +35 -0
- package/dist/swagger/SwaggerCredentials.js.map +1 -0
- package/dist/swagger/SwaggerExplorer.d.ts +31 -0
- package/dist/swagger/SwaggerExplorer.d.ts.map +1 -0
- package/dist/swagger/SwaggerExplorer.js +156 -0
- package/dist/swagger/SwaggerExplorer.js.map +1 -0
- package/dist/swagger/SwaggerMethodBadge.d.ts +10 -0
- package/dist/swagger/SwaggerMethodBadge.d.ts.map +1 -0
- package/dist/swagger/SwaggerMethodBadge.js +27 -0
- package/dist/swagger/SwaggerMethodBadge.js.map +1 -0
- package/dist/swagger/SwaggerNav.d.ts +16 -0
- package/dist/swagger/SwaggerNav.d.ts.map +1 -0
- package/dist/swagger/SwaggerNav.js +63 -0
- package/dist/swagger/SwaggerNav.js.map +1 -0
- package/dist/swagger/SwaggerOperationView.d.ts +22 -0
- package/dist/swagger/SwaggerOperationView.d.ts.map +1 -0
- package/dist/swagger/SwaggerOperationView.js +89 -0
- package/dist/swagger/SwaggerOperationView.js.map +1 -0
- package/dist/swagger/SwaggerParameters.d.ts +11 -0
- package/dist/swagger/SwaggerParameters.d.ts.map +1 -0
- package/dist/swagger/SwaggerParameters.js +80 -0
- package/dist/swagger/SwaggerParameters.js.map +1 -0
- package/dist/swagger/SwaggerRequestBuilder.d.ts +83 -0
- package/dist/swagger/SwaggerRequestBuilder.d.ts.map +1 -0
- package/dist/swagger/SwaggerRequestBuilder.js +231 -0
- package/dist/swagger/SwaggerRequestBuilder.js.map +1 -0
- package/dist/swagger/SwaggerResponseView.d.ts +25 -0
- package/dist/swagger/SwaggerResponseView.d.ts.map +1 -0
- package/dist/swagger/SwaggerResponseView.js +94 -0
- package/dist/swagger/SwaggerResponseView.js.map +1 -0
- package/dist/swagger/SwaggerResponses.d.ts +12 -0
- package/dist/swagger/SwaggerResponses.d.ts.map +1 -0
- package/dist/swagger/SwaggerResponses.js +75 -0
- package/dist/swagger/SwaggerResponses.js.map +1 -0
- package/dist/swagger/SwaggerSchemaView.d.ts +19 -0
- package/dist/swagger/SwaggerSchemaView.d.ts.map +1 -0
- package/dist/swagger/SwaggerSchemaView.js +98 -0
- package/dist/swagger/SwaggerSchemaView.js.map +1 -0
- package/dist/swagger/SwaggerSection.d.ts +14 -0
- package/dist/swagger/SwaggerSection.d.ts.map +1 -0
- package/dist/swagger/SwaggerSection.js +23 -0
- package/dist/swagger/SwaggerSection.js.map +1 -0
- package/dist/swagger/SwaggerTryIt.d.ts +31 -0
- package/dist/swagger/SwaggerTryIt.d.ts.map +1 -0
- package/dist/swagger/SwaggerTryIt.js +68 -0
- package/dist/swagger/SwaggerTryIt.js.map +1 -0
- package/dist/swagger/SwaggerTryItForm.d.ts +20 -0
- package/dist/swagger/SwaggerTryItForm.d.ts.map +1 -0
- package/dist/swagger/SwaggerTryItForm.js +52 -0
- package/dist/swagger/SwaggerTryItForm.js.map +1 -0
- package/dist/swagger/index.d.ts +29 -0
- package/dist/swagger/index.d.ts.map +1 -0
- package/dist/swagger/index.js +18 -0
- package/dist/swagger/useSwaggerAccess.d.ts +24 -0
- package/dist/swagger/useSwaggerAccess.d.ts.map +1 -0
- package/dist/swagger/useSwaggerAccess.js +33 -0
- package/dist/swagger/useSwaggerAccess.js.map +1 -0
- package/dist/table/DataTable.d.ts.map +1 -1
- package/dist/table/DataTable.js +50 -13
- package/dist/table/DataTable.js.map +1 -1
- package/dist/table/DataTableBody.d.ts +18 -1
- package/dist/table/DataTableBody.d.ts.map +1 -1
- package/dist/table/DataTableBody.js +83 -58
- package/dist/table/DataTableBody.js.map +1 -1
- package/dist/table/DataTableRowActionsInline.d.ts +17 -0
- package/dist/table/DataTableRowActionsInline.d.ts.map +1 -0
- package/dist/table/DataTableRowActionsInline.js +45 -0
- package/dist/table/DataTableRowActionsInline.js.map +1 -0
- package/dist/table/PermissionMatrix.d.ts +4 -4
- package/dist/table/PermissionMatrix.js +2 -2
- package/dist/table/PermissionMatrix.js.map +1 -1
- package/dist/table/dataTableBaseProps.d.ts +31 -0
- package/dist/table/dataTableBaseProps.d.ts.map +1 -1
- package/dist/table/dataTableTypes.d.ts +16 -2
- package/dist/table/dataTableTypes.d.ts.map +1 -1
- package/dist/table/useDataTableData.d.ts +3 -0
- package/dist/table/useDataTableData.d.ts.map +1 -1
- package/dist/table/useDataTableData.js +9 -2
- package/dist/table/useDataTableData.js.map +1 -1
- package/dist/table/useDataTableRefresh.d.ts +1 -0
- package/dist/table/useDataTableRefresh.d.ts.map +1 -1
- package/dist/table/useDataTableRefresh.js +13 -1
- package/dist/table/useDataTableRefresh.js.map +1 -1
- package/dist/table/useOptimisticRows.d.ts +64 -0
- package/dist/table/useOptimisticRows.d.ts.map +1 -0
- package/dist/table/useOptimisticRows.js +185 -0
- package/dist/table/useOptimisticRows.js.map +1 -0
- package/dist/table/useRowMotion.d.ts +27 -0
- package/dist/table/useRowMotion.d.ts.map +1 -0
- package/dist/table/useRowMotion.js +112 -0
- package/dist/table/useRowMotion.js.map +1 -0
- package/docs/packages-alepha-ui-core.md +1 -0
- package/docs/packages-alepha-ui-overview.md +53 -1
- package/docs/packages-alepha-ui-swagger.md +35 -0
- package/package.json +11 -3
- package/src/account/AccountBrand.tsx +25 -6
- package/src/account/AccountLayout.tsx +5 -1
- package/src/admin/AdminUserDetail.tsx +3 -3
- package/src/admin/__tests__/AdminUserDetail.spec.ts +2 -2
- package/src/ai/AiChat.tsx +160 -82
- package/src/ai/AiChatComposer.tsx +117 -0
- package/src/ai/AiChatConfirmCard.tsx +7 -5
- package/src/ai/AiChatConfirmFields.tsx +65 -0
- package/src/ai/AiChatEmpty.tsx +73 -0
- package/src/ai/AiChatHistory.tsx +64 -28
- package/src/ai/AiChatMessage.tsx +41 -14
- package/src/ai/__tests__/AiChat.browser.spec.tsx +146 -5
- package/src/ai/index.ts +3 -0
- package/src/ai/useAiChat.ts +18 -0
- package/src/core/Sidebar.tsx +2 -2
- package/src/core/__tests__/useUndoable.browser.spec.tsx +201 -0
- package/src/core/index.ts +7 -0
- package/src/core/useToast.tsx +30 -2
- package/src/core/useUndoable.tsx +285 -0
- package/src/form/__tests__/ControlChoices.browser.spec.tsx +2 -1
- package/src/i18n/fr/uiFr.ts +52 -0
- package/src/markdown/MarkdownView.tsx +27 -9
- package/src/organizations/useInviteOrganizationMember.ts +2 -2
- package/src/shell/AppShellSidebarNavItem.tsx +51 -1
- package/src/shell/PlateTabBar.tsx +8 -2
- package/src/shell/SidebarBackHeader.tsx +58 -0
- package/src/shell/appShellNav.tsx +31 -0
- package/src/shell/index.ts +5 -1
- package/src/swagger/$uiSwagger.tsx +95 -0
- package/src/swagger/OpenApiSpec.ts +300 -0
- package/src/swagger/SwaggerAccessBadge.tsx +64 -0
- package/src/swagger/SwaggerAlephaMeta.tsx +141 -0
- package/src/swagger/SwaggerCredentials.tsx +44 -0
- package/src/swagger/SwaggerExplorer.tsx +208 -0
- package/src/swagger/SwaggerMethodBadge.tsx +32 -0
- package/src/swagger/SwaggerNav.tsx +92 -0
- package/src/swagger/SwaggerOperationView.tsx +102 -0
- package/src/swagger/SwaggerParameters.tsx +74 -0
- package/src/swagger/SwaggerRequestBuilder.ts +331 -0
- package/src/swagger/SwaggerResponseView.tsx +107 -0
- package/src/swagger/SwaggerResponses.tsx +83 -0
- package/src/swagger/SwaggerSchemaView.tsx +134 -0
- package/src/swagger/SwaggerSection.tsx +29 -0
- package/src/swagger/SwaggerTryIt.tsx +95 -0
- package/src/swagger/SwaggerTryItForm.tsx +87 -0
- package/src/swagger/__tests__/$uiSwagger.spec.ts +52 -0
- package/src/swagger/__tests__/OpenApiSpec.spec.ts +139 -0
- package/src/swagger/__tests__/SwaggerAccess.browser.spec.tsx +124 -0
- package/src/swagger/__tests__/SwaggerOperationView.browser.spec.tsx +194 -0
- package/src/swagger/__tests__/SwaggerRequestBuilder.spec.ts +250 -0
- package/src/swagger/index.ts +75 -0
- package/src/swagger/useSwaggerAccess.ts +59 -0
- package/src/table/DataTable.tsx +85 -34
- package/src/table/DataTableBody.tsx +51 -7
- package/src/table/DataTableRowActionsInline.tsx +80 -0
- package/src/table/PermissionMatrix.tsx +4 -4
- package/src/table/__tests__/DataTableEmptyState.browser.spec.tsx +1 -1
- package/src/table/__tests__/DataTableListMode.browser.spec.tsx +174 -0
- package/src/table/__tests__/DataTableOptimistic.browser.spec.tsx +173 -0
- package/src/table/__tests__/PermissionMatrix.browser.spec.tsx +2 -2
- package/src/table/__tests__/queryFilters.spec.ts +10 -12
- package/src/table/dataTableBaseProps.ts +31 -0
- package/src/table/dataTableTypes.ts +16 -2
- package/src/table/useDataTableData.ts +18 -2
- package/src/table/useDataTableRefresh.ts +26 -2
- package/src/table/useOptimisticRows.ts +265 -0
- package/src/table/useRowMotion.ts +152 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTableBody.js","names":[],"sources":["../../src/table/DataTableBody.tsx"],"sourcesContent":["import { useI18n } from \"alepha/react/i18n\";\nimport { Inbox, SearchX } from \"lucide-react\";\nimport type { ReactNode } from \"react\";\n\nimport { Checkbox } from \"../core/Checkbox.tsx\";\nimport { TableBody, TableCell, TableRow } from \"../core/Table.tsx\";\nimport { cn } from \"../core/utils.ts\";\nimport { DataTableRowActionsMenu } from \"./DataTableRowActionsMenu.tsx\";\nimport { DataTableSkeletonRows } from \"./DataTableSkeletonRows.tsx\";\nimport type {\n DataTableCellContext,\n DataTableEmptyState,\n ColumnDef,\n RowActionContext,\n RowActionEntry,\n} from \"./dataTableTypes.ts\";\n\nexport interface DataTableBodyProps<T> {\n /**\n * The table's `cellPadding` classes for a body cell, merged before a\n * column's own `className`.\n */\n cellClassName?: string;\n data: T[];\n /**\n * One key per row of `data`, index for index.\n */\n rowKeys: string[];\n loading: boolean;\n /**\n * The visible columns, in the reader's order.\n */\n visibleCols: Array<[string, ColumnDef<T>]>;\n /**\n * Handed to every cell beside its row.\n */\n cellContext: DataTableCellContext;\n hasCheckbox: boolean;\n hasRowActions: boolean;\n /**\n * Whether a filter is set, which picks the no-match empty state over the\n * no-items one.\n */\n hasActiveFilters: boolean;\n selection: ReadonlyMap<string, T>;\n toggleRow: (item: T) => void;\n rowCtx: RowActionContext;\n rowActions?: (item: T) => RowActionEntry<T>[];\n onRowClick?: (item: T) => void;\n onRowHover?: (item: T | undefined) => void;\n empty?: ReactNode;\n emptyMessage?: string;\n emptyState?: DataTableEmptyState;\n noMatchState?: DataTableEmptyState;\n}\n\n/**\n * The table body: skeleton rows while the first page loads, the empty state\n * when the page came back empty, the rows otherwise.\n */\nexport const DataTableBody = <T,>(props: DataTableBodyProps<T>) => {\n const {\n data,\n rowKeys,\n loading,\n visibleCols,\n hasCheckbox,\n hasRowActions,\n hasActiveFilters,\n selection,\n toggleRow,\n rowCtx,\n } = props;\n const { tr } = useI18n();\n\n // Which empty state applies, resolved here rather than in the JSX because\n // the answer is one boolean and the branch is four values deep.\n //\n // `hasActiveFilters` is already false whenever `props.filters` is unset, so\n // a table with no filter form can only ever reach the \"no items\" side.\n const emptyOverride =\n (hasActiveFilters ? props.noMatchState : props.emptyState) ?? {};\n const EmptyIcon = emptyOverride.icon ?? (hasActiveFilters ? SearchX : Inbox);\n const emptyTitle =\n emptyOverride.title ??\n props.emptyMessage ??\n String(\n hasActiveFilters\n ? tr(\"dataTable.noMatchTitle\", { default: \"No match\" })\n : tr(\"dataTable.emptyTitle\", { default: \"No items\" }),\n );\n const emptyAction = emptyOverride.action;\n // Suppressed by a bare `emptyMessage`: that prop is the whole message, and\n // pairing someone's \"No artifacts yet\" with a stock second line reads as a\n // component talking over its caller.\n const emptyDescription =\n emptyOverride.description ??\n (props.emptyMessage\n ? undefined\n : String(\n hasActiveFilters\n ? tr(\"dataTable.noMatchDescription\", {\n default: \"Try adjusting or clearing the filters.\",\n })\n : tr(\"dataTable.emptyDescription\", {\n default: \"Nothing here yet.\",\n }),\n ));\n\n return (\n <TableBody>\n {loading && data.length === 0 ? (\n <DataTableSkeletonRows\n cellClassName={props.cellClassName}\n rows={5}\n cols={\n visibleCols.length + (hasCheckbox ? 1 : 0) + (hasRowActions ? 1 : 0)\n }\n />\n ) : data.length === 0 ? (\n <TableRow className=\"hover:bg-transparent\">\n <TableCell\n colSpan={\n visibleCols.length +\n (hasCheckbox ? 1 : 0) +\n (hasRowActions ? 1 : 0)\n }\n // `h-full` and the cell's inherited `align-middle` are\n // what centre the state vertically. The chain is three\n // links long and every one is load-bearing: the scroller\n // above grows to the container, the `<table>` takes its\n // height, and this - the only body row - takes what the\n // header leaves. Break any of them and the state sits\n // tucked under the header instead of in the middle.\n //\n // `whitespace-normal` undoes the `whitespace-nowrap` every\n // cell carries, which is right for a data cell and wrong\n // for a sentence: the description would run off the side\n // and widen the table's own horizontal scroller.\n className=\"h-full p-0 whitespace-normal\"\n >\n {props.empty ?? (\n <div className=\"flex flex-col items-center justify-center gap-2 px-6 py-12 text-center\">\n <EmptyIcon className=\"text-muted-foreground size-8 opacity-40\" />\n <p className=\"text-foreground text-sm font-medium\">\n {emptyTitle}\n </p>\n {emptyDescription ? (\n <p className=\"text-muted-foreground max-w-xs text-sm text-balance\">\n {emptyDescription}\n </p>\n ) : null}\n {/* `pt-2` on top of the block's `gap-2`: the action is\n a separate beat from the sentence explaining it,\n and at one gap it reads as a third line of text. */}\n {emptyAction ? <div className=\"pt-2\">{emptyAction}</div> : null}\n </div>\n )}\n </TableCell>\n </TableRow>\n ) : (\n data.map((item, rowIndex) => {\n const key = rowKeys[rowIndex];\n const isSelected = selection.has(key);\n return (\n <TableRow\n key={key}\n onClick={() => props.onRowClick?.(item)}\n // Per row, both halves. Moving from one row to the next fires\n // the old row's `mouseleave` BEFORE the new row's `mouseenter`,\n // so the clear can never wipe the value the enter just set.\n onMouseEnter={() => props.onRowHover?.(item)}\n onMouseLeave={() => props.onRowHover?.(undefined)}\n className={cn(\n // Stays: the global cursor rule in `styles.css` covers\n // controls and menu items, and a `<tr>` is neither. It\n // is also conditional, which no blanket rule could be -\n // a row is only clickable when a handler was given.\n props.onRowClick && \"cursor-pointer\",\n isSelected && \"bg-muted/30\",\n )}\n >\n {hasCheckbox && (\n <TableCell\n className={props.cellClassName}\n onClick={(e) => e.stopPropagation()}\n >\n <Checkbox\n checked={isSelected}\n onCheckedChange={() => toggleRow(item)}\n aria-label={tr(\"dataTable.selectRow\", {\n default: \"Select row\",\n })}\n />\n </TableCell>\n )}\n {visibleCols.map(([key, def]) => (\n <TableCell\n key={key}\n className={cn(\n props.cellClassName,\n def.className,\n def.align === \"right\" && \"text-right\",\n def.align === \"center\" && \"text-center\",\n )}\n >\n {def.cell(item, props.cellContext)}\n </TableCell>\n ))}\n {hasRowActions && (\n <TableCell\n className={cn(props.cellClassName, \"text-right\")}\n onClick={(e) => e.stopPropagation()}\n >\n <DataTableRowActionsMenu\n actions={props.rowActions!(item)}\n item={item}\n ctx={rowCtx}\n />\n </TableCell>\n )}\n </TableRow>\n );\n })\n )}\n </TableBody>\n );\n};\n"],"mappings":";;;;;;;;;;;;;AA4DA,MAAa,iBAAqB,UAAiC;CACjE,MAAM,EACJ,MACA,SACA,SACA,aACA,aACA,eACA,kBACA,WACA,WACA,WACE;CACJ,MAAM,EAAE,OAAO,QAAQ;CAOvB,MAAM,iBACH,mBAAmB,MAAM,eAAe,MAAM,eAAe,CAAC;CACjE,MAAM,YAAY,cAAc,SAAS,mBAAmB,UAAU;CACtE,MAAM,aACJ,cAAc,SACd,MAAM,gBACN,OACE,mBACI,GAAG,0BAA0B,EAAE,SAAS,WAAW,CAAC,IACpD,GAAG,wBAAwB,EAAE,SAAS,WAAW,CAAC,CACxD;CACF,MAAM,cAAc,cAAc;CAIlC,MAAM,mBACJ,cAAc,gBACb,MAAM,eACH,KAAA,IACA,OACE,mBACI,GAAG,gCAAgC,EACjC,SAAS,yCACX,CAAC,IACD,GAAG,8BAA8B,EAC/B,SAAS,oBACX,CAAC,CACP;CAEN,OACE,oBAAC,WAAD,EAAA,UACG,WAAW,KAAK,WAAW,IAC1B,oBAAC,uBAAD;EACE,eAAe,MAAM;EACrB,MAAM;EACN,MACE,YAAY,UAAU,cAAc,IAAI,MAAM,gBAAgB,IAAI;CAErE,CAAA,IACC,KAAK,WAAW,IAClB,oBAAC,UAAD;EAAU,WAAU;EAClB,UAAA,oBAAC,WAAD;GACE,SACE,YAAY,UACX,cAAc,IAAI,MAClB,gBAAgB,IAAI;GAcvB,WAAU;GAET,UAAA,MAAM,SACL,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA;KACE,oBAAC,WAAD,EAAW,WAAU,0CAA2C,CAAA;KAChE,oBAAC,KAAD;MAAG,WAAU;MACV,UAAA;KACA,CAAA;KACF,mBACC,oBAAC,KAAD;MAAG,WAAU;MACV,UAAA;KACA,CAAA,IACD;KAIH,cAAc,oBAAC,OAAD;MAAK,WAAU;MAAQ,UAAA;KAAiB,CAAA,IAAI;IACxD;;EAEE,CAAA;CACH,CAAA,IAEV,KAAK,KAAK,MAAM,aAAa;EAC3B,MAAM,MAAM,QAAQ;EACpB,MAAM,aAAa,UAAU,IAAI,GAAG;EACpC,OACE,qBAAC,UAAD;GAEE,eAAe,MAAM,aAAa,IAAI;GAItC,oBAAoB,MAAM,aAAa,IAAI;GAC3C,oBAAoB,MAAM,aAAa,KAAA,CAAS;GAChD,WAAW,GAKT,MAAM,cAAc,kBACpB,cAAc,aAChB;GAfF,UAAA;IAiBG,eACC,oBAAC,WAAD;KACE,WAAW,MAAM;KACjB,UAAU,MAAM,EAAE,gBAAgB;KAElC,UAAA,oBAAC,UAAD;MACE,SAAS;MACT,uBAAuB,UAAU,IAAI;MACrC,cAAY,GAAG,uBAAuB,EACpC,SAAS,aACX,CAAC;KACF,CAAA;IACQ,CAAA;IAEZ,YAAY,KAAK,CAAC,KAAK,SACtB,oBAAC,WAAD;KAEE,WAAW,GACT,MAAM,eACN,IAAI,WACJ,IAAI,UAAU,WAAW,cACzB,IAAI,UAAU,YAAY,aAC5B;KAEC,UAAA,IAAI,KAAK,MAAM,MAAM,WAAW;IACxB,GATJ,GASI,CACZ;IACA,iBACC,oBAAC,WAAD;KACE,WAAW,GAAG,MAAM,eAAe,YAAY;KAC/C,UAAU,MAAM,EAAE,gBAAgB;KAElC,UAAA,oBAAC,yBAAD;MACE,SAAS,MAAM,WAAY,IAAI;MACzB;MACN,KAAK;KACN,CAAA;IACQ,CAAA;GAEL;EAvDH,GAAA,GAuDG;CAEd,CAAC,EAEM,CAAA;AAEf"}
|
|
1
|
+
{"version":3,"file":"DataTableBody.js","names":[],"sources":["../../src/table/DataTableBody.tsx"],"sourcesContent":["import { useI18n } from \"alepha/react/i18n\";\nimport { Inbox, SearchX } from \"lucide-react\";\nimport { type ReactNode, useRef } from \"react\";\n\nimport { Checkbox } from \"../core/Checkbox.tsx\";\nimport { TableBody, TableCell, TableRow } from \"../core/Table.tsx\";\nimport { cn } from \"../core/utils.ts\";\nimport { DataTableRowActionsInline } from \"./DataTableRowActionsInline.tsx\";\nimport { DataTableRowActionsMenu } from \"./DataTableRowActionsMenu.tsx\";\nimport { DataTableSkeletonRows } from \"./DataTableSkeletonRows.tsx\";\nimport type {\n DataTableCellContext,\n DataTableEmptyState,\n ColumnDef,\n RowActionContext,\n RowActionEntry,\n} from \"./dataTableTypes.ts\";\nimport { useRowMotion } from \"./useRowMotion.ts\";\n\nexport interface DataTableBodyProps<T> {\n /**\n * The table's `cellPadding` classes for a body cell, merged before a\n * column's own `className`.\n */\n cellClassName?: string;\n data: T[];\n /**\n * One key per row of `data`, index for index.\n */\n rowKeys: string[];\n /**\n * Rows an optimistic remove is taking off: drawn, inert, playing their\n * exit.\n */\n leaving?: ReadonlySet<string>;\n /**\n * Rows an optimistic patch just redrew, flashed once.\n */\n flash?: Set<string>;\n loading: boolean;\n /**\n * The visible columns, in the reader's order.\n */\n visibleCols: Array<[string, ColumnDef<T>]>;\n /**\n * Handed to every cell beside its row.\n */\n cellContext: DataTableCellContext;\n hasCheckbox: boolean;\n hasRowActions: boolean;\n /**\n * Whether a filter is set, which picks the no-match empty state over the\n * no-items one.\n */\n hasActiveFilters: boolean;\n selection: ReadonlyMap<string, T>;\n toggleRow: (item: T) => void;\n rowCtx: RowActionContext;\n rowActions?: (item: T) => RowActionEntry<T>[];\n /**\n * The table's `rowActionsDisplay`.\n */\n rowActionsDisplay?: \"menu\" | \"inline\";\n /**\n * The table's `striped`.\n */\n striped?: boolean;\n onRowClick?: (item: T) => void;\n onRowHover?: (item: T | undefined) => void;\n empty?: ReactNode;\n emptyMessage?: string;\n emptyState?: DataTableEmptyState;\n noMatchState?: DataTableEmptyState;\n}\n\n/**\n * The table body: skeleton rows while the first page loads, the empty state\n * when the page came back empty, the rows otherwise.\n */\nexport const DataTableBody = <T,>(props: DataTableBodyProps<T>) => {\n const {\n data,\n rowKeys,\n loading,\n visibleCols,\n hasCheckbox,\n hasRowActions,\n hasActiveFilters,\n selection,\n toggleRow,\n rowCtx,\n } = props;\n const { tr } = useI18n();\n const bodyRef = useRef<HTMLTableSectionElement>(null);\n const leaving = props.leaving ?? NO_KEYS;\n useRowMotion({\n body: bodyRef,\n rowKeys,\n leaving,\n flash: props.flash ?? NO_FLASH,\n });\n\n // Which empty state applies, resolved here rather than in the JSX because\n // the answer is one boolean and the branch is four values deep.\n //\n // `hasActiveFilters` is already false whenever `props.filters` is unset, so\n // a table with no filter form can only ever reach the \"no items\" side.\n const emptyOverride =\n (hasActiveFilters ? props.noMatchState : props.emptyState) ?? {};\n const EmptyIcon = emptyOverride.icon ?? (hasActiveFilters ? SearchX : Inbox);\n const emptyTitle =\n emptyOverride.title ??\n props.emptyMessage ??\n String(\n hasActiveFilters\n ? tr(\"dataTable.noMatchTitle\", { default: \"No match\" })\n : tr(\"dataTable.emptyTitle\", { default: \"No items\" }),\n );\n const emptyAction = emptyOverride.action;\n // Suppressed by a bare `emptyMessage`: that prop is the whole message, and\n // pairing someone's \"No artifacts yet\" with a stock second line reads as a\n // component talking over its caller.\n const emptyDescription =\n emptyOverride.description ??\n (props.emptyMessage\n ? undefined\n : String(\n hasActiveFilters\n ? tr(\"dataTable.noMatchDescription\", {\n default: \"Try adjusting or clearing the filters.\",\n })\n : tr(\"dataTable.emptyDescription\", {\n default: \"Nothing here yet.\",\n }),\n ));\n\n return (\n <TableBody ref={bodyRef}>\n {loading && data.length === 0 ? (\n <DataTableSkeletonRows\n cellClassName={props.cellClassName}\n rows={5}\n cols={\n visibleCols.length + (hasCheckbox ? 1 : 0) + (hasRowActions ? 1 : 0)\n }\n />\n ) : data.length === 0 ? (\n <TableRow className=\"hover:bg-transparent\">\n <TableCell\n colSpan={\n visibleCols.length +\n (hasCheckbox ? 1 : 0) +\n (hasRowActions ? 1 : 0)\n }\n // `h-full` and the cell's inherited `align-middle` are\n // what centre the state vertically. The chain is three\n // links long and every one is load-bearing: the scroller\n // above grows to the container, the `<table>` takes its\n // height, and this - the only body row - takes what the\n // header leaves. Break any of them and the state sits\n // tucked under the header instead of in the middle.\n //\n // `whitespace-normal` undoes the `whitespace-nowrap` every\n // cell carries, which is right for a data cell and wrong\n // for a sentence: the description would run off the side\n // and widen the table's own horizontal scroller.\n className=\"h-full p-0 whitespace-normal\"\n >\n {props.empty ?? (\n <div className=\"flex flex-col items-center justify-center gap-2 px-6 py-12 text-center\">\n <EmptyIcon className=\"text-muted-foreground size-8 opacity-40\" />\n <p className=\"text-foreground text-sm font-medium\">\n {emptyTitle}\n </p>\n {emptyDescription ? (\n <p className=\"text-muted-foreground max-w-xs text-sm text-balance\">\n {emptyDescription}\n </p>\n ) : null}\n {/* `pt-2` on top of the block's `gap-2`: the action is\n a separate beat from the sentence explaining it,\n and at one gap it reads as a third line of text. */}\n {emptyAction ? <div className=\"pt-2\">{emptyAction}</div> : null}\n </div>\n )}\n </TableCell>\n </TableRow>\n ) : (\n data.map((item, rowIndex) => {\n const key = rowKeys[rowIndex];\n const isSelected = selection.has(key);\n const isLeaving = leaving.has(key);\n return (\n <TableRow\n key={key}\n data-row-key={key}\n data-leaving={isLeaving || undefined}\n aria-hidden={isLeaving || undefined}\n inert={isLeaving || undefined}\n onClick={() => props.onRowClick?.(item)}\n // Per row, both halves. Moving from one row to the next fires\n // the old row's `mouseleave` BEFORE the new row's `mouseenter`,\n // so the clear can never wipe the value the enter just set.\n onMouseEnter={() => props.onRowHover?.(item)}\n onMouseLeave={() => props.onRowHover?.(undefined)}\n className={cn(\n // Stays: the global cursor rule in `styles.css` covers\n // controls and menu items, and a `<tr>` is neither. It\n // is also conditional, which no blanket rule could be -\n // a row is only clickable when a handler was given.\n props.onRowClick && \"cursor-pointer\",\n props.striped && \"even:bg-muted/40\",\n isSelected && \"bg-muted/30\",\n )}\n >\n {hasCheckbox && (\n <TableCell\n className={props.cellClassName}\n onClick={(e) => e.stopPropagation()}\n >\n <Checkbox\n checked={isSelected}\n onCheckedChange={() => toggleRow(item)}\n aria-label={tr(\"dataTable.selectRow\", {\n default: \"Select row\",\n })}\n />\n </TableCell>\n )}\n {visibleCols.map(([key, def]) => (\n <TableCell\n key={key}\n className={cn(\n props.cellClassName,\n def.className,\n def.align === \"right\" && \"text-right\",\n def.align === \"center\" && \"text-center\",\n )}\n >\n {def.cell(item, props.cellContext)}\n </TableCell>\n ))}\n {hasRowActions && (\n <TableCell\n className={cn(props.cellClassName, \"text-right\")}\n onClick={(e) => e.stopPropagation()}\n >\n {props.rowActionsDisplay === \"inline\" ? (\n <DataTableRowActionsInline\n actions={props.rowActions!(item)}\n item={item}\n ctx={rowCtx}\n />\n ) : (\n <DataTableRowActionsMenu\n actions={props.rowActions!(item)}\n item={item}\n ctx={rowCtx}\n />\n )}\n </TableCell>\n )}\n </TableRow>\n );\n })\n )}\n </TableBody>\n );\n};\n\nconst NO_KEYS: ReadonlySet<string> = new Set();\nconst NO_FLASH = new Set<string>();\n"],"mappings":";;;;;;;;;;;;;;;;AA+EA,MAAa,iBAAqB,UAAiC;CACjE,MAAM,EACJ,MACA,SACA,SACA,aACA,aACA,eACA,kBACA,WACA,WACA,WACE;CACJ,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,UAAU,OAAgC,IAAI;CACpD,MAAM,UAAU,MAAM,WAAW;CACjC,aAAa;EACX,MAAM;EACN;EACA;EACA,OAAO,MAAM,SAAS;CACxB,CAAC;CAOD,MAAM,iBACH,mBAAmB,MAAM,eAAe,MAAM,eAAe,CAAC;CACjE,MAAM,YAAY,cAAc,SAAS,mBAAmB,UAAU;CACtE,MAAM,aACJ,cAAc,SACd,MAAM,gBACN,OACE,mBACI,GAAG,0BAA0B,EAAE,SAAS,WAAW,CAAC,IACpD,GAAG,wBAAwB,EAAE,SAAS,WAAW,CAAC,CACxD;CACF,MAAM,cAAc,cAAc;CAIlC,MAAM,mBACJ,cAAc,gBACb,MAAM,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,MAAM,EAAE,gBAAgB;MAElC,UAAA,oBAAC,UAAD;OACE,SAAS;OACT,uBAAuB,UAAU,IAAI;OACrC,cAAY,GAAG,uBAAuB,EACpC,SAAS,aACX,CAAC;MACF,CAAA;KACQ,CAAA;KAEZ,YAAY,KAAK,CAAC,KAAK,SACtB,oBAAC,WAAD;MAEE,WAAW,GACT,MAAM,eACN,IAAI,WACJ,IAAI,UAAU,WAAW,cACzB,IAAI,UAAU,YAAY,aAC5B;MAEC,UAAA,IAAI,KAAK,MAAM,MAAM,WAAW;KACxB,GATJ,GASI,CACZ;KACA,iBACC,oBAAC,WAAD;MACE,WAAW,GAAG,MAAM,eAAe,YAAY;MAC/C,UAAU,MAAM,EAAE,gBAAgB;MAEjC,UAAA,MAAM,sBAAsB,WAC3B,oBAAC,2BAAD;OACE,SAAS,MAAM,WAAY,IAAI;OACzB;OACN,KAAK;MACN,CAAA,IAED,oBAAC,yBAAD;OACE,SAAS,MAAM,WAAY,IAAI;OACzB;OACN,KAAK;MACN,CAAA;KAEM,CAAA;IAEL;GApEH,GAAA,GAoEG;EAEd,CAAC;CAEM,CAAA;AAEf;AAEA,MAAM,0BAA+B,IAAI,IAAI;AAC7C,MAAM,2BAAW,IAAI,IAAY"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { RowActionContext, RowActionEntry } from "./dataTableTypes.ts";
|
|
2
|
+
export interface DataTableRowActionsInlineProps<T> {
|
|
3
|
+
actions: RowActionEntry<T>[];
|
|
4
|
+
item: T;
|
|
5
|
+
ctx: RowActionContext;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A row's actions as a line of icon buttons, for `rowActionsDisplay="inline"`:
|
|
9
|
+
* each one outlined, named by a tooltip from its `label`, red when it is
|
|
10
|
+
* `destructive`.
|
|
11
|
+
*
|
|
12
|
+
* A group cannot be one button, so the groups keep a three-dots menu of
|
|
13
|
+
* their own after the buttons. A `checked` entry is a toggle: its button
|
|
14
|
+
* carries `aria-pressed`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const DataTableRowActionsInline: <T>(props: DataTableRowActionsInlineProps<T>) => import("react").JSX.Element | null;
|
|
17
|
+
//# sourceMappingURL=DataTableRowActionsInline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataTableRowActionsInline.d.ts","sourceRoot":"","sources":["../../src/table/DataTableRowActionsInline.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAEV,gBAAgB,EAChB,cAAc,EAEf,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,8BAA8B,CAAC,CAAC;IAC/C,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7B,IAAI,EAAE,CAAC,CAAC;IACR,GAAG,EAAE,gBAAgB,CAAC;CACvB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,GAAI,CAAC,SAClC,8BAA8B,CAAC,CAAC,CAAC,uCAgDzC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Button } from "../core/Button.js";
|
|
2
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../core/Tooltip.js";
|
|
3
|
+
import { DataTableRowActionsMenu } from "./DataTableRowActionsMenu.js";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/table/DataTableRowActionsInline.tsx
|
|
6
|
+
/**
|
|
7
|
+
* A row's actions as a line of icon buttons, for `rowActionsDisplay="inline"`:
|
|
8
|
+
* each one outlined, named by a tooltip from its `label`, red when it is
|
|
9
|
+
* `destructive`.
|
|
10
|
+
*
|
|
11
|
+
* A group cannot be one button, so the groups keep a three-dots menu of
|
|
12
|
+
* their own after the buttons. A `checked` entry is a toggle: its button
|
|
13
|
+
* carries `aria-pressed`.
|
|
14
|
+
*/
|
|
15
|
+
const DataTableRowActionsInline = (props) => {
|
|
16
|
+
const actions = props.actions.filter((entry) => !("children" in entry));
|
|
17
|
+
const groups = props.actions.filter((entry) => "children" in entry);
|
|
18
|
+
if (actions.length === 0 && groups.length === 0) return null;
|
|
19
|
+
return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsxs("div", {
|
|
20
|
+
className: "flex items-center justify-end gap-1",
|
|
21
|
+
children: [actions.map((action) => {
|
|
22
|
+
const Icon = action.icon;
|
|
23
|
+
return /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
|
|
24
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
25
|
+
type: "button",
|
|
26
|
+
variant: "outlined",
|
|
27
|
+
intent: action.destructive ? "danger" : void 0,
|
|
28
|
+
size: Icon ? "icon" : "sm",
|
|
29
|
+
"aria-label": action.label,
|
|
30
|
+
"aria-pressed": action.checked ? action.checked(props.item) : void 0,
|
|
31
|
+
disabled: action.disabled?.(props.item),
|
|
32
|
+
onClick: () => action.onClick(props.item, props.ctx)
|
|
33
|
+
}),
|
|
34
|
+
children: Icon ? /* @__PURE__ */ jsx(Icon, { className: "size-4" }) : action.label
|
|
35
|
+
}), /* @__PURE__ */ jsx(TooltipContent, { children: action.label })] }, action.label);
|
|
36
|
+
}), groups.length > 0 ? /* @__PURE__ */ jsx(DataTableRowActionsMenu, {
|
|
37
|
+
actions: groups,
|
|
38
|
+
item: props.item,
|
|
39
|
+
ctx: props.ctx
|
|
40
|
+
}) : null]
|
|
41
|
+
}) });
|
|
42
|
+
};
|
|
43
|
+
export { DataTableRowActionsInline };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=DataTableRowActionsInline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataTableRowActionsInline.js","names":[],"sources":["../../src/table/DataTableRowActionsInline.tsx"],"sourcesContent":["import { Button } from \"../core/Button.tsx\";\nimport {\n Tooltip,\n TooltipContent,\n TooltipProvider,\n TooltipTrigger,\n} from \"../core/Tooltip.tsx\";\nimport { DataTableRowActionsMenu } from \"./DataTableRowActionsMenu.tsx\";\nimport type {\n RowAction,\n RowActionContext,\n RowActionEntry,\n RowActionGroup,\n} from \"./dataTableTypes.ts\";\n\nexport interface DataTableRowActionsInlineProps<T> {\n actions: RowActionEntry<T>[];\n item: T;\n ctx: RowActionContext;\n}\n\n/**\n * A row's actions as a line of icon buttons, for `rowActionsDisplay=\"inline\"`:\n * each one outlined, named by a tooltip from its `label`, red when it is\n * `destructive`.\n *\n * A group cannot be one button, so the groups keep a three-dots menu of\n * their own after the buttons. A `checked` entry is a toggle: its button\n * carries `aria-pressed`.\n */\nexport const DataTableRowActionsInline = <T,>(\n props: DataTableRowActionsInlineProps<T>,\n) => {\n const actions = props.actions.filter(\n (entry): entry is RowAction<T> => !(\"children\" in entry),\n );\n const groups = props.actions.filter(\n (entry): entry is RowActionGroup<T> => \"children\" in entry,\n );\n if (actions.length === 0 && groups.length === 0) return null;\n return (\n <TooltipProvider>\n <div className=\"flex items-center justify-end gap-1\">\n {actions.map((action) => {\n const Icon = action.icon;\n return (\n <Tooltip key={action.label}>\n <TooltipTrigger\n render={\n <Button\n type=\"button\"\n variant=\"outlined\"\n intent={action.destructive ? \"danger\" : undefined}\n size={Icon ? \"icon\" : \"sm\"}\n aria-label={action.label}\n aria-pressed={\n action.checked ? action.checked(props.item) : undefined\n }\n disabled={action.disabled?.(props.item)}\n onClick={() => action.onClick(props.item, props.ctx)}\n />\n }\n >\n {Icon ? <Icon className=\"size-4\" /> : action.label}\n </TooltipTrigger>\n <TooltipContent>{action.label}</TooltipContent>\n </Tooltip>\n );\n })}\n {groups.length > 0 ? (\n <DataTableRowActionsMenu\n actions={groups}\n item={props.item}\n ctx={props.ctx}\n />\n ) : null}\n </div>\n </TooltipProvider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;AA8BA,MAAa,6BACX,UACG;CACH,MAAM,UAAU,MAAM,QAAQ,QAC3B,UAAiC,EAAE,cAAc,MACpD;CACA,MAAM,SAAS,MAAM,QAAQ,QAC1B,UAAsC,cAAc,KACvD;CACA,IAAI,QAAQ,WAAW,KAAK,OAAO,WAAW,GAAG,OAAO;CACxD,OACE,oBAAC,iBAAD,EAAA,UACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACG,QAAQ,KAAK,WAAW;GACvB,MAAM,OAAO,OAAO;GACpB,OACE,qBAAC,SAAD,EAAA,UAAA,CACE,oBAAC,gBAAD;IACE,QACE,oBAAC,QAAD;KACE,MAAK;KACL,SAAQ;KACR,QAAQ,OAAO,cAAc,WAAW,KAAA;KACxC,MAAM,OAAO,SAAS;KACtB,cAAY,OAAO;KACnB,gBACE,OAAO,UAAU,OAAO,QAAQ,MAAM,IAAI,IAAI,KAAA;KAEhD,UAAU,OAAO,WAAW,MAAM,IAAI;KACtC,eAAe,OAAO,QAAQ,MAAM,MAAM,MAAM,GAAG;IACpD,CAAA;IAGF,UAAA,OAAO,oBAAC,MAAD,EAAM,WAAU,SAAU,CAAA,IAAI,OAAO;GAC/B,CAAA,GAChB,oBAAC,gBAAD,EAAA,UAAiB,OAAO,MAAsB,CAAA,CACvC,EAAA,GApBK,OAAO,KAoBZ;EAEb,CAAC,GACA,OAAO,SAAS,IACf,oBAAC,yBAAD;GACE,SAAS;GACT,MAAM,MAAM;GACZ,KAAK,MAAM;EACZ,CAAA,IACC,IACD;CACU,CAAA,EAAA,CAAA;AAErB"}
|
|
@@ -5,8 +5,8 @@ export interface PermissionMatrixProps {
|
|
|
5
5
|
* The rows, already grouped and already filtered.
|
|
6
6
|
*
|
|
7
7
|
* ⚠️ **Filtering is the caller's job.** Lore hides the permissions of a
|
|
8
|
-
* capability that is switched off;
|
|
9
|
-
*
|
|
8
|
+
* capability that is switched off; another app may have no capability concept
|
|
9
|
+
* and show all of its groups. A `capabilities` prop here would be a
|
|
10
10
|
* Lore-shaped idea that every other consumer passes `undefined` to forever,
|
|
11
11
|
* so this component renders the groups it is handed and asks nothing about
|
|
12
12
|
* where they came from.
|
|
@@ -54,8 +54,8 @@ export interface PermissionMatrixProps {
|
|
|
54
54
|
* a checkbox at each crossing.
|
|
55
55
|
*
|
|
56
56
|
* It lives here rather than in either application because two of them need the
|
|
57
|
-
* same table. Lore renders it for a project's ranks;
|
|
58
|
-
*
|
|
57
|
+
* same table. Lore renders it for a project's ranks; another app renders it
|
|
58
|
+
* for its own. What differs between them is entirely in the props.
|
|
59
59
|
*
|
|
60
60
|
* ## What the component deliberately does not know
|
|
61
61
|
*
|
|
@@ -8,8 +8,8 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
8
8
|
* a checkbox at each crossing.
|
|
9
9
|
*
|
|
10
10
|
* It lives here rather than in either application because two of them need the
|
|
11
|
-
* same table. Lore renders it for a project's ranks;
|
|
12
|
-
*
|
|
11
|
+
* same table. Lore renders it for a project's ranks; another app renders it
|
|
12
|
+
* for its own. What differs between them is entirely in the props.
|
|
13
13
|
*
|
|
14
14
|
* ## What the component deliberately does not know
|
|
15
15
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PermissionMatrix.js","names":[],"sources":["../../src/table/PermissionMatrix.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\n\nimport {\n Table,\n TableBody,\n TableHead,\n TableHeader,\n TableRow,\n} from \"../core/Table.tsx\";\nimport { cn } from \"../core/utils.ts\";\nimport type { IconComponent } from \"../form/iconHint.tsx\";\nimport {\n PermissionMatrixGroupRows,\n permissionChecked,\n} from \"./PermissionMatrixGroupRows.tsx\";\n\nexport interface PermissionMatrixProps {\n /**\n * The rows, already grouped and already filtered.\n *\n * ⚠️ **Filtering is the caller's job.** Lore hides the permissions of a\n * capability that is switched off; Alepha Club has no capability concept and\n * shows all of its groups. A `capabilities` prop here would be a\n * Lore-shaped idea that every other consumer passes `undefined` to forever,\n * so this component renders the groups it is handed and asks nothing about\n * where they came from.\n */\n groups: PermissionMatrixGroup[];\n\n /**\n * The columns, left to right. One per rank.\n */\n columns: PermissionMatrixColumn[];\n\n /**\n * What each column currently grants, keyed by {@link PermissionMatrixColumn.key}.\n *\n * A column missing from the record grants nothing, which is the same thing\n * as an empty array - a caller building this from a server response does not\n * have to fill in the ranks that hold no permission.\n */\n value: Record<string, readonly string[]>;\n\n /**\n * Called with the WHOLE record on every tick, not with a delta.\n *\n * The caller owns the save, so the module's refusals (\"that set is wider\n * than your own\") arrive as ordinary form errors on the page rather than as\n * a state this component would have to model.\n */\n onChange: (next: Record<string, string[]>) => void;\n\n /**\n * Header above the permission column. A label, not a placeholder: the\n * component carries no copy of its own.\n */\n header?: ReactNode;\n\n /**\n * Shown in place of the table when {@link groups} is empty - every\n * capability off, or a filter that matched nothing.\n */\n empty?: ReactNode;\n\n /**\n * Turns every cell off, on top of whatever the columns and rows say.\n * A save in flight, or a reader who may look and not edit.\n */\n disabled?: boolean;\n\n className?: string;\n}\n\n/**\n * Who may do what, as a table: permissions down the left, one column per rank,\n * a checkbox at each crossing.\n *\n * It lives here rather than in either application because two of them need the\n * same table. Lore renders it for a project's ranks; Alepha Club renders it for\n * the club's. What differs between them is entirely in the props.\n *\n * ## What the component deliberately does not know\n *\n * **It does not know what an owner is.** A column that must read all-on and\n * refuse edits is marked `readOnly` by the caller. Teaching the table about\n * ownership would put an application's model inside a component that two\n * applications with different models both use.\n *\n * **It does not know what a capability is.** See {@link PermissionMatrixProps.groups}.\n *\n * **It carries no copy.** Every label is a `ReactNode` the caller supplies,\n * already translated, so an application whose only locale is French renders a\n * French matrix without this package shipping a catalogue.\n *\n * ## The two kinds of locked row\n *\n * A permission can be non-negotiable in either direction, and both are common\n * enough to be data rather than a caller's own rendering:\n *\n * - `lock: \"on\"` is a **floor** - the permission every rank holds, so the row\n * is checked everywhere and cannot be unticked (Lore's `project:read`: a\n * member who cannot read the project is not a member).\n * - `lock: \"off\"` is a **ceiling** - the permission no rank may be granted, so\n * the row is unchecked everywhere and cannot be ticked (Lore's\n * `project:delete`, which belongs to ownership and is transferred rather\n * than granted).\n *\n * A `readOnly` column beats both: an owner column reads all-on including the\n * ceiling rows, because the ceiling describes what may be GRANTED, not what\n * the owner has.\n */\nexport const PermissionMatrix = (props: PermissionMatrixProps) => {\n const granted = (columnKey: string, permission: string): boolean =>\n (props.value[columnKey] ?? []).includes(permission);\n\n const toggle = (\n columnKey: string,\n permission: string,\n next: boolean,\n ): void => {\n const held = props.value[columnKey] ?? [];\n const without = held.filter((it) => it !== permission);\n\n props.onChange({\n // Every column, not only the one that moved: the caller saves a record\n // and a partial one would silently drop the ranks nobody touched.\n ...Object.fromEntries(\n Object.entries(props.value).map(([key, list]) => [key, [...list]]),\n ),\n [columnKey]: next ? [...without, permission] : without,\n });\n };\n\n if (props.groups.length === 0) {\n return (\n <div className=\"text-muted-foreground p-6 text-center text-sm\">\n {props.empty}\n </div>\n );\n }\n\n // Every row in the table, in order, so a column's coverage is counted over\n // the same set the reader can see. Filtering is the caller's job, so a group\n // that is switched off is not in `groups` and correctly does not count\n // against the ratio.\n const rows = props.groups.flatMap((group) => group.permissions);\n\n const coverageOf = (column: PermissionMatrixColumn): number =>\n rows.filter((row) => permissionChecked(column, row, granted)).length;\n\n return (\n <div className={cn(\"w-full overflow-x-auto\", props.className)}>\n <Table>\n {/* The chrome surface, sticky, so a long matrix keeps its rank names\n while it scrolls. `bg-muted` fully opaque and the two inset lines\n are the same pair `DataTable`'s header wears, and for the same\n reasons: a translucent header lets rows scroll through the labels,\n and a border on a sticky `<thead>` is dropped by the collapsed\n border model. */}\n <TableHeader className=\"bg-muted sticky top-0 z-10 shadow-[inset_0_1px_0_0_var(--bevel),inset_0_-1px_0_0_var(--border)]\">\n <TableRow className=\"hover:bg-transparent\">\n <TableHead className=\"min-w-56 align-bottom\">\n {props.header}\n </TableHead>\n {props.columns.map((column) => {\n const held = coverageOf(column);\n\n return (\n <TableHead\n key={column.key}\n className=\"border-border/60 h-auto min-w-36 border-l py-2 text-center align-bottom\"\n >\n <div className=\"flex flex-col items-center gap-1\">\n <span className=\"font-medium\">{column.label}</span>\n {/* The caller's own line and the ratio share one row.\n The ratio is a count, not copy, which is what lets this\n component print it while still shipping no strings:\n `description` carries whatever the application wants\n said (\"1 membre\"), and the separator is punctuation. */}\n <span className=\"text-muted-foreground text-xs font-normal\">\n {column.description ? <>{column.description} · </> : null}\n {held}/{rows.length}\n </span>\n {/* Decorative, and `aria-hidden` for it: the ratio above\n is the same fact in text, and four `role=\"progressbar\"`\n elements announcing a number already read out is noise,\n not access. */}\n <div\n aria-hidden\n className=\"bg-foreground/10 h-1 w-16 overflow-hidden rounded-full\"\n >\n <div\n className=\"bg-primary h-full rounded-full transition-[width]\"\n style={{\n width: `${rows.length === 0 ? 0 : (held / rows.length) * 100}%`,\n }}\n />\n </div>\n </div>\n </TableHead>\n );\n })}\n </TableRow>\n </TableHeader>\n <TableBody>\n {props.groups.map((group) => (\n <PermissionMatrixGroupRows\n key={group.key}\n group={group}\n columns={props.columns}\n disabled={props.disabled === true}\n granted={granted}\n toggle={toggle}\n />\n ))}\n </TableBody>\n </Table>\n </div>\n );\n};\n\nexport interface PermissionMatrixGroup {\n /**\n * Stable identity for the group. Never rendered: {@link label} is.\n */\n key: string;\n\n label: ReactNode;\n\n /**\n * Shown before the label on the heading row. A subject is quicker to find\n * again by its mark than by re-reading four uppercase words, and the heading\n * row is the only thing a reader scans past on the way down a long matrix.\n *\n * Optional, and a group without one simply starts at its label - the heading\n * does not reserve the space, so a matrix that gives icons to none of its\n * groups looks deliberate rather than short of something.\n */\n icon?: IconComponent;\n\n permissions: PermissionMatrixRow[];\n}\n\nexport interface PermissionMatrixRow {\n /**\n * The permission as it is stored and sent, e.g. `quest:create`. This is the\n * value that lands in {@link PermissionMatrixProps.value}.\n */\n name: string;\n\n label: ReactNode;\n\n /**\n * Supplementary prose, shown as a tooltip on the label rather than as a\n * line of its own: the line under the label is the permission's stored name,\n * which every row has, and a third line would loosen the whole table for the\n * few rows that carry one.\n */\n description?: ReactNode;\n\n /**\n * Pins this row in one state on every column. See the component's doc for\n * why a floor and a ceiling are both worth expressing.\n */\n lock?: \"on\" | \"off\";\n}\n\nexport interface PermissionMatrixColumn {\n /**\n * The key this column's grants are stored under in\n * {@link PermissionMatrixProps.value}. A rank key, for both consumers.\n */\n key: string;\n\n label: ReactNode;\n\n description?: ReactNode;\n\n /**\n * All-on and not editable.\n *\n * The caller marks it; the component does not know what an owner is, or that\n * such a column exists at all until it is handed one.\n */\n readOnly?: boolean;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+GA,MAAa,oBAAoB,UAAiC;CAChE,MAAM,WAAW,WAAmB,gBACjC,MAAM,MAAM,cAAc,CAAC,EAAA,CAAG,SAAS,UAAU;CAEpD,MAAM,UACJ,WACA,YACA,SACS;EAET,MAAM,WADO,MAAM,MAAM,cAAc,CAAC,EAAA,CACnB,QAAQ,OAAO,OAAO,UAAU;EAErD,MAAM,SAAS;GAGb,GAAG,OAAO,YACR,OAAO,QAAQ,MAAM,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,UAAU,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CACnE;IACC,YAAY,OAAO,CAAC,GAAG,SAAS,UAAU,IAAI;EACjD,CAAC;CACH;CAEA,IAAI,MAAM,OAAO,WAAW,GAC1B,OACE,oBAAC,OAAD;EAAK,WAAU;EACZ,UAAA,MAAM;CACJ,CAAA;CAQT,MAAM,OAAO,MAAM,OAAO,SAAS,UAAU,MAAM,WAAW;CAE9D,MAAM,cAAc,WAClB,KAAK,QAAQ,QAAQ,kBAAkB,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC;CAEhE,OACE,oBAAC,OAAD;EAAK,WAAW,GAAG,0BAA0B,MAAM,SAAS;EAC1D,UAAA,qBAAC,OAAD,EAAA,UAAA,CAOE,oBAAC,aAAD;GAAa,WAAU;GACrB,UAAA,qBAAC,UAAD;IAAU,WAAU;IAApB,UAAA,CACE,oBAAC,WAAD;KAAW,WAAU;KAClB,UAAA,MAAM;IACE,CAAA,GACV,MAAM,QAAQ,KAAK,WAAW;KAC7B,MAAM,OAAO,WAAW,MAAM;KAE9B,OACE,oBAAC,WAAD;MAEE,WAAU;MAEV,UAAA,qBAAC,OAAD;OAAK,WAAU;OAAf,UAAA;QACE,oBAAC,QAAD;SAAM,WAAU;SAAe,UAAA,OAAO;QAAY,CAAA;QAMlD,qBAAC,QAAD;SAAM,WAAU;SAAhB,UAAA;UACG,OAAO,cAAc,qBAAA,UAAA,EAAA,UAAA,CAAG,OAAO,aAAY,KAAK,EAAA,CAAA,IAAI;UACpD;UAAK;UAAE,KAAK;SACT;;QAKN,oBAAC,OAAD;SACE,eAAA;SACA,WAAU;SAEV,UAAA,oBAAC,OAAD;UACE,WAAU;UACV,OAAO,EACL,OAAO,GAAG,KAAK,WAAW,IAAI,IAAK,OAAO,KAAK,SAAU,IAAI,GAC/D;SACD,CAAA;QACE,CAAA;OACF;;KACI,GA9BJ,OAAO,GA8BH;IAEf,CAAC,CACO;;EACC,CAAA,GACb,oBAAC,WAAD,EAAA,UACG,MAAM,OAAO,KAAK,UACjB,oBAAC,2BAAD;GAES;GACP,SAAS,MAAM;GACf,UAAU,MAAM,aAAa;GACpB;GACD;EACT,GANM,MAAM,GAMZ,CACF,EACQ,CAAA,CACN,EAAA,CAAA;CACJ,CAAA;AAET"}
|
|
1
|
+
{"version":3,"file":"PermissionMatrix.js","names":[],"sources":["../../src/table/PermissionMatrix.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\n\nimport {\n Table,\n TableBody,\n TableHead,\n TableHeader,\n TableRow,\n} from \"../core/Table.tsx\";\nimport { cn } from \"../core/utils.ts\";\nimport type { IconComponent } from \"../form/iconHint.tsx\";\nimport {\n PermissionMatrixGroupRows,\n permissionChecked,\n} from \"./PermissionMatrixGroupRows.tsx\";\n\nexport interface PermissionMatrixProps {\n /**\n * The rows, already grouped and already filtered.\n *\n * ⚠️ **Filtering is the caller's job.** Lore hides the permissions of a\n * capability that is switched off; another app may have no capability concept\n * and show all of its groups. A `capabilities` prop here would be a\n * Lore-shaped idea that every other consumer passes `undefined` to forever,\n * so this component renders the groups it is handed and asks nothing about\n * where they came from.\n */\n groups: PermissionMatrixGroup[];\n\n /**\n * The columns, left to right. One per rank.\n */\n columns: PermissionMatrixColumn[];\n\n /**\n * What each column currently grants, keyed by {@link PermissionMatrixColumn.key}.\n *\n * A column missing from the record grants nothing, which is the same thing\n * as an empty array - a caller building this from a server response does not\n * have to fill in the ranks that hold no permission.\n */\n value: Record<string, readonly string[]>;\n\n /**\n * Called with the WHOLE record on every tick, not with a delta.\n *\n * The caller owns the save, so the module's refusals (\"that set is wider\n * than your own\") arrive as ordinary form errors on the page rather than as\n * a state this component would have to model.\n */\n onChange: (next: Record<string, string[]>) => void;\n\n /**\n * Header above the permission column. A label, not a placeholder: the\n * component carries no copy of its own.\n */\n header?: ReactNode;\n\n /**\n * Shown in place of the table when {@link groups} is empty - every\n * capability off, or a filter that matched nothing.\n */\n empty?: ReactNode;\n\n /**\n * Turns every cell off, on top of whatever the columns and rows say.\n * A save in flight, or a reader who may look and not edit.\n */\n disabled?: boolean;\n\n className?: string;\n}\n\n/**\n * Who may do what, as a table: permissions down the left, one column per rank,\n * a checkbox at each crossing.\n *\n * It lives here rather than in either application because two of them need the\n * same table. Lore renders it for a project's ranks; another app renders it\n * for its own. What differs between them is entirely in the props.\n *\n * ## What the component deliberately does not know\n *\n * **It does not know what an owner is.** A column that must read all-on and\n * refuse edits is marked `readOnly` by the caller. Teaching the table about\n * ownership would put an application's model inside a component that two\n * applications with different models both use.\n *\n * **It does not know what a capability is.** See {@link PermissionMatrixProps.groups}.\n *\n * **It carries no copy.** Every label is a `ReactNode` the caller supplies,\n * already translated, so an application whose only locale is French renders a\n * French matrix without this package shipping a catalogue.\n *\n * ## The two kinds of locked row\n *\n * A permission can be non-negotiable in either direction, and both are common\n * enough to be data rather than a caller's own rendering:\n *\n * - `lock: \"on\"` is a **floor** - the permission every rank holds, so the row\n * is checked everywhere and cannot be unticked (Lore's `project:read`: a\n * member who cannot read the project is not a member).\n * - `lock: \"off\"` is a **ceiling** - the permission no rank may be granted, so\n * the row is unchecked everywhere and cannot be ticked (Lore's\n * `project:delete`, which belongs to ownership and is transferred rather\n * than granted).\n *\n * A `readOnly` column beats both: an owner column reads all-on including the\n * ceiling rows, because the ceiling describes what may be GRANTED, not what\n * the owner has.\n */\nexport const PermissionMatrix = (props: PermissionMatrixProps) => {\n const granted = (columnKey: string, permission: string): boolean =>\n (props.value[columnKey] ?? []).includes(permission);\n\n const toggle = (\n columnKey: string,\n permission: string,\n next: boolean,\n ): void => {\n const held = props.value[columnKey] ?? [];\n const without = held.filter((it) => it !== permission);\n\n props.onChange({\n // Every column, not only the one that moved: the caller saves a record\n // and a partial one would silently drop the ranks nobody touched.\n ...Object.fromEntries(\n Object.entries(props.value).map(([key, list]) => [key, [...list]]),\n ),\n [columnKey]: next ? [...without, permission] : without,\n });\n };\n\n if (props.groups.length === 0) {\n return (\n <div className=\"text-muted-foreground p-6 text-center text-sm\">\n {props.empty}\n </div>\n );\n }\n\n // Every row in the table, in order, so a column's coverage is counted over\n // the same set the reader can see. Filtering is the caller's job, so a group\n // that is switched off is not in `groups` and correctly does not count\n // against the ratio.\n const rows = props.groups.flatMap((group) => group.permissions);\n\n const coverageOf = (column: PermissionMatrixColumn): number =>\n rows.filter((row) => permissionChecked(column, row, granted)).length;\n\n return (\n <div className={cn(\"w-full overflow-x-auto\", props.className)}>\n <Table>\n {/* The chrome surface, sticky, so a long matrix keeps its rank names\n while it scrolls. `bg-muted` fully opaque and the two inset lines\n are the same pair `DataTable`'s header wears, and for the same\n reasons: a translucent header lets rows scroll through the labels,\n and a border on a sticky `<thead>` is dropped by the collapsed\n border model. */}\n <TableHeader className=\"bg-muted sticky top-0 z-10 shadow-[inset_0_1px_0_0_var(--bevel),inset_0_-1px_0_0_var(--border)]\">\n <TableRow className=\"hover:bg-transparent\">\n <TableHead className=\"min-w-56 align-bottom\">\n {props.header}\n </TableHead>\n {props.columns.map((column) => {\n const held = coverageOf(column);\n\n return (\n <TableHead\n key={column.key}\n className=\"border-border/60 h-auto min-w-36 border-l py-2 text-center align-bottom\"\n >\n <div className=\"flex flex-col items-center gap-1\">\n <span className=\"font-medium\">{column.label}</span>\n {/* The caller's own line and the ratio share one row.\n The ratio is a count, not copy, which is what lets this\n component print it while still shipping no strings:\n `description` carries whatever the application wants\n said (\"1 membre\"), and the separator is punctuation. */}\n <span className=\"text-muted-foreground text-xs font-normal\">\n {column.description ? <>{column.description} · </> : null}\n {held}/{rows.length}\n </span>\n {/* Decorative, and `aria-hidden` for it: the ratio above\n is the same fact in text, and four `role=\"progressbar\"`\n elements announcing a number already read out is noise,\n not access. */}\n <div\n aria-hidden\n className=\"bg-foreground/10 h-1 w-16 overflow-hidden rounded-full\"\n >\n <div\n className=\"bg-primary h-full rounded-full transition-[width]\"\n style={{\n width: `${rows.length === 0 ? 0 : (held / rows.length) * 100}%`,\n }}\n />\n </div>\n </div>\n </TableHead>\n );\n })}\n </TableRow>\n </TableHeader>\n <TableBody>\n {props.groups.map((group) => (\n <PermissionMatrixGroupRows\n key={group.key}\n group={group}\n columns={props.columns}\n disabled={props.disabled === true}\n granted={granted}\n toggle={toggle}\n />\n ))}\n </TableBody>\n </Table>\n </div>\n );\n};\n\nexport interface PermissionMatrixGroup {\n /**\n * Stable identity for the group. Never rendered: {@link label} is.\n */\n key: string;\n\n label: ReactNode;\n\n /**\n * Shown before the label on the heading row. A subject is quicker to find\n * again by its mark than by re-reading four uppercase words, and the heading\n * row is the only thing a reader scans past on the way down a long matrix.\n *\n * Optional, and a group without one simply starts at its label - the heading\n * does not reserve the space, so a matrix that gives icons to none of its\n * groups looks deliberate rather than short of something.\n */\n icon?: IconComponent;\n\n permissions: PermissionMatrixRow[];\n}\n\nexport interface PermissionMatrixRow {\n /**\n * The permission as it is stored and sent, e.g. `quest:create`. This is the\n * value that lands in {@link PermissionMatrixProps.value}.\n */\n name: string;\n\n label: ReactNode;\n\n /**\n * Supplementary prose, shown as a tooltip on the label rather than as a\n * line of its own: the line under the label is the permission's stored name,\n * which every row has, and a third line would loosen the whole table for the\n * few rows that carry one.\n */\n description?: ReactNode;\n\n /**\n * Pins this row in one state on every column. See the component's doc for\n * why a floor and a ceiling are both worth expressing.\n */\n lock?: \"on\" | \"off\";\n}\n\nexport interface PermissionMatrixColumn {\n /**\n * The key this column's grants are stored under in\n * {@link PermissionMatrixProps.value}. A rank key, for both consumers.\n */\n key: string;\n\n label: ReactNode;\n\n description?: ReactNode;\n\n /**\n * All-on and not editable.\n *\n * The caller marks it; the component does not know what an owner is, or that\n * such a column exists at all until it is handed one.\n */\n readOnly?: boolean;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+GA,MAAa,oBAAoB,UAAiC;CAChE,MAAM,WAAW,WAAmB,gBACjC,MAAM,MAAM,cAAc,CAAC,EAAA,CAAG,SAAS,UAAU;CAEpD,MAAM,UACJ,WACA,YACA,SACS;EAET,MAAM,WADO,MAAM,MAAM,cAAc,CAAC,EAAA,CACnB,QAAQ,OAAO,OAAO,UAAU;EAErD,MAAM,SAAS;GAGb,GAAG,OAAO,YACR,OAAO,QAAQ,MAAM,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,UAAU,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CACnE;IACC,YAAY,OAAO,CAAC,GAAG,SAAS,UAAU,IAAI;EACjD,CAAC;CACH;CAEA,IAAI,MAAM,OAAO,WAAW,GAC1B,OACE,oBAAC,OAAD;EAAK,WAAU;EACZ,UAAA,MAAM;CACJ,CAAA;CAQT,MAAM,OAAO,MAAM,OAAO,SAAS,UAAU,MAAM,WAAW;CAE9D,MAAM,cAAc,WAClB,KAAK,QAAQ,QAAQ,kBAAkB,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC;CAEhE,OACE,oBAAC,OAAD;EAAK,WAAW,GAAG,0BAA0B,MAAM,SAAS;EAC1D,UAAA,qBAAC,OAAD,EAAA,UAAA,CAOE,oBAAC,aAAD;GAAa,WAAU;GACrB,UAAA,qBAAC,UAAD;IAAU,WAAU;IAApB,UAAA,CACE,oBAAC,WAAD;KAAW,WAAU;KAClB,UAAA,MAAM;IACE,CAAA,GACV,MAAM,QAAQ,KAAK,WAAW;KAC7B,MAAM,OAAO,WAAW,MAAM;KAE9B,OACE,oBAAC,WAAD;MAEE,WAAU;MAEV,UAAA,qBAAC,OAAD;OAAK,WAAU;OAAf,UAAA;QACE,oBAAC,QAAD;SAAM,WAAU;SAAe,UAAA,OAAO;QAAY,CAAA;QAMlD,qBAAC,QAAD;SAAM,WAAU;SAAhB,UAAA;UACG,OAAO,cAAc,qBAAA,UAAA,EAAA,UAAA,CAAG,OAAO,aAAY,KAAK,EAAA,CAAA,IAAI;UACpD;UAAK;UAAE,KAAK;SACT;;QAKN,oBAAC,OAAD;SACE,eAAA;SACA,WAAU;SAEV,UAAA,oBAAC,OAAD;UACE,WAAU;UACV,OAAO,EACL,OAAO,GAAG,KAAK,WAAW,IAAI,IAAK,OAAO,KAAK,SAAU,IAAI,GAC/D;SACD,CAAA;QACE,CAAA;OACF;;KACI,GA9BJ,OAAO,GA8BH;IAEf,CAAC,CACO;;EACC,CAAA,GACb,oBAAC,WAAD,EAAA,UACG,MAAM,OAAO,KAAK,UACjB,oBAAC,2BAAD;GAES;GACP,SAAS,MAAM;GACf,UAAU,MAAM,aAAa;GACpB;GACD;EACT,GANM,MAAM,GAMZ,CACF,EACQ,CAAA,CACN,EAAA,CAAA;CACJ,CAAA;AAET"}
|
|
@@ -87,6 +87,37 @@ export interface DataTableBaseProps<T, F extends DataTableFilterFields = DataTab
|
|
|
87
87
|
* a size the reader stored before the picker went is not restored.
|
|
88
88
|
*/
|
|
89
89
|
pageSizes?: number[];
|
|
90
|
+
/**
|
|
91
|
+
* `false` shows every row on one page, with no footer: no size picker and
|
|
92
|
+
* no pager. For a short list a reader wants whole, such as an app's
|
|
93
|
+
* environment variables, where "page 1 of 1" is noise and a twenty-first
|
|
94
|
+
* row on a second page is a row nobody finds.
|
|
95
|
+
*
|
|
96
|
+
* ⚠️ Static `data` only. A `fetch` table is paged by the server, so it
|
|
97
|
+
* keeps its footer whatever this says: hiding it would hide rows.
|
|
98
|
+
*
|
|
99
|
+
* @default true
|
|
100
|
+
*/
|
|
101
|
+
pagination?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Shade every other row, for a wide table whose rows are hard to follow
|
|
104
|
+
* across.
|
|
105
|
+
*
|
|
106
|
+
* @default false
|
|
107
|
+
*/
|
|
108
|
+
striped?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* How `rowActions` render: `"menu"`, a three-dots menu at the end of the
|
|
111
|
+
* row, or `"inline"`, one outlined icon button per action, named by a
|
|
112
|
+
* tooltip and red when `destructive`.
|
|
113
|
+
*
|
|
114
|
+
* Inline suits a row with two or three actions the reader uses often
|
|
115
|
+
* (edit, remove); past that the row turns into a toolbar. A group still
|
|
116
|
+
* opens a menu, after the buttons.
|
|
117
|
+
*
|
|
118
|
+
* @default "menu"
|
|
119
|
+
*/
|
|
120
|
+
rowActionsDisplay?: "menu" | "inline";
|
|
90
121
|
/**
|
|
91
122
|
* Stable row identifier. Defaults to `item.id`.
|
|
92
123
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataTableBaseProps.d.ts","sourceRoot":"","sources":["../../src/table/dataTableBaseProps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,SAAS,EACT,cAAc,EACd,SAAS,EACT,W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,CAAC;IACnC;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAE,mBAAmB,CAAC;IACnC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB;;;OAGG;IACH,WAAW,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IAC/B;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,KAAK,IAAI,CAAC;IAChD;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B"}
|
|
@@ -5,6 +5,7 @@ import type { BadgeTone } from "../core/Badge.tsx";
|
|
|
5
5
|
import type { ControlProps } from "../form/Control.tsx";
|
|
6
6
|
import type { SelectOption } from "../form/ControlSelect.tsx";
|
|
7
7
|
import type { DataTableFilterOperatorOption, DataTableFilterOperatorPreset, DataTableFilterOperatorValue } from "./DataTableFilterOperator.tsx";
|
|
8
|
+
import type { OptimisticRows } from "./useOptimisticRows.ts";
|
|
8
9
|
type IconType = ComponentType<SVGProps<SVGSVGElement>>;
|
|
9
10
|
/**
|
|
10
11
|
* What a cell may know about its table beyond its own row: the second
|
|
@@ -79,9 +80,20 @@ export interface ColumnDef<T> {
|
|
|
79
80
|
* A row deleted from its own menu may be ticked, and a selection that
|
|
80
81
|
* survives the delete points at a row that no longer exists.
|
|
81
82
|
*/
|
|
82
|
-
export interface RowActionContext {
|
|
83
|
+
export interface RowActionContext<T = any> {
|
|
84
|
+
/**
|
|
85
|
+
* Back to page one and fetch: what a filter change does.
|
|
86
|
+
*/
|
|
83
87
|
refresh: () => void;
|
|
88
|
+
/**
|
|
89
|
+
* Fetch the page again where the reader is, rows kept on screen meanwhile.
|
|
90
|
+
*/
|
|
91
|
+
reload: () => void;
|
|
84
92
|
clearSelection: () => void;
|
|
93
|
+
/**
|
|
94
|
+
* Change rows on screen before the server answers. See `OptimisticRows`.
|
|
95
|
+
*/
|
|
96
|
+
optimistic: OptimisticRows<T>;
|
|
85
97
|
}
|
|
86
98
|
export interface RowAction<T> {
|
|
87
99
|
label: string;
|
|
@@ -128,9 +140,11 @@ export type RowActionEntry<T> = RowAction<T> | RowActionGroup<T>;
|
|
|
128
140
|
* Context passed to every bulk-action `onClick`. `clearSelection()`
|
|
129
141
|
* empties the checkbox set; `refresh()` re-fires the current fetch.
|
|
130
142
|
*/
|
|
131
|
-
export interface BulkActionContext {
|
|
143
|
+
export interface BulkActionContext<T = any> {
|
|
132
144
|
refresh: () => void;
|
|
145
|
+
reload: () => void;
|
|
133
146
|
clearSelection: () => void;
|
|
147
|
+
optimistic: OptimisticRows<T>;
|
|
134
148
|
}
|
|
135
149
|
/**
|
|
136
150
|
* A bulk action that is a button: one click, one handler over the selection.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataTableTypes.d.ts","sourceRoot":"","sources":["../../src/table/dataTableTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,IAAI,EACJ,OAAO,EACP,WAAW,EACX,SAAS,EACT,KAAK,EACN,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEhE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAC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face UseDataTableDataOptions<T> {
|
|
|
30
30
|
export declare const useDataTableData: <T>(options: UseDataTableDataOptions<T>) => {
|
|
31
31
|
page: number;
|
|
32
32
|
setPage: Dispatch<SetStateAction<number>>;
|
|
33
|
+
loadedRequestId: number;
|
|
34
|
+
lastRequestId: () => number;
|
|
35
|
+
isStatic: boolean;
|
|
33
36
|
sizeForm: FormModel<import("zod").ZodObject<{
|
|
34
37
|
size: z.ZodNumber;
|
|
35
38
|
}, import("zod/v4/core").$strip>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDataTableData.d.ts","sourceRoot":"","sources":["../../src/table/useDataTableData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAa,KAAK,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAEjE,OAAO,EAAE,KAAK,SAAS,EAAW,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,cAAc,EAMpB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,SAAS,EACT,SAAS,EACV,MAAM,qBAAqB,CAAC;AAG7B,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACxC,KAAK,EAAE,kBAAkB,CAAC,CAAC,EAAE,qBAAqB,CAAC,GACjD,eAAe,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC;IAC5C;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1C;;;OAGG;IACH,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,WAAW,uBAAuB,CAAC,CAAC,CAAC
|
|
1
|
+
{"version":3,"file":"useDataTableData.d.ts","sourceRoot":"","sources":["../../src/table/useDataTableData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAa,KAAK,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAEjE,OAAO,EAAE,KAAK,SAAS,EAAW,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,cAAc,EAMpB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,SAAS,EACT,SAAS,EACV,MAAM,qBAAqB,CAAC;AAG7B,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACxC,KAAK,EAAE,kBAAkB,CAAC,CAAC,EAAE,qBAAqB,CAAC,GACjD,eAAe,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC;IAC5C;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1C;;;OAGG;IACH,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,WAAW,uBAAuB,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAsN5C,MAAM,OAAO,SAAS,CAAC,CAAC,CAAC;qBAsB3C,MAAM,OACN,SAAS,CAAC,CAAC,CAAC,aACN,KAAK,GAAG,MAAM,GAAG,IAAI;CAkCnC,CAAC"}
|
|
@@ -52,6 +52,7 @@ const useDataTableData = (options) => {
|
|
|
52
52
|
const [fetchedMeta, setMeta] = useState(null);
|
|
53
53
|
const [fetchedFilters, setFetchedFilters] = useState(void 0);
|
|
54
54
|
const [loading, setLoading] = useState(false);
|
|
55
|
+
const [loadedRequestId, setLoadedRequestId] = useState(0);
|
|
55
56
|
const [refreshKey, setRefreshKey] = useState(0);
|
|
56
57
|
const [isRefreshing, setIsRefreshing] = useState(false);
|
|
57
58
|
const sortParam = sort ? sort.direction === "desc" ? `-${sort.field}` : sort.field : void 0;
|
|
@@ -82,6 +83,7 @@ const useDataTableData = (options) => {
|
|
|
82
83
|
setData(res.content);
|
|
83
84
|
setMeta(res.page);
|
|
84
85
|
setFetchedFilters(sent);
|
|
86
|
+
setLoadedRequestId(request.id);
|
|
85
87
|
} catch (error) {
|
|
86
88
|
if (!isLatest()) return;
|
|
87
89
|
alepha.events.emit("react:action:error", {
|
|
@@ -118,9 +120,10 @@ const useDataTableData = (options) => {
|
|
|
118
120
|
if (!props.data) return null;
|
|
119
121
|
const sortValues = {};
|
|
120
122
|
for (const [key, column] of Object.entries(props.columns)) if (column.sortValue) sortValues[column.sortKey ?? key] = column.sortValue;
|
|
123
|
+
const unpaged = props.pagination === false;
|
|
121
124
|
return paginateLocal(props.data, {
|
|
122
|
-
page,
|
|
123
|
-
size,
|
|
125
|
+
page: unpaged ? 0 : page,
|
|
126
|
+
size: unpaged ? Math.max(props.data.length, 1) : size,
|
|
124
127
|
sort: sortParam,
|
|
125
128
|
sortValues,
|
|
126
129
|
filters: form?.currentValues,
|
|
@@ -130,6 +133,7 @@ const useDataTableData = (options) => {
|
|
|
130
133
|
props.data,
|
|
131
134
|
props.columns,
|
|
132
135
|
props.filter,
|
|
136
|
+
props.pagination,
|
|
133
137
|
page,
|
|
134
138
|
size,
|
|
135
139
|
sortParam,
|
|
@@ -188,6 +192,9 @@ const useDataTableData = (options) => {
|
|
|
188
192
|
return {
|
|
189
193
|
page,
|
|
190
194
|
setPage,
|
|
195
|
+
loadedRequestId,
|
|
196
|
+
lastRequestId: useCallback(() => latestRequest.current?.id ?? 0, []),
|
|
197
|
+
isStatic: Boolean(props.data),
|
|
191
198
|
sizeForm,
|
|
192
199
|
sort,
|
|
193
200
|
setSort,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDataTableData.js","names":[],"sources":["../../src/table/useDataTableData.ts"],"sourcesContent":["import { type Alepha, type Page, type ZObject, z } from \"alepha\";\nimport { ActionErrorPolicy } from \"alepha/react\";\nimport { type FormModel, useForm } from \"alepha/react/form\";\nimport {\n type Dispatch,\n type SetStateAction,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nimport type { DataTableBaseProps } from \"./dataTableBaseProps.ts\";\nimport { persistedSort, writePersisted } from \"./dataTablePersistence.ts\";\nimport type {\n DataTableFilterFields,\n DataTableSource,\n ColumnDef,\n SortState,\n} from \"./dataTableTypes.ts\";\nimport { paginateLocal } from \"./paginateLocal.ts\";\n\nexport interface UseDataTableDataOptions<T> {\n props: DataTableBaseProps<T, DataTableFilterFields> &\n DataTableSource<T, DataTableFilterFields>;\n /**\n * The page size and its setter. The state is declared in `DataTable`,\n * first of all its hooks; this hook changes it from the footer's picker.\n */\n size: number;\n setSize: Dispatch<SetStateAction<number>>;\n /**\n * The key the sort is persisted under, or `undefined` when the table does\n * not store it.\n */\n sortKey: string | undefined;\n form: FormModel<ZObject> | undefined;\n alepha: Alepha;\n}\n\n/**\n * The rows `DataTable` renders and the state that picks them: the page, the\n * page-size picker, the sort, and either the fetched page or the static one\n * derived from `data`.\n *\n * The setters are returned alongside the values because the refresh wiring\n * and the scope change in `DataTable` write the same state.\n */\nexport const useDataTableData = <T>(options: UseDataTableDataOptions<T>) => {\n const { props, size, setSize, sortKey, form, alepha } = options;\n\n // -- Paging / sort / data --------------------------------------------------\n\n const [page, setPage] = useState(0);\n\n /**\n * Change the page size and go back to the first page.\n *\n * The reset is the whole point: raising the size while on page 5 can put\n * the reader past the last page, which renders an empty table with no\n * visible cause. Persisted so the choice survives a reload, alongside the\n * filters, sort and columns this table already remembers.\n */\n const changeSize = (next: number) => {\n setSize(next);\n setPage(0);\n if (props.persistenceKey) {\n writePersisted(props.persistenceKey, \"size\", next);\n }\n };\n\n /**\n * The footer's page-size picker, as a form of one field.\n *\n * `Control` is form-bound and this picker is not part of any form, which is\n * why the footer stayed on a raw `<Select>` long after everything else here\n * moved. One field is the whole cost of joining, and it buys the picker the\n * same trigger, popup and keyboard handling as every other select in the\n * table. `keepDirty: false` so the re-seed below actually re-seeds: `size`\n * can move without the picker (a persisted value on mount), and a kept\n * \"edit\" would pin the trigger to a page size the table is not using.\n */\n const sizeForm = useForm({\n schema: z.object({ size: z.number() }),\n initialValues: { size },\n keepDirty: false,\n handler: async () => {},\n onChange: (_key, next) => changeSize(next as number),\n });\n\n const [sort, setSort] = useState<SortState | null>(() =>\n persistedSort(sortKey, props.defaultSort),\n );\n const [fetchedData, setData] = useState<T[]>([]);\n const [fetchedMeta, setMeta] = useState<Page<T>[\"page\"] | null>(null);\n // The filters the fetched rows answer, copied when their request left:\n // `form.currentValues` is mutated in place and already holds what the\n // reader is typing now. Read by the cells through `rowFilters`.\n const [fetchedFilters, setFetchedFilters] = useState<\n Record<string, unknown> | undefined\n >(undefined);\n const [loading, setLoading] = useState(false);\n const [refreshKey, setRefreshKey] = useState(0);\n const [isRefreshing, setIsRefreshing] = useState(false);\n\n // Alepha's pagination parser reads \"field\" as asc and \"-field\" as desc.\n // Multiple comma-separated entries are multi-column sort, so we must\n // NOT use `field,direction` syntax — that would treat \"asc\"/\"desc\" as\n // a second column name and 500 on the backend.\n const sortParam = sort\n ? sort.direction === \"desc\"\n ? `-${sort.field}`\n : sort.field\n : undefined;\n\n // Hold the latest `fetch` in a ref so it is NOT a dependency of `load`.\n // Callers pass `fetch` inline (a new function every render), and a fetcher\n // that writes a store atom the caller also subscribes to would otherwise\n // self-trigger: load → atom write → caller re-render → new `fetch` → new\n // `load` → effect re-runs → infinite loop. The ref keeps the newest closure\n // available while `load` only re-runs on actual inputs (page/size/sort/…).\n const fetchRef = useRef(props.fetch);\n fetchRef.current = props.fetch;\n\n // The newest request, so an older one that answers late cannot put its\n // rows back (#Q2517). A project switch, a filter keystroke or a refresh\n // each start one; only the last may write, and it aborts the one before.\n const latestRequest = useRef<\n { id: number; abort: AbortController } | undefined\n >(undefined);\n\n const load = useCallback(async () => {\n // Static mode owns no request. Bail before touching `loading` too, so a\n // table fed an array never flashes the skeleton over rows it already has.\n const fetcher = fetchRef.current;\n if (!fetcher) return;\n latestRequest.current?.abort.abort();\n const request = {\n id: (latestRequest.current?.id ?? 0) + 1,\n abort: new AbortController(),\n };\n latestRequest.current = request;\n const isLatest = () => latestRequest.current === request;\n setLoading(true);\n const sent = form ? { ...form.currentValues } : undefined;\n try {\n const res = await fetcher({\n page,\n size,\n sort: sortParam,\n filters: form?.currentValues,\n signal: request.abort.signal,\n });\n if (!isLatest()) return;\n setData(res.content);\n setMeta(res.page);\n setFetchedFilters(sent);\n } catch (error) {\n // A superseded request's failure (its own abort included) is nobody's\n // news: a newer one is already answering.\n if (!isLatest()) return;\n // Surface read failures through the same `react:action:error` channel\n // that useAction/useQuery use, so a mounted <ActionErrorToaster /> toasts\n // them. Keep the previous rows on screen rather than blanking the table.\n void alepha.events.emit(\"react:action:error\", {\n type: \"custom\",\n id: \"data-table:load\",\n error: error as Error,\n handled: ActionErrorPolicy.isHandled(error),\n });\n } finally {\n // Only the newest request clears `loading`: an older one finishing\n // first used to hide the spinner while the table still waited.\n if (isLatest()) {\n setLoading(false);\n }\n }\n }, [page, size, sortParam, refreshKey, form, alepha]);\n\n useEffect(() => {\n void load();\n }, [load]);\n\n /**\n * Static mode's equivalent of `load` — derived, not stored.\n *\n * Deliberately NOT routed through `load`: putting `props.data` in that\n * effect's dependencies reproduces the exact loop `fetchRef` exists to\n * prevent (load → setData → re-render → new inline array → new load).\n * Computed synchronously there is no state to go stale, an inline\n * `data={rows.filter(…)}` is safe, and a changed array is on screen in\n * the same render.\n */\n const staticPage = useMemo(() => {\n if (!props.data) return null;\n const sortValues: Record<string, (item: T) => unknown> = {};\n for (const [key, column] of Object.entries(props.columns)) {\n if (column.sortValue) {\n sortValues[column.sortKey ?? key] = column.sortValue;\n }\n }\n return paginateLocal(props.data, {\n page,\n size,\n sort: sortParam,\n sortValues,\n filters: form?.currentValues,\n filter: props.filter,\n });\n // `refreshKey` is what the filter-form subscriptions bump, so it is how\n // a filter change reaches this memo — `form.currentValues` is mutated in\n // place and its identity never changes.\n }, [\n props.data,\n props.columns,\n props.filter,\n page,\n size,\n sortParam,\n refreshKey,\n form,\n ]);\n\n const data = staticPage ? staticPage.content : fetchedData;\n const meta = staticPage ? staticPage.page : fetchedMeta;\n // Static rows are derived in this render from the current values, so those\n // ARE the filters they answer.\n const rowFilters = staticPage ? form?.currentValues : fetchedFilters;\n\n /**\n * Rows vanish under the reader in static mode: the caller detaches one and\n * the page they are on stops existing. Nothing fetches, so nothing else\n * would notice — the table would sit on an empty page with no visible\n * cause. Fetch mode has the same hole, but there the server round-trip\n * needed to see it makes this the wrong place to close it.\n */\n if (staticPage) {\n const totalPages = staticPage.page.totalPages ?? 0;\n if (page > 0 && page > totalPages - 1) {\n // Guarded on `page`, so it settles in one pass and does not need an\n // effect: the clamp lands before the rows render against a page that no\n // longer exists.\n setPage(Math.max(0, totalPages - 1));\n }\n }\n\n // Persist sort to localStorage on every change.\n useEffect(() => {\n if (!sortKey) return;\n writePersisted(sortKey, \"sort\", sort);\n }, [sortKey, sort]);\n\n // -- Sort ------------------------------------------------------------------\n\n const toggleSort = (col: string, def: ColumnDef<T>) => {\n if (!def.sortable) return;\n const field = def.sortKey ?? col;\n setSort((s) => {\n const next: SortState | null =\n !s || s.field !== field\n ? { field, direction: \"asc\" }\n : s.direction === \"asc\"\n ? { field, direction: \"desc\" }\n : null;\n props.onSortChange?.(next);\n return next;\n });\n };\n\n /**\n * Sort in a named direction, or clear it.\n *\n * The header cycles; the menu states. Both write the same state, so a\n * column sorted from the menu shows the header's own arrow.\n */\n const setSortTo = (\n col: string,\n def: ColumnDef<T>,\n direction: \"asc\" | \"desc\" | null,\n ) => {\n if (!def.sortable) return;\n const field = def.sortKey ?? col;\n const next: SortState | null = direction ? { field, direction } : null;\n setSort(next);\n props.onSortChange?.(next);\n };\n\n return {\n page,\n setPage,\n sizeForm,\n sort,\n setSort,\n data,\n meta,\n rowFilters,\n loading,\n refreshKey,\n setRefreshKey,\n isRefreshing,\n setIsRefreshing,\n toggleSort,\n setSortTo,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;AAiDA,MAAa,oBAAuB,YAAwC;CAC1E,MAAM,EAAE,OAAO,MAAM,SAAS,SAAS,MAAM,WAAW;CAIxD,MAAM,CAAC,MAAM,WAAW,SAAS,CAAC;;;;;;;;;CAUlC,MAAM,cAAc,SAAiB;EACnC,QAAQ,IAAI;EACZ,QAAQ,CAAC;EACT,IAAI,MAAM,gBACR,eAAe,MAAM,gBAAgB,QAAQ,IAAI;CAErD;;;;;;;;;;;;CAaA,MAAM,WAAW,QAAQ;EACvB,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;EACrC,eAAe,EAAE,KAAK;EACtB,WAAW;EACX,SAAS,YAAY,CAAC;EACtB,WAAW,MAAM,SAAS,WAAW,IAAc;CACrD,CAAC;CAED,MAAM,CAAC,MAAM,WAAW,eACtB,cAAc,SAAS,MAAM,WAAW,CAC1C;CACA,MAAM,CAAC,aAAa,WAAW,SAAc,CAAC,CAAC;CAC/C,MAAM,CAAC,aAAa,WAAW,SAAiC,IAAI;CAIpE,MAAM,CAAC,gBAAgB,qBAAqB,SAE1C,KAAA,CAAS;CACX,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,YAAY,iBAAiB,SAAS,CAAC;CAC9C,MAAM,CAAC,cAAc,mBAAmB,SAAS,KAAK;CAMtD,MAAM,YAAY,OACd,KAAK,cAAc,SACjB,IAAI,KA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AM;GAC/B;GACA;GACA,MAAM;GACN;GACA,SAAS,MAAM;GACf,QAAQ,MAAM;EAChB,CAAC;CAIH,GAAG;EACD,MAAM;EACN,MAAM;EACN,MAAM;EACN;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,OAAO,aAAa,WAAW,UAAU;CAC/C,MAAM,OAAO,aAAa,WAAW,OAAO;CAG5C,MAAM,aAAa,aAAa,MAAM,gBAAgB;;;;;;;;CAStD,IAAI,YAAY;EACd,MAAM,aAAa,WAAW,KAAK,cAAc;EACjD,IAAI,OAAO,KAAK,OAAO,aAAa,GAIlC,QAAQ,KAAK,IAAI,GAAG,aAAa,CAAC,CAAC;CAEvC;CAGA,gBAAgB;EACd,IAAI,CAAC,SAAS;EACd,eAAe,SAAS,QAAQ,IAAI;CACtC,GAAG,CAAC,SAAS,IAAI,CAAC;CAIlB,MAAM,cAAc,KAAa,QAAsB;EACrD,IAAI,CAAC,IAAI,UAAU;EACnB,MAAM,QAAQ,IAAI,WAAW;EAC7B,SAAS,MAAM;GACb,MAAM,OACJ,CAAC,KAAK,EAAE,UAAU,QACd;IAAE;IAAO,WAAW;GAAM,IAC1B,EAAE,cAAc,QACd;IAAE;IAAO,WAAW;GAAO,IAC3B;GACR,MAAM,eAAe,IAAI;GACzB,OAAO;EACT,CAAC;CACH;;;;;;;CAQA,MAAM,aACJ,KACA,KACA,cACG;EACH,IAAI,CAAC,IAAI,UAAU;EACnB,MAAM,QAAQ,IAAI,WAAW;EAC7B,MAAM,OAAyB,YAAY;GAAE;GAAO;EAAU,IAAI;EAClE,QAAQ,IAAI;EACZ,MAAM,eAAe,IAAI;CAC3B;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useDataTableData.js","names":[],"sources":["../../src/table/useDataTableData.ts"],"sourcesContent":["import { type Alepha, type Page, type ZObject, z } from \"alepha\";\nimport { ActionErrorPolicy } from \"alepha/react\";\nimport { type FormModel, useForm } from \"alepha/react/form\";\nimport {\n type Dispatch,\n type SetStateAction,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nimport type { DataTableBaseProps } from \"./dataTableBaseProps.ts\";\nimport { persistedSort, writePersisted } from \"./dataTablePersistence.ts\";\nimport type {\n DataTableFilterFields,\n DataTableSource,\n ColumnDef,\n SortState,\n} from \"./dataTableTypes.ts\";\nimport { paginateLocal } from \"./paginateLocal.ts\";\n\nexport interface UseDataTableDataOptions<T> {\n props: DataTableBaseProps<T, DataTableFilterFields> &\n DataTableSource<T, DataTableFilterFields>;\n /**\n * The page size and its setter. The state is declared in `DataTable`,\n * first of all its hooks; this hook changes it from the footer's picker.\n */\n size: number;\n setSize: Dispatch<SetStateAction<number>>;\n /**\n * The key the sort is persisted under, or `undefined` when the table does\n * not store it.\n */\n sortKey: string | undefined;\n form: FormModel<ZObject> | undefined;\n alepha: Alepha;\n}\n\n/**\n * The rows `DataTable` renders and the state that picks them: the page, the\n * page-size picker, the sort, and either the fetched page or the static one\n * derived from `data`.\n *\n * The setters are returned alongside the values because the refresh wiring\n * and the scope change in `DataTable` write the same state.\n */\nexport const useDataTableData = <T>(options: UseDataTableDataOptions<T>) => {\n const { props, size, setSize, sortKey, form, alepha } = options;\n\n // -- Paging / sort / data --------------------------------------------------\n\n const [page, setPage] = useState(0);\n\n /**\n * Change the page size and go back to the first page.\n *\n * The reset is the whole point: raising the size while on page 5 can put\n * the reader past the last page, which renders an empty table with no\n * visible cause. Persisted so the choice survives a reload, alongside the\n * filters, sort and columns this table already remembers.\n */\n const changeSize = (next: number) => {\n setSize(next);\n setPage(0);\n if (props.persistenceKey) {\n writePersisted(props.persistenceKey, \"size\", next);\n }\n };\n\n /**\n * The footer's page-size picker, as a form of one field.\n *\n * `Control` is form-bound and this picker is not part of any form, which is\n * why the footer stayed on a raw `<Select>` long after everything else here\n * moved. One field is the whole cost of joining, and it buys the picker the\n * same trigger, popup and keyboard handling as every other select in the\n * table. `keepDirty: false` so the re-seed below actually re-seeds: `size`\n * can move without the picker (a persisted value on mount), and a kept\n * \"edit\" would pin the trigger to a page size the table is not using.\n */\n const sizeForm = useForm({\n schema: z.object({ size: z.number() }),\n initialValues: { size },\n keepDirty: false,\n handler: async () => {},\n onChange: (_key, next) => changeSize(next as number),\n });\n\n const [sort, setSort] = useState<SortState | null>(() =>\n persistedSort(sortKey, props.defaultSort),\n );\n const [fetchedData, setData] = useState<T[]>([]);\n const [fetchedMeta, setMeta] = useState<Page<T>[\"page\"] | null>(null);\n // The filters the fetched rows answer, copied when their request left:\n // `form.currentValues` is mutated in place and already holds what the\n // reader is typing now. Read by the cells through `rowFilters`.\n const [fetchedFilters, setFetchedFilters] = useState<\n Record<string, unknown> | undefined\n >(undefined);\n const [loading, setLoading] = useState(false);\n // The id of the request whose rows are on screen. Optimistic overlays\n // (`useOptimisticRows`) wait for a request that left after the server\n // accepted their write before they let go of a row.\n const [loadedRequestId, setLoadedRequestId] = useState(0);\n const [refreshKey, setRefreshKey] = useState(0);\n const [isRefreshing, setIsRefreshing] = useState(false);\n\n // Alepha's pagination parser reads \"field\" as asc and \"-field\" as desc.\n // Multiple comma-separated entries are multi-column sort, so we must\n // NOT use `field,direction` syntax — that would treat \"asc\"/\"desc\" as\n // a second column name and 500 on the backend.\n const sortParam = sort\n ? sort.direction === \"desc\"\n ? `-${sort.field}`\n : sort.field\n : undefined;\n\n // Hold the latest `fetch` in a ref so it is NOT a dependency of `load`.\n // Callers pass `fetch` inline (a new function every render), and a fetcher\n // that writes a store atom the caller also subscribes to would otherwise\n // self-trigger: load → atom write → caller re-render → new `fetch` → new\n // `load` → effect re-runs → infinite loop. The ref keeps the newest closure\n // available while `load` only re-runs on actual inputs (page/size/sort/…).\n const fetchRef = useRef(props.fetch);\n fetchRef.current = props.fetch;\n\n // The newest request, so an older one that answers late cannot put its\n // rows back (#Q2517). A project switch, a filter keystroke or a refresh\n // each start one; only the last may write, and it aborts the one before.\n const latestRequest = useRef<\n { id: number; abort: AbortController } | undefined\n >(undefined);\n\n const load = useCallback(async () => {\n // Static mode owns no request. Bail before touching `loading` too, so a\n // table fed an array never flashes the skeleton over rows it already has.\n const fetcher = fetchRef.current;\n if (!fetcher) return;\n latestRequest.current?.abort.abort();\n const request = {\n id: (latestRequest.current?.id ?? 0) + 1,\n abort: new AbortController(),\n };\n latestRequest.current = request;\n const isLatest = () => latestRequest.current === request;\n setLoading(true);\n const sent = form ? { ...form.currentValues } : undefined;\n try {\n const res = await fetcher({\n page,\n size,\n sort: sortParam,\n filters: form?.currentValues,\n signal: request.abort.signal,\n });\n if (!isLatest()) return;\n setData(res.content);\n setMeta(res.page);\n setFetchedFilters(sent);\n setLoadedRequestId(request.id);\n } catch (error) {\n // A superseded request's failure (its own abort included) is nobody's\n // news: a newer one is already answering.\n if (!isLatest()) return;\n // Surface read failures through the same `react:action:error` channel\n // that useAction/useQuery use, so a mounted <ActionErrorToaster /> toasts\n // them. Keep the previous rows on screen rather than blanking the table.\n void alepha.events.emit(\"react:action:error\", {\n type: \"custom\",\n id: \"data-table:load\",\n error: error as Error,\n handled: ActionErrorPolicy.isHandled(error),\n });\n } finally {\n // Only the newest request clears `loading`: an older one finishing\n // first used to hide the spinner while the table still waited.\n if (isLatest()) {\n setLoading(false);\n }\n }\n }, [page, size, sortParam, refreshKey, form, alepha]);\n\n useEffect(() => {\n void load();\n }, [load]);\n\n /**\n * Static mode's equivalent of `load` — derived, not stored.\n *\n * Deliberately NOT routed through `load`: putting `props.data` in that\n * effect's dependencies reproduces the exact loop `fetchRef` exists to\n * prevent (load → setData → re-render → new inline array → new load).\n * Computed synchronously there is no state to go stale, an inline\n * `data={rows.filter(…)}` is safe, and a changed array is on screen in\n * the same render.\n */\n const staticPage = useMemo(() => {\n if (!props.data) return null;\n const sortValues: Record<string, (item: T) => unknown> = {};\n for (const [key, column] of Object.entries(props.columns)) {\n if (column.sortValue) {\n sortValues[column.sortKey ?? key] = column.sortValue;\n }\n }\n // `pagination={false}`: one page holding every row.\n const unpaged = props.pagination === false;\n return paginateLocal(props.data, {\n page: unpaged ? 0 : page,\n size: unpaged ? Math.max(props.data.length, 1) : size,\n sort: sortParam,\n sortValues,\n filters: form?.currentValues,\n filter: props.filter,\n });\n // `refreshKey` is what the filter-form subscriptions bump, so it is how\n // a filter change reaches this memo — `form.currentValues` is mutated in\n // place and its identity never changes.\n }, [\n props.data,\n props.columns,\n props.filter,\n props.pagination,\n page,\n size,\n sortParam,\n refreshKey,\n form,\n ]);\n\n const data = staticPage ? staticPage.content : fetchedData;\n const meta = staticPage ? staticPage.page : fetchedMeta;\n // Static rows are derived in this render from the current values, so those\n // ARE the filters they answer.\n const rowFilters = staticPage ? form?.currentValues : fetchedFilters;\n\n /**\n * Rows vanish under the reader in static mode: the caller detaches one and\n * the page they are on stops existing. Nothing fetches, so nothing else\n * would notice — the table would sit on an empty page with no visible\n * cause. Fetch mode has the same hole, but there the server round-trip\n * needed to see it makes this the wrong place to close it.\n */\n if (staticPage) {\n const totalPages = staticPage.page.totalPages ?? 0;\n if (page > 0 && page > totalPages - 1) {\n // Guarded on `page`, so it settles in one pass and does not need an\n // effect: the clamp lands before the rows render against a page that no\n // longer exists.\n setPage(Math.max(0, totalPages - 1));\n }\n }\n\n // Persist sort to localStorage on every change.\n useEffect(() => {\n if (!sortKey) return;\n writePersisted(sortKey, \"sort\", sort);\n }, [sortKey, sort]);\n\n // -- Sort ------------------------------------------------------------------\n\n const toggleSort = (col: string, def: ColumnDef<T>) => {\n if (!def.sortable) return;\n const field = def.sortKey ?? col;\n setSort((s) => {\n const next: SortState | null =\n !s || s.field !== field\n ? { field, direction: \"asc\" }\n : s.direction === \"asc\"\n ? { field, direction: \"desc\" }\n : null;\n props.onSortChange?.(next);\n return next;\n });\n };\n\n /**\n * Sort in a named direction, or clear it.\n *\n * The header cycles; the menu states. Both write the same state, so a\n * column sorted from the menu shows the header's own arrow.\n */\n const setSortTo = (\n col: string,\n def: ColumnDef<T>,\n direction: \"asc\" | \"desc\" | null,\n ) => {\n if (!def.sortable) return;\n const field = def.sortKey ?? col;\n const next: SortState | null = direction ? { field, direction } : null;\n setSort(next);\n props.onSortChange?.(next);\n };\n\n /**\n * The id the newest request carries, or the one the next will exceed.\n */\n const lastRequestId = useCallback(() => latestRequest.current?.id ?? 0, []);\n\n return {\n page,\n setPage,\n loadedRequestId,\n lastRequestId,\n isStatic: Boolean(props.data),\n sizeForm,\n sort,\n setSort,\n data,\n meta,\n rowFilters,\n loading,\n refreshKey,\n setRefreshKey,\n isRefreshing,\n setIsRefreshing,\n toggleSort,\n setSortTo,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;AAiDA,MAAa,oBAAuB,YAAwC;CAC1E,MAAM,EAAE,OAAO,MAAM,SAAS,SAAS,MAAM,WAAW;CAIxD,MAAM,CAAC,MAAM,WAAW,SAAS,CAAC;;;;;;;;;CAUlC,MAAM,cAAc,SAAiB;EACnC,QAAQ,IAAI;EACZ,QAAQ,CAAC;EACT,IAAI,MAAM,gBACR,eAAe,MAAM,gBAAgB,QAAQ,IAAI;CAErD;;;;;;;;;;;;CAaA,MAAM,WAAW,QAAQ;EACvB,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;EACrC,eAAe,EAAE,KAAK;EACtB,WAAW;EACX,SAAS,YAAY,CAAC;EACtB,WAAW,MAAM,SAAS,WAAW,IAAc;CACrD,CAAC;CAED,MAAM,CAAC,MAAM,WAAW,eACtB,cAAc,SAAS,MAAM,WAAW,CAC1C;CACA,MAAM,CAAC,aAAa,WAAW,SAAc,CAAC,CAAC;CAC/C,MAAM,CAAC,aAAa,WAAW,SAAiC,IAAI;CAIpE,MAAM,CAAC,gBAAgB,qBAAqB,SAE1C,KAAA,CAAS;CACX,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAI5C,MAAM,CAAC,iBAAiB,sBAAsB,SAAS,CAAC;CACxD,MAAM,CAAC,Y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I;EAClE,QAAQ,IAAI;EACZ,MAAM,eAAe,IAAI;CAC3B;CAOA,OAAO;EACL;EACA;EACA;EACA,eANoB,kBAAkB,cAAc,SAAS,MAAM,GAAG,CAAC,CAM3D;EACZ,UAAU,QAAQ,MAAM,IAAI;EAC5B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -41,6 +41,7 @@ export interface UseDataTableRefreshOptions<T> {
|
|
|
41
41
|
*/
|
|
42
42
|
export declare const useDataTableRefresh: <T>(options: UseDataTableRefreshOptions<T>) => {
|
|
43
43
|
refresh: () => void;
|
|
44
|
+
reload: () => void;
|
|
44
45
|
handleRefreshClick: () => void;
|
|
45
46
|
resetFilters: () => void;
|
|
46
47
|
canShare: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDataTableRefresh.d.ts","sourceRoot":"","sources":["../../src/table/useDataTableRefresh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,cAAc,EAIpB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAG7B,MAAM,WAAW,0BAA0B,CAAC,CAAC;IAC3C,KAAK,EAAE,kBAAkB,CAAC,CAAC,EAAE,qBAAqB,CAAC,GACjD,eAAe,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC;IAC5C,IAAI,EAAE,SAAS,CAAC,O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CAAC,CAAC,EAAE,qBAAqB,CAAC,GACjD,eAAe,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC;IAC5C,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IACrC;;;OAGG;IACH,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B;;;OAGG;IACH,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B;;;OAGG;IACH,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,EAAE,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1C,aAAa,EAAE,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAChD,eAAe,EAAE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;CACpD;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,WAC1B,0BAA0B,CAAC,CAAC,CAAC;;;;;;;CAqLvC,CAAC"}
|
|
@@ -17,10 +17,21 @@ const useDataTableRefresh = (options) => {
|
|
|
17
17
|
setPage(0);
|
|
18
18
|
setRefreshKey((k) => k + 1);
|
|
19
19
|
}, []);
|
|
20
|
+
/**
|
|
21
|
+
* Fetch the page again where the reader is: no jump to page one, no
|
|
22
|
+
* skeleton (the rows stay until the new ones land). What a row action
|
|
23
|
+
* wants after a write, where `refresh` is what a filter change wants.
|
|
24
|
+
*/
|
|
25
|
+
const reload = useCallback(() => {
|
|
26
|
+
setRefreshKey((k) => k + 1);
|
|
27
|
+
}, []);
|
|
28
|
+
const spinTimer = useRef(void 0);
|
|
29
|
+
useEffect(() => () => clearTimeout(spinTimer.current), []);
|
|
20
30
|
const handleRefreshClick = useCallback(() => {
|
|
21
31
|
setIsRefreshing(true);
|
|
22
32
|
refresh();
|
|
23
|
-
|
|
33
|
+
clearTimeout(spinTimer.current);
|
|
34
|
+
spinTimer.current = setTimeout(() => setIsRefreshing(false), 1e3);
|
|
24
35
|
}, [refresh]);
|
|
25
36
|
const refreshSignalRef = useRef(props.refreshSignal);
|
|
26
37
|
useEffect(() => {
|
|
@@ -126,6 +137,7 @@ const useDataTableRefresh = (options) => {
|
|
|
126
137
|
}, [props.pollMs]);
|
|
127
138
|
return {
|
|
128
139
|
refresh,
|
|
140
|
+
reload,
|
|
129
141
|
handleRefreshClick,
|
|
130
142
|
resetFilters,
|
|
131
143
|
canShare,
|