@marktiderman/genesis-ui-native 2.7.1 → 2.8.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/dist/data/index.d.ts +11 -8
- package/dist/data/index.js +11 -6
- package/dist/data/index.js.map +1 -1
- package/package.json +2 -2
- package/src/data/resource-view/__tests__/native-resource-view.test.tsx +18 -1
- package/src/data/resource-view/index.ts +1 -0
- package/src/data/resource-view/use-native-resource-view.ts +17 -10
package/dist/data/index.d.ts
CHANGED
|
@@ -384,15 +384,18 @@ interface UseNativeResourceViewReturn<T extends Row$2 = Row$2> {
|
|
|
384
384
|
declare function screenValues(...filters: (Filter | undefined)[]): Record<string, string | number | boolean>;
|
|
385
385
|
/** Pages kept loaded by default (cursor paging). */
|
|
386
386
|
declare const DEFAULT_MAX_PAGES = 10;
|
|
387
|
-
|
|
388
|
-
* The server sort: the `groupBy` field first, so every page arrives in section order and a later
|
|
389
|
-
* page never lands in the middle of an earlier section; else the view's `orderBy`. (A second sort
|
|
390
|
-
* key within a group needs `useInfiniteResource` to take several sorts.)
|
|
391
|
-
*/
|
|
392
|
-
declare function serverSort<T extends Row$2>(view: AnyResourceView<T>): {
|
|
387
|
+
type ServerSort = {
|
|
393
388
|
field: string;
|
|
394
389
|
order: "asc" | "desc";
|
|
395
|
-
}
|
|
390
|
+
};
|
|
391
|
+
/**
|
|
392
|
+
* The server sorts: the `groupBy` field first, so every page arrives in section order and a later
|
|
393
|
+
* page never lands in the middle of an earlier section, then the view's `orderBy` within each
|
|
394
|
+
* group. A provider without `multiSort` applies only the first.
|
|
395
|
+
*/
|
|
396
|
+
declare function serverSorts<T extends Row$2>(view: AnyResourceView<T>): ServerSort[];
|
|
397
|
+
/** The first of {@link serverSorts}: what a provider that sorts by one field gets. */
|
|
398
|
+
declare function serverSort<T extends Row$2>(view: AnyResourceView<T>): ServerSort | undefined;
|
|
396
399
|
declare function useNativeResourceView<T extends Row$2 = Row$2>(view: AnyResourceView<T>, options?: NativeResourceViewOptions<T>): UseNativeResourceViewReturn<T>;
|
|
397
400
|
|
|
398
401
|
type Row$1 = Record<string, unknown>;
|
|
@@ -597,4 +600,4 @@ declare function NativeResourceWorkspace<T extends Row = Row>(props: NativeResou
|
|
|
597
600
|
*/
|
|
598
601
|
declare function parseSettingNumber(text: string): number | null;
|
|
599
602
|
|
|
600
|
-
export { type AnyResourceView, DEFAULT_MAX_PAGES, type DisplayContext, type DisplayRenderer, type DisplayRenderers, DisplayRenderersProvider, type DisplayTimeZones, DisplayTimeZonesProvider, type NativeCardFieldDef, NativeDataFilters, type NativeDataFiltersProps, NativeDataPageShell, type NativeDataPageShellProps, type NativeDetailField, NativeDetailPanel, type NativeDetailPanelProps, NativeEmptyState, type NativeEmptyStateProps, type NativeFormField, type NativeFormFieldKind, NativeResourceForm, NativeResourceFormFieldRenderer, type NativeResourceFormFieldRendererProps, type NativeResourceFormProps, NativeResourceFormSheet, type NativeResourceFormSheetProps, NativeResourcePage, type NativeResourcePageProps, type NativeResourceRowItem, type NativeResourceScreenCan, type NativeResourceSection, type NativeResourceSwipeAction, type NativeResourceSwipeableProps, NativeResourceView, type NativeResourceViewMessages, NativeResourceViewMessagesProvider, type NativeResourceViewOptions, type NativeResourceViewProps, NativeResourceWorkspace, type NativeResourceWorkspaceHeaderProps, NativeResourceWorkspaceMenu, type NativeResourceWorkspaceMessages, type NativeResourceWorkspaceProps, SEARCH_DEBOUNCE_MS, SEGMENTED_SECTIONS_MAX, type SaveResult, type UseNativeResourceViewReturn, allowed, dateToDay, dayToDate, defaultNativeResourceViewMessages, defaultNativeResourceWorkspaceMessages, displayText, formFieldsFor, formatDay, formatInstant, getNativeResourceWorkspaceStackOptions, nativeDisplayRenderers, openableUrl, parseSettingNumber, resolveZone, rowItem, screenValues, sectionsFor, serverSort, swipeActionsFor, useDisplayCell, useDisplayTimeZones, useNativeResourceView, useNativeResourceViewMessages, validateValues, writableValues };
|
|
603
|
+
export { type AnyResourceView, DEFAULT_MAX_PAGES, type DisplayContext, type DisplayRenderer, type DisplayRenderers, DisplayRenderersProvider, type DisplayTimeZones, DisplayTimeZonesProvider, type NativeCardFieldDef, NativeDataFilters, type NativeDataFiltersProps, NativeDataPageShell, type NativeDataPageShellProps, type NativeDetailField, NativeDetailPanel, type NativeDetailPanelProps, NativeEmptyState, type NativeEmptyStateProps, type NativeFormField, type NativeFormFieldKind, NativeResourceForm, NativeResourceFormFieldRenderer, type NativeResourceFormFieldRendererProps, type NativeResourceFormProps, NativeResourceFormSheet, type NativeResourceFormSheetProps, NativeResourcePage, type NativeResourcePageProps, type NativeResourceRowItem, type NativeResourceScreenCan, type NativeResourceSection, type NativeResourceSwipeAction, type NativeResourceSwipeableProps, NativeResourceView, type NativeResourceViewMessages, NativeResourceViewMessagesProvider, type NativeResourceViewOptions, type NativeResourceViewProps, NativeResourceWorkspace, type NativeResourceWorkspaceHeaderProps, NativeResourceWorkspaceMenu, type NativeResourceWorkspaceMessages, type NativeResourceWorkspaceProps, SEARCH_DEBOUNCE_MS, SEGMENTED_SECTIONS_MAX, type SaveResult, type UseNativeResourceViewReturn, allowed, dateToDay, dayToDate, defaultNativeResourceViewMessages, defaultNativeResourceWorkspaceMessages, displayText, formFieldsFor, formatDay, formatInstant, getNativeResourceWorkspaceStackOptions, nativeDisplayRenderers, openableUrl, parseSettingNumber, resolveZone, rowItem, screenValues, sectionsFor, serverSort, serverSorts, swipeActionsFor, useDisplayCell, useDisplayTimeZones, useNativeResourceView, useNativeResourceViewMessages, validateValues, writableValues };
|
package/dist/data/index.js
CHANGED
|
@@ -1375,11 +1375,16 @@ function screenValues(...filters) {
|
|
|
1375
1375
|
return out;
|
|
1376
1376
|
}
|
|
1377
1377
|
var DEFAULT_MAX_PAGES = 10;
|
|
1378
|
-
function
|
|
1378
|
+
function serverSorts(view) {
|
|
1379
1379
|
const groupBy = view.definition.groupBy;
|
|
1380
1380
|
const orderBy = view.definition.orderBy;
|
|
1381
|
-
|
|
1382
|
-
return
|
|
1381
|
+
const order = orderBy ? { field: orderBy.field, order: orderBy.direction ?? "asc" } : void 0;
|
|
1382
|
+
if (!groupBy) return order ? [order] : [];
|
|
1383
|
+
if (order?.field === groupBy) return [order];
|
|
1384
|
+
return [{ field: groupBy, order: "asc" }, ...order ? [order] : []];
|
|
1385
|
+
}
|
|
1386
|
+
function serverSort(view) {
|
|
1387
|
+
return serverSorts(view)[0];
|
|
1383
1388
|
}
|
|
1384
1389
|
function useNativeResourceView(view, options = {}) {
|
|
1385
1390
|
const { preset, filter, perPage, maxPages = DEFAULT_MAX_PAGES, searchFields: searchOption, can, live } = options;
|
|
@@ -1390,14 +1395,14 @@ function useNativeResourceView(view, options = {}) {
|
|
|
1390
1395
|
const defaultFilters = useMemo(() => [...filterParams(tabFilter), ...filterParams(filter)], [tabFilter, filter]);
|
|
1391
1396
|
const createKey = JSON.stringify(screenValues(tabFilter, filter));
|
|
1392
1397
|
const createDefaults = useMemo(() => JSON.parse(createKey), [createKey]);
|
|
1393
|
-
const
|
|
1398
|
+
const sorts = useMemo(() => serverSorts(view), [view]);
|
|
1394
1399
|
const searchFields = useMemo(
|
|
1395
1400
|
() => searchOption ?? (view.labelField ? [view.labelField] : void 0),
|
|
1396
1401
|
[searchOption, view.labelField]
|
|
1397
1402
|
);
|
|
1398
1403
|
const pages = useInfiniteResource(view.resource, {
|
|
1399
1404
|
defaultFilters,
|
|
1400
|
-
...
|
|
1405
|
+
...sorts.length ? { defaultSorts: sorts } : {},
|
|
1401
1406
|
...perPage ? { perPage } : {},
|
|
1402
1407
|
maxPages,
|
|
1403
1408
|
...searchFields ? { searchFields } : {},
|
|
@@ -2254,6 +2259,6 @@ function Cell({ last, children }) {
|
|
|
2254
2259
|
] });
|
|
2255
2260
|
}
|
|
2256
2261
|
|
|
2257
|
-
export { DEFAULT_MAX_PAGES, DisplayRenderersProvider, DisplayTimeZonesProvider, NativeDataFilters, NativeDataPageShell, NativeDetailPanel, NativeEmptyState2 as NativeEmptyState, NativeResourceForm, NativeResourceFormFieldRenderer, NativeResourceFormSheet, NativeResourcePage, NativeResourceView, NativeResourceViewMessagesProvider, NativeResourceWorkspace, NativeResourceWorkspaceMenu, SEARCH_DEBOUNCE_MS, SEGMENTED_SECTIONS_MAX, allowed, dateToDay, dayToDate, defaultNativeResourceViewMessages, defaultNativeResourceWorkspaceMessages, displayText, formFieldsFor, formatDay, formatInstant, getNativeResourceWorkspaceStackOptions, nativeDisplayRenderers, openableUrl, parseSettingNumber, resolveZone, rowItem, screenValues, sectionsFor, serverSort, swipeActionsFor, useDisplayCell, useDisplayTimeZones, useNativeResourceView, useNativeResourceViewMessages, validateValues, writableValues };
|
|
2262
|
+
export { DEFAULT_MAX_PAGES, DisplayRenderersProvider, DisplayTimeZonesProvider, NativeDataFilters, NativeDataPageShell, NativeDetailPanel, NativeEmptyState2 as NativeEmptyState, NativeResourceForm, NativeResourceFormFieldRenderer, NativeResourceFormSheet, NativeResourcePage, NativeResourceView, NativeResourceViewMessagesProvider, NativeResourceWorkspace, NativeResourceWorkspaceMenu, SEARCH_DEBOUNCE_MS, SEGMENTED_SECTIONS_MAX, allowed, dateToDay, dayToDate, defaultNativeResourceViewMessages, defaultNativeResourceWorkspaceMessages, displayText, formFieldsFor, formatDay, formatInstant, getNativeResourceWorkspaceStackOptions, nativeDisplayRenderers, openableUrl, parseSettingNumber, resolveZone, rowItem, screenValues, sectionsFor, serverSort, serverSorts, swipeActionsFor, useDisplayCell, useDisplayTimeZones, useNativeResourceView, useNativeResourceViewMessages, validateValues, writableValues };
|
|
2258
2263
|
//# sourceMappingURL=index.js.map
|
|
2259
2264
|
//# sourceMappingURL=index.js.map
|