@marktiderman/genesis-ui-native 2.7.1 → 2.8.1
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 +16 -9
- package/dist/data/index.js +19 -9
- package/dist/data/index.js.map +1 -1
- package/package.json +2 -2
- package/src/data/resource-view/__tests__/native-resource-view.test.tsx +21 -1
- package/src/data/resource-view/display.tsx +12 -3
- 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>;
|
|
@@ -472,7 +475,11 @@ declare function dayToDate(value: unknown): Date | null;
|
|
|
472
475
|
/** A picked Date back to the `YYYY-MM-DD` day it shows, from its local parts (never `toISOString`). */
|
|
473
476
|
declare function dateToDay(date: Date): string;
|
|
474
477
|
/** A calendar day, the same day on every clock. */
|
|
475
|
-
|
|
478
|
+
/**
|
|
479
|
+
* A day. A calendar day (`YYYY-MM-DD`) from its parts; a timestamp as the day it is on `zone`'s
|
|
480
|
+
* clock (core's `wallClock`), so an 8pm edit in New York isn't tomorrow's (its UTC day).
|
|
481
|
+
*/
|
|
482
|
+
declare function formatDay(value: unknown, zone?: string): string;
|
|
476
483
|
/** A column's clock: "viewer" (the default) and "practice" from `zones`, else a valid IANA name. */
|
|
477
484
|
declare function resolveZone(zone: string | undefined, zones: DisplayTimeZones): string;
|
|
478
485
|
/** A timestamp as the clock on the wall in `zone` shows it (core's `wallClock`), not the device's. */
|
|
@@ -597,4 +604,4 @@ declare function NativeResourceWorkspace<T extends Row = Row>(props: NativeResou
|
|
|
597
604
|
*/
|
|
598
605
|
declare function parseSettingNumber(text: string): number | null;
|
|
599
606
|
|
|
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 };
|
|
607
|
+
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
|
@@ -870,9 +870,14 @@ function dateToDay(date) {
|
|
|
870
870
|
const pad = (n) => String(n).padStart(2, "0");
|
|
871
871
|
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
872
872
|
}
|
|
873
|
-
function formatDay(value) {
|
|
873
|
+
function formatDay(value, zone = personTimeZone()) {
|
|
874
874
|
const date = dayToDate(value);
|
|
875
|
-
|
|
875
|
+
if (date) return DAY.format(date);
|
|
876
|
+
const text2 = String(value);
|
|
877
|
+
const at = /^\d{4}-\d{2}-\d{2}[T ]/.test(text2) ? new Date(text2) : null;
|
|
878
|
+
if (!at || Number.isNaN(at.getTime()) || !isTimeZone(zone)) return text2;
|
|
879
|
+
const wall = wallClock(zone, at);
|
|
880
|
+
return DAY.format(new Date(wall.year, wall.month - 1, wall.day));
|
|
876
881
|
}
|
|
877
882
|
function resolveZone(zone, zones) {
|
|
878
883
|
if (!zone || zone === "viewer") return zones.viewer;
|
|
@@ -905,7 +910,7 @@ function displayText(hint, value, messages, timeZone = personTimeZone()) {
|
|
|
905
910
|
case "badge":
|
|
906
911
|
return titleCase(String(value));
|
|
907
912
|
case "date":
|
|
908
|
-
return formatDay(value);
|
|
913
|
+
return formatDay(value, timeZone);
|
|
909
914
|
case "datetime":
|
|
910
915
|
return formatInstant(value, timeZone);
|
|
911
916
|
case "url": {
|
|
@@ -1375,11 +1380,16 @@ function screenValues(...filters) {
|
|
|
1375
1380
|
return out;
|
|
1376
1381
|
}
|
|
1377
1382
|
var DEFAULT_MAX_PAGES = 10;
|
|
1378
|
-
function
|
|
1383
|
+
function serverSorts(view) {
|
|
1379
1384
|
const groupBy = view.definition.groupBy;
|
|
1380
1385
|
const orderBy = view.definition.orderBy;
|
|
1381
|
-
|
|
1382
|
-
return
|
|
1386
|
+
const order = orderBy ? { field: orderBy.field, order: orderBy.direction ?? "asc" } : void 0;
|
|
1387
|
+
if (!groupBy) return order ? [order] : [];
|
|
1388
|
+
if (order?.field === groupBy) return [order];
|
|
1389
|
+
return [{ field: groupBy, order: "asc" }, ...order ? [order] : []];
|
|
1390
|
+
}
|
|
1391
|
+
function serverSort(view) {
|
|
1392
|
+
return serverSorts(view)[0];
|
|
1383
1393
|
}
|
|
1384
1394
|
function useNativeResourceView(view, options = {}) {
|
|
1385
1395
|
const { preset, filter, perPage, maxPages = DEFAULT_MAX_PAGES, searchFields: searchOption, can, live } = options;
|
|
@@ -1390,14 +1400,14 @@ function useNativeResourceView(view, options = {}) {
|
|
|
1390
1400
|
const defaultFilters = useMemo(() => [...filterParams(tabFilter), ...filterParams(filter)], [tabFilter, filter]);
|
|
1391
1401
|
const createKey = JSON.stringify(screenValues(tabFilter, filter));
|
|
1392
1402
|
const createDefaults = useMemo(() => JSON.parse(createKey), [createKey]);
|
|
1393
|
-
const
|
|
1403
|
+
const sorts = useMemo(() => serverSorts(view), [view]);
|
|
1394
1404
|
const searchFields = useMemo(
|
|
1395
1405
|
() => searchOption ?? (view.labelField ? [view.labelField] : void 0),
|
|
1396
1406
|
[searchOption, view.labelField]
|
|
1397
1407
|
);
|
|
1398
1408
|
const pages = useInfiniteResource(view.resource, {
|
|
1399
1409
|
defaultFilters,
|
|
1400
|
-
...
|
|
1410
|
+
...sorts.length ? { defaultSorts: sorts } : {},
|
|
1401
1411
|
...perPage ? { perPage } : {},
|
|
1402
1412
|
maxPages,
|
|
1403
1413
|
...searchFields ? { searchFields } : {},
|
|
@@ -2254,6 +2264,6 @@ function Cell({ last, children }) {
|
|
|
2254
2264
|
] });
|
|
2255
2265
|
}
|
|
2256
2266
|
|
|
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 };
|
|
2267
|
+
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
2268
|
//# sourceMappingURL=index.js.map
|
|
2259
2269
|
//# sourceMappingURL=index.js.map
|