@marktiderman/genesis-ui-native 3.12.1 → 3.14.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/{chunk-TUDJDIGC.js → chunk-DCCOZSGR.js} +4 -2
- package/dist/chunk-DCCOZSGR.js.map +1 -0
- package/dist/{chunk-47CDRP43.js → chunk-G5M2Q7OU.js} +77 -4
- package/dist/chunk-G5M2Q7OU.js.map +1 -0
- package/dist/{chunk-C2ARUGT7.js → chunk-SRCGQWE4.js} +3 -3
- package/dist/{chunk-C2ARUGT7.js.map → chunk-SRCGQWE4.js.map} +1 -1
- package/dist/{chunk-X5CPLUPZ.js → chunk-WTO3LIUS.js} +4 -77
- package/dist/chunk-WTO3LIUS.js.map +1 -0
- package/dist/components/index.js +2 -2
- package/dist/data/index.d.ts +170 -27
- package/dist/data/index.js +493 -24
- package/dist/data/index.js.map +1 -1
- package/dist/{inbox-page-BGqR_cBs.d.ts → inbox-page-DD1cQdF4.d.ts} +6 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/layouts/index.d.ts +2 -2
- package/dist/layouts/index.js +2 -2
- package/package.json +3 -3
- package/src/data/NativeRecordPeek.tsx +12 -1
- package/src/data/__tests__/parity-data.test.tsx +26 -0
- package/src/data/resource-view/NativeRecordView.tsx +15 -2
- package/src/data/resource-view/NativeResourceView.tsx +153 -16
- package/src/data/resource-view/__tests__/native-record-view.test.tsx +24 -0
- package/src/data/resource-view/__tests__/native-resource-inbox.test.tsx +59 -0
- package/src/data/resource-view/__tests__/native-resource-lists.test.tsx +281 -0
- package/src/data/resource-view/index.ts +12 -1
- package/src/data/resource-view/list-controls.tsx +508 -0
- package/src/data/resource-view/mapping.ts +10 -0
- package/src/data/resource-view/messages.ts +70 -0
- package/src/data/resource-view/use-native-resource-view.ts +13 -3
- package/src/layouts/__tests__/inbox-page-start.test.tsx +39 -0
- package/src/layouts/inbox-page.tsx +7 -0
- package/dist/chunk-47CDRP43.js.map +0 -1
- package/dist/chunk-TUDJDIGC.js.map +0 -1
- package/dist/chunk-X5CPLUPZ.js.map +0 -1
|
@@ -130,6 +130,11 @@ interface InboxPageProps extends ScreenHeaderProps {
|
|
|
130
130
|
onRefresh?: () => void | Promise<void>;
|
|
131
131
|
/** Called near the end of the list, to load the next page. */
|
|
132
132
|
onEndReached?: () => void;
|
|
133
|
+
/**
|
|
134
|
+
* Called near the top, to load back a page the list dropped from the front (a list that keeps a
|
|
135
|
+
* bounded number of pages). The rows on screen keep their place while it's added above.
|
|
136
|
+
*/
|
|
137
|
+
onStartReached?: () => void;
|
|
133
138
|
/** A next page is loading: the default footer shows a spinner. */
|
|
134
139
|
loadingMore?: boolean;
|
|
135
140
|
/** Above the group (a filter, a call to action). Prefer `slots.header` for a component. */
|
|
@@ -160,7 +165,7 @@ interface InboxPageProps extends ScreenHeaderProps {
|
|
|
160
165
|
declare function getInboxPageStackOptions(props: ScreenHeaderProps & {
|
|
161
166
|
headerTitle?: string;
|
|
162
167
|
}): Record<string, unknown>;
|
|
163
|
-
declare function InboxPage({ items, refreshing, onRefresh, onEndReached, loadingMore, header, sectionTitle, emptyTitle, emptyBody, emptyActionLabel, onEmptyAction, loading, error, errorTitle, errorBody, formatTime, now, slots, slotProps, testID, }: InboxPageProps): react.JSX.Element;
|
|
168
|
+
declare function InboxPage({ items, refreshing, onRefresh, onEndReached, onStartReached, loadingMore, header, sectionTitle, emptyTitle, emptyBody, emptyActionLabel, onEmptyAction, loading, error, errorTitle, errorBody, formatTime, now, slots, slotProps, testID, }: InboxPageProps): react.JSX.Element;
|
|
164
169
|
/**
|
|
165
170
|
* Opens a row's actions as the system alert. `InboxPage` now opens `NativeContextMenu`; `NativeResourceView`
|
|
166
171
|
* still uses this.
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { G as GenesisDatePickerComponent, a as GenesisDatePickerProps, b as Gene
|
|
|
3
3
|
export { DEFAULT_GALLERY_RATIO, GALLERY_DEFAULTS, GalleryItem, GalleryTileAspect, JustifiedRow, JustifiedTile, galleryItemRatio, justifyRows } from '@marktiderman/genesis-core/gallery';
|
|
4
4
|
export { BrandExtensionsProvider, BrandExtensionsProviderProps, BrandExtensionsValue, MotionHow, MotionSpringConfig, MotionTimingConfig, PressFeedback, PressFeedbackOptions, ThemeMode, ThemeRoleColors, UseMotionOptions, UseThemeRolesOptions, animateMotion, motionSpring, motionTiming, sentBubbleColor, useGenesisExtension, useMotion, usePressFeedback, useReducedMotion, useThemeMode, useThemeRoles } from './hooks/index.js';
|
|
5
5
|
export { ComposerMode, ComposerTone, InboxItem, InboxSwipeAction, JUMP_SETTLE_MS, MessageTone, ThreadAttachment, ThreadComposer, ThreadLabels, ThreadMessage, ThreadMessageStatus, UseThreadJumpOptions, formatInboxTime, readReceiptFor, useThreadJump } from '@marktiderman/genesis-core/conversation';
|
|
6
|
-
export { I as InboxPage, a as InboxPageProps, b as InboxPageSlotMap, S as SafeAreaEdge, c as ScreenContainer, d as ScreenContainerProps, e as ScreenHeaderProps, f as ScrollEdgeBehavior, g as composeHeaderOptions, h as getInboxPageStackOptions, s as showInboxActions } from './inbox-page-
|
|
6
|
+
export { I as InboxPage, a as InboxPageProps, b as InboxPageSlotMap, S as SafeAreaEdge, c as ScreenContainer, d as ScreenContainerProps, e as ScreenHeaderProps, f as ScrollEdgeBehavior, g as composeHeaderOptions, h as getInboxPageStackOptions, s as showInboxActions } from './inbox-page-DD1cQdF4.js';
|
|
7
7
|
export { AppleButtonModuleLike, AppleProviderOptions, AppleSignInButton, AppleSignInButtonProps, AuthBranding, AuthBrandingProps, AuthForm, AuthFormProps, AuthFormValues, AuthScreen, AuthScreenProps, AuthScreenSlotMap, DashboardPage, DashboardPageProps, DetailPage, DetailPageProps, DocumentPage, DocumentPageProps, ForgotPasswordLink, FormPage, FormPageProps, GoogleProviderOptions, KEYBOARD_TOOLBAR_HEIGHT, KeyboardScrollProps, KeyboardScrollProvider, KeyboardStickyProps, KeyboardToolbarProps, NavBarSaveButton, NavBarSaveButtonProps, NavBarSearchBar, NavBarSearchBarProps, NavBarTitle, NavBarTitleProps, NotificationItem, NotificationsPage, NotificationsPageProps, NotificationsPageSlotMap, SettingsPage, SettingsPageDangerousAction, SettingsPageProps, SettingsPageRow, SettingsPageSection, SettingsPageSlotMap, SettingsSubPage, SettingsSubPageProps, SocialAuthProvider, SocialAuthRow, SocialAuthRowProps, ThreadPage, ThreadPageProps, ThreadPageSlotMap, appleProvider, confirmDiscardChanges, defaultStickyHeaderOffset, getNotificationsPageStackOptions, getSettingsPageStackOptions, getSettingsSubPageStackOptions, getThreadPageStackOptions, googleProvider, iosCompactNavigationBarHeight, useKeyboardScroll, useKeyboardSticky, useKeyboardToolbar } from './layouts/index.js';
|
|
8
8
|
export { cn } from './utils.js';
|
|
9
9
|
import 'react';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { Box, FULL_SCREEN_DARK, Grid, Inline, LIGHTBOX_DISMISS_DISTANCE, LIGHTBOX_DISMISS_VELOCITY, LIGHTBOX_DOUBLE_TAP_MS, LIGHTBOX_MAX_ZOOM, NativeAccordion, NativeAccordionContent, NativeAccordionItem, NativeAccordionTrigger, NativeBulkBar, NativeButtonGroup, NativeCalendar, NativeCarousel, NativeChartContainer,
|
|
2
|
-
export { DEFAULT_GALLERY_RATIO, GALLERY_DEFAULTS, NativeAlert, NativeAlertDescription, NativeAlertTitle, NativeAvatar, NativeCard, NativeCardContent, NativeCardDescription, NativeCardFooter, NativeCardHeader, NativeCardTitle, NativeCheckbox, NativeDatePicker, NativeGalleryGrid, NativeLabel, NativeProgress, NativeSearchBar, NativeSegmentedControl, NativeSelect, NativeSelectContent, NativeSelectItem, NativeSelectTrigger, NativeSeparator, NativeSwitch, NativeTextarea, NativeTimePicker, alertVariants, galleryItemRatio, justifyRows } from './chunk-
|
|
1
|
+
export { Box, FULL_SCREEN_DARK, Grid, Inline, LIGHTBOX_DISMISS_DISTANCE, LIGHTBOX_DISMISS_VELOCITY, LIGHTBOX_DOUBLE_TAP_MS, LIGHTBOX_MAX_ZOOM, NativeAccordion, NativeAccordionContent, NativeAccordionItem, NativeAccordionTrigger, NativeBulkBar, NativeButtonGroup, NativeCalendar, NativeCarousel, NativeChartContainer, NativeChoiceCard, NativeCombobox, NativeDialog, NativeDialogContent, NativeDialogDescription, NativeDialogFooter, NativeDialogHeader, NativeDialogTitle, NativeDrawer, NativeDropdownMenu, NativeDropdownMenuContent, NativeDropdownMenuItem, NativeDropdownMenuTrigger, NativeFollowUpList, NativeFullScreenModal, NativeGalleryCard, NativeGlassSurface, NativeHeaderCard, NativeHeadlineNumbers, NativeInputGroup, NativeInputOTP, NativeLightbox, NativeLiveIndicator, NativeNumberInput, NativePagination, NativePasswordToggleField, NativePopover, NativePopoverContent, NativePopoverTrigger, NativeRadioGroup, NativeRadioGroupItem, NativeRangeSlider, NativeRating, NativeReadinessChip, NativeResourceSettingsPage, NativeResponsesToolbar, NativeSettingsRow, NativeShareSheet, NativeSlider, NativeSortableList, NativeStatCard, NativeStatusBadge, NativeStepper, NativeSummaryCard, NativeTabBar, NativeTabs, NativeTabsContent, NativeTabsList, NativeTabsTrigger, NativeTierBadge, NativeToastProvider, NativeToggle, NativeToggleRow, NativeTooltip, NativeTooltipContent, NativeTooltipTrigger, NativeUserAvatar, NativeWhatsNewSheet, NativeWorkspaceSwitcher, NativeZoomablePhoto, Stack, defaultNativeLightboxLabels, lightboxPanLimit, lightboxPinchScale, lightboxShouldDismiss, lightboxTouchDistance, nextRating, spaceScale, spacingClass, toggleVariants, useLiquidGlass, useReduceTransparency, useToast } from './chunk-WTO3LIUS.js';
|
|
2
|
+
export { DEFAULT_GALLERY_RATIO, GALLERY_DEFAULTS, NativeAlert, NativeAlertDescription, NativeAlertTitle, NativeAvatar, NativeCard, NativeCardContent, NativeCardDescription, NativeCardFooter, NativeCardHeader, NativeCardTitle, NativeCheckbox, NativeChip, NativeChipGroup, NativeDatePicker, NativeGalleryGrid, NativeLabel, NativeProgress, NativeSearchBar, NativeSegmentedControl, NativeSelect, NativeSelectContent, NativeSelectItem, NativeSelectTrigger, NativeSeparator, NativeSwitch, NativeTextarea, NativeTimePicker, alertVariants, galleryItemRatio, justifyRows } from './chunk-G5M2Q7OU.js';
|
|
3
3
|
export { BrandExtensionsProvider, JUMP_SETTLE_MS, useGenesisExtension, useThreadJump } from './chunk-FOJJB6AB.js';
|
|
4
|
-
export { AppleSignInButton, AuthBranding, AuthForm, AuthScreen, DashboardPage, DetailPage, DocumentPage, ForgotPasswordLink, FormPage, KEYBOARD_TOOLBAR_HEIGHT, KeyboardScrollProvider, NotificationsPage, SettingsPage, SettingsSubPage, SocialAuthRow, ThreadPage, appleProvider, confirmDiscardChanges, defaultStickyHeaderOffset, getNotificationsPageStackOptions, getSettingsPageStackOptions, getSettingsSubPageStackOptions, getThreadPageStackOptions, googleProvider, iosCompactNavigationBarHeight, readReceiptFor, useKeyboardScroll, useKeyboardSticky, useKeyboardToolbar } from './chunk-
|
|
4
|
+
export { AppleSignInButton, AuthBranding, AuthForm, AuthScreen, DashboardPage, DetailPage, DocumentPage, ForgotPasswordLink, FormPage, KEYBOARD_TOOLBAR_HEIGHT, KeyboardScrollProvider, NotificationsPage, SettingsPage, SettingsSubPage, SocialAuthRow, ThreadPage, appleProvider, confirmDiscardChanges, defaultStickyHeaderOffset, getNotificationsPageStackOptions, getSettingsPageStackOptions, getSettingsSubPageStackOptions, getThreadPageStackOptions, googleProvider, iosCompactNavigationBarHeight, readReceiptFor, useKeyboardScroll, useKeyboardSticky, useKeyboardToolbar } from './chunk-SRCGQWE4.js';
|
|
5
5
|
export { NativeComposerBar, NativeThreadList, THREAD_AT_BOTTOM_POINTS, threadListMode, threadNearBottom } from './chunk-BQYT6TH2.js';
|
|
6
|
-
export { InboxPage, NavBarSaveButton, NavBarSearchBar, NavBarTitle, ScreenContainer, composeHeaderOptions, formatInboxTime, getInboxPageStackOptions, showInboxActions } from './chunk-
|
|
6
|
+
export { InboxPage, NavBarSaveButton, NavBarSearchBar, NavBarTitle, ScreenContainer, composeHeaderOptions, formatInboxTime, getInboxPageStackOptions, showInboxActions } from './chunk-DCCOZSGR.js';
|
|
7
7
|
export { NATIVE_ICON_NAMES, NativeBadge, NativeBanner, NativeButton, NativeContextMenu, NativeEmptyState, NativeIcon, NativeImage, NativeInlineAlert, NativeInput, NativeListItem, NativeListItemDivider, NativeLoadingState, NativeNoFeaturesFound, NativeNoFeedbackFound, NativeNoSearchResults, NativeRefreshControl, NativeSectionListHeader, NativeSheet, NativeSheetProvider, NativeSheetScrollView, NativeSkeleton, NativeSwipeRow, NativeText, SF_SYMBOLS, badgeTextVariants, badgeVariants, buttonTextVariants, buttonVariants, textVariants } from './chunk-D4UU6KIF.js';
|
|
8
8
|
export { GenesisModulesProvider, animateMotion, motionSpring, motionTiming, playHaptic, sentBubbleColor, useGenesisModules, useHaptics, useMotion, usePressFeedback, useReducedMotion, useThemeMode, useThemeRoles } from './chunk-VHUUOH46.js';
|
|
9
9
|
export { cn } from './chunk-OHZD7KRO.js';
|
package/dist/layouts/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { e as ScreenHeaderProps, d as ScreenContainerProps } from '../inbox-page-
|
|
2
|
-
export { I as InboxPage, a as InboxPageProps, b as InboxPageSlotMap, S as SafeAreaEdge, c as ScreenContainer, f as ScrollEdgeBehavior, g as composeHeaderOptions, h as getInboxPageStackOptions, s as showInboxActions } from '../inbox-page-
|
|
1
|
+
import { e as ScreenHeaderProps, d as ScreenContainerProps } from '../inbox-page-DD1cQdF4.js';
|
|
2
|
+
export { I as InboxPage, a as InboxPageProps, b as InboxPageSlotMap, S as SafeAreaEdge, c as ScreenContainer, f as ScrollEdgeBehavior, g as composeHeaderOptions, h as getInboxPageStackOptions, s as showInboxActions } from '../inbox-page-DD1cQdF4.js';
|
|
3
3
|
import * as react from 'react';
|
|
4
4
|
import { ReactNode, ComponentType } from 'react';
|
|
5
5
|
import { Slots, SlotPropsFor } from '@marktiderman/genesis-core/slots';
|
package/dist/layouts/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { AppleSignInButton, AuthBranding, AuthForm, AuthScreen, DashboardPage, DetailPage, DocumentPage, ForgotPasswordLink, FormPage, KEYBOARD_TOOLBAR_HEIGHT, KeyboardScrollProvider, NotificationsPage, SettingsPage, SettingsSubPage, SocialAuthRow, ThreadPage, appleProvider, confirmDiscardChanges, defaultStickyHeaderOffset, getNotificationsPageStackOptions, getSettingsPageStackOptions, getSettingsSubPageStackOptions, getThreadPageStackOptions, googleProvider, iosCompactNavigationBarHeight, readReceiptFor, useKeyboardScroll, useKeyboardSticky, useKeyboardToolbar } from '../chunk-
|
|
1
|
+
export { AppleSignInButton, AuthBranding, AuthForm, AuthScreen, DashboardPage, DetailPage, DocumentPage, ForgotPasswordLink, FormPage, KEYBOARD_TOOLBAR_HEIGHT, KeyboardScrollProvider, NotificationsPage, SettingsPage, SettingsSubPage, SocialAuthRow, ThreadPage, appleProvider, confirmDiscardChanges, defaultStickyHeaderOffset, getNotificationsPageStackOptions, getSettingsPageStackOptions, getSettingsSubPageStackOptions, getThreadPageStackOptions, googleProvider, iosCompactNavigationBarHeight, readReceiptFor, useKeyboardScroll, useKeyboardSticky, useKeyboardToolbar } from '../chunk-SRCGQWE4.js';
|
|
2
2
|
import '../chunk-BQYT6TH2.js';
|
|
3
|
-
export { InboxPage, NavBarSaveButton, NavBarSearchBar, NavBarTitle, ScreenContainer, composeHeaderOptions, formatInboxTime, getInboxPageStackOptions, showInboxActions } from '../chunk-
|
|
3
|
+
export { InboxPage, NavBarSaveButton, NavBarSearchBar, NavBarTitle, ScreenContainer, composeHeaderOptions, formatInboxTime, getInboxPageStackOptions, showInboxActions } from '../chunk-DCCOZSGR.js';
|
|
4
4
|
import '../chunk-D4UU6KIF.js';
|
|
5
5
|
import '../chunk-VHUUOH46.js';
|
|
6
6
|
import '../chunk-OHZD7KRO.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marktiderman/genesis-ui-native",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.14.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -83,8 +83,8 @@
|
|
|
83
83
|
"@expo/ui": ">=58.0.0",
|
|
84
84
|
"@gorhom/bottom-sheet": ">=5.0.0",
|
|
85
85
|
"@hookform/resolvers": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
86
|
-
"@marktiderman/genesis-core": "^2.
|
|
87
|
-
"@marktiderman/genesis-design-system": "^1.
|
|
86
|
+
"@marktiderman/genesis-core": "^2.18.0",
|
|
87
|
+
"@marktiderman/genesis-design-system": "^1.13.0",
|
|
88
88
|
"@react-native-community/datetimepicker": ">=8.0.0",
|
|
89
89
|
"@shopify/flash-list": ">=2.0.0",
|
|
90
90
|
"@tanstack/react-query": "^5.0.0",
|
|
@@ -35,6 +35,12 @@ export interface NativeRecordPeekProps<T extends Row = Row> extends Omit<NativeR
|
|
|
35
35
|
* promise: the sheet closes when it resolves, and a rejection is shown in plain words.
|
|
36
36
|
*/
|
|
37
37
|
onDelete?: (row: T) => unknown;
|
|
38
|
+
/**
|
|
39
|
+
* `false` when `onDelete` confirms on its own (a list's own delete handler): the peek calls it at
|
|
40
|
+
* once instead of asking first. Default `true`, as genesis-ui's RecordPeek, so one `onDelete`
|
|
41
|
+
* means the same on both.
|
|
42
|
+
*/
|
|
43
|
+
confirmDelete?: boolean;
|
|
38
44
|
/** The screen's own rule, as NativeResourceView's `can`: `false` hides Edit or Delete, a sentence refuses it. Only narrows the view's guards. */
|
|
39
45
|
can?: NativeResourceScreenCan<T>;
|
|
40
46
|
/** Above the record (a link to its full page). */
|
|
@@ -51,6 +57,7 @@ export function NativeRecordPeek<T extends Row = Row>({
|
|
|
51
57
|
onClose,
|
|
52
58
|
onEdit,
|
|
53
59
|
onDelete,
|
|
60
|
+
confirmDelete: confirmFirst = true,
|
|
54
61
|
can,
|
|
55
62
|
header,
|
|
56
63
|
snapPoints = ["60%", "92%"],
|
|
@@ -82,8 +89,12 @@ export function NativeRecordPeek<T extends Row = Row>({
|
|
|
82
89
|
setDeleting(false);
|
|
83
90
|
}
|
|
84
91
|
};
|
|
92
|
+
// A handler that confirms on its own owns the rest (its confirm, the write, closing the peek), as
|
|
93
|
+
// on the web: the peek hands the call straight through and stays open.
|
|
85
94
|
const confirmDelete = (r: T) =>
|
|
86
|
-
|
|
95
|
+
!confirmFirst
|
|
96
|
+
? void onDelete?.(r)
|
|
97
|
+
: Alert.alert(labels.deleteTitle ?? fill(words.confirmTitle, { name: title }), labels.deleteBody ?? words.confirmBody, [
|
|
87
98
|
{ text: labels.cancel ?? messages.common.cancel, style: "cancel" },
|
|
88
99
|
{ text: deleteLabel, style: "destructive", onPress: () => void runDelete(r) },
|
|
89
100
|
]);
|
|
@@ -290,6 +290,32 @@ describe("NativeRecordPeek", () => {
|
|
|
290
290
|
alert.mockRestore();
|
|
291
291
|
});
|
|
292
292
|
|
|
293
|
+
it("with confirmDelete={false}, calls a handler that confirms on its own at once, as the web's RecordPeek", async () => {
|
|
294
|
+
const onDelete = vi.fn();
|
|
295
|
+
const alert = vi.spyOn(Alert, "alert").mockImplementation(() => {});
|
|
296
|
+
render(<NativeRecordPeek view={recordView} row={PEOPLE[0]!} open onClose={() => undefined} onDelete={onDelete} confirmDelete={false} />, { wrapper: wrap() });
|
|
297
|
+
await screen.findByTestId("record-peek-page");
|
|
298
|
+
await act(async () => {
|
|
299
|
+
fireEvent.click(screen.getByTestId("record-peek-delete"));
|
|
300
|
+
});
|
|
301
|
+
expect(alert).not.toHaveBeenCalled();
|
|
302
|
+
expect(onDelete).toHaveBeenCalledWith(PEOPLE[0]);
|
|
303
|
+
alert.mockRestore();
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it("with confirmDelete={false}, leaves closing to the handler: a cancelled confirm keeps the peek open", async () => {
|
|
307
|
+
// The handler opens its own confirm and returns at once; the person then cancels.
|
|
308
|
+
const onDelete = vi.fn(() => undefined);
|
|
309
|
+
const onClose = vi.fn();
|
|
310
|
+
render(<NativeRecordPeek view={recordView} row={PEOPLE[0]!} open onClose={onClose} onDelete={onDelete} confirmDelete={false} />, { wrapper: wrap() });
|
|
311
|
+
await screen.findByTestId("record-peek-page");
|
|
312
|
+
await act(async () => {
|
|
313
|
+
fireEvent.click(screen.getByTestId("record-peek-delete"));
|
|
314
|
+
});
|
|
315
|
+
expect(onDelete).toHaveBeenCalledWith(PEOPLE[0]);
|
|
316
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
317
|
+
});
|
|
318
|
+
|
|
293
319
|
it("hides what the screen's can turns off and explains what the view's guard refuses", async () => {
|
|
294
320
|
const guarded = defineRecordView(
|
|
295
321
|
defineView(people, { can: { delete: () => "Only owners delete people." } }),
|
|
@@ -116,7 +116,11 @@ function useHeaderActions<T extends Row>({ view: recordView, row, onAction, can,
|
|
|
116
116
|
const viewer = useViewer();
|
|
117
117
|
const actions = recordView.headerFor(row as T & DataRow, {
|
|
118
118
|
viewer,
|
|
119
|
-
runnable
|
|
119
|
+
// Not runnable until the provider has answered (an action run before then, or after a failed
|
|
120
|
+
// answer, would go without its version).
|
|
121
|
+
runnable:
|
|
122
|
+
Boolean(onAction) ||
|
|
123
|
+
(Boolean(provider.runAction) && (!provider.capabilities || capabilities.isSuccess) && capabilities.data?.actions !== false),
|
|
120
124
|
...(!onAction && described.data?.actions ? { served: described.data.actions.map((a) => a.name) } : {}),
|
|
121
125
|
...(can ? { can: (name: string) => can(name, row) } : {}),
|
|
122
126
|
}).actions;
|
|
@@ -129,7 +133,16 @@ function useHeaderActions<T extends Row>({ view: recordView, row, onAction, can,
|
|
|
129
133
|
setPending(true);
|
|
130
134
|
try {
|
|
131
135
|
if (onAction) await onAction(a.name, row);
|
|
132
|
-
else if (provider.runAction)
|
|
136
|
+
else if (provider.runAction) {
|
|
137
|
+
// At the version the record was read at, so a record changed since is a conflict.
|
|
138
|
+
const field = capabilities.data?.version?.field;
|
|
139
|
+
const value = field ? (row as Record<string, unknown>)[field] : undefined;
|
|
140
|
+
await provider.runAction(view.resource, {
|
|
141
|
+
id: recordView.recordId(row as T & DataRow),
|
|
142
|
+
action: a.name,
|
|
143
|
+
...(value == null ? {} : { expectedVersion: String(value) }),
|
|
144
|
+
});
|
|
145
|
+
}
|
|
133
146
|
else throw new DataWriteError("error", fill(words.noRunner, { name: a.label }));
|
|
134
147
|
await queryClient.invalidateQueries({ queryKey: [...resourceKeys(view.resource).all] });
|
|
135
148
|
} catch (error) {
|
|
@@ -20,9 +20,11 @@ import { Alert, Platform, Pressable, SectionList, View } from "react-native";
|
|
|
20
20
|
import { SafeAreaView } from "react-native-safe-area-context";
|
|
21
21
|
import type { BaseRecord, DataRow } from "@marktiderman/genesis-core";
|
|
22
22
|
import { personTimeZone } from "@marktiderman/genesis-core/dates";
|
|
23
|
-
import {
|
|
23
|
+
import { resourceKeys, useDataProvider, useViewer } from "@marktiderman/genesis-core";
|
|
24
|
+
import { scopeClock, useCapabilities, useListState, useOne, useOptionalViewerScope } from "@marktiderman/genesis-core/hooks";
|
|
25
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
24
26
|
import type { GalleryItem } from "@marktiderman/genesis-core/gallery";
|
|
25
|
-
import type { RowPicture, ViewGallery } from "@marktiderman/genesis-core/resource-view";
|
|
27
|
+
import type { RowPicture, SavedViewStore, ViewGallery } from "@marktiderman/genesis-core/resource-view";
|
|
26
28
|
import { NativeAvatar } from "../../components/avatar";
|
|
27
29
|
import { NativeBadge } from "../../components/badge";
|
|
28
30
|
import { NativeImage } from "../../components/image";
|
|
@@ -38,7 +40,7 @@ import { NativeSectionListHeader } from "../../components/section-list";
|
|
|
38
40
|
import { NativeSheet } from "../../components/sheet";
|
|
39
41
|
import { NativeText } from "../../components/text";
|
|
40
42
|
import { useThemeRoles } from "../../hooks/use-theme-roles";
|
|
41
|
-
import { showInboxActions, type InboxPageSlotMap } from "../../layouts/inbox-page";
|
|
43
|
+
import { InboxPage, showInboxActions, type InboxPageSlotMap } from "../../layouts/inbox-page";
|
|
42
44
|
import { NativeDetailPanel } from "../NativeDetailPanel";
|
|
43
45
|
import {
|
|
44
46
|
badgeVariant,
|
|
@@ -50,6 +52,7 @@ import {
|
|
|
50
52
|
import type { AnyResourceView, NativeResourceRowItem, NativeResourceSection, NativeResourceSwipeAction } from "./mapping";
|
|
51
53
|
import { fill } from "./messages";
|
|
52
54
|
import { NativeResourceFormSheet } from "./NativeResourceFormSheet";
|
|
55
|
+
import { NativeListControls, NativeResourceBoard, NativeResourceCalendar, nativeSwitchableTypes } from "./list-controls";
|
|
53
56
|
import {
|
|
54
57
|
recordKey,
|
|
55
58
|
useNativeResourceView,
|
|
@@ -67,8 +70,8 @@ export type NativeResourceSwipeableProps = Omit<InboxPageSlotMap["swipeable"], "
|
|
|
67
70
|
/** How rows show: a list (the default) or cards in columns, as the web's `mode`. */
|
|
68
71
|
export type NativeResourceViewMode = "list" | "grid";
|
|
69
72
|
|
|
70
|
-
/** The view types the phone draws
|
|
71
|
-
export type NativeResourceViewType = NativeResourceViewMode | "gallery";
|
|
73
|
+
/** The view types the phone draws (ADR 0021). @stability Beta */
|
|
74
|
+
export type NativeResourceViewType = NativeResourceViewMode | "gallery" | "inbox" | "board" | "calendar";
|
|
72
75
|
|
|
73
76
|
/**
|
|
74
77
|
* Spread onto your card's Pressable: the press (the screen's `onRowPress`, else the peek), the
|
|
@@ -126,10 +129,28 @@ export interface NativeResourceViewProps<T extends Row = Row> extends NativeReso
|
|
|
126
129
|
mode?: NativeResourceViewMode;
|
|
127
130
|
/**
|
|
128
131
|
* The view type (ADR 0021), as the web's `<ResourceView type>`: `"list"` (default), `"grid"`, or
|
|
129
|
-
* `"gallery"` (the grid as photos, from the view's `gallery` block)
|
|
130
|
-
*
|
|
132
|
+
* `"gallery"` (the grid as photos, from the view's `gallery` block), or `"inbox"` (InboxPage's
|
|
133
|
+
* rows from the view's `inbox` block: unread in bold, a preview, a time, swipe actions), `"board"`
|
|
134
|
+
* (the view's board block: columns side by side, a long press moves a card) or `"calendar"` (the
|
|
135
|
+
* view's calendar block: an agenda or a month). Wins over `mode`, and fixes the type: the
|
|
136
|
+
* switcher stays off unless `switcher` asks for it.
|
|
131
137
|
*/
|
|
132
138
|
type?: NativeResourceViewType;
|
|
139
|
+
/**
|
|
140
|
+
* The view-type switcher above the list (ADR 0017 §11): the view's `types` the phone draws, the
|
|
141
|
+
* person's choice kept in `savedViews`. Default on when the view declares `types` (two or more
|
|
142
|
+
* the phone draws) and the screen fixes neither `type` nor `mode`.
|
|
143
|
+
*/
|
|
144
|
+
switcher?: boolean;
|
|
145
|
+
/** Where the person's choices (the view type) are kept: the app's saved-view store, the web's contract. */
|
|
146
|
+
savedViews?: SavedViewStore;
|
|
147
|
+
/** The segment the list opens on. Default the view's first. */
|
|
148
|
+
defaultSegment?: string;
|
|
149
|
+
/**
|
|
150
|
+
* Runs one of the view's actions on a row (a swipe or the long-press menu). Default: the
|
|
151
|
+
* provider's `runAction`, after the action's `confirm`.
|
|
152
|
+
*/
|
|
153
|
+
onAction?: (name: string, row: T) => void | Promise<void>;
|
|
133
154
|
/** Columns in grid mode (React Native's FlatList name). Default 2. */
|
|
134
155
|
numColumns?: number;
|
|
135
156
|
/**
|
|
@@ -482,15 +503,80 @@ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
|
|
|
482
503
|
renderCard,
|
|
483
504
|
scopeTimeZone: _zone,
|
|
484
505
|
testID = "native-resource-view",
|
|
506
|
+
switcher,
|
|
507
|
+
savedViews,
|
|
508
|
+
defaultSegment,
|
|
509
|
+
onAction,
|
|
485
510
|
...options
|
|
486
511
|
} = props;
|
|
512
|
+
// The list's state (ADR 0017): core's, the same the web's ResourceView holds. The segment and
|
|
513
|
+
// declared filters narrow the read; the type comes from the switcher when it's on.
|
|
514
|
+
const switchTypes = useMemo(() => nativeSwitchableTypes(view as AnyResourceView<Row>), [view]);
|
|
515
|
+
// On by default only where the view declares its `types` and the screen fixes neither type nor mode.
|
|
516
|
+
const switcherOn = (switcher ?? (type === undefined && props.mode === undefined && !!view.definition.types)) && switchTypes.length >= 2;
|
|
517
|
+
const list = useListState({
|
|
518
|
+
view: view as never,
|
|
519
|
+
store: savedViews,
|
|
520
|
+
types: switchTypes,
|
|
521
|
+
defaultType: type ?? (switcherOn ? switchTypes[0] : undefined) ?? modeProp,
|
|
522
|
+
rememberType: switcherOn,
|
|
523
|
+
defaultSegment,
|
|
524
|
+
});
|
|
525
|
+
const shown = (switcherOn ? (list.type as NativeResourceViewType | undefined) : undefined) ?? type;
|
|
487
526
|
// `type` is the view type's name (ADR 0021); `mode` its alias. A gallery is the grid as photos.
|
|
488
|
-
|
|
489
|
-
|
|
527
|
+
// An inbox is the list drawn as InboxPage's rows (from the view's inbox block).
|
|
528
|
+
const inbox = shown === "inbox";
|
|
529
|
+
const board = shown === "board";
|
|
530
|
+
const calendar = shown === "calendar";
|
|
531
|
+
const mode: NativeResourceViewMode = shown === "gallery" ? "grid" : shown === "grid" ? "grid" : shown === undefined ? modeProp : "list";
|
|
532
|
+
if (shown === "gallery" && !view.definition.gallery && !screenGallery?.image) {
|
|
490
533
|
throw new Error(`NativeResourceView(${view.resource}): type="gallery" needs a gallery block: the view's gallery.image, or gallery={{ image }}`);
|
|
491
534
|
}
|
|
535
|
+
if (inbox && !view.definition.inbox) {
|
|
536
|
+
throw new Error(`NativeResourceView(${view.resource}): type="inbox" needs the view's inbox block (which field is the title, the time, unread)`);
|
|
537
|
+
}
|
|
492
538
|
void _zone;
|
|
493
|
-
|
|
539
|
+
// The board and the calendar read their own rows; the list waits for them, and for the screen.
|
|
540
|
+
const state = useNativeResourceView<T>(view, { ...options, listFilters: list.filters, enabled: options.enabled !== false && !board && !calendar });
|
|
541
|
+
// The view's own actions, run through the provider (or the screen's `onAction`) after their confirm.
|
|
542
|
+
const provider = useDataProvider();
|
|
543
|
+
const queryClient = useQueryClient();
|
|
544
|
+
const viewer = useViewer();
|
|
545
|
+
// The provider runs this view's actions when it has a runner and doesn't say it serves none for
|
|
546
|
+
// this resource (`capabilities().actions === false`).
|
|
547
|
+
const askCaps = !onAction && !!provider.runAction && !!provider.capabilities;
|
|
548
|
+
const actionCaps = useCapabilities(view.resource, { enabled: askCaps });
|
|
549
|
+
const runAction = useCallback(
|
|
550
|
+
async (name: string, row: T) => {
|
|
551
|
+
if (onAction) await onAction(name, row);
|
|
552
|
+
else if (provider.runAction) {
|
|
553
|
+
// At the version the row was read at, so a row changed since is a conflict.
|
|
554
|
+
const field = actionCaps.data?.version?.field;
|
|
555
|
+
const value = field ? (row as Record<string, unknown>)[field] : undefined;
|
|
556
|
+
await provider.runAction(view.resource, {
|
|
557
|
+
id: recordKey(view as AnyResourceView<Row>, row),
|
|
558
|
+
action: name,
|
|
559
|
+
...(value == null ? {} : { expectedVersion: String(value) }),
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
await queryClient.invalidateQueries({ queryKey: resourceKeys(view.resource).all });
|
|
563
|
+
},
|
|
564
|
+
[onAction, provider, view, queryClient, actionCaps.data],
|
|
565
|
+
);
|
|
566
|
+
// Not on until the provider has said (an action shown before then could run without its version).
|
|
567
|
+
const actionsOn = !!onAction || (!!provider.runAction && (!askCaps || actionCaps.isSuccess) && actionCaps.data?.actions !== false);
|
|
568
|
+
const cancelWord = useNativeResourceViewMessages().common.cancel;
|
|
569
|
+
const confirmAction = useCallback(
|
|
570
|
+
(name: string, row: T) => {
|
|
571
|
+
const action = view.actions().find((a) => a.name === name);
|
|
572
|
+
const run = () => void runAction(name, row).catch((error: unknown) => Alert.alert(action?.label ?? name, error instanceof Error ? error.message : String(error)));
|
|
573
|
+
if (action?.confirm) Alert.alert(action.confirm, undefined, [{ text: cancelWord, style: "cancel" }, { text: action.label, style: action.destructive ? "destructive" : "default", onPress: run }]);
|
|
574
|
+
else run();
|
|
575
|
+
},
|
|
576
|
+
[view, runAction, cancelWord],
|
|
577
|
+
);
|
|
578
|
+
// Opening an unread inbox row runs the view's markRead action, when it declares one and allows it.
|
|
579
|
+
const markRead = view.inboxActions().markRead;
|
|
494
580
|
const keyExtractor = useCallback((row: T) => recordKey(view as AnyResourceView<Row>, row), [view]);
|
|
495
581
|
const messages = useNativeResourceViewMessages();
|
|
496
582
|
const colors = useThemeRoles();
|
|
@@ -523,7 +609,10 @@ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
|
|
|
523
609
|
setPeekId(null);
|
|
524
610
|
setSheet({ mode: "edit", row });
|
|
525
611
|
}, []);
|
|
526
|
-
const handlers = useMemo(
|
|
612
|
+
const handlers = useMemo(
|
|
613
|
+
() => ({ onEdit: edit, onDelete: confirmDelete, onRefused: refused, ...(actionsOn ? { onAction: confirmAction } : {}) }),
|
|
614
|
+
[edit, confirmDelete, refused, actionsOn, confirmAction],
|
|
615
|
+
);
|
|
527
616
|
|
|
528
617
|
// The screen's handler through a ref, so an inline `onRowPress` doesn't redraw every row.
|
|
529
618
|
const rowPress = useRef(onRowPress);
|
|
@@ -612,7 +701,8 @@ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
|
|
|
612
701
|
else if (typeof state.canCreate === "string") refused(fill(messages.common.create, { noun: view.noun }), state.canCreate);
|
|
613
702
|
};
|
|
614
703
|
|
|
615
|
-
|
|
704
|
+
// A board and a calendar read the segment and filters, not the search box.
|
|
705
|
+
const showSearch = !board && !calendar && (searchable ?? !!(options.searchFields?.length || view.labelField));
|
|
616
706
|
const heading = title === false ? null : (title ?? view.title);
|
|
617
707
|
const hasRows = state.rows.length > 0;
|
|
618
708
|
|
|
@@ -664,6 +754,7 @@ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
|
|
|
664
754
|
onDismiss={state.dismissRefusal}
|
|
665
755
|
/>
|
|
666
756
|
) : null}
|
|
757
|
+
<NativeListControls view={view as AnyResourceView<Row>} state={list} baseFilters={state.baseFilters} types={switcherOn ? switchTypes : []} enabled={options.enabled !== false} testID={testID} />
|
|
667
758
|
{header}
|
|
668
759
|
{state.loadingPrevious ? (
|
|
669
760
|
<NativeLoadingState fullScreen={false} size="small" label={messages.list.loadingMore} testID={`${testID}-previous`} />
|
|
@@ -697,9 +788,11 @@ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
|
|
|
697
788
|
)))
|
|
698
789
|
);
|
|
699
790
|
|
|
700
|
-
// The peek and the edit sheet read the row by id: the list's select may be narrower.
|
|
701
|
-
|
|
702
|
-
const
|
|
791
|
+
// The peek and the edit sheet read the row by id: the list's select may be narrower. They read in
|
|
792
|
+
// the list's scope (as the web's inbox and table do): a function source takes its scope there.
|
|
793
|
+
const recordScope = useMemo(() => [...state.baseFilters, ...list.filters], [state.baseFilters, list.filters]);
|
|
794
|
+
const peekRow = useOne<T & BaseRecord>(view.resource, peekId ? ((peekId.row as DataRow).id as string) : null, { scope: recordScope });
|
|
795
|
+
const editRow = useOne<T & BaseRecord>(view.resource, sheet?.mode === "edit" ? ((sheet.row as DataRow).id as string) : null, { scope: recordScope });
|
|
703
796
|
const peek = peekId ? ((peekRow.data as T | undefined) ?? peekId.row) : null;
|
|
704
797
|
|
|
705
798
|
// Peek: the view's full column list, drawn like the cells (so `when` hides there too), never
|
|
@@ -739,7 +832,51 @@ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
|
|
|
739
832
|
|
|
740
833
|
return (
|
|
741
834
|
<SafeAreaView testID={testID} edges={["left", "right", "bottom"]} style={{ flex: 1, backgroundColor: colors.groupedBackground }}>
|
|
742
|
-
{
|
|
835
|
+
{board ? (
|
|
836
|
+
<NativeResourceBoard
|
|
837
|
+
view={view as AnyResourceView<Row>}
|
|
838
|
+
filters={[...state.baseFilters, ...list.filters]}
|
|
839
|
+
enabled={options.enabled !== false}
|
|
840
|
+
{...(options.can ? { can: options.can as never } : {})}
|
|
841
|
+
onOpen={(row) => press(row as T)}
|
|
842
|
+
header={listHeader}
|
|
843
|
+
testID={testID}
|
|
844
|
+
/>
|
|
845
|
+
) : calendar ? (
|
|
846
|
+
<NativeResourceCalendar view={view as AnyResourceView<Row>} filters={[...state.baseFilters, ...list.filters]} enabled={options.enabled !== false} onOpen={(row) => press(row as T)} header={listHeader} testID={testID} />
|
|
847
|
+
) : inbox ? (
|
|
848
|
+
<InboxPage
|
|
849
|
+
testID={`${testID}-inbox`}
|
|
850
|
+
items={state.rows.map((row) => {
|
|
851
|
+
const r = view.inboxRow(row as never);
|
|
852
|
+
return {
|
|
853
|
+
id: r.id,
|
|
854
|
+
title: r.title,
|
|
855
|
+
unread: r.unread,
|
|
856
|
+
...(r.preview ? { preview: r.preview } : {}),
|
|
857
|
+
...(r.time ? { timestamp: r.time } : {}),
|
|
858
|
+
...(r.from || r.badge ? { meta: [r.from, r.badge?.label].filter(Boolean).join(" · ") } : {}),
|
|
859
|
+
onPress: () => {
|
|
860
|
+
if (r.unread && markRead && actionsOn && view.canAction(markRead, row as never, viewer) === true) void runAction(markRead, row).catch(() => undefined);
|
|
861
|
+
press(row);
|
|
862
|
+
},
|
|
863
|
+
// The view's swipe actions (edit, delete, its own), as the list's rows have them.
|
|
864
|
+
swipeActions: actionsFor(row, handlers).map((a) => ({ id: a.id, label: a.label, onPress: a.onPress, ...(a.destructive ? { destructive: true } : {}) })),
|
|
865
|
+
};
|
|
866
|
+
})}
|
|
867
|
+
header={listHeader}
|
|
868
|
+
loading={state.loading}
|
|
869
|
+
error={Boolean(state.error)}
|
|
870
|
+
refreshing={state.refreshing}
|
|
871
|
+
onRefresh={() => state.refresh()}
|
|
872
|
+
loadingMore={state.loadingMore}
|
|
873
|
+
{...(state.hasMore ? { onEndReached: state.loadMore } : {})}
|
|
874
|
+
// maxPages drops pages from the front, as in the list: reaching the top loads them back.
|
|
875
|
+
{...(state.hasPrevious ? { onStartReached: state.loadPrevious } : {})}
|
|
876
|
+
{...(view.definition.copy?.empty?.title ? { emptyTitle: view.definition.copy.empty.title } : {})}
|
|
877
|
+
{...(view.definition.copy?.empty?.body ? { emptyBody: view.definition.copy.empty.body } : {})}
|
|
878
|
+
/>
|
|
879
|
+
) : photos ? (
|
|
743
880
|
<NativeGalleryGrid
|
|
744
881
|
testID={`${testID}-gallery`}
|
|
745
882
|
items={photos.items}
|
|
@@ -134,6 +134,20 @@ describe("NativeRecordView", () => {
|
|
|
134
134
|
await waitFor(() => expect(onAction).toHaveBeenCalledWith("archive", { ...brand, is_default: false }));
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
+
it("runs an action at the version the record was read at", async () => {
|
|
138
|
+
// @feat:declared-data-access
|
|
139
|
+
const sheet = vi.spyOn(ActionSheetIOS, "showActionSheetWithOptions").mockImplementation(() => {});
|
|
140
|
+
const p = provider({ capabilities: vi.fn(async () => ({ search: true, sort: true, filterOperators: [], bulkWrites: false, versionedWrites: true, compositeKeys: false, actions: true, version: { field: "name", kind: "timestamp" as const } })), });
|
|
141
|
+
render(<NativeRecordViewMenu view={page} row={brand} />, { wrapper: wrap(p) });
|
|
142
|
+
await waitFor(() => expect(p.capabilities).toHaveBeenCalled());
|
|
143
|
+
// Let the capabilities answer land before the click, as a person's would.
|
|
144
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
145
|
+
fireEvent.click(screen.getByTestId("native-resource-workspace-menu"));
|
|
146
|
+
sheet.mock.calls[0];
|
|
147
|
+
await waitFor(() => expect(p.runAction).toHaveBeenCalledWith("brands", { id: "b1", action: "publish", expectedVersion: "Northwind" }));
|
|
148
|
+
sheet.mockRestore();
|
|
149
|
+
});
|
|
150
|
+
|
|
137
151
|
it("Android: the menu is a sheet of rows, never an alert with too many buttons", async () => {
|
|
138
152
|
const os = Platform.OS;
|
|
139
153
|
Platform.OS = "android";
|
|
@@ -180,6 +194,16 @@ describe("NativeRecordView", () => {
|
|
|
180
194
|
await waitFor(() => expect(p.runAction).toHaveBeenCalledWith("brands", { id: "b1", action: "activate" }));
|
|
181
195
|
});
|
|
182
196
|
|
|
197
|
+
it("offers no provider action until the provider's capabilities arrive", async () => {
|
|
198
|
+
// @feat:declared-data-access
|
|
199
|
+
let answer: (c: Awaited<ReturnType<NonNullable<DataProvider["capabilities"]>>>) => void = () => {};
|
|
200
|
+
const p = provider({ capabilities: vi.fn(() => new Promise((resolve) => (answer = resolve))) as DataProvider["capabilities"] });
|
|
201
|
+
render(<NativeRecordViewMenu view={page} row={brand} testID="late" />, { wrapper: wrap(p) });
|
|
202
|
+
expect(screen.queryByTestId("late")).toBeNull();
|
|
203
|
+
answer({ search: true, sort: true, filterOperators: [], bulkWrites: false, versionedWrites: false, compositeKeys: false, actions: true });
|
|
204
|
+
expect(await screen.findByTestId("late")).toBeTruthy();
|
|
205
|
+
});
|
|
206
|
+
|
|
183
207
|
it("hides actions when nothing can run them, or the screen turns them off", () => {
|
|
184
208
|
render(<NativeRecordViewMenu view={page} row={brand} testID="none" />, { wrapper: wrap(provider({ runAction: undefined })) });
|
|
185
209
|
expect(screen.queryByTestId("none")).toBeNull();
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// @feat:view-inbox @feat:native-components
|
|
2
|
+
/** NativeResourceView `type="inbox"`: the view's rows as InboxPage's, unread first in weight, a press opening the row. */
|
|
3
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
4
|
+
import { QueryClient } from "@tanstack/react-query";
|
|
5
|
+
import type { ReactNode } from "react";
|
|
6
|
+
import { describe, expect, it, vi } from "vitest";
|
|
7
|
+
import { defineResource, GenesisProvider, type DataProvider } from "@marktiderman/genesis-core";
|
|
8
|
+
import { defineView } from "@marktiderman/genesis-core/resource-view";
|
|
9
|
+
import { NativeResourceView } from "..";
|
|
10
|
+
|
|
11
|
+
type Ticket = { id: string; subject: string; body: string; unread: boolean };
|
|
12
|
+
|
|
13
|
+
const tickets = defineResource<Ticket>()({
|
|
14
|
+
name: "tickets",
|
|
15
|
+
key: "id",
|
|
16
|
+
labelField: "subject",
|
|
17
|
+
fields: [
|
|
18
|
+
{ name: "id", type: "string", hasDefault: true },
|
|
19
|
+
{ name: "subject", type: "string" },
|
|
20
|
+
{ name: "body", type: "string" },
|
|
21
|
+
{ name: "unread", type: "boolean" },
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const ROWS: Ticket[] = [
|
|
26
|
+
{ id: "t1", subject: "Can't sign in", body: "The code never arrives.", unread: true },
|
|
27
|
+
{ id: "t2", subject: "Invoice copy", body: "Please resend it.", unread: false },
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const view = defineView(tickets, { inbox: { preview: "body", unread: "unread" } });
|
|
31
|
+
|
|
32
|
+
function wrap(p: DataProvider) {
|
|
33
|
+
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false, staleTime: Infinity } } });
|
|
34
|
+
return ({ children }: { children: ReactNode }) => (
|
|
35
|
+
<GenesisProvider provider={p} queryClient={queryClient}>
|
|
36
|
+
{children}
|
|
37
|
+
</GenesisProvider>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe("NativeResourceView inbox", () => {
|
|
42
|
+
it("draws the rows as an inbox, with their preview, and opens one on press", async () => {
|
|
43
|
+
const p = {
|
|
44
|
+
getList: vi.fn(async () => ({ data: ROWS, total: ROWS.length })),
|
|
45
|
+
getOne: vi.fn(async (_r: string, { id }: { id: string }) => ({ data: ROWS.find((r) => r.id === id) })),
|
|
46
|
+
getMany: vi.fn(async () => ({ data: [] })),
|
|
47
|
+
create: vi.fn(),
|
|
48
|
+
update: vi.fn(),
|
|
49
|
+
deleteOne: vi.fn(),
|
|
50
|
+
} as unknown as DataProvider;
|
|
51
|
+
const onRowPress = vi.fn();
|
|
52
|
+
render(<NativeResourceView view={view} type="inbox" onRowPress={onRowPress} />, { wrapper: wrap(p) });
|
|
53
|
+
expect(await screen.findByText("Can't sign in")).toBeTruthy();
|
|
54
|
+
expect(screen.getByText("Please resend it.")).toBeTruthy();
|
|
55
|
+
expect(screen.queryByTestId("native-resource-view-list")).toBeNull();
|
|
56
|
+
fireEvent.click(screen.getByText("Invoice copy"));
|
|
57
|
+
expect(onRowPress).toHaveBeenCalledWith(expect.objectContaining({ id: "t2" }));
|
|
58
|
+
});
|
|
59
|
+
});
|