@cratis/components 4.29.1 → 4.31.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/compat-manifest.json +11 -11
- package/dist/esm/CommandForm/AutoCommandForm.d.ts +2 -1
- package/dist/esm/CommandForm/AutoCommandForm.d.ts.map +1 -1
- package/dist/esm/CommandForm/AutoCommandForm.js +9 -1
- package/dist/esm/CommandForm/AutoCommandForm.js.map +1 -1
- package/dist/esm/CommandForm/fields/GuidField.d.ts +49 -0
- package/dist/esm/CommandForm/fields/GuidField.d.ts.map +1 -0
- package/dist/esm/CommandForm/fields/GuidField.js +85 -0
- package/dist/esm/CommandForm/fields/GuidField.js.map +1 -0
- package/dist/esm/CommandForm/fields/index.d.ts +1 -0
- package/dist/esm/CommandForm/fields/index.d.ts.map +1 -1
- package/dist/esm/CommandForm/fields/index.js +1 -0
- package/dist/esm/CommandForm/fields/index.js.map +1 -1
- package/dist/esm/CommandForm/index.js +1 -0
- package/dist/esm/CommandForm/index.js.map +1 -1
- package/dist/esm/DataPage/DataPage.d.ts +7 -0
- package/dist/esm/DataPage/DataPage.d.ts.map +1 -1
- package/dist/esm/DataPage/DataPage.js.map +1 -1
- package/dist/esm/DataTables/DataTableForObservableQuery.d.ts +7 -0
- package/dist/esm/DataTables/DataTableForObservableQuery.d.ts.map +1 -1
- package/dist/esm/DataTables/DataTableForObservableQuery.js +4 -2
- package/dist/esm/DataTables/DataTableForObservableQuery.js.map +1 -1
- package/dist/esm/DataTables/DataTableForQuery.d.ts +8 -1
- package/dist/esm/DataTables/DataTableForQuery.d.ts.map +1 -1
- package/dist/esm/DataTables/DataTableForQuery.js +9 -3
- package/dist/esm/DataTables/DataTableForQuery.js.map +1 -1
- package/dist/esm/DataTables/DataTableServerQuery.d.ts +38 -0
- package/dist/esm/DataTables/DataTableServerQuery.d.ts.map +1 -0
- package/dist/esm/DataTables/DataTableServerQuery.js +4 -0
- package/dist/esm/DataTables/DataTableServerQuery.js.map +1 -0
- package/dist/esm/DataTables/DataTableServerQueryState.d.ts +9 -0
- package/dist/esm/DataTables/DataTableServerQueryState.d.ts.map +1 -0
- package/dist/esm/DataTables/DataTableServerQueryState.js +4 -0
- package/dist/esm/DataTables/DataTableServerQueryState.js.map +1 -0
- package/dist/esm/DataTables/hasRequiredArguments.d.ts +9 -0
- package/dist/esm/DataTables/hasRequiredArguments.d.ts.map +1 -0
- package/dist/esm/DataTables/hasRequiredArguments.js +7 -0
- package/dist/esm/DataTables/hasRequiredArguments.js.map +1 -0
- package/dist/esm/DataTables/index.d.ts +2 -0
- package/dist/esm/DataTables/index.d.ts.map +1 -1
- package/dist/esm/DataTables/index.js +1 -0
- package/dist/esm/DataTables/index.js.map +1 -1
- package/dist/esm/DataTables/resolveDataTableStatus.d.ts +2 -7
- package/dist/esm/DataTables/resolveDataTableStatus.d.ts.map +1 -1
- package/dist/esm/DataTables/resolveDataTableStatus.js.map +1 -1
- package/dist/esm/DataTables/useServerQuery.d.ts +32 -0
- package/dist/esm/DataTables/useServerQuery.d.ts.map +1 -0
- package/dist/esm/DataTables/useServerQuery.js +67 -0
- package/dist/esm/DataTables/useServerQuery.js.map +1 -0
- package/dist/esm/QueryStatus/resolveQueryStatus.d.ts +10 -3
- package/dist/esm/QueryStatus/resolveQueryStatus.d.ts.map +1 -1
- package/dist/esm/QueryStatus/resolveQueryStatus.js +2 -0
- package/dist/esm/QueryStatus/resolveQueryStatus.js.map +1 -1
- package/dist/esm/types/parts.d.ts +4 -0
- package/dist/esm/types/parts.d.ts.map +1 -1
- package/dist/esm/types/parts.js +4 -0
- package/dist/esm/types/parts.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTableForObservableQuery.d.ts","sourceRoot":"","sources":["../../../DataTables/DataTableForObservableQuery.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAiB,CAAC;AACtD,OAAO,KAAK,E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AAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,uEAAuE;IACvE,SAAS,CAAC,EAAE,mBAAmB,CAAC,WAAW,CAAC,CAAC;IAE7C,uDAAuD;IACvD,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B,mDAAmD;IACnD,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAElC;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B,6EAA6E;IAC7E,mBAAmB,CAAC,EAAE,mBAAmB,CAAC,YAAY,CAAC,CAAC;CAC3D;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,2BAA2B,GACpC,MAAM,SACA,mBAAmB,CAAC,SAAS,EAAE,UAAU,CAAC,GAC1C,mBAAmB,CAAC,SAAS,EAAE,EAAE,UAAU,CAAC,EAClD,SAAS,SAAS,MAAM,EACxB,UAAU,SAAS,MAAM,SAElB,gCAAgC,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,gCA2IzE,CAAC"}
|
|
@@ -5,10 +5,12 @@ import { useRef, useState, useEffect } from 'react';
|
|
|
5
5
|
import { DataTableCore } from './DataTableCore.js';
|
|
6
6
|
import { TablePaginator } from './TablePaginator.js';
|
|
7
7
|
import { resolveDataTableStatus } from './resolveDataTableStatus.js';
|
|
8
|
+
import { useServerQuery } from './useServerQuery.js';
|
|
8
9
|
|
|
9
10
|
const paging = new Paging(0, 20);
|
|
10
11
|
const DataTableForObservableQuery = (props) => {
|
|
11
|
-
const
|
|
12
|
+
const server = useServerQuery(props.serverQuery, props.queryArguments, props.defaultFilters);
|
|
13
|
+
const [result, setSorting, setPage] = useObservableQueryWithPaging(props.query, paging, server.queryArguments);
|
|
12
14
|
const containerRef = useRef(null);
|
|
13
15
|
const [tableHeight, setTableHeight] = useState(600);
|
|
14
16
|
const timeoutRef = useRef(undefined);
|
|
@@ -56,7 +58,7 @@ const DataTableForObservableQuery = (props) => {
|
|
|
56
58
|
border: '1px solid var(--cratis-surface-border)',
|
|
57
59
|
borderRadius: 'var(--cratis-border-radius)',
|
|
58
60
|
overflow: 'hidden',
|
|
59
|
-
}, children: [jsx("div", { style: { height: `${tableHeight}px`, overflow: 'hidden' }, children: jsx(DataTableCore, { data: rows, dataKey: props.dataKey, emptyMessage: props.emptyMessage, status: status, loadingMessage: props.loadingMessage, failureMessage: props.failureMessage, unauthorizedMessage: props.unauthorizedMessage, selectionMode: props.selectionMode ?? 'single', selection: props.selection, onSelectionChange: props.onSelectionChange, selectedItems: props.selectedItems, onSelectedItemsChange: props.onSelectedItemsChange, globalFilterFields: props.globalFilterFields, globalSearchPlaceholder: props.globalSearchPlaceholder, globalSearchAriaLabel: props.globalSearchAriaLabel, defaultFilters: props.defaultFilters, scrollable: true, scrollHeight: '100%', className: props.className, style: { minWidth: '100%' }, pt: props.pt, ptOptions: props.ptOptions, unstyled: props.unstyled, children: props.children }) }), showPaginator && (jsx("div", { style: {
|
|
61
|
+
}, children: [jsx("div", { style: { height: `${tableHeight}px`, overflow: 'hidden' }, children: jsx(DataTableCore, { data: rows, dataKey: props.dataKey, emptyMessage: props.emptyMessage, status: status, loadingMessage: props.loadingMessage, failureMessage: props.failureMessage, unauthorizedMessage: props.unauthorizedMessage, selectionMode: props.selectionMode ?? 'single', selection: props.selection, onSelectionChange: props.onSelectionChange, selectedItems: props.selectedItems, onSelectedItemsChange: props.onSelectedItemsChange, globalFilterFields: props.globalFilterFields, globalSearchPlaceholder: props.globalSearchPlaceholder, globalSearchAriaLabel: props.globalSearchAriaLabel, defaultFilters: props.defaultFilters, ...server.tableProps({ setSorting, setPage }), scrollable: true, scrollHeight: '100%', className: props.className, style: { minWidth: '100%' }, pt: props.pt, ptOptions: props.ptOptions, unstyled: props.unstyled, children: props.children }) }), showPaginator && (jsx("div", { style: {
|
|
60
62
|
borderTop: '1px solid var(--cratis-surface-border)',
|
|
61
63
|
flexShrink: 0,
|
|
62
64
|
}, children: jsx(TablePaginator, { page: result.paging.page, pageCount: pageCount, onPageChange: setPage, totalItems: totalItems, pageSize: paging.pageSize, pageLinks: props.pageLinks, className: props.paginatorClassName, ariaLabels: props.paginatorAriaLabels, pt: props.paginatorPt, ptOptions: props.paginatorPtOptions }) }))] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTableForObservableQuery.js","sources":["../../../DataTables/DataTableForObservableQuery.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { DataTableParts } from './DataTableCore';\nimport type { Constructor } from '@cratis/fundamentals';\nimport { type IObservableQueryFor, Paging } from '@cratis/arc/queries';\nimport { useObservableQueryWithPaging } from '@cratis/arc.react/queries';\nimport { type ReactNode, useState, useRef, useEffect } from 'react';\nimport { DataTableCore } from './DataTableCore';\nimport {\n TablePaginator,\n type TablePaginatorParts,\n type TablePaginatorProps,\n} from './TablePaginator';\nimport type { DataTableFilterMeta } from './DataTableFilterMeta';\nimport type { DataTableSelectionChangeEvent } from './DataTableSelectionChangeEvent';\nimport { resolveDataTableStatus } from './resolveDataTableStatus';\n\n/**\n * Props for {@link DataTableForObservableQuery}.\n *\n * @typeParam TQuery - The query class implementing `IObservableQueryFor`.\n * @typeParam TDataType - The row type returned by the query.\n * @typeParam TArguments - The query's argument object type.\n */\nexport interface DataTableForObservableQueryProps<\n TQuery extends\n | IObservableQueryFor<TDataType, TArguments>\n | IObservableQueryFor<TDataType[], TArguments>,\n TDataType extends object,\n TArguments extends object,\n> {\n /**\n * Children to render — `<Column>` elements describing the visible columns.\n */\n children?: ReactNode;\n\n /**\n * The type of query to use\n */\n query: Constructor<TQuery>;\n\n /**\n * Optional arguments to pass to the query\n */\n queryArguments?: TArguments;\n\n /**\n * The message to show when there is no data\n */\n emptyMessage: string;\n\n /** Message shown while loading without rows. */\n loadingMessage?: ReactNode;\n /** Message shown when the query fails. */\n failureMessage?: ReactNode;\n /** Message shown when access is denied. */\n unauthorizedMessage?: ReactNode;\n\n /**\n * The key to use for the data\n */\n dataKey?: string | undefined;\n\n /**\n * The current selection.\n */\n selection?: TDataType | undefined | null;\n\n /**\n * Callback for when the selection changes\n */\n onSelectionChange?(event: DataTableSelectionChangeEvent<TDataType>): void;\n\n /**\n * The row selection mode. Defaults to `'single'`.\n */\n selectionMode?: 'single' | 'multiple';\n\n /**\n * The currently selected rows, for `selectionMode='multiple'`.\n */\n selectedItems?: TDataType[];\n\n /**\n * Callback for when a multiple selection changes, with the full selected set.\n */\n onSelectedItemsChange?(items: TDataType[]): void;\n\n /**\n * Fields to use for global filtering\n */\n globalFilterFields?: string[] | undefined;\n\n /** Placeholder for the loaded-page search input. */\n globalSearchPlaceholder?: string;\n\n /** Accessible name for the loaded-page search input. */\n globalSearchAriaLabel?: string;\n\n /**\n * Default filters to use\n */\n defaultFilters?: DataTableFilterMeta;\n\n /**\n * @deprecated Filtering is always applied to the currently loaded page.\n * This compatibility prop no longer toggles behavior and does not change\n * server-reported pagination totals. Retained for source compatibility only.\n */\n clientFiltering?: boolean;\n\n /**\n * Extra CSS class name forwarded to the underlying DataTable root.\n */\n className?: string;\n\n /** Cratis-owned per-part attributes applied to the underlying table. */\n pt?: DataTableParts;\n\n /**\n * @deprecated Cratis parts always merge. Remove this renderer-era option.\n */\n ptOptions?: object;\n\n /**\n * @deprecated Components always uses consumer-owned CSS. Customize through `pt` and CSS instead.\n */\n unstyled?: boolean;\n\n /** Shows numbered page buttons in the paginator. Defaults to false. */\n pageLinks?: TablePaginatorProps['pageLinks'];\n\n /** Extra CSS class name forwarded to the paginator. */\n paginatorClassName?: string;\n\n /** Cratis-owned attributes for paginator parts. */\n paginatorPt?: TablePaginatorParts;\n\n /**\n * @deprecated Cratis paginator parts always merge. Remove this renderer-era option.\n */\n paginatorPtOptions?: object;\n\n /** Accessible names for the paginator controls. Override any to localize. */\n paginatorAriaLabels?: TablePaginatorProps['ariaLabels'];\n}\n\nconst paging = new Paging(0, 20);\n\n/**\n * A paged data table bound to a real-time Cratis Arc observable query\n * (`IObservableQueryFor<TDataType, TArguments>`). Subscribes via\n * `useObservableQueryWithPaging`, so the table re-renders automatically as the\n * underlying read model changes server-side. Rows render through the semantic Cratis-owned\n * {@link DataTableCore} inside an internally-scrolling region that resizes to\n * fill its container.\n *\n * ## Children\n *\n * Children are Cratis `<Column>` elements describing the visible columns.\n *\n * ```tsx\n * import { DataTableForObservableQuery, Column } from '@cratis/components/DataTables';\n * import { AllTasks } from './AllTasks'; // observable proxy from C#\n *\n * <DataTableForObservableQuery query={AllTasks} emptyMessage=\"No tasks\">\n * <Column field=\"title\" header=\"Title\" sortable />\n * <Column field=\"assignee\" header=\"Assignee\" />\n * </DataTableForObservableQuery>\n * ```\n *\n * Use {@link DataTableForQuery} for one-shot snapshot queries. Use\n * {@link DataPage} for a higher-level layout that combines this table with\n * an action menubar, selection, and a details pane.\n *\n * @typeParam TQuery - The query class (proxy generated from C# `IObservableQueryFor`).\n * @typeParam TDataType - The row type returned by the query.\n * @typeParam TArguments - The query's argument object type.\n * @param props - {@link DataTableForObservableQueryProps}.\n */\nexport const DataTableForObservableQuery = <\n TQuery extends\n | IObservableQueryFor<TDataType, TArguments>\n | IObservableQueryFor<TDataType[], TArguments>,\n TDataType extends object,\n TArguments extends object,\n>(\n props: DataTableForObservableQueryProps<TQuery, TDataType, TArguments>,\n) => {\n // Type arguments are supplied explicitly, and the constructor is erased on the way in\n // (Cratis/Components#135). Two separate defects in `@cratis/arc.react` make the plain call\n // fail to type-check:\n //\n // 1. `useObservableQueryWithPaging<TDataType, TQuery extends IObservableQueryFor<TDataType>, …>`\n // gives `TDataType` no inference site — it appears only inside `TQuery`'s constraint — so it\n // silently falls back to `unknown` and `result` comes back as `QueryResultWithState<unknown>`.\n // 2. `ObservableQuerySubscription<T>` carries a `private _connection`, which makes it nominally\n // typed. `@cratis/arc.react` pins `@cratis/arc` to an exact version, so any consumer whose own\n // `@cratis/arc` differs by even a patch gets a second nested copy — two declarations of that\n // class, and TS2345 \"types have separate declarations of a private property\". Our peer range\n // allows multiple Arc versions, so we cannot assume a consumer's tree is deduped.\n //\n // Erasing the constructor type sidesteps the nominal comparison, and naming `TDataType`\n // explicitly recovers the row type this component is generic over — strictly better than the\n // `unknown` the inference would otherwise produce. Remove both once Arc returns an interface\n // from `subscribe()` and makes `TDataType` inferable.\n const [result, , setPage] = useObservableQueryWithPaging<\n TDataType,\n never,\n TArguments\n >(props.query as never, paging, props.queryArguments);\n const containerRef = useRef<HTMLDivElement>(null);\n const [tableHeight, setTableHeight] = useState<number>(600);\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const totalItems = result.paging.totalItems;\n const pageCount = result.paging.totalPages;\n const showPaginator = totalItems > 0 && pageCount > 1;\n\n // SAFETY: Arc observable collection queries are row-typed while runtime data is the current row array.\n const rows = result.data as unknown as TDataType[];\n const status = resolveDataTableStatus(result);\n\n useEffect(() => {\n if (!containerRef.current) return;\n\n const resizeObserver = new ResizeObserver((entries) => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n timeoutRef.current = setTimeout(() => {\n for (const entry of entries) {\n const containerHeight = entry.contentRect.height;\n if (containerHeight > 0) {\n const paginatorHeight = showPaginator ? 56 : 0;\n const calculatedHeight = containerHeight - paginatorHeight - 2;\n const newHeight = Math.max(calculatedHeight, 200);\n\n setTableHeight((prevHeight) => {\n if (Math.abs(newHeight - prevHeight) > 5) {\n return newHeight;\n }\n return prevHeight;\n });\n }\n }\n }, 10);\n });\n\n resizeObserver.observe(containerRef.current);\n\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n resizeObserver.disconnect();\n };\n }, [showPaginator]);\n\n return (\n <div\n ref={containerRef}\n style={{\n display: 'flex',\n flexDirection: 'column',\n height: '100%',\n border: '1px solid var(--cratis-surface-border)',\n borderRadius: 'var(--cratis-border-radius)',\n overflow: 'hidden',\n }}\n >\n <div style={{ height: `${tableHeight}px`, overflow: 'hidden' }}>\n <DataTableCore<TDataType>\n data={rows}\n dataKey={props.dataKey}\n emptyMessage={props.emptyMessage}\n status={status}\n loadingMessage={props.loadingMessage}\n failureMessage={props.failureMessage}\n unauthorizedMessage={props.unauthorizedMessage}\n selectionMode={props.selectionMode ?? 'single'}\n selection={props.selection}\n onSelectionChange={props.onSelectionChange}\n selectedItems={props.selectedItems}\n onSelectedItemsChange={props.onSelectedItemsChange}\n globalFilterFields={props.globalFilterFields}\n globalSearchPlaceholder={props.globalSearchPlaceholder}\n globalSearchAriaLabel={props.globalSearchAriaLabel}\n defaultFilters={props.defaultFilters}\n scrollable\n scrollHeight='100%'\n className={props.className}\n style={{ minWidth: '100%' }}\n pt={props.pt}\n ptOptions={props.ptOptions}\n unstyled={props.unstyled}\n >\n {props.children}\n </DataTableCore>\n </div>\n\n {showPaginator && (\n <div\n style={{\n borderTop: '1px solid var(--cratis-surface-border)',\n flexShrink: 0,\n }}\n >\n <TablePaginator\n page={result.paging.page}\n pageCount={pageCount}\n onPageChange={setPage}\n totalItems={totalItems}\n pageSize={paging.pageSize}\n pageLinks={props.pageLinks}\n className={props.paginatorClassName}\n ariaLabels={props.paginatorAriaLabels}\n pt={props.paginatorPt}\n ptOptions={props.paginatorPtOptions}\n />\n </div>\n )}\n </div>\n );\n};\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;AAoJA,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC;AAiCzB,MAAM,2BAA2B,GAAG,CAOvC,KAAsE,KACtE;IAkBA,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,4BAA4B,CAItD,KAAK,CAAC,KAAc,EAAE,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC;AACrD,IAAA,MAAM,YAAY,GAAG,MAAM,CAAiB,IAAI,CAAC;IACjD,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAS,GAAG,CAAC;AAC3D,IAAA,MAAM,UAAU,GAAG,MAAM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AAuB,EACtD,qBAAqB,EAAE,KAAK,CAAC,qBAAqB,EAClD,cAAc,EAAE,KAAK,CAAC,cAAc,EACpC,UAAU,EAAA,IAAA,EACV,YAAY,EAAC,MAAM,EACnB,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,EAC3B,EAAE,EAAE,KAAK,CAAC,EAAE,EACZ,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ,YAEvB,KAAK,CAAC,QAAQ,EAAA,CACH,GACd,EAEL,aAAa,KACVA,GAAA,CAAA,KAAA,EAAA,EACI,KAAK,EAAE;AACH,oBAAA,SAAS,EAAE,wCAAwC;AACnD,oBAAA,UAAU,EAAE,CAAC;AAChB,iBAAA,EAAA,QAAA,EAEDA,GAAA,CAAC,cAAc,EAAA,EACX,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EACxB,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,OAAO,EACrB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,SAAS,EAAE,KAAK,CAAC,kBAAkB,EACnC,UAAU,EAAE,KAAK,CAAC,mBAAmB,EACrC,EAAE,EAAE,KAAK,CAAC,WAAW,EACrB,SAAS,EAAE,KAAK,CAAC,kBAAkB,EAAA,CACrC,EAAA,CACA,CACT,CAAA,EAAA,CACC;AAEd;;"}
|
|
1
|
+
{"version":3,"file":"DataTableForObservableQuery.js","sources":["../../../DataTables/DataTableForObservableQuery.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { DataTableParts } from './DataTableCore';\nimport type { Constructor } from '@cratis/fundamentals';\nimport { type IObservableQueryFor, Paging } from '@cratis/arc/queries';\nimport { useObservableQueryWithPaging } from '@cratis/arc.react/queries';\nimport { type ReactNode, useState, useRef, useEffect } from 'react';\nimport { DataTableCore } from './DataTableCore';\nimport {\n TablePaginator,\n type TablePaginatorParts,\n type TablePaginatorProps,\n} from './TablePaginator';\nimport type { DataTableFilterMeta } from './DataTableFilterMeta';\nimport type { DataTableSelectionChangeEvent } from './DataTableSelectionChangeEvent';\nimport { resolveDataTableStatus } from './resolveDataTableStatus';\nimport type { DataTableServerQuery } from './DataTableServerQuery';\nimport { useServerQuery } from './useServerQuery';\n\n/**\n * Props for {@link DataTableForObservableQuery}.\n *\n * @typeParam TQuery - The query class implementing `IObservableQueryFor`.\n * @typeParam TDataType - The row type returned by the query.\n * @typeParam TArguments - The query's argument object type.\n */\nexport interface DataTableForObservableQueryProps<\n TQuery extends\n | IObservableQueryFor<TDataType, TArguments>\n | IObservableQueryFor<TDataType[], TArguments>,\n TDataType extends object,\n TArguments extends object,\n> {\n /**\n * Children to render — `<Column>` elements describing the visible columns.\n */\n children?: ReactNode;\n\n /**\n * The type of query to use\n */\n query: Constructor<TQuery>;\n\n /**\n * Optional arguments to pass to the query\n */\n queryArguments?: TArguments;\n\n /**\n * The message to show when there is no data\n */\n emptyMessage: string;\n\n /** Message shown while loading without rows. */\n loadingMessage?: ReactNode;\n /** Message shown when the query fails. */\n failureMessage?: ReactNode;\n /** Message shown when access is denied. */\n unauthorizedMessage?: ReactNode;\n\n /**\n * The key to use for the data\n */\n dataKey?: string | undefined;\n\n /**\n * The current selection.\n */\n selection?: TDataType | undefined | null;\n\n /**\n * Callback for when the selection changes\n */\n onSelectionChange?(event: DataTableSelectionChangeEvent<TDataType>): void;\n\n /**\n * The row selection mode. Defaults to `'single'`.\n */\n selectionMode?: 'single' | 'multiple';\n\n /**\n * The currently selected rows, for `selectionMode='multiple'`.\n */\n selectedItems?: TDataType[];\n\n /**\n * Callback for when a multiple selection changes, with the full selected set.\n */\n onSelectedItemsChange?(items: TDataType[]): void;\n\n /**\n * Fields to use for global filtering\n */\n globalFilterFields?: string[] | undefined;\n\n /** Placeholder for the loaded-page search input. */\n globalSearchPlaceholder?: string;\n\n /** Accessible name for the loaded-page search input. */\n globalSearchAriaLabel?: string;\n\n /**\n * Default filters to use\n */\n defaultFilters?: DataTableFilterMeta;\n\n /**\n * @deprecated Filtering is always applied to the currently loaded page.\n * This compatibility prop no longer toggles behavior and does not change\n * server-reported pagination totals. Retained for source compatibility only.\n */\n clientFiltering?: boolean;\n\n /**\n * Opts into server mode: the query sorts, filters and searches the complete result before\n * paging, and the table renders the rows as returned. Leave undefined to sort, filter and search\n * the loaded page. See {@link DataTableServerQuery}.\n */\n serverQuery?: DataTableServerQuery<TArguments>;\n\n /**\n * Extra CSS class name forwarded to the underlying DataTable root.\n */\n className?: string;\n\n /** Cratis-owned per-part attributes applied to the underlying table. */\n pt?: DataTableParts;\n\n /**\n * @deprecated Cratis parts always merge. Remove this renderer-era option.\n */\n ptOptions?: object;\n\n /**\n * @deprecated Components always uses consumer-owned CSS. Customize through `pt` and CSS instead.\n */\n unstyled?: boolean;\n\n /** Shows numbered page buttons in the paginator. Defaults to false. */\n pageLinks?: TablePaginatorProps['pageLinks'];\n\n /** Extra CSS class name forwarded to the paginator. */\n paginatorClassName?: string;\n\n /** Cratis-owned attributes for paginator parts. */\n paginatorPt?: TablePaginatorParts;\n\n /**\n * @deprecated Cratis paginator parts always merge. Remove this renderer-era option.\n */\n paginatorPtOptions?: object;\n\n /** Accessible names for the paginator controls. Override any to localize. */\n paginatorAriaLabels?: TablePaginatorProps['ariaLabels'];\n}\n\nconst paging = new Paging(0, 20);\n\n/**\n * A paged data table bound to a real-time Cratis Arc observable query\n * (`IObservableQueryFor<TDataType, TArguments>`). Subscribes via\n * `useObservableQueryWithPaging`, so the table re-renders automatically as the\n * underlying read model changes server-side. Rows render through the semantic Cratis-owned\n * {@link DataTableCore} inside an internally-scrolling region that resizes to\n * fill its container.\n *\n * ## Children\n *\n * Children are Cratis `<Column>` elements describing the visible columns.\n *\n * ```tsx\n * import { DataTableForObservableQuery, Column } from '@cratis/components/DataTables';\n * import { AllTasks } from './AllTasks'; // observable proxy from C#\n *\n * <DataTableForObservableQuery query={AllTasks} emptyMessage=\"No tasks\">\n * <Column field=\"title\" header=\"Title\" sortable />\n * <Column field=\"assignee\" header=\"Assignee\" />\n * </DataTableForObservableQuery>\n * ```\n *\n * Use {@link DataTableForQuery} for one-shot snapshot queries. Use\n * {@link DataPage} for a higher-level layout that combines this table with\n * an action menubar, selection, and a details pane.\n *\n * @typeParam TQuery - The query class (proxy generated from C# `IObservableQueryFor`).\n * @typeParam TDataType - The row type returned by the query.\n * @typeParam TArguments - The query's argument object type.\n * @param props - {@link DataTableForObservableQueryProps}.\n */\nexport const DataTableForObservableQuery = <\n TQuery extends\n | IObservableQueryFor<TDataType, TArguments>\n | IObservableQueryFor<TDataType[], TArguments>,\n TDataType extends object,\n TArguments extends object,\n>(\n props: DataTableForObservableQueryProps<TQuery, TDataType, TArguments>,\n) => {\n // Type arguments are supplied explicitly, and the constructor is erased on the way in\n // (Cratis/Components#135). Two separate defects in `@cratis/arc.react` make the plain call\n // fail to type-check:\n //\n // 1. `useObservableQueryWithPaging<TDataType, TQuery extends IObservableQueryFor<TDataType>, …>`\n // gives `TDataType` no inference site — it appears only inside `TQuery`'s constraint — so it\n // silently falls back to `unknown` and `result` comes back as `QueryResultWithState<unknown>`.\n // 2. `ObservableQuerySubscription<T>` carries a `private _connection`, which makes it nominally\n // typed. `@cratis/arc.react` pins `@cratis/arc` to an exact version, so any consumer whose own\n // `@cratis/arc` differs by even a patch gets a second nested copy — two declarations of that\n // class, and TS2345 \"types have separate declarations of a private property\". Our peer range\n // allows multiple Arc versions, so we cannot assume a consumer's tree is deduped.\n //\n // Erasing the constructor type sidesteps the nominal comparison, and naming `TDataType`\n // explicitly recovers the row type this component is generic over — strictly better than the\n // `unknown` the inference would otherwise produce. Remove both once Arc returns an interface\n // from `subscribe()` and makes `TDataType` inferable.\n const server = useServerQuery(props.serverQuery, props.queryArguments, props.defaultFilters);\n const [result, setSorting, setPage] = useObservableQueryWithPaging<\n TDataType,\n never,\n TArguments\n >(props.query as never, paging, server.queryArguments);\n const containerRef = useRef<HTMLDivElement>(null);\n const [tableHeight, setTableHeight] = useState<number>(600);\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const totalItems = result.paging.totalItems;\n const pageCount = result.paging.totalPages;\n const showPaginator = totalItems > 0 && pageCount > 1;\n\n // SAFETY: Arc observable collection queries are row-typed while runtime data is the current row array.\n const rows = result.data as unknown as TDataType[];\n const status = resolveDataTableStatus(result);\n\n useEffect(() => {\n if (!containerRef.current) return;\n\n const resizeObserver = new ResizeObserver((entries) => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n timeoutRef.current = setTimeout(() => {\n for (const entry of entries) {\n const containerHeight = entry.contentRect.height;\n if (containerHeight > 0) {\n const paginatorHeight = showPaginator ? 56 : 0;\n const calculatedHeight = containerHeight - paginatorHeight - 2;\n const newHeight = Math.max(calculatedHeight, 200);\n\n setTableHeight((prevHeight) => {\n if (Math.abs(newHeight - prevHeight) > 5) {\n return newHeight;\n }\n return prevHeight;\n });\n }\n }\n }, 10);\n });\n\n resizeObserver.observe(containerRef.current);\n\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n resizeObserver.disconnect();\n };\n }, [showPaginator]);\n\n return (\n <div\n ref={containerRef}\n style={{\n display: 'flex',\n flexDirection: 'column',\n height: '100%',\n border: '1px solid var(--cratis-surface-border)',\n borderRadius: 'var(--cratis-border-radius)',\n overflow: 'hidden',\n }}\n >\n <div style={{ height: `${tableHeight}px`, overflow: 'hidden' }}>\n <DataTableCore<TDataType>\n data={rows}\n dataKey={props.dataKey}\n emptyMessage={props.emptyMessage}\n status={status}\n loadingMessage={props.loadingMessage}\n failureMessage={props.failureMessage}\n unauthorizedMessage={props.unauthorizedMessage}\n selectionMode={props.selectionMode ?? 'single'}\n selection={props.selection}\n onSelectionChange={props.onSelectionChange}\n selectedItems={props.selectedItems}\n onSelectedItemsChange={props.onSelectedItemsChange}\n globalFilterFields={props.globalFilterFields}\n globalSearchPlaceholder={props.globalSearchPlaceholder}\n globalSearchAriaLabel={props.globalSearchAriaLabel}\n defaultFilters={props.defaultFilters}\n {...server.tableProps({ setSorting, setPage })}\n scrollable\n scrollHeight='100%'\n className={props.className}\n style={{ minWidth: '100%' }}\n pt={props.pt}\n ptOptions={props.ptOptions}\n unstyled={props.unstyled}\n >\n {props.children}\n </DataTableCore>\n </div>\n\n {showPaginator && (\n <div\n style={{\n borderTop: '1px solid var(--cratis-surface-border)',\n flexShrink: 0,\n }}\n >\n <TablePaginator\n page={result.paging.page}\n pageCount={pageCount}\n onPageChange={setPage}\n totalItems={totalItems}\n pageSize={paging.pageSize}\n pageLinks={props.pageLinks}\n className={props.paginatorClassName}\n ariaLabels={props.paginatorAriaLabels}\n pt={props.paginatorPt}\n ptOptions={props.paginatorPtOptions}\n />\n </div>\n )}\n </div>\n );\n};\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;AA6JA,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC;AAiCzB,MAAM,2BAA2B,GAAG,CAOvC,KAAsE,KACtE;AAkBA,IAAA,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC;IAC5F,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,GAAG,4BAA4B,CAIhE,KAAK,CAAC,KAAc,EAAE,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;AACtD,IAAA,MAAM,YAAY,GAAG,MAAM,CAAiB,IAAI,CAAC;IACjD,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAS,GAAG,CAAC;AAC3D,IAAA,MAAM,UAAU,GAAG,MAAM,CAA4C,SAAS,CAAC;AAC/E,IAAA,MAAM,UAAU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E,KAAK,CAAC,cAAc,EAAA,GAChC,MAAM,CAAC,UAAU,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,EAC9C,UAAU,QACV,YAAY,EAAC,MAAM,EACnB,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,EAC3B,EAAE,EAAE,KAAK,CAAC,EAAE,EACZ,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ,YAEvB,KAAK,CAAC,QAAQ,EAAA,CACH,GACd,EAEL,aAAa,KACVA,GAAA,CAAA,KAAA,EAAA,EACI,KAAK,EAAE;AACH,oBAAA,SAAS,EAAE,wCAAwC;AACnD,oBAAA,UAAU,EAAE,CAAC;AAChB,iBAAA,EAAA,QAAA,EAEDA,GAAA,CAAC,cAAc,EAAA,EACX,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EACxB,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,OAAO,EACrB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,SAAS,EAAE,KAAK,CAAC,kBAAkB,EACnC,UAAU,EAAE,KAAK,CAAC,mBAAmB,EACrC,EAAE,EAAE,KAAK,CAAC,WAAW,EACrB,SAAS,EAAE,KAAK,CAAC,kBAAkB,EAAA,CACrC,EAAA,CACA,CACT,CAAA,EAAA,CACC;AAEd;;"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { DataTableParts } from './DataTableCore.js';
|
|
2
2
|
import type { Constructor } from '@cratis/fundamentals';
|
|
3
3
|
import { type IQueryFor } from '@cratis/arc/queries';
|
|
4
|
-
import type
|
|
4
|
+
import { type ReactNode } from 'react';
|
|
5
5
|
import { type TablePaginatorParts, type TablePaginatorProps } from './TablePaginator.js';
|
|
6
6
|
import type { DataTableFilterMeta } from './DataTableFilterMeta.js';
|
|
7
7
|
import type { DataTableSelectionChangeEvent } from './DataTableSelectionChangeEvent.js';
|
|
8
|
+
import type { DataTableServerQuery } from './DataTableServerQuery.js';
|
|
8
9
|
/**
|
|
9
10
|
* Props for {@link DataTableForQuery}.
|
|
10
11
|
*
|
|
@@ -77,6 +78,12 @@ export interface DataTableForQueryProps<TQuery extends IQueryFor<TDataType, TArg
|
|
|
77
78
|
* server-reported pagination totals. Retained for source compatibility only.
|
|
78
79
|
*/
|
|
79
80
|
clientFiltering?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Opts into server mode: the query sorts, filters and searches the complete result before
|
|
83
|
+
* paging, and the table renders the rows as returned. Leave undefined to sort, filter and search
|
|
84
|
+
* the loaded page. See {@link DataTableServerQuery}.
|
|
85
|
+
*/
|
|
86
|
+
serverQuery?: DataTableServerQuery<TArguments>;
|
|
80
87
|
/**
|
|
81
88
|
* Extra CSS class name forwarded to the underlying DataTable root.
|
|
82
89
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTableForQuery.d.ts","sourceRoot":"","sources":["../../../DataTables/DataTableForQuery.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,KAAK,SAAS,EAAU,MAAM,qBAAqB,CAAC;AAE7D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"DataTableForQuery.d.ts","sourceRoot":"","sources":["../../../DataTables/DataTableForQuery.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,KAAK,SAAS,EAAU,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,KAAK,SAAS,EAAW,MAAM,OAA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
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { Paging } from '@cratis/arc/queries';
|
|
3
3
|
import { useQueryWithPaging } from '@cratis/arc.react/queries';
|
|
4
|
+
import { useMemo } from 'react';
|
|
4
5
|
import { DataTableCore } from './DataTableCore.js';
|
|
5
6
|
import { TablePaginator } from './TablePaginator.js';
|
|
6
7
|
import { resolveDataTableStatus } from './resolveDataTableStatus.js';
|
|
8
|
+
import { useServerQuery } from './useServerQuery.js';
|
|
9
|
+
import { hasRequiredArguments } from './hasRequiredArguments.js';
|
|
7
10
|
|
|
8
11
|
const paging = new Paging(0, 20);
|
|
9
12
|
const DataTableForQuery = (props) => {
|
|
10
|
-
const
|
|
13
|
+
const server = useServerQuery(props.serverQuery, props.queryArguments, props.defaultFilters);
|
|
14
|
+
const [result, , setSorting, setPage] = useQueryWithPaging(props.query, paging, server.queryArguments);
|
|
11
15
|
const totalItems = result.paging.totalItems;
|
|
12
16
|
const pageCount = result.paging.totalPages;
|
|
13
17
|
const rows = result.data;
|
|
14
|
-
const
|
|
18
|
+
const requiredArguments = useMemo(() => new props.query().requiredRequestParameters, [props.query]);
|
|
19
|
+
const isWaitingForArguments = !hasRequiredArguments(requiredArguments, server.queryArguments);
|
|
20
|
+
const status = resolveDataTableStatus(isWaitingForArguments ? { ...result, isSuccess: true } : result);
|
|
15
21
|
return (jsxs("div", { style: {
|
|
16
22
|
display: 'flex',
|
|
17
23
|
flexDirection: 'column',
|
|
@@ -19,7 +25,7 @@ const DataTableForQuery = (props) => {
|
|
|
19
25
|
border: '1px solid var(--cratis-surface-border)',
|
|
20
26
|
borderRadius: 'var(--cratis-border-radius)',
|
|
21
27
|
overflow: 'hidden',
|
|
22
|
-
}, children: [jsx("div", { style: { flex: 1, minHeight: 0, overflow: 'hidden' }, children: jsx(DataTableCore, { data: rows, dataKey: props.dataKey, emptyMessage: props.emptyMessage, status: status, loadingMessage: props.loadingMessage, failureMessage: props.failureMessage, unauthorizedMessage: props.unauthorizedMessage, selectionMode: props.selectionMode ?? 'single', selection: props.selection, onSelectionChange: props.onSelectionChange, selectedItems: props.selectedItems, onSelectedItemsChange: props.onSelectedItemsChange, globalFilterFields: props.globalFilterFields, globalSearchPlaceholder: props.globalSearchPlaceholder, globalSearchAriaLabel: props.globalSearchAriaLabel, defaultFilters: props.defaultFilters, scrollable: true, scrollHeight: '100%', className: props.className, style: { minWidth: '100%' }, pt: props.pt, ptOptions: props.ptOptions, unstyled: props.unstyled, children: props.children }) }), totalItems > 0 && pageCount > 1 && (jsx("div", { style: {
|
|
28
|
+
}, children: [jsx("div", { style: { flex: 1, minHeight: 0, overflow: 'hidden' }, children: jsx(DataTableCore, { data: rows, dataKey: props.dataKey, emptyMessage: props.emptyMessage, status: status, loadingMessage: props.loadingMessage, failureMessage: props.failureMessage, unauthorizedMessage: props.unauthorizedMessage, selectionMode: props.selectionMode ?? 'single', selection: props.selection, onSelectionChange: props.onSelectionChange, selectedItems: props.selectedItems, onSelectedItemsChange: props.onSelectedItemsChange, globalFilterFields: props.globalFilterFields, globalSearchPlaceholder: props.globalSearchPlaceholder, globalSearchAriaLabel: props.globalSearchAriaLabel, defaultFilters: props.defaultFilters, ...server.tableProps({ setSorting, setPage }), scrollable: true, scrollHeight: '100%', className: props.className, style: { minWidth: '100%' }, pt: props.pt, ptOptions: props.ptOptions, unstyled: props.unstyled, children: props.children }) }), totalItems > 0 && pageCount > 1 && (jsx("div", { style: {
|
|
23
29
|
borderTop: '1px solid var(--cratis-surface-border)',
|
|
24
30
|
flexShrink: 0,
|
|
25
31
|
}, children: jsx(TablePaginator, { page: result.paging.page, pageCount: pageCount, onPageChange: setPage, totalItems: totalItems, pageSize: paging.pageSize, pageLinks: props.pageLinks, className: props.paginatorClassName, ariaLabels: props.paginatorAriaLabels, pt: props.paginatorPt, ptOptions: props.paginatorPtOptions }) }))] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTableForQuery.js","sources":["../../../DataTables/DataTableForQuery.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { DataTableParts } from './DataTableCore';\nimport type { Constructor } from '@cratis/fundamentals';\nimport { type IQueryFor, Paging } from '@cratis/arc/queries';\nimport { useQueryWithPaging } from '@cratis/arc.react/queries';\nimport type { ReactNode } from 'react';\nimport { DataTableCore } from './DataTableCore';\nimport {\n TablePaginator,\n type TablePaginatorParts,\n type TablePaginatorProps,\n} from './TablePaginator';\nimport type { DataTableFilterMeta } from './DataTableFilterMeta';\nimport type { DataTableSelectionChangeEvent } from './DataTableSelectionChangeEvent';\nimport { resolveDataTableStatus } from './resolveDataTableStatus';\n\n/**\n * Props for {@link DataTableForQuery}.\n *\n * @typeParam TQuery - The query class implementing `IQueryFor`.\n * @typeParam TDataType - The row type returned by the query.\n * @typeParam TArguments - The query's argument object type, or `object` if it takes none.\n */\nexport interface DataTableForQueryProps<\n TQuery extends IQueryFor<TDataType, TArguments> | IQueryFor<TDataType[], TArguments>,\n TDataType extends object,\n TArguments extends object,\n> {\n /**\n * Children to render — `<Column>` elements describing the visible columns.\n */\n children?: ReactNode;\n\n /**\n * The type of query to use\n */\n query: Constructor<TQuery>;\n\n /**\n * Optional Arguments to pass to the query\n */\n queryArguments?: TArguments;\n\n /**\n * The message to show when there is no data\n */\n emptyMessage: string;\n\n /** Message shown while loading without rows. */\n loadingMessage?: ReactNode;\n /** Message shown when the query fails. */\n failureMessage?: ReactNode;\n /** Message shown when access is denied. */\n unauthorizedMessage?: ReactNode;\n\n /**\n * The key to use for the data\n */\n dataKey?: string | undefined;\n\n /**\n * The current selection.\n */\n selection?: TDataType | undefined | null;\n\n /**\n * Callback for when the selection changes\n */\n onSelectionChange?(event: DataTableSelectionChangeEvent<TDataType>): void;\n\n /**\n * The row selection mode. Defaults to `'single'`.\n */\n selectionMode?: 'single' | 'multiple';\n\n /**\n * The currently selected rows, for `selectionMode='multiple'`.\n */\n selectedItems?: TDataType[];\n\n /**\n * Callback for when a multiple selection changes, with the full selected set.\n */\n onSelectedItemsChange?(items: TDataType[]): void;\n\n /**\n * Fields to use for global filtering\n */\n globalFilterFields?: string[] | undefined;\n\n /** Placeholder for the loaded-page search input. */\n globalSearchPlaceholder?: string;\n\n /** Accessible name for the loaded-page search input. */\n globalSearchAriaLabel?: string;\n\n /**\n * Default filters to use\n */\n defaultFilters?: DataTableFilterMeta;\n\n /**\n * @deprecated Filtering is always applied to the currently loaded page.\n * This compatibility prop no longer toggles behavior and does not change\n * server-reported pagination totals. Retained for source compatibility only.\n */\n clientFiltering?: boolean;\n\n /**\n * Extra CSS class name forwarded to the underlying DataTable root.\n */\n className?: string;\n\n /** Cratis-owned per-part attributes applied to the underlying table. */\n pt?: DataTableParts;\n\n /**\n * @deprecated Cratis parts always merge. Remove this renderer-era option.\n */\n ptOptions?: object;\n\n /**\n * @deprecated Components always uses consumer-owned CSS. Customize through `pt` and CSS instead.\n */\n unstyled?: boolean;\n\n /** Shows numbered page buttons in the paginator. Defaults to false. */\n pageLinks?: TablePaginatorProps['pageLinks'];\n\n /** Extra CSS class name forwarded to the paginator. */\n paginatorClassName?: string;\n\n /** Cratis-owned attributes for paginator parts. */\n paginatorPt?: TablePaginatorParts;\n\n /**\n * @deprecated Cratis paginator parts always merge. Remove this renderer-era option.\n */\n paginatorPtOptions?: object;\n\n /** Accessible names for the paginator controls. Override any to localize. */\n paginatorAriaLabels?: TablePaginatorProps['ariaLabels'];\n}\n\nconst paging = new Paging(0, 20);\n\n/**\n * A paged data table bound to a snapshot Cratis Arc query\n * (`IQueryFor<TDataType, TArguments>`). Subscribes via\n * `useQueryWithPaging` from `@cratis/arc.react/queries`, renders the result\n * page through the semantic Cratis-owned {@link DataTableCore}, and shows a\n * {@link TablePaginator} when the result set exceeds one page.\n *\n * ## What `TQuery` is\n *\n * `TQuery` is the auto-generated TypeScript class produced by the Arc proxy\n * generator from a C# read model's static query method. `dotnet build`\n * writes a `.ts` file per query with the right return type and a `use()`\n * hook; importing the class is all the connection-to-the-backend you need.\n *\n * ## Children\n *\n * Children are Cratis `<Column>` elements describing the visible columns —\n * `field`, `header`, custom `body` templates, and `sortable`.\n *\n * ```tsx\n * import { DataTableForQuery, Column } from '@cratis/components/DataTables';\n * import { AllAuthors } from './AllAuthors'; // proxy from C#\n *\n * <DataTableForQuery query={AllAuthors} emptyMessage=\"No authors\">\n * <Column field=\"name\" header=\"Name\" sortable />\n * <Column field=\"email\" header=\"Email\" />\n * </DataTableForQuery>\n * ```\n *\n * Use {@link DataTableForObservableQuery} for queries that should update in\n * real time as the underlying read model changes server-side. Use\n * {@link DataPage} for a higher-level layout that combines this table with\n * an action menubar, selection, and a details pane.\n *\n * ## Styling\n *\n * Forward `pt` / `ptOptions` / `unstyled` / `className` to the underlying\n * DataTable. See [pass-through cheat sheet](../../Documentation/Styling/pass-through.md).\n *\n * @typeParam TQuery - The query class (proxy generated from C# `IQueryFor`).\n * @typeParam TDataType - The row type returned by the query.\n * @typeParam TArguments - The query's argument object type.\n * @param props - {@link DataTableForQueryProps}.\n */\nexport const DataTableForQuery = <\n TQuery extends IQueryFor<TDataType, TArguments> | IQueryFor<TDataType[], TArguments>,\n TDataType extends object,\n TArguments extends object,\n>(\n props: DataTableForQueryProps<TQuery, TDataType, TArguments>,\n) => {\n const [result, , , setPage] = useQueryWithPaging(\n props.query,\n paging,\n props.queryArguments,\n );\n const totalItems = result.paging.totalItems;\n const pageCount = result.paging.totalPages;\n\n // SAFETY: Arc collection queries are row-typed while their runtime data is the current row array.\n const rows = result.data as unknown as TDataType[];\n const status = resolveDataTableStatus(result);\n\n return (\n <div\n style={{\n display: 'flex',\n flexDirection: 'column',\n height: '100%',\n border: '1px solid var(--cratis-surface-border)',\n borderRadius: 'var(--cratis-border-radius)',\n overflow: 'hidden',\n }}\n >\n {/* The scroll container must be `DataTableCore`'s own bounded container rather than\n this wrapper. `.cratis-datatable__container` sets `overflow-x: auto`, and CSS\n computes the matching `overflow-y: visible` to `auto`, so that element is always\n the nearest scrolling ancestor for the `position: sticky` header cells. Scrolling\n out here would leave the header sticking to a container that never scrolls, so the\n header would not freeze. */}\n <div style={{ flex: 1, minHeight: 0, overflow: 'hidden' }}>\n <DataTableCore<TDataType>\n data={rows}\n dataKey={props.dataKey}\n emptyMessage={props.emptyMessage}\n status={status}\n loadingMessage={props.loadingMessage}\n failureMessage={props.failureMessage}\n unauthorizedMessage={props.unauthorizedMessage}\n selectionMode={props.selectionMode ?? 'single'}\n selection={props.selection}\n onSelectionChange={props.onSelectionChange}\n selectedItems={props.selectedItems}\n onSelectedItemsChange={props.onSelectedItemsChange}\n globalFilterFields={props.globalFilterFields}\n globalSearchPlaceholder={props.globalSearchPlaceholder}\n globalSearchAriaLabel={props.globalSearchAriaLabel}\n defaultFilters={props.defaultFilters}\n scrollable\n scrollHeight='100%'\n className={props.className}\n style={{ minWidth: '100%' }}\n pt={props.pt}\n ptOptions={props.ptOptions}\n unstyled={props.unstyled}\n >\n {props.children}\n </DataTableCore>\n </div>\n\n {totalItems > 0 && pageCount > 1 && (\n <div\n style={{\n borderTop: '1px solid var(--cratis-surface-border)',\n flexShrink: 0,\n }}\n >\n <TablePaginator\n page={result.paging.page}\n pageCount={pageCount}\n onPageChange={setPage}\n totalItems={totalItems}\n pageSize={paging.pageSize}\n pageLinks={props.pageLinks}\n className={props.paginatorClassName}\n ariaLabels={props.paginatorAriaLabels}\n pt={props.paginatorPt}\n ptOptions={props.paginatorPtOptions}\n />\n </div>\n )}\n </div>\n );\n};\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;AAkJA,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC;AA8CzB,MAAM,iBAAiB,GAAG,CAK7B,KAA4D,KAC5D;IACA,MAAM,CAAC,MAAM,MAAM,OAAO,CAAC,GAAG,kBAAkB,CAC5C,KAAK,CAAC,KAAK,EACX,MAAM,EACN,KAAK,CAAC,cAAc,CACvB;AACD,IA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UAAU,EAAA,IAAA,EACV,YAAY,EAAC,MAAM,EACnB,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,EAC3B,EAAE,EAAE,KAAK,CAAC,EAAE,EACZ,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ,YAEvB,KAAK,CAAC,QAAQ,EAAA,CACH,EAAA,CACd,EAEL,UAAU,GAAG,CAAC,IAAI,SAAS,GAAG,CAAC,KAC5BA,GAAA,CAAA,KAAA,EAAA,EACI,KAAK,EAAE;AACH,oBAAA,SAAS,EAAE,wCAAwC;AACnD,oBAAA,UAAU,EAAE,CAAC;AAChB,iBAAA,EAAA,QAAA,EAEDA,GAAA,CAAC,cAAc,EAAA,EACX,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EACxB,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,OAAO,EACrB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,SAAS,EAAE,KAAK,CAAC,kBAAkB,EACnC,UAAU,EAAE,KAAK,CAAC,mBAAmB,EACrC,EAAE,EAAE,KAAK,CAAC,WAAW,EACrB,SAAS,EAAE,KAAK,CAAC,kBAAkB,EAAA,CACrC,EAAA,CACA,CACT,CAAA,EAAA,CACC;AAEd;;"}
|
|
1
|
+
{"version":3,"file":"DataTableForQuery.js","sources":["../../../DataTables/DataTableForQuery.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { DataTableParts } from './DataTableCore';\nimport type { Constructor } from '@cratis/fundamentals';\nimport { type IQueryFor, Paging } from '@cratis/arc/queries';\nimport { useQueryWithPaging } from '@cratis/arc.react/queries';\nimport { type ReactNode, useMemo } from 'react';\nimport { DataTableCore } from './DataTableCore';\nimport {\n TablePaginator,\n type TablePaginatorParts,\n type TablePaginatorProps,\n} from './TablePaginator';\nimport type { DataTableFilterMeta } from './DataTableFilterMeta';\nimport type { DataTableSelectionChangeEvent } from './DataTableSelectionChangeEvent';\nimport { resolveDataTableStatus } from './resolveDataTableStatus';\nimport type { DataTableServerQuery } from './DataTableServerQuery';\nimport { useServerQuery } from './useServerQuery';\nimport { hasRequiredArguments } from './hasRequiredArguments';\n\n/**\n * Props for {@link DataTableForQuery}.\n *\n * @typeParam TQuery - The query class implementing `IQueryFor`.\n * @typeParam TDataType - The row type returned by the query.\n * @typeParam TArguments - The query's argument object type, or `object` if it takes none.\n */\nexport interface DataTableForQueryProps<\n TQuery extends IQueryFor<TDataType, TArguments> | IQueryFor<TDataType[], TArguments>,\n TDataType extends object,\n TArguments extends object,\n> {\n /**\n * Children to render — `<Column>` elements describing the visible columns.\n */\n children?: ReactNode;\n\n /**\n * The type of query to use\n */\n query: Constructor<TQuery>;\n\n /**\n * Optional Arguments to pass to the query\n */\n queryArguments?: TArguments;\n\n /**\n * The message to show when there is no data\n */\n emptyMessage: string;\n\n /** Message shown while loading without rows. */\n loadingMessage?: ReactNode;\n /** Message shown when the query fails. */\n failureMessage?: ReactNode;\n /** Message shown when access is denied. */\n unauthorizedMessage?: ReactNode;\n\n /**\n * The key to use for the data\n */\n dataKey?: string | undefined;\n\n /**\n * The current selection.\n */\n selection?: TDataType | undefined | null;\n\n /**\n * Callback for when the selection changes\n */\n onSelectionChange?(event: DataTableSelectionChangeEvent<TDataType>): void;\n\n /**\n * The row selection mode. Defaults to `'single'`.\n */\n selectionMode?: 'single' | 'multiple';\n\n /**\n * The currently selected rows, for `selectionMode='multiple'`.\n */\n selectedItems?: TDataType[];\n\n /**\n * Callback for when a multiple selection changes, with the full selected set.\n */\n onSelectedItemsChange?(items: TDataType[]): void;\n\n /**\n * Fields to use for global filtering\n */\n globalFilterFields?: string[] | undefined;\n\n /** Placeholder for the loaded-page search input. */\n globalSearchPlaceholder?: string;\n\n /** Accessible name for the loaded-page search input. */\n globalSearchAriaLabel?: string;\n\n /**\n * Default filters to use\n */\n defaultFilters?: DataTableFilterMeta;\n\n /**\n * @deprecated Filtering is always applied to the currently loaded page.\n * This compatibility prop no longer toggles behavior and does not change\n * server-reported pagination totals. Retained for source compatibility only.\n */\n clientFiltering?: boolean;\n\n /**\n * Opts into server mode: the query sorts, filters and searches the complete result before\n * paging, and the table renders the rows as returned. Leave undefined to sort, filter and search\n * the loaded page. See {@link DataTableServerQuery}.\n */\n serverQuery?: DataTableServerQuery<TArguments>;\n\n /**\n * Extra CSS class name forwarded to the underlying DataTable root.\n */\n className?: string;\n\n /** Cratis-owned per-part attributes applied to the underlying table. */\n pt?: DataTableParts;\n\n /**\n * @deprecated Cratis parts always merge. Remove this renderer-era option.\n */\n ptOptions?: object;\n\n /**\n * @deprecated Components always uses consumer-owned CSS. Customize through `pt` and CSS instead.\n */\n unstyled?: boolean;\n\n /** Shows numbered page buttons in the paginator. Defaults to false. */\n pageLinks?: TablePaginatorProps['pageLinks'];\n\n /** Extra CSS class name forwarded to the paginator. */\n paginatorClassName?: string;\n\n /** Cratis-owned attributes for paginator parts. */\n paginatorPt?: TablePaginatorParts;\n\n /**\n * @deprecated Cratis paginator parts always merge. Remove this renderer-era option.\n */\n paginatorPtOptions?: object;\n\n /** Accessible names for the paginator controls. Override any to localize. */\n paginatorAriaLabels?: TablePaginatorProps['ariaLabels'];\n}\n\nconst paging = new Paging(0, 20);\n\n/**\n * A paged data table bound to a snapshot Cratis Arc query\n * (`IQueryFor<TDataType, TArguments>`). Subscribes via\n * `useQueryWithPaging` from `@cratis/arc.react/queries`, renders the result\n * page through the semantic Cratis-owned {@link DataTableCore}, and shows a\n * {@link TablePaginator} when the result set exceeds one page.\n *\n * ## What `TQuery` is\n *\n * `TQuery` is the auto-generated TypeScript class produced by the Arc proxy\n * generator from a C# read model's static query method. `dotnet build`\n * writes a `.ts` file per query with the right return type and a `use()`\n * hook; importing the class is all the connection-to-the-backend you need.\n *\n * ## Children\n *\n * Children are Cratis `<Column>` elements describing the visible columns —\n * `field`, `header`, custom `body` templates, and `sortable`.\n *\n * ```tsx\n * import { DataTableForQuery, Column } from '@cratis/components/DataTables';\n * import { AllAuthors } from './AllAuthors'; // proxy from C#\n *\n * <DataTableForQuery query={AllAuthors} emptyMessage=\"No authors\">\n * <Column field=\"name\" header=\"Name\" sortable />\n * <Column field=\"email\" header=\"Email\" />\n * </DataTableForQuery>\n * ```\n *\n * Use {@link DataTableForObservableQuery} for queries that should update in\n * real time as the underlying read model changes server-side. Use\n * {@link DataPage} for a higher-level layout that combines this table with\n * an action menubar, selection, and a details pane.\n *\n * ## Styling\n *\n * Forward `pt` / `ptOptions` / `unstyled` / `className` to the underlying\n * DataTable. See [pass-through cheat sheet](../../Documentation/Styling/pass-through.md).\n *\n * @typeParam TQuery - The query class (proxy generated from C# `IQueryFor`).\n * @typeParam TDataType - The row type returned by the query.\n * @typeParam TArguments - The query's argument object type.\n * @param props - {@link DataTableForQueryProps}.\n */\nexport const DataTableForQuery = <\n TQuery extends IQueryFor<TDataType, TArguments> | IQueryFor<TDataType[], TArguments>,\n TDataType extends object,\n TArguments extends object,\n>(\n props: DataTableForQueryProps<TQuery, TDataType, TArguments>,\n) => {\n const server = useServerQuery(props.serverQuery, props.queryArguments, props.defaultFilters);\n const [result, , setSorting, setPage] = useQueryWithPaging(\n props.query,\n paging,\n server.queryArguments,\n );\n const totalItems = result.paging.totalItems;\n const pageCount = result.paging.totalPages;\n\n // SAFETY: Arc collection queries are row-typed while their runtime data is the current row array.\n const rows = result.data as unknown as TDataType[];\n const requiredArguments = useMemo(() => new props.query().requiredRequestParameters, [props.query]);\n // Arc settles a snapshot query it did not send, because a required argument is missing, as\n // unsuccessful. That is a table waiting for its arguments, not a failed query.\n const isWaitingForArguments = !hasRequiredArguments(requiredArguments, server.queryArguments);\n const status = resolveDataTableStatus(isWaitingForArguments ? { ...result, isSuccess: true } : result);\n\n return (\n <div\n style={{\n display: 'flex',\n flexDirection: 'column',\n height: '100%',\n border: '1px solid var(--cratis-surface-border)',\n borderRadius: 'var(--cratis-border-radius)',\n overflow: 'hidden',\n }}\n >\n {/* The scroll container must be `DataTableCore`'s own bounded container rather than\n this wrapper. `.cratis-datatable__container` sets `overflow-x: auto`, and CSS\n computes the matching `overflow-y: visible` to `auto`, so that element is always\n the nearest scrolling ancestor for the `position: sticky` header cells. Scrolling\n out here would leave the header sticking to a container that never scrolls, so the\n header would not freeze. */}\n <div style={{ flex: 1, minHeight: 0, overflow: 'hidden' }}>\n <DataTableCore<TDataType>\n data={rows}\n dataKey={props.dataKey}\n emptyMessage={props.emptyMessage}\n status={status}\n loadingMessage={props.loadingMessage}\n failureMessage={props.failureMessage}\n unauthorizedMessage={props.unauthorizedMessage}\n selectionMode={props.selectionMode ?? 'single'}\n selection={props.selection}\n onSelectionChange={props.onSelectionChange}\n selectedItems={props.selectedItems}\n onSelectedItemsChange={props.onSelectedItemsChange}\n globalFilterFields={props.globalFilterFields}\n globalSearchPlaceholder={props.globalSearchPlaceholder}\n globalSearchAriaLabel={props.globalSearchAriaLabel}\n defaultFilters={props.defaultFilters}\n {...server.tableProps({ setSorting, setPage })}\n scrollable\n scrollHeight='100%'\n className={props.className}\n style={{ minWidth: '100%' }}\n pt={props.pt}\n ptOptions={props.ptOptions}\n unstyled={props.unstyled}\n >\n {props.children}\n </DataTableCore>\n </div>\n\n {totalItems > 0 && pageCount > 1 && (\n <div\n style={{\n borderTop: '1px solid var(--cratis-surface-border)',\n flexShrink: 0,\n }}\n >\n <TablePaginator\n page={result.paging.page}\n pageCount={pageCount}\n onPageChange={setPage}\n totalItems={totalItems}\n pageSize={paging.pageSize}\n pageLinks={props.pageLinks}\n className={props.paginatorClassName}\n ariaLabels={props.paginatorAriaLabels}\n pt={props.paginatorPt}\n ptOptions={props.paginatorPtOptions}\n />\n </div>\n )}\n </div>\n );\n};\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;AA4JA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,cAAc,EAAA,EACX,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EACxB,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,OAAO,EACrB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,SAAS,EAAE,KAAK,CAAC,kBAAkB,EACnC,UAAU,EAAE,KAAK,CAAC,mBAAmB,EACrC,EAAE,EAAE,KAAK,CAAC,WAAW,EACrB,SAAS,EAAE,KAAK,CAAC,kBAAkB,EAAA,CACrC,EAAA,CACA,CACT,CAAA,EAAA,CACC;AAEd;;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { DataTableServerQueryState } from './DataTableServerQueryState.js';
|
|
2
|
+
/** How long the search text must stay unchanged before it reaches the query, unless configured. */
|
|
3
|
+
export declare const defaultServerQuerySearchDebounceMilliseconds = 300;
|
|
4
|
+
/**
|
|
5
|
+
* Opts a query-bound table into server mode: the server sorts and filters the complete result
|
|
6
|
+
* before paging, instead of the table sorting and filtering the loaded page.
|
|
7
|
+
*
|
|
8
|
+
* In server mode the table renders the rows exactly as the query returns them. A sort change is sent
|
|
9
|
+
* as Arc sorting (`sortBy` and `sortDirection`). Column filters and search text are sent as query
|
|
10
|
+
* arguments built by {@link toArguments}; Components never guesses the query's argument names or
|
|
11
|
+
* operators. Every change goes back to the first page, and search text is sent once typing pauses.
|
|
12
|
+
* The paginator shows the totals Arc reports for the filtered result.
|
|
13
|
+
*
|
|
14
|
+
* The query must return an `IQueryable` or use MongoDB `Observe` so Arc can sort and page the complete
|
|
15
|
+
* result, and it must apply the filter arguments itself.
|
|
16
|
+
*
|
|
17
|
+
* @typeParam TArguments - The query's argument object type.
|
|
18
|
+
*/
|
|
19
|
+
export interface DataTableServerQuery<TArguments extends object = object> {
|
|
20
|
+
/**
|
|
21
|
+
* Builds the query arguments for the current filters and search text. They are merged over
|
|
22
|
+
* `queryArguments`, so they can add optional arguments or replace one.
|
|
23
|
+
* @param state - The applied column filters and the settled search text.
|
|
24
|
+
* @returns The arguments that carry the filters and search text to the query.
|
|
25
|
+
*/
|
|
26
|
+
toArguments(state: DataTableServerQueryState): Partial<TArguments>;
|
|
27
|
+
/**
|
|
28
|
+
* The field to sort by on the server, keyed by column field. A column that is not listed sorts by
|
|
29
|
+
* its own field. Arc converts the field to PascalCase on the server.
|
|
30
|
+
*/
|
|
31
|
+
sortFields?: Readonly<Record<string, string>>;
|
|
32
|
+
/**
|
|
33
|
+
* Milliseconds the search text must stay unchanged before it is sent. Defaults to
|
|
34
|
+
* {@link defaultServerQuerySearchDebounceMilliseconds}; `0` sends every change at once.
|
|
35
|
+
*/
|
|
36
|
+
searchDebounceMilliseconds?: number;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=DataTableServerQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataTableServerQuery.d.ts","sourceRoot":"","sources":["../../../DataTables/DataTableServerQuery.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAA6B,CAAC;AAE7E,mGAAmG;AACnG,eAAO,MAAM,4CAA4C,MAAM,CAAC;AAEhE;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,oBAAoB,CAAC,UAAU,SAAS,MAAM,GAAG,MAAM;IACpE;;;;;OAKG;IACH,WAAW,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAEnE;;;OAGG;IACH,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAE9C;;;OAGG;IACH,0BAA0B,CAAC,EAAE,MAAM,CAAC;CACvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataTableServerQuery.js","sources":["../../../DataTables/DataTableServerQuery.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { DataTableServerQueryState } from './DataTableServerQueryState';\n\n/** How long the search text must stay unchanged before it reaches the query, unless configured. */\nexport const defaultServerQuerySearchDebounceMilliseconds = 300;\n\n/**\n * Opts a query-bound table into server mode: the server sorts and filters the complete result\n * before paging, instead of the table sorting and filtering the loaded page.\n *\n * In server mode the table renders the rows exactly as the query returns them. A sort change is sent\n * as Arc sorting (`sortBy` and `sortDirection`). Column filters and search text are sent as query\n * arguments built by {@link toArguments}; Components never guesses the query's argument names or\n * operators. Every change goes back to the first page, and search text is sent once typing pauses.\n * The paginator shows the totals Arc reports for the filtered result.\n *\n * The query must return an `IQueryable` or use MongoDB `Observe` so Arc can sort and page the complete\n * result, and it must apply the filter arguments itself.\n *\n * @typeParam TArguments - The query's argument object type.\n */\nexport interface DataTableServerQuery<TArguments extends object = object> {\n /**\n * Builds the query arguments for the current filters and search text. They are merged over\n * `queryArguments`, so they can add optional arguments or replace one.\n * @param state - The applied column filters and the settled search text.\n * @returns The arguments that carry the filters and search text to the query.\n */\n toArguments(state: DataTableServerQueryState): Partial<TArguments>;\n\n /**\n * The field to sort by on the server, keyed by column field. A column that is not listed sorts by\n * its own field. Arc converts the field to PascalCase on the server.\n */\n sortFields?: Readonly<Record<string, string>>;\n\n /**\n * Milliseconds the search text must stay unchanged before it is sent. Defaults to\n * {@link defaultServerQuerySearchDebounceMilliseconds}; `0` sends every change at once.\n */\n searchDebounceMilliseconds?: number;\n}\n"],"names":[],"mappings":"AAMO,MAAM,4CAA4C,GAAG;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DataTableFilterMeta } from './DataTableFilterMeta.js';
|
|
2
|
+
/** The filter and search state a server query turns into query arguments. */
|
|
3
|
+
export interface DataTableServerQueryState {
|
|
4
|
+
/** The applied column filters, keyed by column field. Empty when no column is filtered. */
|
|
5
|
+
filters: DataTableFilterMeta;
|
|
6
|
+
/** The search text once typing has paused. Empty when nothing is searched for. */
|
|
7
|
+
globalFilter: string;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=DataTableServerQueryState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataTableServerQueryState.d.ts","sourceRoot":"","sources":["../../../DataTables/DataTableServerQueryState.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAAuB,CAAC;AAEjE,6EAA6E;AAC7E,MAAM,WAAW,yBAAyB;IACtC,2FAA2F;IAC3F,OAAO,EAAE,mBAAmB,CAAC;IAC7B,kFAAkF;IAClF,YAAY,EAAE,MAAM,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataTableServerQueryState.js","sourceRoot":"","sources":["../../../DataTables/DataTableServerQueryState.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG","sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { DataTableFilterMeta } from './DataTableFilterMeta';\n\n/** The filter and search state a server query turns into query arguments. */\nexport interface DataTableServerQueryState {\n /** The applied column filters, keyed by column field. Empty when no column is filtered. */\n filters: DataTableFilterMeta;\n /** The search text once typing has paused. Empty when nothing is searched for. */\n globalFilter: string;\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether every required query argument has a value, by the rule Arc uses before it sends a snapshot
|
|
3
|
+
* query: undefined, null and an empty string count as missing.
|
|
4
|
+
* @param required The names of the query's required arguments.
|
|
5
|
+
* @param args The query arguments.
|
|
6
|
+
* @returns True when no required argument is missing.
|
|
7
|
+
*/
|
|
8
|
+
export declare const hasRequiredArguments: (required: readonly string[], args?: object) => boolean;
|
|
9
|
+
//# sourceMappingURL=hasRequiredArguments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasRequiredArguments.d.ts","sourceRoot":"","sources":["../../../DataTables/hasRequiredArguments.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,aAAc,SAAS,MAAM,EAAE,SAAS,MAAM,KAAG,OAI5E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasRequiredArguments.js","sources":["../../../DataTables/hasRequiredArguments.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/**\n * Whether every required query argument has a value, by the rule Arc uses before it sends a snapshot\n * query: undefined, null and an empty string count as missing.\n * @param required The names of the query's required arguments.\n * @param args The query arguments.\n * @returns True when no required argument is missing.\n */\nexport const hasRequiredArguments = (required: readonly string[], args?: object): boolean =>\n required.every((name) => {\n const value = (args as Record<string, unknown> | undefined)?.[name];\n return value !== undefined && value !== null && value !== '';\n });\n"],"names":[],"mappings":"AAUO,MAAM,oBAAoB,GAAG,CAAC,QAA2B,EAAE,IAAa,KAC3E,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,KAAI;AACpB,IAAA,MAAM,KAAK,GAAI,IAA4C,GAAG,IAAI,CAAC;IACnE,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE;AAChE,CAAC;;"}
|
|
@@ -12,5 +12,7 @@ export * from './DataTableFilterMeta.js';
|
|
|
12
12
|
export type { DataTableSort } from './DataTableSort.js';
|
|
13
13
|
export { DataTableSortDirection } from './DataTableSortDirection.js';
|
|
14
14
|
export { DataTableRowProcessing } from './DataTableRowProcessing.js';
|
|
15
|
+
export { defaultServerQuerySearchDebounceMilliseconds, type DataTableServerQuery, } from './DataTableServerQuery.js';
|
|
16
|
+
export type { DataTableServerQueryState } from './DataTableServerQueryState.js';
|
|
15
17
|
export { registerDataTableFilterMatcher, resolveDataTableFilterMatcher, unregisterDataTableFilterMatcher, type DataTableFilterMatcherRegistration, } from './DataTableFilterMatcherRegistry.js';
|
|
16
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../DataTables/index.ts"],"names":[],"mappings":"AAGA,cAAc,oBAAiB,CAAC;AAChC,cAAc,sBAAmB,CAAC;AAClC,cAAc,wBAAqB,CAAC;AACpC,cAAc,kCAA+B,CAAC;AAC9C,cAAc,aAAU,CAAC;AACzB,cAAc,uBAAoB,CAAC;AACnC,cAAc,qBAAkB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAkB,CAAC;AAClD,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAqB,CAAC;AAC7D,cAAc,oCAAiC,CAAC;AAChD,cAAc,0BAAuB,CAAC;AACtC,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAiB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA0B,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA0B,CAAC;AAClE,OAAO,EACH,8BAA8B,EAC9B,6BAA6B,EAC7B,gCAAgC,EAChC,KAAK,kCAAkC,GAC1C,MAAM,qCAAkC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../DataTables/index.ts"],"names":[],"mappings":"AAGA,cAAc,oBAAiB,CAAC;AAChC,cAAc,sBAAmB,CAAC;AAClC,cAAc,wBAAqB,CAAC;AACpC,cAAc,kCAA+B,CAAC;AAC9C,cAAc,aAAU,CAAC;AACzB,cAAc,uBAAoB,CAAC;AACnC,cAAc,qBAAkB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAkB,CAAC;AAClD,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAqB,CAAC;AAC7D,cAAc,oCAAiC,CAAC;AAChD,cAAc,0BAAuB,CAAC;AACtC,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAiB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA0B,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA0B,CAAC;AAClE,OAAO,EACH,4CAA4C,EAC5C,KAAK,oBAAoB,GAC5B,MAAM,2BAAwB,CAAC;AAChC,YAAY,EAAE,yBAAyB,EAAE,MAAM,gCAA6B,CAAC;AAC7E,OAAO,EACH,8BAA8B,EAC9B,6BAA6B,EAC7B,gCAAgC,EAChC,KAAK,kCAAkC,GAC1C,MAAM,qCAAkC,CAAC"}
|
|
@@ -9,5 +9,6 @@ export { paginatorPages } from './paginatorPages.js';
|
|
|
9
9
|
export { DataTableFilterMatchMode } from './DataTableFilterMeta.js';
|
|
10
10
|
export { DataTableSortDirection } from './DataTableSortDirection.js';
|
|
11
11
|
export { DataTableRowProcessing } from './DataTableRowProcessing.js';
|
|
12
|
+
export { defaultServerQuerySearchDebounceMilliseconds } from './DataTableServerQuery.js';
|
|
12
13
|
export { registerDataTableFilterMatcher, resolveDataTableFilterMatcher, unregisterDataTableFilterMatcher } from './DataTableFilterMatcherRegistry.js';
|
|
13
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
+
import { type QueryStatusFlags } from '../QueryStatus/resolveQueryStatus.js';
|
|
1
2
|
import { DataTableStatus } from './DataTableStatus.js';
|
|
2
3
|
/** Resolve Arc query flags into the table's display state. */
|
|
3
|
-
export declare const resolveDataTableStatus: (result:
|
|
4
|
-
isAuthorized?: boolean;
|
|
5
|
-
hasExceptions?: boolean;
|
|
6
|
-
isValid?: boolean;
|
|
7
|
-
isPerforming?: boolean;
|
|
8
|
-
isReady?: boolean;
|
|
9
|
-
}) => DataTableStatus;
|
|
4
|
+
export declare const resolveDataTableStatus: (result: QueryStatusFlags) => DataTableStatus;
|
|
10
5
|
//# sourceMappingURL=resolveDataTableStatus.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveDataTableStatus.d.ts","sourceRoot":"","sources":["../../../DataTables/resolveDataTableStatus.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolveDataTableStatus.d.ts","sourceRoot":"","sources":["../../../DataTables/resolveDataTableStatus.ts"],"names":[],"mappings":"AAIA,OAAO,EAAsB,KAAK,gBAAgB,EAAE,MAAM,sCAAmC,CAAC;AAC9F,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAmB,CAAC;AASpD,8DAA8D;AAC9D,eAAO,MAAM,sBAAsB,WAAY,gBAAgB,KAAG,eACV,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveDataTableStatus.js","sources":["../../../DataTables/resolveDataTableStatus.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { QueryStatus } from '../QueryStatus/QueryStatus';\nimport { resolveQueryStatus } from '../QueryStatus/resolveQueryStatus';\nimport { DataTableStatus } from './DataTableStatus';\n\nconst tableStatusByQueryStatus: Record<QueryStatus, DataTableStatus> = {\n [QueryStatus.Ready]: DataTableStatus.Ready,\n [QueryStatus.Loading]: DataTableStatus.Loading,\n [QueryStatus.Failed]: DataTableStatus.Failed,\n [QueryStatus.Unauthorized]: DataTableStatus.Unauthorized,\n};\n\n/** Resolve Arc query flags into the table's display state. */\nexport const resolveDataTableStatus = (result:
|
|
1
|
+
{"version":3,"file":"resolveDataTableStatus.js","sources":["../../../DataTables/resolveDataTableStatus.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { QueryStatus } from '../QueryStatus/QueryStatus';\nimport { resolveQueryStatus, type QueryStatusFlags } from '../QueryStatus/resolveQueryStatus';\nimport { DataTableStatus } from './DataTableStatus';\n\nconst tableStatusByQueryStatus: Record<QueryStatus, DataTableStatus> = {\n [QueryStatus.Ready]: DataTableStatus.Ready,\n [QueryStatus.Loading]: DataTableStatus.Loading,\n [QueryStatus.Failed]: DataTableStatus.Failed,\n [QueryStatus.Unauthorized]: DataTableStatus.Unauthorized,\n};\n\n/** Resolve Arc query flags into the table's display state. */\nexport const resolveDataTableStatus = (result: QueryStatusFlags): DataTableStatus =>\n tableStatusByQueryStatus[resolveQueryStatus(result)];\n"],"names":[],"mappings":";;;;AAOA,MAAM,wBAAwB,GAAyC;AACnE,IAAA,CAAC,WAAW,CAAC,KAAK,GAAG,eAAe,CAAC,KAAK;AAC1C,IAAA,CAAC,WAAW,CAAC,OAAO,GAAG,eAAe,CAAC,OAAO;AAC9C,IAAA,CAAC,WAAW,CAAC,MAAM,GAAG,eAAe,CAAC,MAAM;AAC5C,IAAA,CAAC,WAAW,CAAC,YAAY,GAAG,eAAe,CAAC,YAAY;CAC3D;AAGM,MAAM,sBAAsB,GAAG,CAAC,MAAwB,KAC3D,wBAAwB,CAAC,kBAAkB,CAAC,MAAM,CAAC;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Sorting } from '@cratis/arc/queries';
|
|
2
|
+
import type { DataTableCoreProps } from './DataTableCore.js';
|
|
3
|
+
import type { DataTableFilterMeta } from './DataTableFilterMeta.js';
|
|
4
|
+
import { type DataTableServerQuery } from './DataTableServerQuery.js';
|
|
5
|
+
/** The sorting and paging delegates of an Arc paging hook. */
|
|
6
|
+
export interface ServerQueryControls {
|
|
7
|
+
setSorting: (sorting: Sorting) => unknown;
|
|
8
|
+
setPage: (page: number) => unknown;
|
|
9
|
+
}
|
|
10
|
+
/** The table props that hand a table's sort, filter and search state to the server. */
|
|
11
|
+
export type ServerQueryTableProps = Pick<DataTableCoreProps<object>, 'rowProcessing' | 'sort' | 'onSortChange' | 'filters' | 'onFilter' | 'globalFilter' | 'onGlobalFilterChange'>;
|
|
12
|
+
/** What a bound table needs to run in server mode, or to run unchanged without it. */
|
|
13
|
+
export interface ServerQueryBinding<TArguments extends object> {
|
|
14
|
+
/** The arguments to perform the query with. */
|
|
15
|
+
queryArguments: TArguments | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Builds the table props that drive the query through the paging hook's delegates.
|
|
18
|
+
* @param controls - The paging hook's sorting and paging delegates.
|
|
19
|
+
* @returns No props without a server query, so the table keeps its loaded-page behavior.
|
|
20
|
+
*/
|
|
21
|
+
tableProps(controls: ServerQueryControls): ServerQueryTableProps;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Keeps a bound table's sort, filter and search state for server mode and turns it into Arc sorting
|
|
25
|
+
* and query arguments. Without a server query it passes the arguments through and adds no table props.
|
|
26
|
+
* @param serverQuery - The server mode options, or undefined for loaded-page mode.
|
|
27
|
+
* @param queryArguments - The arguments the table was given.
|
|
28
|
+
* @param defaultFilters - The initial column filters.
|
|
29
|
+
* @returns The arguments to query with and the table props for server mode.
|
|
30
|
+
*/
|
|
31
|
+
export declare const useServerQuery: <TArguments extends object>(serverQuery: DataTableServerQuery<TArguments> | undefined, queryArguments: TArguments | undefined, defaultFilters: DataTableFilterMeta | undefined) => ServerQueryBinding<TArguments>;
|
|
32
|
+
//# sourceMappingURL=useServerQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useServerQuery.d.ts","sourceRoot":"","sources":["../../../DataTables/useServerQuery.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiB,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAiB,CAAC;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAAuB,CAAC;AAEjE,OAAO,EAEH,KAAK,oBAAoB,EAC5B,MAAM,2BAAwB,CAAC;AAIhC,8DAA8D;AAC9D,MAAM,WAAW,mBAAmB;IAChC,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;IAC1C,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACtC;AAED,uFAAuF;AACvF,MAAM,MAAM,qBAAqB,GAAG,IAAI,CACpC,kBAAkB,CAAC,MAAM,CAAC,EACxB,eAAe,GACf,MAAM,GACN,cAAc,GACd,SAAS,GACT,UAAU,GACV,cAAc,GACd,sBAAsB,CAC3B,CAAC;AAEF,sFAAsF;AACtF,MAAM,WAAW,kBAAkB,CAAC,UAAU,SAAS,MAAM;IACzD,+CAA+C;IAC/C,cAAc,EAAE,UAAU,GAAG,SAAS,CAAC;IACvC;;;;OAIG;IACH,UAAU,CAAC,QAAQ,EAAE,mBAAmB,GAAG,qBAAqB,CAAC;CACpE;AAiBD;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,UAAU,SAAS,MAAM,eACvC,oBAAoB,CAAC,UAAU,CAAC,GAAG,SAAS,kBACzC,UAAU,GAAG,SAAS,kBACtB,mBAAmB,GAAG,SAAS,KAChD,kBAAkB,CAAC,UAAU,CAsD/B,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useState, useRef, useEffect } from 'react';
|
|
2
|
+
import { Sorting, SortDirection } from '@cratis/arc/queries';
|
|
3
|
+
import { DataTableRowProcessing } from './DataTableRowProcessing.js';
|
|
4
|
+
import { defaultServerQuerySearchDebounceMilliseconds } from './DataTableServerQuery.js';
|
|
5
|
+
import { DataTableSortDirection } from './DataTableSortDirection.js';
|
|
6
|
+
|
|
7
|
+
const firstPage = 0;
|
|
8
|
+
const toSorting = (sort, sortFields) => sort
|
|
9
|
+
? new Sorting(sortFields?.[sort.field] ?? sort.field, sort.direction === DataTableSortDirection.Descending
|
|
10
|
+
? SortDirection.descending
|
|
11
|
+
: SortDirection.ascending)
|
|
12
|
+
: Sorting.none;
|
|
13
|
+
const useServerQuery = (serverQuery, queryArguments, defaultFilters) => {
|
|
14
|
+
const [sort, setSort] = useState(null);
|
|
15
|
+
const [filters, setFilters] = useState(defaultFilters ?? {});
|
|
16
|
+
const [searchText, setSearchText] = useState('');
|
|
17
|
+
const [appliedSearch, setAppliedSearch] = useState('');
|
|
18
|
+
const appliedSearchRef = useRef('');
|
|
19
|
+
const searchTimerRef = useRef(undefined);
|
|
20
|
+
useEffect(() => () => clearTimeout(searchTimerRef.current), []);
|
|
21
|
+
if (!serverQuery) {
|
|
22
|
+
return { queryArguments, tableProps: () => ({}) };
|
|
23
|
+
}
|
|
24
|
+
const debounceMilliseconds = serverQuery.searchDebounceMilliseconds ?? defaultServerQuerySearchDebounceMilliseconds;
|
|
25
|
+
const serverArguments = {
|
|
26
|
+
...queryArguments,
|
|
27
|
+
...serverQuery.toArguments({ filters, globalFilter: appliedSearch }),
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
queryArguments: serverArguments,
|
|
31
|
+
tableProps: ({ setSorting, setPage }) => ({
|
|
32
|
+
rowProcessing: DataTableRowProcessing.None,
|
|
33
|
+
sort,
|
|
34
|
+
onSortChange: (next) => {
|
|
35
|
+
setSort(next);
|
|
36
|
+
setSorting(toSorting(next, serverQuery.sortFields));
|
|
37
|
+
setPage(firstPage);
|
|
38
|
+
},
|
|
39
|
+
filters,
|
|
40
|
+
onFilter: (next) => {
|
|
41
|
+
setFilters(next);
|
|
42
|
+
setPage(firstPage);
|
|
43
|
+
},
|
|
44
|
+
globalFilter: searchText,
|
|
45
|
+
onGlobalFilterChange: (next) => {
|
|
46
|
+
setSearchText(next);
|
|
47
|
+
clearTimeout(searchTimerRef.current);
|
|
48
|
+
const apply = () => {
|
|
49
|
+
if (next === appliedSearchRef.current)
|
|
50
|
+
return;
|
|
51
|
+
appliedSearchRef.current = next;
|
|
52
|
+
setAppliedSearch(next);
|
|
53
|
+
setPage(firstPage);
|
|
54
|
+
};
|
|
55
|
+
if (debounceMilliseconds > 0) {
|
|
56
|
+
searchTimerRef.current = setTimeout(apply, debounceMilliseconds);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
apply();
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
}),
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export { useServerQuery };
|
|
67
|
+
//# sourceMappingURL=useServerQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useServerQuery.js","sources":["../../../DataTables/useServerQuery.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { useEffect, useRef, useState } from 'react';\nimport { SortDirection, Sorting } from '@cratis/arc/queries';\nimport type { DataTableCoreProps } from './DataTableCore';\nimport type { DataTableFilterMeta } from './DataTableFilterMeta';\nimport { DataTableRowProcessing } from './DataTableRowProcessing';\nimport {\n defaultServerQuerySearchDebounceMilliseconds,\n type DataTableServerQuery,\n} from './DataTableServerQuery';\nimport type { DataTableSort } from './DataTableSort';\nimport { DataTableSortDirection } from './DataTableSortDirection';\n\n/** The sorting and paging delegates of an Arc paging hook. */\nexport interface ServerQueryControls {\n setSorting: (sorting: Sorting) => unknown;\n setPage: (page: number) => unknown;\n}\n\n/** The table props that hand a table's sort, filter and search state to the server. */\nexport type ServerQueryTableProps = Pick<\n DataTableCoreProps<object>,\n | 'rowProcessing'\n | 'sort'\n | 'onSortChange'\n | 'filters'\n | 'onFilter'\n | 'globalFilter'\n | 'onGlobalFilterChange'\n>;\n\n/** What a bound table needs to run in server mode, or to run unchanged without it. */\nexport interface ServerQueryBinding<TArguments extends object> {\n /** The arguments to perform the query with. */\n queryArguments: TArguments | undefined;\n /**\n * Builds the table props that drive the query through the paging hook's delegates.\n * @param controls - The paging hook's sorting and paging delegates.\n * @returns No props without a server query, so the table keeps its loaded-page behavior.\n */\n tableProps(controls: ServerQueryControls): ServerQueryTableProps;\n}\n\nconst firstPage = 0;\n\nconst toSorting = (\n sort: DataTableSort | null,\n sortFields: Readonly<Record<string, string>> | undefined,\n): Sorting =>\n sort\n ? new Sorting(\n sortFields?.[sort.field] ?? sort.field,\n sort.direction === DataTableSortDirection.Descending\n ? SortDirection.descending\n : SortDirection.ascending,\n )\n : Sorting.none;\n\n/**\n * Keeps a bound table's sort, filter and search state for server mode and turns it into Arc sorting\n * and query arguments. Without a server query it passes the arguments through and adds no table props.\n * @param serverQuery - The server mode options, or undefined for loaded-page mode.\n * @param queryArguments - The arguments the table was given.\n * @param defaultFilters - The initial column filters.\n * @returns The arguments to query with and the table props for server mode.\n */\nexport const useServerQuery = <TArguments extends object>(\n serverQuery: DataTableServerQuery<TArguments> | undefined,\n queryArguments: TArguments | undefined,\n defaultFilters: DataTableFilterMeta | undefined,\n): ServerQueryBinding<TArguments> => {\n const [sort, setSort] = useState<DataTableSort | null>(null);\n const [filters, setFilters] = useState<DataTableFilterMeta>(defaultFilters ?? {});\n const [searchText, setSearchText] = useState('');\n const [appliedSearch, setAppliedSearch] = useState('');\n const appliedSearchRef = useRef('');\n const searchTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n useEffect(() => () => clearTimeout(searchTimerRef.current), []);\n\n if (!serverQuery) {\n return { queryArguments, tableProps: () => ({}) };\n }\n\n const debounceMilliseconds =\n serverQuery.searchDebounceMilliseconds ?? defaultServerQuerySearchDebounceMilliseconds;\n const serverArguments = {\n ...queryArguments,\n ...serverQuery.toArguments({ filters, globalFilter: appliedSearch }),\n } as TArguments;\n\n return {\n queryArguments: serverArguments,\n tableProps: ({ setSorting, setPage }) => ({\n rowProcessing: DataTableRowProcessing.None,\n sort,\n onSortChange: (next) => {\n setSort(next);\n setSorting(toSorting(next, serverQuery.sortFields));\n setPage(firstPage);\n },\n filters,\n onFilter: (next) => {\n setFilters(next);\n setPage(firstPage);\n },\n globalFilter: searchText,\n onGlobalFilterChange: (next) => {\n setSearchText(next);\n clearTimeout(searchTimerRef.current);\n const apply = () => {\n if (next === appliedSearchRef.current) return;\n appliedSearchRef.current = next;\n setAppliedSearch(next);\n setPage(firstPage);\n };\n if (debounceMilliseconds > 0) {\n searchTimerRef.current = setTimeout(apply, debounceMilliseconds);\n } else {\n apply();\n }\n },\n }),\n };\n};\n"],"names":[],"mappings":";;;;;;AA6CA,MAAM,SAAS,GAAG,CAAC;AAEnB,MAAM,SAAS,GAAG,CACd,IAA0B,EAC1B,UAAwD,KAExD;MACM,IAAI,OAAO,CACT,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,EACtC,IAAI,CAAC,SAAS,KAAK,sBAAsB,CAAC;UACpC,aAAa,CAAC;AAChB,UAAE,aAAa,CAAC,SAAS;AAEjC,MAAE,OAAO,CAAC,IAAI;AAUf,MAAM,cAAc,GAAG,CAC1B,WAAyD,EACzD,cAAsC,EACtC,cAA+C,KACf;IAChC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAuB,IAAI,CAAC;AAC5D,IAAA,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAsB,cAAc,IAAI,EAAE,CAAC;IACjF,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC;IAChD,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC;AACtD,IAAA,MAAM,gBAAgB,GAAG,MAAM,CAAC,EAAE,CAAC;AACnC,IAAA,MAAM,cAAc,GAAG,MAAM,CAA4C,SAAS,CAAC;AAEnF,IAAA,SAAS,CAAC,MAAM,MAAM,YAAY,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;IAE/D,IAAI,CAAC,WAAW,EAAE;AACd,QAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,EAAE;IACrD;AAEA,IAAA,MAAM,oBAAoB,GACtB,WAAW,CAAC,0BAA0B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
|
1
1
|
import { QueryStatus } from './QueryStatus.js';
|
|
2
|
-
/**
|
|
3
|
-
export
|
|
2
|
+
/** The Arc query flags a display state is resolved from. */
|
|
3
|
+
export interface QueryStatusFlags {
|
|
4
|
+
isSuccess?: boolean;
|
|
4
5
|
isAuthorized?: boolean;
|
|
5
6
|
hasExceptions?: boolean;
|
|
6
7
|
isValid?: boolean;
|
|
7
8
|
isPerforming?: boolean;
|
|
8
9
|
isReady?: boolean;
|
|
9
|
-
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Resolve Arc query flags into a component-neutral display state. A settled result that is not
|
|
13
|
+
* successful is a failure even when no other flag explains why, such as a response Arc could not
|
|
14
|
+
* read; it never resolves to ready, which would present the failure as an empty result.
|
|
15
|
+
*/
|
|
16
|
+
export declare const resolveQueryStatus: (result: QueryStatusFlags) => QueryStatus;
|
|
10
17
|
//# sourceMappingURL=resolveQueryStatus.d.ts.map
|