@applicaster/zapp-react-native-utils 14.0.0-alpha.7900711229 → 14.0.0-alpha.9567513212
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/actionsExecutor/ActionExecutorContext.tsx +83 -60
- package/appUtils/contextKeysManager/contextResolver.ts +1 -14
- package/arrayUtils/__tests__/isFilledArray.test.ts +1 -1
- package/arrayUtils/index.ts +2 -7
- package/configurationUtils/__tests__/configurationUtils.test.js +31 -0
- package/configurationUtils/index.ts +34 -63
- package/manifestUtils/{_internals/index.js → _internals.js} +25 -2
- package/manifestUtils/createConfig.js +1 -4
- package/manifestUtils/defaultManifestConfigurations/player.js +200 -1231
- package/manifestUtils/progressBar/__tests__/mobileProgressBar.test.js +30 -0
- package/package.json +2 -2
- package/playerUtils/__tests__/configurationUtils.test.ts +65 -1
- package/playerUtils/configurationGenerator.ts +2572 -0
- package/playerUtils/configurationUtils.ts +44 -0
- package/playerUtils/index.ts +51 -2
- package/playerUtils/useValidatePlayerConfig.tsx +19 -22
- package/reactHooks/cell-click/index.ts +1 -8
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +0 -20
- package/reactHooks/feed/useBatchLoading.ts +2 -2
- package/reactHooks/feed/useFeedLoader.tsx +5 -12
- package/reactHooks/navigation/useRoute.ts +2 -7
- package/utils/index.ts +1 -12
- package/actionsExecutor/ScreenActions.ts +0 -163
- package/actionsExecutor/StorageActions.ts +0 -110
- package/actionsExecutor/feedDecorator.ts +0 -171
- package/actionsExecutor/screenResolver.ts +0 -11
- package/arrayUtils/__tests__/isEmptyArray.test.ts +0 -63
- package/audioPlayerUtils/__tests__/getArtworkImage.test.ts +0 -144
- package/audioPlayerUtils/__tests__/getBackgroundImage.test.ts +0 -72
- package/audioPlayerUtils/__tests__/getImageFromEntry.test.ts +0 -110
- package/audioPlayerUtils/assets/index.ts +0 -2
- package/audioPlayerUtils/index.ts +0 -242
- package/conf/player/__tests__/selectors.test.ts +0 -34
- package/conf/player/selectors.ts +0 -10
- package/configurationUtils/__tests__/getMediaItems.test.ts +0 -65
- package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +0 -34
- package/manifestUtils/_internals/getDefaultConfiguration.js +0 -28
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
- package/playerUtils/_internals/__tests__/utils.test.ts +0 -71
- package/playerUtils/_internals/index.ts +0 -1
- package/playerUtils/_internals/utils.ts +0 -31
- package/playerUtils/getPlayerActionButtons.ts +0 -17
- package/reactHooks/navigation/useScreenStateStore.ts +0 -11
- package/storage/ScreenSingleValueProvider.ts +0 -197
- package/storage/ScreenStateMultiSelectProvider.ts +0 -282
- package/storage/StorageMultiSelectProvider.ts +0 -192
- package/storage/StorageSingleSelectProvider.ts +0 -108
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
import { parseJsonIfNeeded } from "../functionUtils";
|
|
2
2
|
import * as R from "ramda";
|
|
3
3
|
|
|
4
|
+
import { getNativeName as nativeNameUtil } from "../localizationUtils/localeLanguage";
|
|
5
|
+
|
|
6
|
+
export const modifyDefaultConfigValues = (
|
|
7
|
+
configuration: ConfigurationKeys,
|
|
8
|
+
mapping: ConfigValuesMapping
|
|
9
|
+
): DefaultConfiguration => {
|
|
10
|
+
return R.mapObjIndexed((value, key) => {
|
|
11
|
+
const isFieldlessKey = key === "custom_configuration_fields";
|
|
12
|
+
const keyMapping = mapping[key];
|
|
13
|
+
const fields = value?.fields || value;
|
|
14
|
+
|
|
15
|
+
if (!keyMapping) {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const mapper = (obj) => {
|
|
20
|
+
if (obj.fields) {
|
|
21
|
+
return R.mergeLeft({ fields: R.map(mapper)(obj.fields) })(obj);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return R.mergeLeft(keyMapping?.[obj.key])(obj);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const mappedFields = R.map(mapper)(fields);
|
|
28
|
+
|
|
29
|
+
return R.unless(() => isFieldlessKey, R.objOf("fields"))(mappedFields);
|
|
30
|
+
})(configuration);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export function nativeName(localeCode) {
|
|
34
|
+
try {
|
|
35
|
+
const {
|
|
36
|
+
getNativeName,
|
|
37
|
+
} = require("@applicaster/zapp-react-native-utils/localizationUtils/localeLanguage");
|
|
38
|
+
|
|
39
|
+
return getNativeName(localeCode);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
// eslint-disable-next-line no-console
|
|
42
|
+
console.warn("Could not load localeLanguage utils from QB", error);
|
|
43
|
+
|
|
44
|
+
return nativeNameUtil(localeCode);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
4
48
|
const setTrackType = R.curry(
|
|
5
49
|
(
|
|
6
50
|
type: QuickBrickPlayer.TrackType,
|
package/playerUtils/index.ts
CHANGED
|
@@ -5,8 +5,7 @@ import { isFilledArray } from "@applicaster/zapp-react-native-utils/arrayUtils";
|
|
|
5
5
|
import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
6
6
|
|
|
7
7
|
import { getBoolFromConfigValue } from "../configurationUtils";
|
|
8
|
-
|
|
9
|
-
export { getPlayerActionButtons } from "./getPlayerActionButtons";
|
|
8
|
+
import { Dimensions } from "react-native";
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Gets duration value from player manager, and from extensions
|
|
@@ -97,3 +96,53 @@ export const isAudioItem = (item: Option<ZappEntry>) => {
|
|
|
97
96
|
export const isInlineTV = (screenData) => {
|
|
98
97
|
return isTV() && isFilledArray(screenData?.ui_components);
|
|
99
98
|
};
|
|
99
|
+
|
|
100
|
+
const isPercentage = (value: string | number): boolean => {
|
|
101
|
+
if (typeof value === "string") {
|
|
102
|
+
return value.includes("%");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return false;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const getPercentageOf = (percent: string, value: number) => {
|
|
109
|
+
const percentageValue = parseFloat(percent.replace("%", ""));
|
|
110
|
+
|
|
111
|
+
if (isNaN(percentageValue)) {
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return (value * percentageValue) / 100;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
type DimensionsT = {
|
|
119
|
+
width: number | string;
|
|
120
|
+
height: number | string | undefined;
|
|
121
|
+
aspectRatio?: number;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export const getTabletWidth = (
|
|
125
|
+
tablet_landscape_sidebar_width,
|
|
126
|
+
dimensions: DimensionsT
|
|
127
|
+
) => {
|
|
128
|
+
const { width: SCREEN_WIDTH } = Dimensions.get("screen");
|
|
129
|
+
|
|
130
|
+
const { width } = dimensions;
|
|
131
|
+
let widthValue = Number(width);
|
|
132
|
+
|
|
133
|
+
if (isPercentage(width)) {
|
|
134
|
+
widthValue = getPercentageOf(width.toString(), SCREEN_WIDTH);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const sidebarWidth = Number(tablet_landscape_sidebar_width?.replace("%", ""));
|
|
138
|
+
|
|
139
|
+
if (tablet_landscape_sidebar_width?.includes("%")) {
|
|
140
|
+
return widthValue * (1 - sidebarWidth / 100);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (Number.isNaN(sidebarWidth)) {
|
|
144
|
+
return widthValue * 0.65;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return widthValue - sidebarWidth;
|
|
148
|
+
};
|
|
@@ -1,37 +1,34 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import * as R from "ramda";
|
|
3
|
+
import generateConfiguration from "./configurationGenerator";
|
|
2
4
|
import { createLogger } from "../logger";
|
|
3
|
-
import { createConfig } from "../manifestUtils/createConfig";
|
|
4
|
-
import { getAllFields, getConfigurationDiff } from "./_internals";
|
|
5
5
|
|
|
6
6
|
export const logger = createLogger({
|
|
7
7
|
category: "useValidatePlayerConfig",
|
|
8
8
|
subsystem: "useValidatePlayerConfig",
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
const {
|
|
13
|
-
styles,
|
|
14
|
-
general,
|
|
15
|
-
localizations,
|
|
16
|
-
custom_configuration_fields,
|
|
17
|
-
}: DefaultConfiguration = createConfig(
|
|
18
|
-
() => {
|
|
19
|
-
return {};
|
|
20
|
-
},
|
|
21
|
-
{ extend: "player" }
|
|
22
|
-
) as any;
|
|
23
|
-
|
|
24
|
-
const QBPlayerConfigFields = getAllFields(
|
|
25
|
-
styles,
|
|
26
|
-
general,
|
|
27
|
-
localizations,
|
|
28
|
-
custom_configuration_fields
|
|
29
|
-
);
|
|
11
|
+
const configuration = generateConfiguration();
|
|
30
12
|
|
|
31
13
|
export const useValidatePlayerConfig = (config) => {
|
|
32
14
|
React.useEffect(() => {
|
|
33
15
|
try {
|
|
34
|
-
const
|
|
16
|
+
const QBPlayerConfigFields = R.compose(
|
|
17
|
+
R.map(R.prop("key")),
|
|
18
|
+
R.flatten,
|
|
19
|
+
R.map(R.compose(R.when(R.propEq("group", true), R.prop("fields")))),
|
|
20
|
+
R.concat
|
|
21
|
+
)(
|
|
22
|
+
configuration.styles.fields,
|
|
23
|
+
configuration.general.fields,
|
|
24
|
+
configuration.localizations.fields,
|
|
25
|
+
configuration.custom_configuration_fields
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const diff = R.compose(
|
|
29
|
+
R.difference(QBPlayerConfigFields),
|
|
30
|
+
R.keys
|
|
31
|
+
)(config);
|
|
35
32
|
|
|
36
33
|
logger.log_info(
|
|
37
34
|
"Missing following configuration properties. Some elements of the player may not work correctly. Check QuickBrickPlayerPlugin for the configuration reference https://github.com/applicaster/QuickBrick/tree/main/plugins/zapp-react-native-default-player/manifests",
|
|
@@ -16,8 +16,7 @@ import { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/acti
|
|
|
16
16
|
import { isFunction, noop } from "../../functionUtils";
|
|
17
17
|
import { useSendAnalyticsOnPress } from "../analytics";
|
|
18
18
|
import { logOnPress, warnEmptyContentType } from "./helpers";
|
|
19
|
-
import { useCurrentScreenData
|
|
20
|
-
import { useScreenStateStore } from "../navigation/useScreenStateStore";
|
|
19
|
+
import { useCurrentScreenData } from "../screen";
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
22
|
* If onCellTap is defined execute the function and
|
|
@@ -43,12 +42,10 @@ export const useCellClick = ({
|
|
|
43
42
|
}: Props): onPressReturnFn => {
|
|
44
43
|
const { push, currentRoute } = useNavigation();
|
|
45
44
|
const { pathname } = useRoute();
|
|
46
|
-
const screenStateStore = useScreenStateStore();
|
|
47
45
|
|
|
48
46
|
const onCellTap: Option<Function> = React.useContext(CellTapContext);
|
|
49
47
|
const actionExecutor = React.useContext(ActionExecutorContext);
|
|
50
48
|
const screenData = useCurrentScreenData();
|
|
51
|
-
const screenState = useScreenContext()?.options;
|
|
52
49
|
|
|
53
50
|
const cellSelectable = toBooleanWithDefaultTrue(
|
|
54
51
|
component?.rules?.component_cells_selectable
|
|
@@ -86,9 +83,6 @@ export const useCellClick = ({
|
|
|
86
83
|
await actionExecutor?.handleEntryActions(selectedItem, {
|
|
87
84
|
component,
|
|
88
85
|
screenData,
|
|
89
|
-
screenState,
|
|
90
|
-
screenRoute: pathname,
|
|
91
|
-
screenStateStore,
|
|
92
86
|
});
|
|
93
87
|
}
|
|
94
88
|
|
|
@@ -123,7 +117,6 @@ export const useCellClick = ({
|
|
|
123
117
|
push,
|
|
124
118
|
sendAnalyticsOnPress,
|
|
125
119
|
screenData,
|
|
126
|
-
screenState,
|
|
127
120
|
]
|
|
128
121
|
);
|
|
129
122
|
|
|
@@ -138,11 +138,6 @@ describe("useFeedLoader", () => {
|
|
|
138
138
|
expect(loadPipesDataSpy).toBeCalledWith(feedUrl, {
|
|
139
139
|
clearCache: true,
|
|
140
140
|
riverId: undefined,
|
|
141
|
-
resolvers: {
|
|
142
|
-
screen: {
|
|
143
|
-
screenStateStore: undefined,
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
141
|
});
|
|
147
142
|
|
|
148
143
|
const store2 = mockStore({
|
|
@@ -184,11 +179,6 @@ describe("useFeedLoader", () => {
|
|
|
184
179
|
expect(loadPipesDataSpy).toBeCalledWith(feedUrl, {
|
|
185
180
|
clearCache: true,
|
|
186
181
|
riverId: undefined,
|
|
187
|
-
resolvers: {
|
|
188
|
-
screen: {
|
|
189
|
-
screenStateStore: undefined,
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
182
|
});
|
|
193
183
|
|
|
194
184
|
const store2 = mockStore({
|
|
@@ -238,11 +228,6 @@ describe("useFeedLoader", () => {
|
|
|
238
228
|
expect(loadPipesDataSpy).toBeCalledWith(feedUrl, {
|
|
239
229
|
clearCache: true,
|
|
240
230
|
silentRefresh: true,
|
|
241
|
-
resolvers: {
|
|
242
|
-
screen: {
|
|
243
|
-
screenStateStore: undefined,
|
|
244
|
-
},
|
|
245
|
-
},
|
|
246
231
|
});
|
|
247
232
|
|
|
248
233
|
loadPipesDataSpy.mockRestore();
|
|
@@ -282,11 +267,6 @@ describe("useFeedLoader", () => {
|
|
|
282
267
|
expect(loadPipesDataSpy).toBeCalledWith(nextUrl, {
|
|
283
268
|
parentFeed: feedUrlWithNext,
|
|
284
269
|
silentRefresh: true,
|
|
285
|
-
resolvers: {
|
|
286
|
-
screen: {
|
|
287
|
-
screenStateStore: undefined,
|
|
288
|
-
},
|
|
289
|
-
},
|
|
290
270
|
});
|
|
291
271
|
|
|
292
272
|
loadPipesDataSpy.mockRestore();
|
|
@@ -144,11 +144,11 @@ export const useBatchLoading = (
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
});
|
|
147
|
-
}, [feedUrls
|
|
147
|
+
}, [feedUrls]);
|
|
148
148
|
|
|
149
149
|
React.useEffect(() => {
|
|
150
150
|
runBatchLoading();
|
|
151
|
-
}, [
|
|
151
|
+
}, []);
|
|
152
152
|
|
|
153
153
|
React.useEffect(() => {
|
|
154
154
|
// check if all feeds are ready and set hasEverBeenReady to true
|
|
@@ -8,7 +8,6 @@ import { reactHooksLogger } from "../logger";
|
|
|
8
8
|
import { shouldDispatchData, useIsInitialRender } from "../utils";
|
|
9
9
|
import { useInflatedUrl } from "./useInflatedUrl";
|
|
10
10
|
import { useRoute } from "../navigation";
|
|
11
|
-
import { useScreenResolvers } from "@applicaster/zapp-react-native-utils/actionsExecutor/screenResolver";
|
|
12
11
|
|
|
13
12
|
const logger = reactHooksLogger.addSubsystem("useFeedLoader");
|
|
14
13
|
|
|
@@ -52,7 +51,6 @@ export const useFeedLoader = ({
|
|
|
52
51
|
const isInitialRender = useIsInitialRender();
|
|
53
52
|
const dispatch = useDispatch();
|
|
54
53
|
const { screenData } = useRoute();
|
|
55
|
-
const resolvers = useScreenResolvers();
|
|
56
54
|
|
|
57
55
|
const callableFeedUrl = useInflatedUrl({ feedUrl, mapping });
|
|
58
56
|
|
|
@@ -71,12 +69,11 @@ export const useFeedLoader = ({
|
|
|
71
69
|
silentRefresh,
|
|
72
70
|
callback,
|
|
73
71
|
riverId,
|
|
74
|
-
resolvers,
|
|
75
72
|
})
|
|
76
73
|
);
|
|
77
74
|
}
|
|
78
75
|
},
|
|
79
|
-
[callableFeedUrl
|
|
76
|
+
[callableFeedUrl]
|
|
80
77
|
);
|
|
81
78
|
|
|
82
79
|
const loadNext: FeedLoaderResponse["loadNext"] = React.useCallback(() => {
|
|
@@ -89,12 +86,11 @@ export const useFeedLoader = ({
|
|
|
89
86
|
silentRefresh: true,
|
|
90
87
|
parentFeed: callableFeedUrl,
|
|
91
88
|
riverId,
|
|
92
|
-
resolvers,
|
|
93
89
|
})
|
|
94
90
|
);
|
|
95
91
|
}
|
|
96
92
|
}
|
|
97
|
-
}, [callableFeedUrl, currentFeed?.data?.next
|
|
93
|
+
}, [callableFeedUrl, currentFeed?.data?.next]);
|
|
98
94
|
|
|
99
95
|
useEffect(() => {
|
|
100
96
|
if (
|
|
@@ -106,7 +102,6 @@ export const useFeedLoader = ({
|
|
|
106
102
|
...pipesOptions,
|
|
107
103
|
clearCache: true,
|
|
108
104
|
riverId,
|
|
109
|
-
resolvers,
|
|
110
105
|
})
|
|
111
106
|
);
|
|
112
107
|
} else if (!callableFeedUrl) {
|
|
@@ -131,16 +126,14 @@ export const useFeedLoader = ({
|
|
|
131
126
|
jsOnly: true,
|
|
132
127
|
});
|
|
133
128
|
}
|
|
134
|
-
}, [
|
|
129
|
+
}, []);
|
|
135
130
|
|
|
136
131
|
// Reload feed when feedUrl changes, unless skipLoading is true
|
|
137
132
|
useEffect(() => {
|
|
138
133
|
if (!isInitialRender && callableFeedUrl && !pipesOptions.skipLoading) {
|
|
139
|
-
dispatch(
|
|
140
|
-
loadPipesData(callableFeedUrl, { ...pipesOptions, riverId, resolvers })
|
|
141
|
-
);
|
|
134
|
+
dispatch(loadPipesData(callableFeedUrl, { ...pipesOptions, riverId }));
|
|
142
135
|
}
|
|
143
|
-
}, [callableFeedUrl
|
|
136
|
+
}, [callableFeedUrl]);
|
|
144
137
|
|
|
145
138
|
return React.useMemo(() => {
|
|
146
139
|
if (!callableFeedUrl || !feedUrl) {
|
|
@@ -28,19 +28,14 @@ const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
|
|
|
28
28
|
|
|
29
29
|
type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
|
|
30
30
|
|
|
31
|
-
export const useRoute = (
|
|
32
|
-
useLegacy = true
|
|
33
|
-
): {
|
|
31
|
+
export const useRoute = (): {
|
|
34
32
|
screenData: VariousScreenData;
|
|
35
33
|
pathname: string;
|
|
36
34
|
} => {
|
|
37
35
|
const pathname = usePathname() || "";
|
|
38
36
|
const navigator = useNavigation();
|
|
39
|
-
const screenContext = useContext(ScreenDataContext);
|
|
40
37
|
|
|
41
|
-
const screenDataContext =
|
|
42
|
-
? legacyScreenData(screenContext)
|
|
43
|
-
: screenContext;
|
|
38
|
+
const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
|
|
44
39
|
|
|
45
40
|
const { plugins, contentTypes, rivers } = usePickFromState([
|
|
46
41
|
"plugins",
|
package/utils/index.ts
CHANGED
|
@@ -2,15 +2,4 @@ export { chunk } from "./chunk";
|
|
|
2
2
|
|
|
3
3
|
export { times } from "./times";
|
|
4
4
|
|
|
5
|
-
export {
|
|
6
|
-
cloneDeep as clone,
|
|
7
|
-
flatten,
|
|
8
|
-
drop,
|
|
9
|
-
size,
|
|
10
|
-
isNil,
|
|
11
|
-
isEmpty,
|
|
12
|
-
get,
|
|
13
|
-
has,
|
|
14
|
-
flatMap,
|
|
15
|
-
difference,
|
|
16
|
-
} from "lodash";
|
|
5
|
+
export { cloneDeep as clone, flatten, drop, size, isNil } from "lodash";
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
// import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
2
|
-
|
|
3
|
-
import { log_error, log_info } from "./ActionExecutorContext";
|
|
4
|
-
import { ActionResult } from "./ActionExecutor";
|
|
5
|
-
import { get } from "lodash";
|
|
6
|
-
|
|
7
|
-
import { onMaxTagsReached } from "./StorageActions";
|
|
8
|
-
import { ScreenMultiSelectProvider } from "../storage/ScreenStateMultiSelectProvider";
|
|
9
|
-
import { ScreenSingleValueProvider } from "../storage/ScreenSingleValueProvider";
|
|
10
|
-
|
|
11
|
-
export const screenSetVariable = async (
|
|
12
|
-
screenRoute: string,
|
|
13
|
-
screenStateStore: ScreenStateStore,
|
|
14
|
-
context: Record<string, any>,
|
|
15
|
-
action: ActionType
|
|
16
|
-
): Promise<ActionResult> => {
|
|
17
|
-
if (!context) {
|
|
18
|
-
log_error("handleAction: screenSetVariable action missing context");
|
|
19
|
-
|
|
20
|
-
return ActionResult.Error;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const entry = context?.entry as ZappEntry;
|
|
24
|
-
|
|
25
|
-
if (!entry) {
|
|
26
|
-
log_error(
|
|
27
|
-
"handleAction: screenSetVariable action missing entry. Entry is required to get the value."
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
return ActionResult.Error;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const tag = action.options?.selector
|
|
34
|
-
? get(entry, action.options.selector)
|
|
35
|
-
: (entry.extensions?.tag ?? entry.id);
|
|
36
|
-
|
|
37
|
-
const keyNamespace = action.options?.key;
|
|
38
|
-
|
|
39
|
-
if (!keyNamespace) {
|
|
40
|
-
log_error("handleAction: screenSetVariable action missing key namespace", {
|
|
41
|
-
keyNamespace,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return ActionResult.Error;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (!tag) {
|
|
48
|
-
log_error(
|
|
49
|
-
"handleAction: screenSetVariable action could not determine tag",
|
|
50
|
-
{ selector: action.options?.selector, value: action.options?.value }
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
return ActionResult.Error;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
const singleValueProvider = ScreenSingleValueProvider.getProvider(
|
|
58
|
-
keyNamespace,
|
|
59
|
-
screenRoute,
|
|
60
|
-
screenStateStore
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
const currentValue = await singleValueProvider.getValueAsync();
|
|
64
|
-
|
|
65
|
-
log_info(
|
|
66
|
-
`handleAction: screenSetVariable setting value: ${tag} for keyNamespace: ${keyNamespace}, previous value: ${currentValue}`
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
await singleValueProvider.setValue(String(tag));
|
|
70
|
-
|
|
71
|
-
log_info(
|
|
72
|
-
`handleAction: screenSetVariable successfully set value: ${tag} for keyNamespace: ${keyNamespace}`
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
return ActionResult.Success;
|
|
76
|
-
} catch (error) {
|
|
77
|
-
log_error("handleAction: screenSetVariable failed to set value", {
|
|
78
|
-
keyNamespace,
|
|
79
|
-
tag,
|
|
80
|
-
error,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
return ActionResult.Error;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export const screenToggleFlag = async (
|
|
88
|
-
screenRoute: string,
|
|
89
|
-
screenStateStore: ScreenStateStore,
|
|
90
|
-
context: Record<string, any>,
|
|
91
|
-
action: ActionType
|
|
92
|
-
) => {
|
|
93
|
-
if (!context) {
|
|
94
|
-
log_error("handleAction: screenToggleFlag action missing context");
|
|
95
|
-
|
|
96
|
-
return ActionResult.Error;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const entry = context?.entry as ZappEntry;
|
|
100
|
-
|
|
101
|
-
if (!entry) {
|
|
102
|
-
log_error(
|
|
103
|
-
"handleAction: screenToggleFlag action missing entry. Entry is required to get the tag."
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
return ActionResult.Error;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const tag = action.options?.selector
|
|
110
|
-
? get(entry, action.options.selector)
|
|
111
|
-
: (entry.extensions?.tag ?? entry.id);
|
|
112
|
-
|
|
113
|
-
const keyNamespace = action.options?.key;
|
|
114
|
-
|
|
115
|
-
if (keyNamespace && tag) {
|
|
116
|
-
const multiSelectProvider = ScreenMultiSelectProvider.getProvider(
|
|
117
|
-
keyNamespace,
|
|
118
|
-
screenRoute,
|
|
119
|
-
screenStateStore
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
const selectedItems = await multiSelectProvider.getSelectedAsync();
|
|
123
|
-
const isTagInSelectedItems = selectedItems.includes(tag);
|
|
124
|
-
|
|
125
|
-
log_info(
|
|
126
|
-
`handleAction: screenToggleFlag event will ${
|
|
127
|
-
isTagInSelectedItems ? "remove" : "add"
|
|
128
|
-
} tag: ${tag} for keyNamespace: ${keyNamespace}, current selectedItems: ${selectedItems}`
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
if (selectedItems.includes(tag)) {
|
|
132
|
-
await multiSelectProvider.removeItem(tag);
|
|
133
|
-
} else {
|
|
134
|
-
const maxItems = action.options?.max_items;
|
|
135
|
-
|
|
136
|
-
if (maxItems && selectedItems.length >= maxItems) {
|
|
137
|
-
log_info(
|
|
138
|
-
`handleAction: screenToggleFlag event reached max items limit: ${maxItems}, cannot add tag: ${tag}`
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
await onMaxTagsReached({
|
|
142
|
-
selectedItems,
|
|
143
|
-
maxItems,
|
|
144
|
-
tag,
|
|
145
|
-
keyNamespace,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
return ActionResult.Cancel;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
await multiSelectProvider.addItem(tag);
|
|
152
|
-
}
|
|
153
|
-
} else {
|
|
154
|
-
log_error(
|
|
155
|
-
"handleAction: screenToggleFlag event missing keyNamespace or tag",
|
|
156
|
-
{ keyNamespace, tag }
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
return ActionResult.Error;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return ActionResult.Success;
|
|
163
|
-
};
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { ActionResult } from "./ActionExecutor";
|
|
2
|
-
import { get } from "lodash";
|
|
3
|
-
import { StorageMultiSelectProvider } from "@applicaster/zapp-react-native-utils/storage/StorageMultiSelectProvider";
|
|
4
|
-
import { log_error, log_info } from "./ActionExecutorContext";
|
|
5
|
-
import { postEvent } from "../reactHooks/useSubscriberFor";
|
|
6
|
-
import { TOGGLE_FLAG_MAX_ITEMS_REACHED_EVENT } from "./consts";
|
|
7
|
-
import { StorageType } from "../appUtils/contextKeysManager/consts";
|
|
8
|
-
|
|
9
|
-
// send all data just in case (like for message string formatting)
|
|
10
|
-
// Type is not exported for now
|
|
11
|
-
type MaxTagsReachedEvent = {
|
|
12
|
-
selectedItems: string[];
|
|
13
|
-
maxItems: number;
|
|
14
|
-
tag: string;
|
|
15
|
-
keyNamespace: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export async function onMaxTagsReached(data: MaxTagsReachedEvent) {
|
|
19
|
-
postEvent(TOGGLE_FLAG_MAX_ITEMS_REACHED_EVENT, [data]);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export async function storageToggleFlag(
|
|
23
|
-
context: Record<string, any>,
|
|
24
|
-
action: ActionType,
|
|
25
|
-
storageType: StorageType
|
|
26
|
-
) {
|
|
27
|
-
if (!context) {
|
|
28
|
-
log_error("handleAction: localStorageToggleFlag action missing context");
|
|
29
|
-
|
|
30
|
-
return ActionResult.Error;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const entry = context?.entry as ZappEntry;
|
|
34
|
-
|
|
35
|
-
if (!entry) {
|
|
36
|
-
log_error(
|
|
37
|
-
"handleAction: localStorageToggleFlag action missing entry. Entry is required to get the tag."
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
return ActionResult.Error;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const tag = action.options?.selector
|
|
44
|
-
? get(entry, action.options.selector)
|
|
45
|
-
: (entry.extensions?.tag ?? entry.id);
|
|
46
|
-
|
|
47
|
-
const keyNamespace = action.options?.key;
|
|
48
|
-
|
|
49
|
-
if (keyNamespace && tag) {
|
|
50
|
-
const multiSelectProvider = StorageMultiSelectProvider.getProvider(
|
|
51
|
-
keyNamespace,
|
|
52
|
-
storageType
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const selectedItems = await multiSelectProvider.getSelectedAsync();
|
|
56
|
-
const isTagInSelectedItems = selectedItems.includes(tag);
|
|
57
|
-
|
|
58
|
-
log_info(
|
|
59
|
-
`handleAction: localStorageToggleFlag event will ${
|
|
60
|
-
isTagInSelectedItems ? "remove" : "add"
|
|
61
|
-
} tag: ${tag} for keyNamespace: ${keyNamespace}, current selectedItems: ${selectedItems}`
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
if (selectedItems.includes(tag)) {
|
|
65
|
-
await multiSelectProvider.removeItem(tag);
|
|
66
|
-
} else {
|
|
67
|
-
const maxItems = action.options?.max_items;
|
|
68
|
-
|
|
69
|
-
if (maxItems && selectedItems.length >= maxItems) {
|
|
70
|
-
log_info(
|
|
71
|
-
`handleAction: localStorageToggleFlag event reached max items limit: ${maxItems}, cannot add tag: ${tag}`
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
await onMaxTagsReached({
|
|
75
|
-
selectedItems,
|
|
76
|
-
maxItems,
|
|
77
|
-
tag,
|
|
78
|
-
keyNamespace,
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
return ActionResult.Cancel;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
await multiSelectProvider.addItem(tag);
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
log_error(
|
|
88
|
-
"handleAction: localStorageToggleFlag event missing keyNamespace or tag",
|
|
89
|
-
{ keyNamespace, tag }
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
return ActionResult.Error;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return ActionResult.Success;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export async function sessionStorageToggleFlag(
|
|
99
|
-
context: Record<string, any>,
|
|
100
|
-
action: ActionType
|
|
101
|
-
) {
|
|
102
|
-
return storageToggleFlag(context, action, StorageType.session);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export async function localStorageToggleFlag(
|
|
106
|
-
context: Record<string, any>,
|
|
107
|
-
action: ActionType
|
|
108
|
-
) {
|
|
109
|
-
return storageToggleFlag(context, action, StorageType.local);
|
|
110
|
-
}
|