@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
package/src/table/DataTable.tsx
CHANGED
|
@@ -41,6 +41,7 @@ import { useDataTableFilterForm } from "./useDataTableFilterForm.ts";
|
|
|
41
41
|
import { useDataTableFilterVisibility } from "./useDataTableFilterVisibility.ts";
|
|
42
42
|
import { useDataTableRefresh } from "./useDataTableRefresh.ts";
|
|
43
43
|
import { useDataTableSummary } from "./useDataTableSummary.ts";
|
|
44
|
+
import { useOptimisticRows } from "./useOptimisticRows.ts";
|
|
44
45
|
import { useTableSelection } from "./useTableSelection.ts";
|
|
45
46
|
|
|
46
47
|
export type DataTableProps<
|
|
@@ -135,10 +136,13 @@ export const DataTable = <
|
|
|
135
136
|
sizeForm,
|
|
136
137
|
sort,
|
|
137
138
|
setSort,
|
|
138
|
-
data,
|
|
139
|
+
data: serverData,
|
|
139
140
|
meta,
|
|
140
141
|
rowFilters,
|
|
141
142
|
loading,
|
|
143
|
+
loadedRequestId,
|
|
144
|
+
lastRequestId,
|
|
145
|
+
isStatic,
|
|
142
146
|
refreshKey,
|
|
143
147
|
setRefreshKey,
|
|
144
148
|
isRefreshing,
|
|
@@ -154,20 +158,26 @@ export const DataTable = <
|
|
|
154
158
|
alepha,
|
|
155
159
|
});
|
|
156
160
|
|
|
157
|
-
const {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
161
|
+
const {
|
|
162
|
+
refresh,
|
|
163
|
+
reload,
|
|
164
|
+
handleRefreshClick,
|
|
165
|
+
resetFilters,
|
|
166
|
+
canShare,
|
|
167
|
+
shareFilters,
|
|
168
|
+
} = useDataTableRefresh({
|
|
169
|
+
props: untyped,
|
|
170
|
+
form,
|
|
171
|
+
filterKeys: filterDefinition?.keys ?? [],
|
|
172
|
+
resetShownFilters: filterVisibility.resetShown,
|
|
173
|
+
filtersKey,
|
|
174
|
+
alepha,
|
|
175
|
+
toast,
|
|
176
|
+
tr,
|
|
177
|
+
setPage,
|
|
178
|
+
setRefreshKey,
|
|
179
|
+
setIsRefreshing,
|
|
180
|
+
});
|
|
171
181
|
|
|
172
182
|
const summary = useDataTableSummary({
|
|
173
183
|
summary: untyped.summary,
|
|
@@ -190,19 +200,52 @@ export const DataTable = <
|
|
|
190
200
|
* Selection was broken by the same thing - `selection.has(rowKey(item))`
|
|
191
201
|
* compared against a key generated one render earlier, so it never matched.
|
|
192
202
|
*/
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
203
|
+
/**
|
|
204
|
+
* A row's key from the row alone, so a row redrawn by an optimistic patch
|
|
205
|
+
* (a new object) keeps the key of the one it replaces.
|
|
206
|
+
*/
|
|
207
|
+
const keyOf = useCallback(
|
|
208
|
+
(item: T, index: number): string => {
|
|
209
|
+
if (props.rowKey) return props.rowKey(item);
|
|
210
|
+
const id = (item as { id?: unknown })?.id;
|
|
211
|
+
// Coercion at a boundary: the value is a form/route/chart primitive
|
|
212
|
+
// whose declared type is wider than what can reach here.
|
|
213
|
+
// oxlint-disable-next-line typescript/no-base-to-string -- a coercion at a boundary, see the comment above
|
|
214
|
+
return id != null ? String(id) : `page-${page}-row-${index}`;
|
|
215
|
+
},
|
|
216
|
+
[page, props.rowKey],
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
const serverRowKeys = useMemo(
|
|
220
|
+
() => serverData.map((item, index) => keyOf(item, index)),
|
|
221
|
+
[serverData, keyOf],
|
|
204
222
|
);
|
|
205
223
|
|
|
224
|
+
// -- Optimistic overlay ----------------------------------------------------
|
|
225
|
+
|
|
226
|
+
const serverKeyByItem = useMemo(() => {
|
|
227
|
+
const map = new Map<T, string>();
|
|
228
|
+
serverData.forEach((item, index) => map.set(item, serverRowKeys[index]));
|
|
229
|
+
return map;
|
|
230
|
+
}, [serverData, serverRowKeys]);
|
|
231
|
+
|
|
232
|
+
const overlayKey = useCallback(
|
|
233
|
+
(item: T) => serverKeyByItem.get(item) ?? keyOf(item, -1),
|
|
234
|
+
[serverKeyByItem, keyOf],
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
const overlay = useOptimisticRows<T>({
|
|
238
|
+
data: serverData,
|
|
239
|
+
rowKeys: serverRowKeys,
|
|
240
|
+
rowKey: overlayKey,
|
|
241
|
+
loadedRequestId,
|
|
242
|
+
lastRequestId,
|
|
243
|
+
reload,
|
|
244
|
+
isStatic,
|
|
245
|
+
});
|
|
246
|
+
const data = overlay.data;
|
|
247
|
+
const rowKeys = overlay.rowKeys;
|
|
248
|
+
|
|
206
249
|
/**
|
|
207
250
|
* Selection asks for a key by item, not by index. Every item it can ask
|
|
208
251
|
* about is one of `data`'s, so a lookup keyed on identity covers it without
|
|
@@ -321,13 +364,13 @@ export const DataTable = <
|
|
|
321
364
|
const hasCheckbox = Boolean(props.bulkActions?.length);
|
|
322
365
|
const hasRowActions = Boolean(props.rowActions);
|
|
323
366
|
|
|
324
|
-
const rowCtx: RowActionContext = useMemo(
|
|
325
|
-
() => ({ refresh, clearSelection }),
|
|
326
|
-
[refresh, clearSelection],
|
|
367
|
+
const rowCtx: RowActionContext<T> = useMemo(
|
|
368
|
+
() => ({ refresh, reload, clearSelection, optimistic: overlay.optimistic }),
|
|
369
|
+
[refresh, reload, clearSelection, overlay.optimistic],
|
|
327
370
|
);
|
|
328
|
-
const bulkCtx: BulkActionContext = useMemo(
|
|
329
|
-
() => ({ refresh, clearSelection }),
|
|
330
|
-
[refresh, clearSelection],
|
|
371
|
+
const bulkCtx: BulkActionContext<T> = useMemo(
|
|
372
|
+
() => ({ refresh, reload, clearSelection, optimistic: overlay.optimistic }),
|
|
373
|
+
[refresh, reload, clearSelection, overlay.optimistic],
|
|
331
374
|
);
|
|
332
375
|
|
|
333
376
|
/**
|
|
@@ -412,9 +455,13 @@ export const DataTable = <
|
|
|
412
455
|
// the count beside them. A table that hid the picker (`pageSizes={[]}`)
|
|
413
456
|
// and fits on one page has neither, and "Page 1 of 1" alone is a bar
|
|
414
457
|
// saying nothing, so it goes. The links' condition is the footer's own.
|
|
458
|
+
// `pagination={false}` holds for static rows only: a fetched table is
|
|
459
|
+
// paged by the server, and hiding its pager would hide rows.
|
|
460
|
+
const unpaged = props.pagination === false && Boolean(props.data);
|
|
415
461
|
const showFooter =
|
|
416
|
-
|
|
417
|
-
|
|
462
|
+
!unpaged &&
|
|
463
|
+
((props.pageSizes ?? PAGE_SIZES).length > 0 ||
|
|
464
|
+
Boolean(meta?.totalPages && meta.totalPages > 1));
|
|
418
465
|
const showColumnPicker = !props.hideColumnPicker && allColumnKeys.length > 0;
|
|
419
466
|
const showActionsMenu = !props.hideActionsMenu;
|
|
420
467
|
|
|
@@ -584,6 +631,8 @@ export const DataTable = <
|
|
|
584
631
|
data={data}
|
|
585
632
|
cellContext={cellContext}
|
|
586
633
|
rowKeys={rowKeys}
|
|
634
|
+
leaving={overlay.leaving}
|
|
635
|
+
flash={overlay.flash}
|
|
587
636
|
loading={loading}
|
|
588
637
|
visibleCols={visibleCols}
|
|
589
638
|
hasCheckbox={hasCheckbox}
|
|
@@ -593,6 +642,8 @@ export const DataTable = <
|
|
|
593
642
|
toggleRow={toggleRow}
|
|
594
643
|
rowCtx={rowCtx}
|
|
595
644
|
rowActions={props.rowActions}
|
|
645
|
+
rowActionsDisplay={props.rowActionsDisplay}
|
|
646
|
+
striped={props.striped}
|
|
596
647
|
onRowClick={props.onRowClick}
|
|
597
648
|
onRowHover={props.onRowHover}
|
|
598
649
|
empty={props.empty}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { useI18n } from "alepha/react/i18n";
|
|
2
2
|
import { Inbox, SearchX } from "lucide-react";
|
|
3
|
-
import type
|
|
3
|
+
import { type ReactNode, useRef } from "react";
|
|
4
4
|
|
|
5
5
|
import { Checkbox } from "../core/Checkbox.tsx";
|
|
6
6
|
import { TableBody, TableCell, TableRow } from "../core/Table.tsx";
|
|
7
7
|
import { cn } from "../core/utils.ts";
|
|
8
|
+
import { DataTableRowActionsInline } from "./DataTableRowActionsInline.tsx";
|
|
8
9
|
import { DataTableRowActionsMenu } from "./DataTableRowActionsMenu.tsx";
|
|
9
10
|
import { DataTableSkeletonRows } from "./DataTableSkeletonRows.tsx";
|
|
10
11
|
import type {
|
|
@@ -14,6 +15,7 @@ import type {
|
|
|
14
15
|
RowActionContext,
|
|
15
16
|
RowActionEntry,
|
|
16
17
|
} from "./dataTableTypes.ts";
|
|
18
|
+
import { useRowMotion } from "./useRowMotion.ts";
|
|
17
19
|
|
|
18
20
|
export interface DataTableBodyProps<T> {
|
|
19
21
|
/**
|
|
@@ -26,6 +28,15 @@ export interface DataTableBodyProps<T> {
|
|
|
26
28
|
* One key per row of `data`, index for index.
|
|
27
29
|
*/
|
|
28
30
|
rowKeys: string[];
|
|
31
|
+
/**
|
|
32
|
+
* Rows an optimistic remove is taking off: drawn, inert, playing their
|
|
33
|
+
* exit.
|
|
34
|
+
*/
|
|
35
|
+
leaving?: ReadonlySet<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Rows an optimistic patch just redrew, flashed once.
|
|
38
|
+
*/
|
|
39
|
+
flash?: Set<string>;
|
|
29
40
|
loading: boolean;
|
|
30
41
|
/**
|
|
31
42
|
* The visible columns, in the reader's order.
|
|
@@ -46,6 +57,14 @@ export interface DataTableBodyProps<T> {
|
|
|
46
57
|
toggleRow: (item: T) => void;
|
|
47
58
|
rowCtx: RowActionContext;
|
|
48
59
|
rowActions?: (item: T) => RowActionEntry<T>[];
|
|
60
|
+
/**
|
|
61
|
+
* The table's `rowActionsDisplay`.
|
|
62
|
+
*/
|
|
63
|
+
rowActionsDisplay?: "menu" | "inline";
|
|
64
|
+
/**
|
|
65
|
+
* The table's `striped`.
|
|
66
|
+
*/
|
|
67
|
+
striped?: boolean;
|
|
49
68
|
onRowClick?: (item: T) => void;
|
|
50
69
|
onRowHover?: (item: T | undefined) => void;
|
|
51
70
|
empty?: ReactNode;
|
|
@@ -72,6 +91,14 @@ export const DataTableBody = <T,>(props: DataTableBodyProps<T>) => {
|
|
|
72
91
|
rowCtx,
|
|
73
92
|
} = props;
|
|
74
93
|
const { tr } = useI18n();
|
|
94
|
+
const bodyRef = useRef<HTMLTableSectionElement>(null);
|
|
95
|
+
const leaving = props.leaving ?? NO_KEYS;
|
|
96
|
+
useRowMotion({
|
|
97
|
+
body: bodyRef,
|
|
98
|
+
rowKeys,
|
|
99
|
+
leaving,
|
|
100
|
+
flash: props.flash ?? NO_FLASH,
|
|
101
|
+
});
|
|
75
102
|
|
|
76
103
|
// Which empty state applies, resolved here rather than in the JSX because
|
|
77
104
|
// the answer is one boolean and the branch is four values deep.
|
|
@@ -108,7 +135,7 @@ export const DataTableBody = <T,>(props: DataTableBodyProps<T>) => {
|
|
|
108
135
|
));
|
|
109
136
|
|
|
110
137
|
return (
|
|
111
|
-
<TableBody>
|
|
138
|
+
<TableBody ref={bodyRef}>
|
|
112
139
|
{loading && data.length === 0 ? (
|
|
113
140
|
<DataTableSkeletonRows
|
|
114
141
|
cellClassName={props.cellClassName}
|
|
@@ -162,9 +189,14 @@ export const DataTableBody = <T,>(props: DataTableBodyProps<T>) => {
|
|
|
162
189
|
data.map((item, rowIndex) => {
|
|
163
190
|
const key = rowKeys[rowIndex];
|
|
164
191
|
const isSelected = selection.has(key);
|
|
192
|
+
const isLeaving = leaving.has(key);
|
|
165
193
|
return (
|
|
166
194
|
<TableRow
|
|
167
195
|
key={key}
|
|
196
|
+
data-row-key={key}
|
|
197
|
+
data-leaving={isLeaving || undefined}
|
|
198
|
+
aria-hidden={isLeaving || undefined}
|
|
199
|
+
inert={isLeaving || undefined}
|
|
168
200
|
onClick={() => props.onRowClick?.(item)}
|
|
169
201
|
// Per row, both halves. Moving from one row to the next fires
|
|
170
202
|
// the old row's `mouseleave` BEFORE the new row's `mouseenter`,
|
|
@@ -177,6 +209,7 @@ export const DataTableBody = <T,>(props: DataTableBodyProps<T>) => {
|
|
|
177
209
|
// is also conditional, which no blanket rule could be -
|
|
178
210
|
// a row is only clickable when a handler was given.
|
|
179
211
|
props.onRowClick && "cursor-pointer",
|
|
212
|
+
props.striped && "even:bg-muted/40",
|
|
180
213
|
isSelected && "bg-muted/30",
|
|
181
214
|
)}
|
|
182
215
|
>
|
|
@@ -212,11 +245,19 @@ export const DataTableBody = <T,>(props: DataTableBodyProps<T>) => {
|
|
|
212
245
|
className={cn(props.cellClassName, "text-right")}
|
|
213
246
|
onClick={(e) => e.stopPropagation()}
|
|
214
247
|
>
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
248
|
+
{props.rowActionsDisplay === "inline" ? (
|
|
249
|
+
<DataTableRowActionsInline
|
|
250
|
+
actions={props.rowActions!(item)}
|
|
251
|
+
item={item}
|
|
252
|
+
ctx={rowCtx}
|
|
253
|
+
/>
|
|
254
|
+
) : (
|
|
255
|
+
<DataTableRowActionsMenu
|
|
256
|
+
actions={props.rowActions!(item)}
|
|
257
|
+
item={item}
|
|
258
|
+
ctx={rowCtx}
|
|
259
|
+
/>
|
|
260
|
+
)}
|
|
220
261
|
</TableCell>
|
|
221
262
|
)}
|
|
222
263
|
</TableRow>
|
|
@@ -226,3 +267,6 @@ export const DataTableBody = <T,>(props: DataTableBodyProps<T>) => {
|
|
|
226
267
|
</TableBody>
|
|
227
268
|
);
|
|
228
269
|
};
|
|
270
|
+
|
|
271
|
+
const NO_KEYS: ReadonlySet<string> = new Set();
|
|
272
|
+
const NO_FLASH = new Set<string>();
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Button } from "../core/Button.tsx";
|
|
2
|
+
import {
|
|
3
|
+
Tooltip,
|
|
4
|
+
TooltipContent,
|
|
5
|
+
TooltipProvider,
|
|
6
|
+
TooltipTrigger,
|
|
7
|
+
} from "../core/Tooltip.tsx";
|
|
8
|
+
import { DataTableRowActionsMenu } from "./DataTableRowActionsMenu.tsx";
|
|
9
|
+
import type {
|
|
10
|
+
RowAction,
|
|
11
|
+
RowActionContext,
|
|
12
|
+
RowActionEntry,
|
|
13
|
+
RowActionGroup,
|
|
14
|
+
} from "./dataTableTypes.ts";
|
|
15
|
+
|
|
16
|
+
export interface DataTableRowActionsInlineProps<T> {
|
|
17
|
+
actions: RowActionEntry<T>[];
|
|
18
|
+
item: T;
|
|
19
|
+
ctx: RowActionContext;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A row's actions as a line of icon buttons, for `rowActionsDisplay="inline"`:
|
|
24
|
+
* each one outlined, named by a tooltip from its `label`, red when it is
|
|
25
|
+
* `destructive`.
|
|
26
|
+
*
|
|
27
|
+
* A group cannot be one button, so the groups keep a three-dots menu of
|
|
28
|
+
* their own after the buttons. A `checked` entry is a toggle: its button
|
|
29
|
+
* carries `aria-pressed`.
|
|
30
|
+
*/
|
|
31
|
+
export const DataTableRowActionsInline = <T,>(
|
|
32
|
+
props: DataTableRowActionsInlineProps<T>,
|
|
33
|
+
) => {
|
|
34
|
+
const actions = props.actions.filter(
|
|
35
|
+
(entry): entry is RowAction<T> => !("children" in entry),
|
|
36
|
+
);
|
|
37
|
+
const groups = props.actions.filter(
|
|
38
|
+
(entry): entry is RowActionGroup<T> => "children" in entry,
|
|
39
|
+
);
|
|
40
|
+
if (actions.length === 0 && groups.length === 0) return null;
|
|
41
|
+
return (
|
|
42
|
+
<TooltipProvider>
|
|
43
|
+
<div className="flex items-center justify-end gap-1">
|
|
44
|
+
{actions.map((action) => {
|
|
45
|
+
const Icon = action.icon;
|
|
46
|
+
return (
|
|
47
|
+
<Tooltip key={action.label}>
|
|
48
|
+
<TooltipTrigger
|
|
49
|
+
render={
|
|
50
|
+
<Button
|
|
51
|
+
type="button"
|
|
52
|
+
variant="outlined"
|
|
53
|
+
intent={action.destructive ? "danger" : undefined}
|
|
54
|
+
size={Icon ? "icon" : "sm"}
|
|
55
|
+
aria-label={action.label}
|
|
56
|
+
aria-pressed={
|
|
57
|
+
action.checked ? action.checked(props.item) : undefined
|
|
58
|
+
}
|
|
59
|
+
disabled={action.disabled?.(props.item)}
|
|
60
|
+
onClick={() => action.onClick(props.item, props.ctx)}
|
|
61
|
+
/>
|
|
62
|
+
}
|
|
63
|
+
>
|
|
64
|
+
{Icon ? <Icon className="size-4" /> : action.label}
|
|
65
|
+
</TooltipTrigger>
|
|
66
|
+
<TooltipContent>{action.label}</TooltipContent>
|
|
67
|
+
</Tooltip>
|
|
68
|
+
);
|
|
69
|
+
})}
|
|
70
|
+
{groups.length > 0 ? (
|
|
71
|
+
<DataTableRowActionsMenu
|
|
72
|
+
actions={groups}
|
|
73
|
+
item={props.item}
|
|
74
|
+
ctx={props.ctx}
|
|
75
|
+
/>
|
|
76
|
+
) : null}
|
|
77
|
+
</div>
|
|
78
|
+
</TooltipProvider>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
@@ -19,8 +19,8 @@ export interface PermissionMatrixProps {
|
|
|
19
19
|
* The rows, already grouped and already filtered.
|
|
20
20
|
*
|
|
21
21
|
* ⚠️ **Filtering is the caller's job.** Lore hides the permissions of a
|
|
22
|
-
* capability that is switched off;
|
|
23
|
-
*
|
|
22
|
+
* capability that is switched off; another app may have no capability concept
|
|
23
|
+
* and show all of its groups. A `capabilities` prop here would be a
|
|
24
24
|
* Lore-shaped idea that every other consumer passes `undefined` to forever,
|
|
25
25
|
* so this component renders the groups it is handed and asks nothing about
|
|
26
26
|
* where they came from.
|
|
@@ -76,8 +76,8 @@ export interface PermissionMatrixProps {
|
|
|
76
76
|
* a checkbox at each crossing.
|
|
77
77
|
*
|
|
78
78
|
* It lives here rather than in either application because two of them need the
|
|
79
|
-
* same table. Lore renders it for a project's ranks;
|
|
80
|
-
*
|
|
79
|
+
* same table. Lore renders it for a project's ranks; another app renders it
|
|
80
|
+
* for its own. What differs between them is entirely in the props.
|
|
81
81
|
*
|
|
82
82
|
* ## What the component deliberately does not know
|
|
83
83
|
*
|
|
@@ -108,7 +108,7 @@ describe("DataTable (empty states)", () => {
|
|
|
108
108
|
// with a different cause.
|
|
109
109
|
await mount(
|
|
110
110
|
<DataTable<Row, typeof filterFields>
|
|
111
|
-
data={[{ id: 1, title: "
|
|
111
|
+
data={[{ id: 1, title: "venue" }]}
|
|
112
112
|
columns={columns}
|
|
113
113
|
filters={{
|
|
114
114
|
fields: filterFields,
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
2
|
+
import { Alepha } from "alepha";
|
|
3
|
+
import { AlephaContext } from "alepha/react";
|
|
4
|
+
import { AlephaReactI18n } from "alepha/react/i18n";
|
|
5
|
+
import { AlephaReactRouter } from "alepha/react/router";
|
|
6
|
+
import { setupJsdomMocks } from "alepha/testing/react";
|
|
7
|
+
import { Bot, Pencil, Trash2 } from "lucide-react";
|
|
8
|
+
import { afterEach, beforeAll, describe, expect, it } from "vitest";
|
|
9
|
+
|
|
10
|
+
import { DataTable } from "../DataTable.tsx";
|
|
11
|
+
|
|
12
|
+
interface Row {
|
|
13
|
+
id: number;
|
|
14
|
+
title: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const columns = {
|
|
18
|
+
title: { label: "Title", cell: (r: Row) => r.title },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const rows = (count: number): Row[] =>
|
|
22
|
+
Array.from({ length: count }, (_, i) => ({
|
|
23
|
+
id: i + 1,
|
|
24
|
+
title: `Row ${i + 1}`,
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A DataTable laid out as a plain list: every row on one page with no
|
|
29
|
+
* footer (`pagination={false}`), shaded rows (`striped`), and the row's
|
|
30
|
+
* actions as buttons rather than a menu (`rowActionsDisplay="inline"`).
|
|
31
|
+
*/
|
|
32
|
+
describe("DataTable (list mode)", () => {
|
|
33
|
+
let alepha: Alepha | undefined;
|
|
34
|
+
|
|
35
|
+
beforeAll(() => {
|
|
36
|
+
setupJsdomMocks();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterEach(async () => {
|
|
40
|
+
await alepha?.stop();
|
|
41
|
+
alepha = undefined;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const mount = async (ui: React.ReactNode) => {
|
|
45
|
+
alepha = Alepha.create().with(AlephaReactRouter).with(AlephaReactI18n);
|
|
46
|
+
await alepha.start();
|
|
47
|
+
return render(
|
|
48
|
+
<AlephaContext.Provider value={alepha}>{ui}</AlephaContext.Provider>,
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
describe("pagination={false}", () => {
|
|
53
|
+
it("shows every row past the default page size, and no footer", async () => {
|
|
54
|
+
await mount(
|
|
55
|
+
<DataTable<Row> data={rows(45)} columns={columns} pagination={false} />,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
await waitFor(() => expect(screen.getByText("Row 45")).toBeTruthy());
|
|
59
|
+
expect(screen.getByText("Row 1")).toBeTruthy();
|
|
60
|
+
expect(screen.queryByText(/page 1 of/i)).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("pages by default, which is what it turns off", async () => {
|
|
64
|
+
await mount(<DataTable<Row> data={rows(45)} columns={columns} />);
|
|
65
|
+
|
|
66
|
+
await waitFor(() => expect(screen.getByText("Row 1")).toBeTruthy());
|
|
67
|
+
expect(screen.queryByText("Row 45")).toBeNull();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe("striped", () => {
|
|
72
|
+
it("shades every other row only when asked", async () => {
|
|
73
|
+
const { container, rerender } = await mount(
|
|
74
|
+
<DataTable<Row> data={rows(3)} columns={columns} striped />,
|
|
75
|
+
);
|
|
76
|
+
await waitFor(() => expect(screen.getByText("Row 3")).toBeTruthy());
|
|
77
|
+
const shaded = () =>
|
|
78
|
+
container.querySelectorAll("tbody tr[class*='even:bg-muted']").length;
|
|
79
|
+
expect(shaded()).toBe(3);
|
|
80
|
+
|
|
81
|
+
rerender(
|
|
82
|
+
<AlephaContext.Provider value={alepha!}>
|
|
83
|
+
<DataTable<Row> data={rows(3)} columns={columns} />
|
|
84
|
+
</AlephaContext.Provider>,
|
|
85
|
+
);
|
|
86
|
+
expect(shaded()).toBe(0);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('rowActionsDisplay="inline"', () => {
|
|
91
|
+
it("renders each action as a named button that runs it, with no menu", async () => {
|
|
92
|
+
const clicked: string[] = [];
|
|
93
|
+
await mount(
|
|
94
|
+
<DataTable<Row>
|
|
95
|
+
data={rows(1)}
|
|
96
|
+
columns={columns}
|
|
97
|
+
rowActionsDisplay="inline"
|
|
98
|
+
rowActions={() => [
|
|
99
|
+
{
|
|
100
|
+
label: "Edit",
|
|
101
|
+
icon: Pencil,
|
|
102
|
+
onClick: (row) => clicked.push(`edit ${row.title}`),
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
label: "Remove",
|
|
106
|
+
icon: Trash2,
|
|
107
|
+
destructive: true,
|
|
108
|
+
onClick: (row) => clicked.push(`remove ${row.title}`),
|
|
109
|
+
},
|
|
110
|
+
]}
|
|
111
|
+
/>,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const edit = await waitFor(() =>
|
|
115
|
+
screen.getByRole("button", { name: "Edit" }),
|
|
116
|
+
);
|
|
117
|
+
fireEvent.click(edit);
|
|
118
|
+
fireEvent.click(screen.getByRole("button", { name: "Remove" }));
|
|
119
|
+
|
|
120
|
+
expect(clicked).toEqual(["edit Row 1", "remove Row 1"]);
|
|
121
|
+
expect(
|
|
122
|
+
screen.queryByRole("button", { name: "Open row actions" }),
|
|
123
|
+
).toBeNull();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("keeps a menu for a group, after the buttons", async () => {
|
|
127
|
+
await mount(
|
|
128
|
+
<DataTable<Row>
|
|
129
|
+
data={rows(1)}
|
|
130
|
+
columns={columns}
|
|
131
|
+
rowActionsDisplay="inline"
|
|
132
|
+
rowActions={() => [
|
|
133
|
+
{ label: "Edit", icon: Pencil, onClick: () => {} },
|
|
134
|
+
{
|
|
135
|
+
label: "Agents",
|
|
136
|
+
icon: Bot,
|
|
137
|
+
children: [{ label: "Run", onClick: () => {} }],
|
|
138
|
+
},
|
|
139
|
+
]}
|
|
140
|
+
/>,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
await waitFor(() =>
|
|
144
|
+
expect(screen.getByRole("button", { name: "Edit" })).toBeTruthy(),
|
|
145
|
+
);
|
|
146
|
+
expect(
|
|
147
|
+
screen.getByRole("button", { name: "Open row actions" }),
|
|
148
|
+
).toBeTruthy();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("disables an action its row refuses", async () => {
|
|
152
|
+
await mount(
|
|
153
|
+
<DataTable<Row>
|
|
154
|
+
data={rows(1)}
|
|
155
|
+
columns={columns}
|
|
156
|
+
rowActionsDisplay="inline"
|
|
157
|
+
rowActions={() => [
|
|
158
|
+
{
|
|
159
|
+
label: "Edit",
|
|
160
|
+
icon: Pencil,
|
|
161
|
+
disabled: () => true,
|
|
162
|
+
onClick: () => {},
|
|
163
|
+
},
|
|
164
|
+
]}
|
|
165
|
+
/>,
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
const edit = await waitFor(() =>
|
|
169
|
+
screen.getByRole("button", { name: "Edit" }),
|
|
170
|
+
);
|
|
171
|
+
expect((edit as HTMLButtonElement).disabled).toBe(true);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
});
|