@applicaster/zapp-react-native-ui-components 15.0.0-alpha.7413430163 → 15.0.0-alpha.7607942912
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/BaseFocusable/index.ios.ts +12 -2
- package/Components/Cell/FocusableWrapper.tsx +3 -0
- package/Components/Cell/TvOSCellComponent.tsx +17 -5
- package/Components/Focusable/FocusableTvOS.tsx +12 -2
- package/Components/Focusable/__tests__/__snapshots__/FocusableTvOS.test.tsx.snap +1 -0
- package/Components/FocusableGroup/FocusableTvOS.tsx +11 -0
- package/Components/HandlePlayable/HandlePlayable.tsx +10 -7
- package/Components/Layout/TV/LayoutBackground.tsx +5 -2
- package/Components/Layout/TV/ScreenContainer.tsx +2 -6
- package/Components/Layout/TV/index.tsx +3 -4
- package/Components/Layout/TV/index.web.tsx +3 -4
- package/Components/LinkHandler/LinkHandler.tsx +2 -2
- package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +4 -4
- package/Components/MasterCell/DefaultComponents/Image/Image.android.tsx +5 -1
- package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +11 -3
- package/Components/MasterCell/DefaultComponents/Image/Image.web.tsx +9 -1
- package/Components/MasterCell/DefaultComponents/Image/hooks/useImage.ts +15 -14
- package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +10 -6
- package/Components/MasterCell/utils/__tests__/resolveColor.test.js +82 -3
- package/Components/MasterCell/utils/index.ts +61 -31
- package/Components/MeasurmentsPortal/MeasurementsPortal.tsx +102 -87
- package/Components/MeasurmentsPortal/__tests__/MeasurementsPortal.test.tsx +355 -0
- package/Components/OfflineHandler/NotificationView/NotificationView.tsx +2 -2
- package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +17 -18
- package/Components/OfflineHandler/__tests__/index.test.tsx +27 -18
- package/Components/PlayerContainer/PlayerContainer.tsx +4 -3
- package/Components/Screen/TV/index.web.tsx +4 -2
- package/Components/Screen/__tests__/Screen.test.tsx +65 -42
- package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +68 -44
- package/Components/Screen/hooks.ts +2 -3
- package/Components/Screen/index.tsx +2 -3
- package/Components/Screen/navigationHandler.ts +49 -24
- package/Components/Screen/orientationHandler.ts +3 -3
- package/Components/ScreenResolver/index.tsx +13 -7
- package/Components/ScreenRevealManager/ScreenRevealManager.ts +40 -8
- package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +86 -69
- package/Components/Transitioner/Scene.tsx +15 -2
- package/Components/Transitioner/index.js +3 -3
- package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +13 -9
- package/Components/VideoModal/utils.ts +12 -9
- package/Decorators/Analytics/index.tsx +6 -5
- package/Decorators/ZappPipesDataConnector/index.tsx +2 -2
- package/Decorators/ZappPipesDataConnector/resolvers/StaticFeedResolver.tsx +1 -1
- package/Helpers/DataSourceHelper/__tests__/itemLimitForData.test.ts +80 -0
- package/Helpers/DataSourceHelper/index.ts +19 -0
- package/package.json +6 -5
- package/Helpers/DataSourceHelper/index.js +0 -19
|
@@ -2,106 +2,123 @@ import {
|
|
|
2
2
|
ScreenRevealManager,
|
|
3
3
|
COMPONENT_LOADING_STATE,
|
|
4
4
|
} from "../ScreenRevealManager";
|
|
5
|
+
import { Subject } from "rxjs";
|
|
6
|
+
|
|
7
|
+
jest.mock("@applicaster/zapp-react-native-utils/arrayUtils", () => ({
|
|
8
|
+
makeListOf: jest.fn((value: any, length: number) =>
|
|
9
|
+
Array(length).fill(value)
|
|
10
|
+
),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
jest.mock("@applicaster/zapp-react-native-utils/componentsUtils", () => ({
|
|
14
|
+
isFirstComponentGallery: jest.fn(),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
jest.mock("@applicaster/zapp-react-native-utils/idleUtils", () => ({
|
|
18
|
+
withTimeout$: jest.fn(),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
import { makeListOf } from "@applicaster/zapp-react-native-utils/arrayUtils";
|
|
22
|
+
import { isFirstComponentGallery } from "@applicaster/zapp-react-native-utils/componentsUtils";
|
|
23
|
+
import { withTimeout$ } from "@applicaster/zapp-react-native-utils/idleUtils";
|
|
5
24
|
|
|
6
25
|
describe("ScreenRevealManager", () => {
|
|
7
|
-
|
|
26
|
+
let mockCallback: jest.Mock;
|
|
27
|
+
let timeout$: Subject<void>;
|
|
8
28
|
|
|
9
29
|
beforeEach(() => {
|
|
10
|
-
jest.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
it("should initialize with the correct number of components to wait for", () => {
|
|
14
|
-
const componentsToRender: ZappUIComponent[] = [
|
|
15
|
-
{ component_type: "component1" },
|
|
16
|
-
{ component_type: "component2" },
|
|
17
|
-
{ component_type: "component3" },
|
|
18
|
-
];
|
|
30
|
+
jest.useFakeTimers();
|
|
31
|
+
mockCallback = jest.fn();
|
|
32
|
+
timeout$ = new Subject();
|
|
19
33
|
|
|
20
|
-
|
|
34
|
+
(withTimeout$ as jest.Mock).mockReturnValue(timeout$);
|
|
35
|
+
(isFirstComponentGallery as jest.Mock).mockReturnValue(false);
|
|
21
36
|
|
|
22
|
-
|
|
37
|
+
(makeListOf as jest.Mock).mockImplementation((value, length) =>
|
|
38
|
+
Array(length).fill(value)
|
|
39
|
+
);
|
|
40
|
+
});
|
|
23
41
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
]);
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
jest.clearAllTimers();
|
|
44
|
+
jest.useRealTimers();
|
|
45
|
+
jest.resetAllMocks();
|
|
29
46
|
});
|
|
30
47
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
{ component_type: "component3" },
|
|
36
|
-
];
|
|
48
|
+
// ────────────────────────────────────────────────
|
|
49
|
+
it("should initialize with correct number of components and UNKNOWN state", () => {
|
|
50
|
+
const components = new Array(5).fill({});
|
|
51
|
+
const mgr = new ScreenRevealManager(components, mockCallback);
|
|
37
52
|
|
|
38
|
-
|
|
53
|
+
expect(mgr.numberOfComponentsWaitToLoadBeforePresent).toBe(3);
|
|
54
|
+
expect(makeListOf).toHaveBeenCalledWith(COMPONENT_LOADING_STATE.UNKNOWN, 3);
|
|
55
|
+
});
|
|
39
56
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
57
|
+
// ────────────────────────────────────────────────
|
|
58
|
+
it("should set numberOfComponentsWaitToLoadBeforePresent to 1 if first component is gallery", () => {
|
|
59
|
+
(isFirstComponentGallery as jest.Mock).mockReturnValue(true);
|
|
43
60
|
|
|
44
|
-
|
|
61
|
+
const components = new Array(5).fill({});
|
|
62
|
+
const mgr = new ScreenRevealManager(components, mockCallback);
|
|
63
|
+
|
|
64
|
+
expect(mgr.numberOfComponentsWaitToLoadBeforePresent).toBe(1);
|
|
45
65
|
});
|
|
46
66
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
{ component_type: "component3" },
|
|
52
|
-
];
|
|
67
|
+
// ────────────────────────────────────────────────
|
|
68
|
+
it("should trigger callback after all components load successfully", () => {
|
|
69
|
+
const components = new Array(3).fill({});
|
|
70
|
+
const mgr = new ScreenRevealManager(components, mockCallback);
|
|
53
71
|
|
|
54
|
-
|
|
72
|
+
mgr.onLoadFinished(0);
|
|
73
|
+
expect(mockCallback).not.toHaveBeenCalled();
|
|
55
74
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
manager.onLoadFailed(2);
|
|
75
|
+
mgr.onLoadFinished(1);
|
|
76
|
+
expect(mockCallback).not.toHaveBeenCalled();
|
|
59
77
|
|
|
78
|
+
mgr.onLoadFinished(2);
|
|
60
79
|
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
61
80
|
});
|
|
62
81
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
{ component_type: "component3" },
|
|
68
|
-
];
|
|
69
|
-
|
|
70
|
-
const manager = new ScreenRevealManager(componentsToRender, mockCallback);
|
|
82
|
+
// ────────────────────────────────────────────────
|
|
83
|
+
it("should trigger callback after some components fail to load but all finished", () => {
|
|
84
|
+
const components = new Array(3).fill({});
|
|
85
|
+
const mgr = new ScreenRevealManager(components, mockCallback);
|
|
71
86
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
87
|
+
mgr.onLoadFinished(0);
|
|
88
|
+
mgr.onLoadFailed(1);
|
|
89
|
+
mgr.onLoadFailed(2);
|
|
75
90
|
|
|
76
91
|
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
77
92
|
});
|
|
78
93
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
{ component_type: "component3" },
|
|
84
|
-
];
|
|
85
|
-
|
|
86
|
-
const manager = new ScreenRevealManager(componentsToRender, mockCallback);
|
|
94
|
+
// ────────────────────────────────────────────────
|
|
95
|
+
it("should not trigger callback twice when same component finishes twice", () => {
|
|
96
|
+
const components = new Array(3).fill({});
|
|
97
|
+
const mgr = new ScreenRevealManager(components, mockCallback);
|
|
87
98
|
|
|
88
|
-
|
|
89
|
-
|
|
99
|
+
mgr.onLoadFinished(0);
|
|
100
|
+
mgr.onLoadFinished(0); // duplicate
|
|
101
|
+
mgr.onLoadFinished(1);
|
|
102
|
+
mgr.onLoadFinished(2);
|
|
90
103
|
|
|
91
|
-
expect(mockCallback).
|
|
104
|
+
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
92
105
|
});
|
|
93
106
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
{ component_type: "component3" },
|
|
99
|
-
];
|
|
107
|
+
// ────────────────────────────────────────────────
|
|
108
|
+
it("should trigger callback when timeout$ emits before all loaded", () => {
|
|
109
|
+
const components = new Array(3).fill({});
|
|
110
|
+
new ScreenRevealManager(components, mockCallback);
|
|
100
111
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
manager.onLoadFinished(0);
|
|
112
|
+
timeout$.next(); // simulate timeout event from withTimeout$
|
|
104
113
|
|
|
105
114
|
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
106
115
|
});
|
|
116
|
+
|
|
117
|
+
// ────────────────────────────────────────────────
|
|
118
|
+
it("should not call callback if nothing loads and no timeout emitted", () => {
|
|
119
|
+
const components = new Array(3).fill({});
|
|
120
|
+
new ScreenRevealManager(components, mockCallback);
|
|
121
|
+
|
|
122
|
+
expect(mockCallback).not.toHaveBeenCalled();
|
|
123
|
+
});
|
|
107
124
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useEffect } from "react";
|
|
2
2
|
import { equals } from "ramda";
|
|
3
3
|
import { Animated, ViewProps, ViewStyle } from "react-native";
|
|
4
4
|
import { useSafeAreaFrame } from "react-native-safe-area-context";
|
|
@@ -95,9 +95,22 @@ function SceneComponent({
|
|
|
95
95
|
});
|
|
96
96
|
|
|
97
97
|
const frame = useSafeAreaFrame();
|
|
98
|
+
|
|
99
|
+
const [memoFrame, setMemoFrame] = React.useState(frame);
|
|
100
|
+
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
if (isActive) {
|
|
103
|
+
setMemoFrame((oldFrame) =>
|
|
104
|
+
oldFrame.width === frame.width && oldFrame.height === frame.height
|
|
105
|
+
? oldFrame
|
|
106
|
+
: frame
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}, [isActive, frame.width, frame.height]);
|
|
110
|
+
|
|
98
111
|
const isAnimating = animating && overlayStyle;
|
|
99
112
|
|
|
100
|
-
const dimensions = isAnimating ? fullWidthDimensions :
|
|
113
|
+
const dimensions = isAnimating ? fullWidthDimensions : memoFrame;
|
|
101
114
|
|
|
102
115
|
return (
|
|
103
116
|
<Animated.View
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
|
|
3
3
|
import { useDimensions } from "@applicaster/zapp-react-native-utils/reactHooks/layout";
|
|
4
|
-
import {
|
|
4
|
+
import { useAppData } from "@applicaster/zapp-react-native-redux";
|
|
5
|
+
|
|
5
6
|
import { TransitionerComponent } from "./Transitioner";
|
|
6
7
|
|
|
7
8
|
export const Transitioner = (props) => {
|
|
@@ -16,8 +17,7 @@ export const Transitioner = (props) => {
|
|
|
16
17
|
deviceInfo: true,
|
|
17
18
|
});
|
|
18
19
|
|
|
19
|
-
const {
|
|
20
|
-
const isTabletPortrait = appData?.isTabletPortrait;
|
|
20
|
+
const { isTabletPortrait } = useAppData();
|
|
21
21
|
|
|
22
22
|
return (
|
|
23
23
|
<TransitionerComponent
|
|
@@ -4,8 +4,11 @@ import { Animated, Dimensions } from "react-native";
|
|
|
4
4
|
import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
|
|
5
5
|
|
|
6
6
|
import { useConfiguration } from "../utils";
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
useAppData,
|
|
9
|
+
usePlugins,
|
|
10
|
+
} from "@applicaster/zapp-react-native-redux/hooks";
|
|
11
|
+
import { isBottomTabVisible } from "../../Screen/navigationHandler";
|
|
9
12
|
|
|
10
13
|
import {
|
|
11
14
|
useSafeAreaFrame,
|
|
@@ -18,7 +21,6 @@ import {
|
|
|
18
21
|
import { getTabBarHeight } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/getTabBarHeight";
|
|
19
22
|
import { PROGRESS_BAR_HEIGHT } from "./utils";
|
|
20
23
|
import { useIsTablet as getIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
21
|
-
import { useAppSelector } from "@applicaster/zapp-react-native-redux";
|
|
22
24
|
|
|
23
25
|
export type ModalAnimationContextT = {
|
|
24
26
|
yTranslate: React.MutableRefObject<Animated.AnimatedInterpolation<number>>;
|
|
@@ -64,13 +66,15 @@ const Provider = ({ children }: { children: React.ReactNode }) => {
|
|
|
64
66
|
screenData,
|
|
65
67
|
} = useNavigation();
|
|
66
68
|
|
|
67
|
-
const isTabletPortrait =
|
|
68
|
-
(state) => state.appData.isTabletPortrait
|
|
69
|
-
);
|
|
69
|
+
const { isTabletPortrait } = useAppData();
|
|
70
70
|
|
|
71
71
|
const plugins = usePlugins();
|
|
72
72
|
|
|
73
|
-
const
|
|
73
|
+
const bottomTabsVisible = isBottomTabVisible(
|
|
74
|
+
currentRoute,
|
|
75
|
+
screenData,
|
|
76
|
+
plugins
|
|
77
|
+
);
|
|
74
78
|
|
|
75
79
|
const frame = useSafeAreaFrame();
|
|
76
80
|
const insets = useSafeAreaInsets();
|
|
@@ -115,7 +119,7 @@ const Provider = ({ children }: { children: React.ReactNode }) => {
|
|
|
115
119
|
React.useEffect(() => {
|
|
116
120
|
const collapsedHeight =
|
|
117
121
|
minimisedHeight +
|
|
118
|
-
(
|
|
122
|
+
(bottomTabsVisible ? bottomTabBarHeight : 0) +
|
|
119
123
|
(isOldAndroidDevice ? 0 : insets.bottom) + // insets.bottom is added to properly display docked modal
|
|
120
124
|
PROGRESS_BAR_HEIGHT;
|
|
121
125
|
|
|
@@ -136,7 +140,7 @@ const Provider = ({ children }: { children: React.ReactNode }) => {
|
|
|
136
140
|
setHeightAboveMinimised(heightAboveMinimised);
|
|
137
141
|
offset.current = heightAboveMinimised;
|
|
138
142
|
}
|
|
139
|
-
}, [frame.height, insets.bottom,
|
|
143
|
+
}, [frame.height, insets.bottom, bottomTabsVisible, minimisedHeight]);
|
|
140
144
|
|
|
141
145
|
return (
|
|
142
146
|
<ReactContext.Provider
|
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
import { mergeRight } from "ramda";
|
|
2
2
|
import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
useAppSelector,
|
|
5
|
+
useContentTypes,
|
|
6
|
+
} from "@applicaster/zapp-react-native-redux/hooks";
|
|
4
7
|
import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
|
|
5
8
|
import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks/device/useIsTablet";
|
|
6
9
|
import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils";
|
|
7
10
|
import { create } from "zustand";
|
|
11
|
+
import { useRivers } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
12
|
+
import { selectPluginConfigurationsByPluginId } from "@applicaster/zapp-react-native-redux";
|
|
8
13
|
|
|
9
14
|
export const useConfiguration = () => {
|
|
10
15
|
const {
|
|
11
16
|
videoModalState: { item },
|
|
12
17
|
} = useNavigation();
|
|
13
18
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
"contentTypes",
|
|
17
|
-
"pluginConfigurations",
|
|
18
|
-
]);
|
|
19
|
+
const rivers = useRivers();
|
|
20
|
+
const contentTypes = useContentTypes();
|
|
19
21
|
|
|
20
22
|
const targetScreenId = contentTypes?.[item?.type?.value]?.screen_id;
|
|
21
23
|
const targetScreenConfiguration = rivers?.[targetScreenId];
|
|
22
24
|
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
+
const { configuration_json } = useAppSelector((state) =>
|
|
26
|
+
selectPluginConfigurationsByPluginId(state, targetScreenConfiguration?.type)
|
|
27
|
+
);
|
|
25
28
|
|
|
26
29
|
const playerPluginConfig = playerManager.getPluginConfiguration();
|
|
27
30
|
|
|
28
31
|
const config = mergeRight(playerPluginConfig, {
|
|
29
|
-
...
|
|
32
|
+
...configuration_json,
|
|
30
33
|
...targetScreenConfiguration?.general,
|
|
31
34
|
...targetScreenConfiguration?.styles,
|
|
32
35
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
3
|
import { getAnalyticsFunctions } from "@applicaster/zapp-react-native-utils/analyticsUtils";
|
|
4
|
-
import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
5
4
|
|
|
6
5
|
type ComponentProps = {
|
|
7
6
|
component: {
|
|
@@ -21,11 +20,13 @@ type ComponentProps = {
|
|
|
21
20
|
|
|
22
21
|
function withAnalytics(Component) {
|
|
23
22
|
return function WithAnalytics(props: ComponentProps) {
|
|
24
|
-
const { appData } = usePickFromState(["appData"]);
|
|
25
|
-
|
|
26
23
|
const analyticsFunctions = React.useMemo(
|
|
27
|
-
() =>
|
|
28
|
-
|
|
24
|
+
() =>
|
|
25
|
+
getAnalyticsFunctions({
|
|
26
|
+
component: props.component,
|
|
27
|
+
zappPipesData: props.zappPipesData,
|
|
28
|
+
} as any),
|
|
29
|
+
[props.component, props.zappPipesData]
|
|
29
30
|
);
|
|
30
31
|
|
|
31
32
|
return (
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="@applicaster/zapp-react-native-ui-components" />
|
|
3
3
|
import React from "react";
|
|
4
4
|
import { useRoute } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
|
|
5
|
-
import {
|
|
5
|
+
import { usePlugins } from "@applicaster/zapp-react-native-redux/hooks";
|
|
6
6
|
import { ZappPipesSearchContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
|
|
7
7
|
import { useScreenContext } from "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext";
|
|
8
8
|
import { ResolverSelector } from "./ResolverSelector";
|
|
@@ -23,7 +23,7 @@ export function zappPipesDataConnector(
|
|
|
23
23
|
) {
|
|
24
24
|
return function WrappedWithZappPipesData(props: Props) {
|
|
25
25
|
const { screenData } = useRoute();
|
|
26
|
-
const
|
|
26
|
+
const plugins = usePlugins();
|
|
27
27
|
const screenContextData = useScreenContext();
|
|
28
28
|
|
|
29
29
|
const {
|
|
@@ -76,7 +76,7 @@ export function StaticFeedResolver({
|
|
|
76
76
|
|
|
77
77
|
const zappPipesDataProps = useMemo(
|
|
78
78
|
() => ({
|
|
79
|
-
zappPipesData: { url, loading, data, error },
|
|
79
|
+
zappPipesData: { url, loading, data, error }, // todo: add applyItemLimit
|
|
80
80
|
reloadData,
|
|
81
81
|
loadNextData: undefined, // Static resolver doesn't support pagination
|
|
82
82
|
}),
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { itemLimitForData } from "..";
|
|
2
|
+
|
|
3
|
+
describe("itemLimitForData (no mocks)", () => {
|
|
4
|
+
test("returns full array when item_limit is undefined (default Infinity)", () => {
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const result = itemLimitForData([1, 2, 3], {
|
|
7
|
+
rules: { item_limit: undefined },
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
expect(result).toEqual([1, 2, 3]);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("enforces positive numeric item_limit", () => {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
const result = itemLimitForData([1, 2, 3, 4], {
|
|
16
|
+
rules: { item_limit: 2 },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(result).toEqual([1, 2]);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("returns empty array when entry is empty", () => {
|
|
23
|
+
const result = itemLimitForData([], {
|
|
24
|
+
rules: { item_limit: 3 },
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
expect(result).toEqual([]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("defaults entry to empty array when it is undefined", () => {
|
|
31
|
+
const result = itemLimitForData(undefined, {
|
|
32
|
+
rules: { item_limit: 5 },
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
expect(result).toEqual([]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("handles missing component", () => {
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
const result = itemLimitForData([10, 20, 30], undefined);
|
|
41
|
+
// missing component → item_limit = undefined → fallback to Infinity
|
|
42
|
+
expect(result).toEqual([10, 20, 30]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("handles missing rules object", () => {
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
const result = itemLimitForData([10, 20, 30], {});
|
|
48
|
+
|
|
49
|
+
expect(result).toEqual([10, 20, 30]);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("non-positive item_limit should fall back to Infinity", () => {
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
const result = itemLimitForData([1, 2, 3], {
|
|
55
|
+
rules: { item_limit: -10 },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// -10 → invalid → fallback to Infinity → no limit
|
|
59
|
+
expect(result).toEqual([1, 2, 3]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("zero item_limit should fall back to Infinity", () => {
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
const result = itemLimitForData([1, 2, 3], {
|
|
65
|
+
rules: { item_limit: 0 },
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// 0 → invalid → fallback to Infinity
|
|
69
|
+
expect(result).toEqual([1, 2, 3]);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("NaN item_limit should fall back to Infinity", () => {
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
const result = itemLimitForData([1, 2, 3], {
|
|
75
|
+
rules: { item_limit: NaN },
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
expect(result).toEqual([1, 2, 3]);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { toPositiveNumberWithDefault } from "@applicaster/zapp-react-native-utils/numberUtils";
|
|
2
|
+
|
|
3
|
+
export function itemLimitForData(
|
|
4
|
+
entry: ZappEntry[],
|
|
5
|
+
component: {
|
|
6
|
+
rules?: { item_limit?: number | string };
|
|
7
|
+
}
|
|
8
|
+
) {
|
|
9
|
+
if (!component?.rules?.item_limit) {
|
|
10
|
+
return entry;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const itemLimit = toPositiveNumberWithDefault(
|
|
14
|
+
Infinity,
|
|
15
|
+
component?.rules?.item_limit
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
return (entry || []).slice(0, itemLimit);
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-ui-components",
|
|
3
|
-
"version": "15.0.0-alpha.
|
|
3
|
+
"version": "15.0.0-alpha.7607942912",
|
|
4
4
|
"description": "Applicaster Zapp React Native ui components for the Quick Brick App",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,10 +28,11 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "15.0.0-alpha.
|
|
32
|
-
"@applicaster/zapp-react-native-bridge": "15.0.0-alpha.
|
|
33
|
-
"@applicaster/zapp-react-native-redux": "15.0.0-alpha.
|
|
34
|
-
"@applicaster/zapp-react-native-utils": "15.0.0-alpha.
|
|
31
|
+
"@applicaster/applicaster-types": "15.0.0-alpha.7607942912",
|
|
32
|
+
"@applicaster/zapp-react-native-bridge": "15.0.0-alpha.7607942912",
|
|
33
|
+
"@applicaster/zapp-react-native-redux": "15.0.0-alpha.7607942912",
|
|
34
|
+
"@applicaster/zapp-react-native-utils": "15.0.0-alpha.7607942912",
|
|
35
|
+
"fast-json-stable-stringify": "^2.1.0",
|
|
35
36
|
"promise": "^8.3.0",
|
|
36
37
|
"url": "^0.11.0",
|
|
37
38
|
"uuid": "^3.3.2"
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as R from "ramda";
|
|
2
|
-
|
|
3
|
-
export function itemLimitForData(entry = [], component) {
|
|
4
|
-
const itemLimitValue = Number(R.path(["rules", "item_limit"], component));
|
|
5
|
-
|
|
6
|
-
const itemLimit =
|
|
7
|
-
itemLimitValue && itemLimitValue > 0
|
|
8
|
-
? itemLimitValue
|
|
9
|
-
: Number.MAX_SAFE_INTEGER;
|
|
10
|
-
|
|
11
|
-
const isInRange = (min, max) => R.both(R.gte(R.__, min), R.lt(R.__, max));
|
|
12
|
-
|
|
13
|
-
const entryShouldBeSliced = (entry) =>
|
|
14
|
-
isInRange(0, R.length(entry))(itemLimit);
|
|
15
|
-
|
|
16
|
-
const sliceEntriesUpToItemLimit = R.slice(0, itemLimit);
|
|
17
|
-
|
|
18
|
-
return R.when(entryShouldBeSliced, sliceEntriesUpToItemLimit)(entry);
|
|
19
|
-
}
|