@applicaster/zapp-react-native-ui-components 15.0.0-rc.99 → 16.0.0-rc.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/Components/Cell/TvOSCellComponent.tsx +1 -3
- package/Components/GeneralContentScreen/GeneralContentScreen.tsx +39 -28
- package/Components/GeneralContentScreen/__tests__/GeneralContentScreen.test.tsx +104 -0
- package/Components/GeneralContentScreen/utils/__tests__/getScreenDataSource.test.ts +19 -0
- package/Components/GeneralContentScreen/utils/getScreenDataSource.ts +9 -0
- package/Components/HandlePlayable/HandlePlayable.tsx +16 -29
- package/Components/HandlePlayable/utils.ts +31 -0
- package/Components/HookRenderer/HookRenderer.tsx +40 -10
- package/Components/HookRenderer/__tests__/HookRenderer.test.tsx +60 -0
- package/Components/Layout/TV/NavBarContainer.tsx +1 -10
- package/Components/Layout/TV/__tests__/__snapshots__/NavBarContainer.test.tsx.snap +7 -12
- package/Components/Layout/TV/__tests__/__snapshots__/ScreenContainer.test.tsx.snap +7 -12
- package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +5 -0
- package/Components/MasterCell/CONFIG_BUILDER_TO_REACT_COMPONENT.md +144 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/model.test.ts +80 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +187 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/selectors.test.ts +45 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/style.test.ts +49 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/ActionButtonController.tsx +165 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/__tests__/ActionButtonController.test.tsx +405 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/index.ts +1 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/model.ts +47 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +170 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/selectors.ts +26 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/style.ts +29 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/types.ts +37 -0
- package/Components/MasterCell/DefaultComponents/Button.tsx +0 -15
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/components/HorizontalSeparator.tsx +8 -0
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tsx +15 -0
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tv.android.tsx +58 -0
- package/Components/MasterCell/DefaultComponents/{tv/ButtonContainerView/index.tsx → ButtonContainerView/index.tv.tsx} +3 -11
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.web.ts +1 -0
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/types.ts +40 -0
- package/Components/MasterCell/DefaultComponents/DataProvider/index.tsx +163 -0
- package/Components/MasterCell/DefaultComponents/FocusableView/index.android.tsx +2 -23
- package/Components/MasterCell/DefaultComponents/FocusableView/index.tsx +4 -22
- package/Components/MasterCell/DefaultComponents/Image/Image.android.tsx +3 -1
- package/Components/MasterCell/DefaultComponents/LiveImage/__tests__/prepareEntry.test.ts +352 -0
- package/Components/MasterCell/DefaultComponents/LiveImage/executePreloadHooks.ts +136 -0
- package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +33 -16
- package/Components/MasterCell/DefaultComponents/PressableView.tsx +34 -0
- package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +11 -0
- package/Components/MasterCell/DefaultComponents/Text/index.tsx +2 -6
- package/Components/MasterCell/DefaultComponents/__tests__/DataProvider.test.tsx +141 -0
- package/Components/MasterCell/DefaultComponents/index.ts +9 -3
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +135 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Asset.ts +33 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/AssetComponent.tsx +22 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +125 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +16 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabel.ts +67 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +37 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +393 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/builders.test.ts +141 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +343 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/helpers.ts +105 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +122 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +118 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +238 -0
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/Asset.ts +4 -18
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/Button.ts +24 -73
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/TextLabelsContainer.ts +37 -18
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/TvActionButton.tsx +27 -0
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/__tests__/index.test.ts +89 -0
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/__tests__/renderedTree.test.tsx +231 -0
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/index.ts +47 -52
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/getPluginIdentifier.test.ts +35 -171
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +98 -145
- package/Components/MasterCell/MappingFunctions/index.js +3 -2
- package/Components/MasterCell/README.md +4 -0
- package/Components/MasterCell/__tests__/__snapshots__/dataAdapter.test.js.snap +24 -0
- package/Components/MasterCell/__tests__/configInflater.test.js +1 -0
- package/Components/MasterCell/__tests__/elementMapper.test.js +46 -0
- package/Components/MasterCell/dataAdapter.ts +4 -1
- package/Components/MasterCell/elementMapper.tsx +52 -7
- package/Components/MasterCell/utils/__tests__/cloneChildrenWithIds.test.tsx +43 -0
- package/Components/MasterCell/utils/__tests__/useFilterChildren.test.tsx +80 -0
- package/Components/MasterCell/utils/index.ts +85 -15
- package/Components/Navigator/StackNavigator.tsx +6 -0
- package/Components/PlayerContainer/PlayerContainer.tsx +2 -19
- package/Components/PreloaderWrapper/__tests__/index.test.tsx +26 -0
- package/Components/PreloaderWrapper/index.tsx +15 -0
- package/Components/River/ComponentsMap/ComponentsMap.tsx +2 -16
- package/Components/River/RefreshControl.tsx +19 -82
- package/Components/River/River.tsx +9 -82
- package/Components/River/RiverItem.tsx +26 -20
- package/Components/River/hooks/__tests__/usePullToRefresh.test.ts +132 -0
- package/Components/River/hooks/index.ts +1 -0
- package/Components/River/hooks/usePullToRefresh.ts +51 -0
- package/Components/Screen/__tests__/Screen.test.tsx +1 -0
- package/Components/Screen/hooks.ts +73 -3
- package/Components/Screen/index.tsx +7 -1
- package/Components/ScreenFeedLoader/ScreenFeedLoader.tsx +46 -0
- package/Components/ScreenFeedLoader/__tests__/ScreenFeedLoader.test.tsx +94 -0
- package/Components/ScreenFeedLoader/index.ts +1 -0
- package/Components/ScreenResolver/__tests__/screenResolver.test.js +24 -0
- package/Components/ScreenResolver/hooks/index.ts +3 -0
- package/Components/ScreenResolver/hooks/useGetComponent.ts +15 -0
- package/Components/ScreenResolver/hooks/useScreenComponentResolver.tsx +90 -0
- package/Components/ScreenResolver/index.tsx +15 -117
- package/Components/ScreenResolver/utils/__tests__/getScreenTypeProps.test.ts +45 -0
- package/Components/ScreenResolver/utils/getScreenTypeProps.ts +43 -0
- package/Components/ScreenResolver/utils/index.ts +1 -0
- package/Components/ScreenResolver/withDefaultScreenContext.tsx +16 -0
- package/Components/ScreenResolverFeedProvider/ScreenResolverFeedProvider.tsx +25 -0
- package/Components/ScreenResolverFeedProvider/__tests__/ScreenResolverFeedProvider.test.tsx +44 -0
- package/Components/ScreenResolverFeedProvider/index.ts +1 -0
- package/Components/ScreenRevealManager/withScreenRevealManager.tsx +4 -1
- package/Components/TopCutoffOverlay/__tests__/TopCutoffOverlay.test.tsx +201 -0
- package/Components/TopCutoffOverlay/hooks/__tests__/useMarginTop.test.ts +130 -0
- package/Components/TopCutoffOverlay/hooks/index.ts +1 -0
- package/Components/TopCutoffOverlay/hooks/useMarginTop.ts +59 -0
- package/Components/TopCutoffOverlay/index.tsx +55 -0
- package/Components/Transitioner/Scene.tsx +9 -15
- package/Components/VideoLive/LiveImageManager.ts +199 -54
- package/Components/VideoLive/PlayerLiveImageComponent.tsx +31 -33
- package/Components/VideoLive/__tests__/PlayerLiveImageComponent.test.tsx +2 -17
- package/Components/Viewport/ViewportAware/__tests__/viewportAware.test.js +0 -2
- package/Components/Viewport/ViewportAware/index.tsx +16 -7
- package/Components/ZappUIComponent/index.tsx +12 -6
- package/Components/default-cell-renderer/viewTrees/mobile/index.ts +0 -3
- package/Components/index.js +1 -1
- package/Contexts/ScreenContext/__tests__/index.test.tsx +57 -0
- package/Contexts/ScreenContext/index.tsx +46 -1
- package/Contexts/ZappPipesContext/ZappPipesContextFactory.tsx +18 -7
- package/Decorators/ZappPipesDataConnector/ResolverSelector.tsx +25 -7
- package/Decorators/ZappPipesDataConnector/__tests__/ResolverSelector.test.tsx +212 -5
- package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +39 -21
- package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +18 -7
- package/package.json +5 -5
- package/Components/MasterCell/DefaultComponents/Text/utils/__tests__/withAdjustedLineHeight.test.ts +0 -46
- package/Components/MasterCell/DefaultComponents/Text/utils/index.ts +0 -21
- package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/index.android.tsx +0 -135
- package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/types.ts +0 -25
- package/Components/PlayerContainer/ErrorDisplay/ErrorDisplay.tsx +0 -57
- package/Components/PlayerContainer/ErrorDisplay/index.ts +0 -9
- package/Components/PlayerContainer/useRestrictMobilePlayback.tsx +0 -101
- /package/Components/HookRenderer/{index.tsx → index.ts} +0 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DefaultCell } from "./DefaultCell";
|
|
2
2
|
import { GridCell } from "./GridCell";
|
|
3
3
|
import { HeroCell } from "./HeroCell";
|
|
4
|
-
// import { ScreenSelectorLabel } from "./ScreenSelectorLabel";
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Return a view tree ready to be injected with styles etc. Mapping is done
|
|
@@ -15,8 +14,6 @@ export function viewTreeResolver({ component_type }) {
|
|
|
15
14
|
switch (component_type) {
|
|
16
15
|
case "hero":
|
|
17
16
|
return HeroCell;
|
|
18
|
-
// case "screen_picker":
|
|
19
|
-
// return ScreenSelectorLabel;
|
|
20
17
|
case "grid":
|
|
21
18
|
return GridCell;
|
|
22
19
|
case "horizontal_list":
|
package/Components/index.js
CHANGED
|
@@ -10,7 +10,7 @@ export { ContentScreen } from "./ContentScreen";
|
|
|
10
10
|
|
|
11
11
|
export { TextInputTv } from "./TextInputTv";
|
|
12
12
|
|
|
13
|
-
export { HookRenderer } from "./HookRenderer";
|
|
13
|
+
export { HookRenderer } from "./HookRenderer/HookRenderer";
|
|
14
14
|
|
|
15
15
|
export { Touchable } from "./Touchable";
|
|
16
16
|
|
|
@@ -2,6 +2,32 @@ import { render } from "@testing-library/react-native";
|
|
|
2
2
|
import { ScreenContext, ScreenContextProvider, withScreenContext } from "../";
|
|
3
3
|
import React from "react";
|
|
4
4
|
|
|
5
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks", () => ({
|
|
6
|
+
useCurrentScreenData: jest.fn(() => ({})),
|
|
7
|
+
useNavigation: jest.fn(() => ({
|
|
8
|
+
data: {},
|
|
9
|
+
modalData: null,
|
|
10
|
+
videoModalState: {},
|
|
11
|
+
canGoBack: jest.fn(() => false),
|
|
12
|
+
})),
|
|
13
|
+
useRoute: jest.fn(() => ({ screenData: null })),
|
|
14
|
+
isNavBarVisible: jest.fn(() => true),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
jest.mock(
|
|
18
|
+
"@applicaster/zapp-react-native-ui-components/Contexts/ModalNavigationContext",
|
|
19
|
+
() => ({
|
|
20
|
+
useModalNavigationContext: jest.fn(() => false),
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
jest.mock(
|
|
25
|
+
"@applicaster/zapp-react-native-ui-components/Contexts/NestedNavigationContext",
|
|
26
|
+
() => ({
|
|
27
|
+
useNestedNavigationContext: jest.fn(() => false),
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
|
|
5
31
|
describe("ScreenContext", () => {
|
|
6
32
|
describe("ScreneContext context", () => {
|
|
7
33
|
it("should return the context", () => {
|
|
@@ -13,6 +39,37 @@ describe("ScreenContext", () => {
|
|
|
13
39
|
it("should return the provider", () => {
|
|
14
40
|
expect(ScreenContextProvider).toBeDefined();
|
|
15
41
|
});
|
|
42
|
+
|
|
43
|
+
it("recreates _feedStore when pathname changes", () => {
|
|
44
|
+
const contexts = [];
|
|
45
|
+
|
|
46
|
+
const CaptureContext = () => {
|
|
47
|
+
const context = React.useContext(ScreenContext);
|
|
48
|
+
contexts.push(context);
|
|
49
|
+
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const { rerender } = render(
|
|
54
|
+
<ScreenContextProvider pathname="/screen-a">
|
|
55
|
+
<CaptureContext />
|
|
56
|
+
</ScreenContextProvider>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const first = contexts[contexts.length - 1];
|
|
60
|
+
first._feedStore.setState({ screenFeed: "screen-a" });
|
|
61
|
+
|
|
62
|
+
rerender(
|
|
63
|
+
<ScreenContextProvider pathname="/screen-b">
|
|
64
|
+
<CaptureContext />
|
|
65
|
+
</ScreenContextProvider>
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const second = contexts[contexts.length - 1];
|
|
69
|
+
|
|
70
|
+
expect(second._feedStore).not.toBe(first._feedStore);
|
|
71
|
+
expect(second._feedStore.getState()).toEqual({});
|
|
72
|
+
});
|
|
16
73
|
});
|
|
17
74
|
|
|
18
75
|
describe("withScreenContext", () => {
|
|
@@ -88,16 +88,39 @@ const createStore = () =>
|
|
|
88
88
|
}))
|
|
89
89
|
);
|
|
90
90
|
|
|
91
|
+
const createScreenComponentsStore = () =>
|
|
92
|
+
create(subscribeWithSelector<Record<string, unknown>>((_) => ({})));
|
|
93
|
+
|
|
94
|
+
const createFeedStore = () =>
|
|
95
|
+
create(subscribeWithSelector<Record<string, unknown>>((_) => ({})));
|
|
96
|
+
|
|
91
97
|
type ScreenContextType = {
|
|
92
98
|
_navBarStore: ReturnType<typeof createStore>;
|
|
93
99
|
_stateStore: ReturnType<typeof createStateStore>;
|
|
100
|
+
_feedStore: ReturnType<typeof createFeedStore>;
|
|
94
101
|
navBar: NavBarState;
|
|
95
102
|
legacyFormatScreenData: LegacyNavigationScreenData | null;
|
|
103
|
+
/**
|
|
104
|
+
* Zustand store for component-level state within a screen.
|
|
105
|
+
*
|
|
106
|
+
* **Purpose:** Persists state across component mount/unmount cycles (e.g., during virtualization)
|
|
107
|
+
* and enables state sharing between components using the same key within the same screen.
|
|
108
|
+
*
|
|
109
|
+
* **Lifecycle:** Tied to the screen/route — recreated on each route change.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* // Used by useComponentScreenState hook:
|
|
113
|
+
* const store = useScreenContextV2()._componentStateStore;
|
|
114
|
+
* store.setState({ 'my-key': value });
|
|
115
|
+
* const value = store.getState()['my-key'];
|
|
116
|
+
*/
|
|
117
|
+
_componentStateStore: ReturnType<typeof createScreenComponentsStore>;
|
|
96
118
|
};
|
|
97
119
|
|
|
98
120
|
export const ScreenContext = createContext<ScreenContextType>({
|
|
99
121
|
_stateStore: createStateStore(),
|
|
100
122
|
_navBarStore: createStore(),
|
|
123
|
+
_feedStore: createFeedStore(),
|
|
101
124
|
navBar: {
|
|
102
125
|
visible: true,
|
|
103
126
|
title: "",
|
|
@@ -107,6 +130,7 @@ export const ScreenContext = createContext<ScreenContextType>({
|
|
|
107
130
|
setSummary: (_subtitle) => void 0,
|
|
108
131
|
},
|
|
109
132
|
legacyFormatScreenData: {} as LegacyNavigationScreenData,
|
|
133
|
+
_componentStateStore: createScreenComponentsStore(),
|
|
110
134
|
});
|
|
111
135
|
|
|
112
136
|
export function ScreenContextProvider({
|
|
@@ -138,6 +162,10 @@ export function ScreenContextProvider({
|
|
|
138
162
|
null
|
|
139
163
|
);
|
|
140
164
|
|
|
165
|
+
const screenFeedStoreRef = useRef<null | ReturnType<typeof createFeedStore>>(
|
|
166
|
+
null
|
|
167
|
+
);
|
|
168
|
+
|
|
141
169
|
const getScreenState = useCallback(() => {
|
|
142
170
|
if (screenStateRef.current !== null) {
|
|
143
171
|
return screenStateRef.current;
|
|
@@ -160,6 +188,21 @@ export function ScreenContextProvider({
|
|
|
160
188
|
return navBarState;
|
|
161
189
|
}, []);
|
|
162
190
|
|
|
191
|
+
// Assign feed store to ref to persist it across re-renders, but recreate on pathname change
|
|
192
|
+
const screenFeedStore = useMemo(() => createFeedStore(), [pathname]);
|
|
193
|
+
|
|
194
|
+
if (screenFeedStoreRef.current !== screenFeedStore) {
|
|
195
|
+
screenFeedStoreRef.current = screenFeedStore;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Component state store - recreated when pathname changes (route change).
|
|
199
|
+
// Unlike _navBarStore and _stateStore (cached via refs), this store
|
|
200
|
+
// resets only when pathname changes to provide a clean state for the new route.
|
|
201
|
+
const componentStateStore = useMemo(
|
|
202
|
+
() => createScreenComponentsStore(),
|
|
203
|
+
[pathname]
|
|
204
|
+
);
|
|
205
|
+
|
|
163
206
|
const screenNavBarState = getScreenNavBarState()(
|
|
164
207
|
useShallow((state) => ({
|
|
165
208
|
visible: state.visible,
|
|
@@ -210,10 +253,12 @@ export function ScreenContextProvider({
|
|
|
210
253
|
() => ({
|
|
211
254
|
_navBarStore: getScreenNavBarState(),
|
|
212
255
|
_stateStore: getScreenState(),
|
|
256
|
+
_feedStore: screenFeedStoreRef.current,
|
|
213
257
|
navBar: navBarState,
|
|
214
258
|
legacyFormatScreenData: routeScreenData,
|
|
259
|
+
_componentStateStore: componentStateStore,
|
|
215
260
|
}),
|
|
216
|
-
[navBarState, screenData, routeScreenData]
|
|
261
|
+
[navBarState, screenData, routeScreenData, componentStateStore]
|
|
217
262
|
)}
|
|
218
263
|
>
|
|
219
264
|
{children}
|
|
@@ -5,10 +5,10 @@ import React, {
|
|
|
5
5
|
useMemo,
|
|
6
6
|
useState,
|
|
7
7
|
} from "react";
|
|
8
|
-
import * as R from "ramda";
|
|
9
8
|
|
|
10
|
-
type ProviderProps = {
|
|
9
|
+
type ProviderProps<S> = {
|
|
11
10
|
children: React.ReactChild;
|
|
11
|
+
initialContextValue?: S;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
type ContextType<T> = {
|
|
@@ -27,21 +27,29 @@ export function createZappPipesContext<T, S = T>(
|
|
|
27
27
|
) {
|
|
28
28
|
const Context = createContext<ContextType<S>>(initialContext);
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const defaultSelector = (c: any) => c;
|
|
31
|
+
const defaultPrepareContext = (n: any) => n;
|
|
32
|
+
const joinArgs = (args: any[]) => args.join("-");
|
|
33
|
+
|
|
34
|
+
const { selector = defaultSelector, prepareContext = defaultPrepareContext } =
|
|
35
|
+
options || {};
|
|
31
36
|
|
|
32
37
|
function useZappPipesContext(...hookArgs: any[]): [T, (T) => void] {
|
|
33
38
|
const { context, setContext } = useContext(Context);
|
|
39
|
+
const joinedArgs = joinArgs(hookArgs);
|
|
34
40
|
|
|
35
41
|
const contextValue = useMemo(
|
|
36
42
|
() => selector(context, ...hookArgs),
|
|
37
|
-
|
|
43
|
+
// eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
|
|
44
|
+
[context, joinedArgs]
|
|
38
45
|
);
|
|
39
46
|
|
|
40
47
|
const contextSetter = useCallback(
|
|
41
48
|
(newContext: T) => {
|
|
42
49
|
setContext(prepareContext(newContext, context, ...hookArgs));
|
|
43
50
|
},
|
|
44
|
-
|
|
51
|
+
// eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
|
|
52
|
+
[context, joinedArgs]
|
|
45
53
|
);
|
|
46
54
|
|
|
47
55
|
return useMemo(
|
|
@@ -50,8 +58,11 @@ export function createZappPipesContext<T, S = T>(
|
|
|
50
58
|
);
|
|
51
59
|
}
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
/** Provider accepts `initialContextValue` prop to set the initial context value */
|
|
62
|
+
function Provider({ children, initialContextValue }: ProviderProps<S>) {
|
|
63
|
+
const [context, setContext] = useState<S>(
|
|
64
|
+
initialContextValue ?? initialContext.context
|
|
65
|
+
);
|
|
55
66
|
|
|
56
67
|
return (
|
|
57
68
|
<Context.Provider value={{ context, setContext }}>
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// ResolverSelector.tsx
|
|
2
1
|
import React from "react";
|
|
3
2
|
import { ComponentDataSourceContext, ZappPipesDataProps } from "./types";
|
|
4
3
|
import { StaticFeedResolver } from "./resolvers/StaticFeedResolver";
|
|
@@ -12,14 +11,33 @@ type ResolverSelectorProps = ComponentDataSourceContext & {
|
|
|
12
11
|
export function ResolverSelector(props: ResolverSelectorProps) {
|
|
13
12
|
const { getStaticComponentFeed, component, feedUrl, children } = props;
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
const renderDefaultResolver = (
|
|
15
|
+
fallbackChildren: (dataProps: ZappPipesDataProps) => React.ReactNode
|
|
16
|
+
) => {
|
|
17
|
+
if (feedUrl || component?.data?.source) {
|
|
18
|
+
return <UrlFeedResolver {...props}>{fallbackChildren}</UrlFeedResolver>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return <NullFeedResolver>{fallbackChildren}</NullFeedResolver>;
|
|
22
|
+
};
|
|
23
|
+
|
|
16
24
|
if (getStaticComponentFeed) {
|
|
17
|
-
return
|
|
18
|
-
|
|
25
|
+
return (
|
|
26
|
+
<StaticFeedResolver {...props}>
|
|
27
|
+
{(zappPipesDataProps) => {
|
|
28
|
+
const { data, loading, error } = zappPipesDataProps.zappPipesData;
|
|
29
|
+
|
|
30
|
+
const shouldFallback = !loading && data === null && !error;
|
|
31
|
+
|
|
32
|
+
if (shouldFallback) {
|
|
33
|
+
return renderDefaultResolver(children);
|
|
34
|
+
}
|
|
19
35
|
|
|
20
|
-
|
|
21
|
-
|
|
36
|
+
return children(zappPipesDataProps);
|
|
37
|
+
}}
|
|
38
|
+
</StaticFeedResolver>
|
|
39
|
+
);
|
|
22
40
|
}
|
|
23
41
|
|
|
24
|
-
return
|
|
42
|
+
return renderDefaultResolver(children);
|
|
25
43
|
}
|
|
@@ -7,15 +7,30 @@ import { UrlFeedResolver } from "../resolvers/UrlFeedResolver";
|
|
|
7
7
|
import { NullFeedResolver } from "../resolvers/NullFeedResolver";
|
|
8
8
|
|
|
9
9
|
jest.mock("../resolvers/StaticFeedResolver", () => ({
|
|
10
|
-
StaticFeedResolver: jest.fn(() =>
|
|
10
|
+
StaticFeedResolver: jest.fn(({ children }) =>
|
|
11
|
+
children({
|
|
12
|
+
zappPipesData: { loading: true, data: null, error: null },
|
|
13
|
+
reloadData: jest.fn(),
|
|
14
|
+
})
|
|
15
|
+
),
|
|
11
16
|
}));
|
|
12
17
|
|
|
13
18
|
jest.mock("../resolvers/UrlFeedResolver", () => ({
|
|
14
|
-
UrlFeedResolver: jest.fn(() =>
|
|
19
|
+
UrlFeedResolver: jest.fn(({ children }) =>
|
|
20
|
+
children({
|
|
21
|
+
zappPipesData: { loading: true, data: null, error: null },
|
|
22
|
+
reloadData: jest.fn(),
|
|
23
|
+
})
|
|
24
|
+
),
|
|
15
25
|
}));
|
|
16
26
|
|
|
17
27
|
jest.mock("../resolvers/NullFeedResolver", () => ({
|
|
18
|
-
NullFeedResolver: jest.fn(() =>
|
|
28
|
+
NullFeedResolver: jest.fn(({ children }) =>
|
|
29
|
+
children({
|
|
30
|
+
zappPipesData: { loading: false, data: null, error: null },
|
|
31
|
+
reloadData: jest.fn(),
|
|
32
|
+
})
|
|
33
|
+
),
|
|
19
34
|
}));
|
|
20
35
|
|
|
21
36
|
const testPlugin = {
|
|
@@ -52,7 +67,7 @@ describe("ResolverSelector", () => {
|
|
|
52
67
|
expect.objectContaining({
|
|
53
68
|
getStaticComponentFeed: props.getStaticComponentFeed,
|
|
54
69
|
component: mockComponent,
|
|
55
|
-
children:
|
|
70
|
+
children: expect.any(Function),
|
|
56
71
|
}),
|
|
57
72
|
expect.anything()
|
|
58
73
|
);
|
|
@@ -151,7 +166,10 @@ describe("ResolverSelector", () => {
|
|
|
151
166
|
render(<ResolverSelector {...props} />);
|
|
152
167
|
|
|
153
168
|
expect(StaticFeedResolver).toHaveBeenCalledWith(
|
|
154
|
-
expect.objectContaining(
|
|
169
|
+
expect.objectContaining({
|
|
170
|
+
...props,
|
|
171
|
+
children: expect.any(Function),
|
|
172
|
+
}),
|
|
155
173
|
expect.anything()
|
|
156
174
|
);
|
|
157
175
|
});
|
|
@@ -202,4 +220,193 @@ describe("ResolverSelector", () => {
|
|
|
202
220
|
expect(UrlFeedResolver).not.toHaveBeenCalled();
|
|
203
221
|
expect(NullFeedResolver).not.toHaveBeenCalled();
|
|
204
222
|
});
|
|
223
|
+
|
|
224
|
+
describe("Fallback Logic", () => {
|
|
225
|
+
it("should fallback to UrlFeedResolver when StaticFeedResolver returns null and feedUrl is present", () => {
|
|
226
|
+
const props = {
|
|
227
|
+
getStaticComponentFeed: jest.fn(),
|
|
228
|
+
feedUrl: "https://example.com/feed",
|
|
229
|
+
component: mockComponent,
|
|
230
|
+
children: mockChildren,
|
|
231
|
+
riverId: "test-river",
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
(StaticFeedResolver as jest.Mock).mockImplementation(({ children }) =>
|
|
235
|
+
children({
|
|
236
|
+
zappPipesData: { loading: false, data: null, error: null },
|
|
237
|
+
reloadData: jest.fn(),
|
|
238
|
+
})
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
render(<ResolverSelector {...props} />);
|
|
242
|
+
|
|
243
|
+
expect(StaticFeedResolver).toHaveBeenCalled();
|
|
244
|
+
|
|
245
|
+
expect(UrlFeedResolver).toHaveBeenCalledWith(
|
|
246
|
+
expect.objectContaining({
|
|
247
|
+
feedUrl: props.feedUrl,
|
|
248
|
+
component: mockComponent,
|
|
249
|
+
children: mockChildren,
|
|
250
|
+
}),
|
|
251
|
+
expect.anything()
|
|
252
|
+
);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("should fallback to UrlFeedResolver when StaticFeedResolver returns null and component.data.source is present", () => {
|
|
256
|
+
const componentWithSource = {
|
|
257
|
+
...mockComponent,
|
|
258
|
+
data: {
|
|
259
|
+
source: "data-source",
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const props = {
|
|
264
|
+
getStaticComponentFeed: jest.fn(),
|
|
265
|
+
component: componentWithSource,
|
|
266
|
+
children: mockChildren,
|
|
267
|
+
riverId: "test-river",
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
(StaticFeedResolver as jest.Mock).mockImplementation(({ children }) =>
|
|
271
|
+
children({
|
|
272
|
+
zappPipesData: { loading: false, data: null, error: null },
|
|
273
|
+
reloadData: jest.fn(),
|
|
274
|
+
})
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
render(<ResolverSelector {...props} />);
|
|
278
|
+
|
|
279
|
+
expect(StaticFeedResolver).toHaveBeenCalled();
|
|
280
|
+
|
|
281
|
+
expect(UrlFeedResolver).toHaveBeenCalledWith(
|
|
282
|
+
expect.objectContaining({
|
|
283
|
+
component: componentWithSource,
|
|
284
|
+
children: mockChildren,
|
|
285
|
+
}),
|
|
286
|
+
expect.anything()
|
|
287
|
+
);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("should fallback to NullFeedResolver when StaticFeedResolver returns null and no feedUrl/source is present", () => {
|
|
291
|
+
const props = {
|
|
292
|
+
getStaticComponentFeed: jest.fn(),
|
|
293
|
+
component: mockComponent,
|
|
294
|
+
children: mockChildren,
|
|
295
|
+
riverId: "test-river",
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
(StaticFeedResolver as jest.Mock).mockImplementation(({ children }) =>
|
|
299
|
+
children({
|
|
300
|
+
zappPipesData: { loading: false, data: null, error: null },
|
|
301
|
+
reloadData: jest.fn(),
|
|
302
|
+
})
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
render(<ResolverSelector {...props} />);
|
|
306
|
+
|
|
307
|
+
expect(StaticFeedResolver).toHaveBeenCalled();
|
|
308
|
+
expect(UrlFeedResolver).not.toHaveBeenCalled();
|
|
309
|
+
|
|
310
|
+
expect(NullFeedResolver).toHaveBeenCalledWith(
|
|
311
|
+
expect.objectContaining({
|
|
312
|
+
children: mockChildren,
|
|
313
|
+
}),
|
|
314
|
+
expect.anything()
|
|
315
|
+
);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("should NOT fallback and call children with static data when StaticFeedResolver returns data", () => {
|
|
319
|
+
const staticData = { entry: [{ id: "1" }] };
|
|
320
|
+
|
|
321
|
+
const props = {
|
|
322
|
+
getStaticComponentFeed: jest.fn(),
|
|
323
|
+
feedUrl: "https://example.com/feed",
|
|
324
|
+
component: mockComponent,
|
|
325
|
+
children: mockChildren,
|
|
326
|
+
riverId: "test-river",
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
(StaticFeedResolver as jest.Mock).mockImplementation(({ children }) =>
|
|
330
|
+
children({
|
|
331
|
+
zappPipesData: { loading: false, data: staticData, error: null },
|
|
332
|
+
reloadData: jest.fn(),
|
|
333
|
+
})
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
render(<ResolverSelector {...props} />);
|
|
337
|
+
|
|
338
|
+
expect(StaticFeedResolver).toHaveBeenCalled();
|
|
339
|
+
expect(UrlFeedResolver).not.toHaveBeenCalled();
|
|
340
|
+
|
|
341
|
+
expect(mockChildren).toHaveBeenCalledWith(
|
|
342
|
+
expect.objectContaining({
|
|
343
|
+
zappPipesData: expect.objectContaining({
|
|
344
|
+
data: staticData,
|
|
345
|
+
}),
|
|
346
|
+
})
|
|
347
|
+
);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it("should NOT fallback and call children with loading state when StaticFeedResolver is loading", () => {
|
|
351
|
+
const props = {
|
|
352
|
+
getStaticComponentFeed: jest.fn(),
|
|
353
|
+
feedUrl: "https://example.com/feed",
|
|
354
|
+
component: mockComponent,
|
|
355
|
+
children: mockChildren,
|
|
356
|
+
riverId: "test-river",
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
(StaticFeedResolver as jest.Mock).mockImplementation(({ children }) =>
|
|
360
|
+
children({
|
|
361
|
+
zappPipesData: { loading: true, data: null, error: null },
|
|
362
|
+
reloadData: jest.fn(),
|
|
363
|
+
})
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
render(<ResolverSelector {...props} />);
|
|
367
|
+
|
|
368
|
+
expect(StaticFeedResolver).toHaveBeenCalled();
|
|
369
|
+
expect(UrlFeedResolver).not.toHaveBeenCalled();
|
|
370
|
+
|
|
371
|
+
expect(mockChildren).toHaveBeenCalledWith(
|
|
372
|
+
expect.objectContaining({
|
|
373
|
+
zappPipesData: expect.objectContaining({
|
|
374
|
+
loading: true,
|
|
375
|
+
}),
|
|
376
|
+
})
|
|
377
|
+
);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
it("should NOT fallback and call children with error when StaticFeedResolver returns error", () => {
|
|
381
|
+
const error = new Error("Static error");
|
|
382
|
+
|
|
383
|
+
const props = {
|
|
384
|
+
getStaticComponentFeed: jest.fn(),
|
|
385
|
+
feedUrl: "https://example.com/feed",
|
|
386
|
+
component: mockComponent,
|
|
387
|
+
children: mockChildren,
|
|
388
|
+
riverId: "test-river",
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
(StaticFeedResolver as jest.Mock).mockImplementation(({ children }) =>
|
|
392
|
+
children({
|
|
393
|
+
zappPipesData: { loading: false, data: null, error },
|
|
394
|
+
reloadData: jest.fn(),
|
|
395
|
+
})
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
render(<ResolverSelector {...props} />);
|
|
399
|
+
|
|
400
|
+
expect(StaticFeedResolver).toHaveBeenCalled();
|
|
401
|
+
expect(UrlFeedResolver).not.toHaveBeenCalled();
|
|
402
|
+
|
|
403
|
+
expect(mockChildren).toHaveBeenCalledWith(
|
|
404
|
+
expect.objectContaining({
|
|
405
|
+
zappPipesData: expect.objectContaining({
|
|
406
|
+
error,
|
|
407
|
+
}),
|
|
408
|
+
})
|
|
409
|
+
);
|
|
410
|
+
});
|
|
411
|
+
});
|
|
205
412
|
});
|