@applicaster/zapp-react-native-utils 16.0.0-alpha.9183418480 → 16.0.0-alpha.9506982263
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/ActionExecutor.ts +8 -10
- package/actionsExecutor/ActionExecutorContext.tsx +43 -326
- package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
- package/actionsExecutor/actions/appRestart.ts +24 -0
- package/actionsExecutor/actions/confirmDialog.ts +53 -0
- package/actionsExecutor/actions/index.ts +30 -0
- package/actionsExecutor/actions/localStorageRemove.ts +27 -0
- package/actionsExecutor/actions/localStorageSet.ts +28 -0
- package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
- package/actionsExecutor/actions/navigateToScreen.ts +123 -0
- package/actionsExecutor/actions/refreshComponent.ts +79 -0
- package/actionsExecutor/actions/screenSetVariable.ts +35 -0
- package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
- package/actionsExecutor/actions/sendCloudEvent.ts +88 -0
- package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
- package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
- package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
- package/actionsExecutor/actions/showToast.ts +87 -0
- package/actionsExecutor/actions/switchLayout.ts +40 -0
- package/actionsExecutor/types.ts +59 -0
- package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -2
- package/analyticsUtils/PlayerAnalyticsManager.ts +12 -2
- package/analyticsUtils/__tests__/analyticsMapper.test.ts +35 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testACP_events.json +1 -1
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testBlockUnlistedParams_rules.json +1 -1
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_events.json +4 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_rules.json +6 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEventRegex_events.json +3 -9
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_events.json +18 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_rules.json +16 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_events.json +4 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_rules.json +6 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_events.json +4 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_rules.json +6 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_events.json +4 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_rules.json +6 -0
- package/analyticsUtils/__tests__/fixtures/index.js +20 -0
- package/analyticsUtils/analyticsMapper.ts +4 -1
- package/analyticsUtils/playerAnalyticsTracker.ts +26 -3
- package/appUtils/HooksManager/index.ts +3 -8
- package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -1
- package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -1
- package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
- package/appUtils/contextKeysManager/index.ts +1 -1
- package/appUtils/contextKeysManager/utils/index.ts +38 -25
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +138 -51
- package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
- package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
- package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
- package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
- package/appUtils/playerManager/{conts.ts → const.ts} +20 -0
- package/appUtils/playerManager/index.ts +1 -1
- package/appUtils/playerManager/player.ts +115 -3
- package/appUtils/playerManager/playerFactory.ts +1 -1
- package/appUtils/playerManager/playerNative.ts +1 -1
- package/appUtils/playerManager/usePlayerContent.tsx +43 -0
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
- package/appUtils/playerManager/userLanguagePreference.ts +1 -1
- package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
- package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
- package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
- package/arrayUtils/__tests__/isFirst.test.ts +17 -0
- package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
- package/arrayUtils/__tests__/isLast.test.ts +31 -0
- package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
- package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
- package/arrayUtils/__tests__/sample.test.ts +61 -0
- package/arrayUtils/index.ts +57 -20
- package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
- package/bottomSheet/index.ts +17 -0
- package/cellUtils/index.ts +3 -5
- package/colorUtils/__tests__/isTransparentColor.test.ts +76 -0
- package/colorUtils/__tests__/isValidColor.test.ts +70 -0
- package/colorUtils/index.ts +50 -0
- package/manifestUtils/_internals/index.js +6 -0
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +35 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +185 -19
- package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
- package/manifestUtils/fieldUtils/index.js +125 -0
- package/manifestUtils/keys.js +9 -0
- package/manifestUtils/mobileAction/button/index.js +16 -0
- package/manifestUtils/mobileAction/container/index.js +3 -1
- package/manifestUtils/mobileAction/groups/defaults.js +3 -1
- package/manifestUtils/platformIsTV.js +1 -0
- package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
- package/numberUtils/__tests__/isZero.test.ts +27 -0
- package/numberUtils/__tests__/requireNumber.test.ts +50 -0
- package/numberUtils/__tests__/toNumber.test.ts +27 -0
- package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
- package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
- package/numberUtils/index.ts +27 -8
- package/package.json +2 -2
- package/pipesUtils/__tests__/buildUrlWithQuery.test.ts +33 -0
- package/pipesUtils/__tests__/withPipesEndpoint.test.tsx +56 -0
- package/pipesUtils/index.ts +1 -0
- package/pipesUtils/withPipesEndpoint.tsx +54 -0
- package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
- package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
- package/playerUtils/contentDataKeys.ts +134 -0
- package/playerUtils/index.ts +24 -17
- package/playerUtils/isAudioItem.ts +26 -0
- package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
- package/reactHooks/actions/index.ts +51 -1
- package/reactHooks/cell-click/index.ts +18 -10
- package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
- package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
- package/reactHooks/feed/index.ts +5 -1
- package/reactHooks/feed/useBatchLoading.ts +9 -1
- package/reactHooks/feed/{usePipesCacheReset.ts → useMarkPipesDataStale.ts} +12 -4
- package/reactHooks/layout/index.ts +1 -1
- package/reactHooks/navigation/__mocks__/index.ts +4 -0
- package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
- package/reactHooks/navigation/index.ts +1 -1
- package/reactHooks/navigation/useIsScreenActive.ts +29 -8
- package/reactHooks/state/useComponentScreenState.ts +1 -1
- package/reactHooks/utils/index.ts +3 -2
- package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +22 -4
- package/riverComponetsMeasurementProvider/index.tsx +12 -8
- package/stringUtils/__tests__/stringUtils.test.js +42 -0
- package/stringUtils/index.ts +2 -2
- package/uiActionsRegistrator/index.ts +203 -0
- package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
- package/zappFrameworkUtils/localStorageHelper.ts +19 -15
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
- package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createLogger } from "../logger";
|
|
2
|
+
import type { ActionExecutionContext, ActionHandler } from "./types";
|
|
2
3
|
|
|
3
4
|
export enum ActionResult {
|
|
4
5
|
Success = "success",
|
|
@@ -12,12 +13,12 @@ const { log_error, log_debug, log_info } = createLogger({
|
|
|
12
13
|
});
|
|
13
14
|
|
|
14
15
|
class ActionExecutor {
|
|
15
|
-
private registeredActions: Record<string,
|
|
16
|
-
// TODO: Remove context
|
|
16
|
+
private registeredActions: Record<string, ActionHandler> = {};
|
|
17
17
|
|
|
18
|
+
// TODO: Remove context
|
|
18
19
|
handleAction = async (
|
|
19
20
|
action: ActionType,
|
|
20
|
-
context?:
|
|
21
|
+
context?: ActionExecutionContext
|
|
21
22
|
): Promise<ActionResult> => {
|
|
22
23
|
const handler = this.registeredActions[action.type];
|
|
23
24
|
const entry = context?.entry as ZappEntry;
|
|
@@ -52,7 +53,7 @@ class ActionExecutor {
|
|
|
52
53
|
|
|
53
54
|
handleActions = async (
|
|
54
55
|
actionTypes: ActionType[],
|
|
55
|
-
context?:
|
|
56
|
+
context?: ActionExecutionContext
|
|
56
57
|
): Promise<ActionResult> => {
|
|
57
58
|
for (const action of actionTypes) {
|
|
58
59
|
// TODO: Handle action result error
|
|
@@ -70,7 +71,7 @@ class ActionExecutor {
|
|
|
70
71
|
|
|
71
72
|
handleEntryActions = async (
|
|
72
73
|
entry: ZappEntry,
|
|
73
|
-
context?:
|
|
74
|
+
context?: ActionExecutionContext
|
|
74
75
|
): Promise<ActionResult> => {
|
|
75
76
|
const tapActions = entry.extensions?.tap_actions?.actions;
|
|
76
77
|
|
|
@@ -98,12 +99,9 @@ class ActionExecutor {
|
|
|
98
99
|
delete this.registeredActions[actionType];
|
|
99
100
|
};
|
|
100
101
|
|
|
101
|
-
registerAction = (
|
|
102
|
+
registerAction = <TOptions = Record<string, any>>(
|
|
102
103
|
type: string,
|
|
103
|
-
handler:
|
|
104
|
-
action: ActionType,
|
|
105
|
-
context?: Record<string, any>
|
|
106
|
-
) => Promise<ActionResult>
|
|
104
|
+
handler: ActionHandler<TOptions>
|
|
107
105
|
) => {
|
|
108
106
|
if (this.registeredActions[type]) {
|
|
109
107
|
log_error(`registerAction: action type: ${type} already registered`);
|
|
@@ -5,300 +5,92 @@ import {
|
|
|
5
5
|
actionExecutor as _actionExecutor,
|
|
6
6
|
ActionResult,
|
|
7
7
|
} from "./ActionExecutor";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
batchSave,
|
|
11
|
-
} from "../zappFrameworkUtils/localStorageHelper";
|
|
8
|
+
import { ActionExecutionContext, ActionHandler } from "./types";
|
|
9
|
+
import { batchRemoveAllFromNamespaceForStorage } from "../zappFrameworkUtils/localStorageHelper";
|
|
12
10
|
import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
|
|
13
11
|
|
|
14
|
-
import * as QuickBrickManager from "@applicaster/zapp-react-native-bridge/QuickBrick";
|
|
15
|
-
import { QUICK_BRICK_EVENTS } from "@applicaster/zapp-react-native-bridge/QuickBrick";
|
|
16
|
-
import { showConfirmationDialog } from "../alertUtils";
|
|
17
|
-
import { createCloudEvent, sendCloudEvent } from "../cloudEventsUtils";
|
|
18
|
-
import { createLogger } from "../logger";
|
|
19
|
-
import { ACTIVE_LAYOUT_ID_STORAGE_KEY } from "@applicaster/quick-brick-core/App/remoteContextReloader/consts";
|
|
20
|
-
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
21
|
-
import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
|
|
22
|
-
import {
|
|
23
|
-
EntryResolver,
|
|
24
|
-
resolveObjectValues,
|
|
25
|
-
} from "../appUtils/contextKeysManager/contextResolver";
|
|
26
12
|
import { useNavigation, useRivers } from "../reactHooks";
|
|
27
|
-
import {
|
|
28
|
-
getInflatedDataSourceUrl,
|
|
29
|
-
getSearchContext,
|
|
30
|
-
} from "../reactHooks/feed/useInflatedUrl";
|
|
31
|
-
|
|
32
13
|
import { useContentTypes } from "@applicaster/zapp-react-native-redux/hooks";
|
|
33
14
|
import { useSubscriberFor } from "../reactHooks/useSubscriberFor";
|
|
34
15
|
import { APP_EVENTS } from "../appUtils/events";
|
|
35
|
-
import {
|
|
36
|
-
localStorageToggleFlag,
|
|
37
|
-
sessionStorageToggleFlag,
|
|
38
|
-
} from "./StorageActions";
|
|
16
|
+
import { createLogger } from "../logger";
|
|
39
17
|
|
|
40
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
appRestartAction,
|
|
20
|
+
confirmDialogAction,
|
|
21
|
+
createNavigateToScreenAction,
|
|
22
|
+
localStorageRemoveAction,
|
|
23
|
+
localStorageSetAction,
|
|
24
|
+
localStorageToggleFlagAction,
|
|
25
|
+
refreshComponentAction,
|
|
26
|
+
screenSetVariableAction,
|
|
27
|
+
screenToggleFlagAction,
|
|
28
|
+
sendCloudEventAction,
|
|
29
|
+
sessionStorageRemoveAction,
|
|
30
|
+
sessionStorageSetAction,
|
|
31
|
+
sessionStorageToggleFlagAction,
|
|
32
|
+
switchLayoutAction,
|
|
33
|
+
showToastAction,
|
|
34
|
+
} from "./actions";
|
|
41
35
|
|
|
42
36
|
export const { log_error, log_info, log_debug } = createLogger({
|
|
43
37
|
subsystem: "ActionExecutorContext",
|
|
44
38
|
category: "General",
|
|
45
39
|
});
|
|
46
40
|
|
|
47
|
-
type ActionExecutorContextType = {
|
|
48
|
-
registerAction: (
|
|
41
|
+
export type ActionExecutorContextType = {
|
|
42
|
+
registerAction: <TOptions = Record<string, any>>(
|
|
49
43
|
type: string,
|
|
50
|
-
handler:
|
|
51
|
-
action: ActionType,
|
|
52
|
-
context?: Record<string, any>
|
|
53
|
-
) => Promise<ActionResult>
|
|
44
|
+
handler: ActionHandler<TOptions>
|
|
54
45
|
) => void;
|
|
55
46
|
unregisterAction: (type: string) => void;
|
|
56
47
|
handleAction: (
|
|
57
48
|
action: ActionType,
|
|
58
|
-
context?:
|
|
49
|
+
context?: ActionExecutionContext
|
|
59
50
|
) => Promise<ActionResult>;
|
|
60
51
|
handleActions: (
|
|
61
52
|
actions: ActionType[],
|
|
62
|
-
context
|
|
53
|
+
context?: ActionExecutionContext
|
|
63
54
|
) => Promise<ActionResult>;
|
|
64
55
|
handleEntryActions: (
|
|
65
56
|
entry: ZappEntry,
|
|
66
|
-
context?:
|
|
57
|
+
context?: ActionExecutionContext
|
|
67
58
|
) => Promise<ActionResult>;
|
|
68
59
|
};
|
|
60
|
+
|
|
69
61
|
type Props = {
|
|
70
62
|
children: React.ReactNode;
|
|
71
63
|
};
|
|
72
64
|
|
|
73
|
-
function findParentComponent(
|
|
74
|
-
childId: string,
|
|
75
|
-
parent: ZappRiver | ZappUIComponent
|
|
76
|
-
): ZappRiver | ZappUIComponent | null {
|
|
77
|
-
for (const child of parent.ui_components) {
|
|
78
|
-
if (child.id === childId) return parent;
|
|
79
|
-
|
|
80
|
-
if (child.ui_components) {
|
|
81
|
-
const found = findParentComponent(childId, child);
|
|
82
|
-
if (found) return found;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
65
|
const prepareDefaultActions = (actionExecutor) => {
|
|
90
|
-
actionExecutor.registerAction("localStorageSet",
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
// TODO: Add support for ownershipKey and ownershipNamespace
|
|
94
|
-
|
|
95
|
-
return ActionResult.Success;
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
actionExecutor.registerAction("sessionStorageSet", async (action) => {
|
|
99
|
-
const namespaces = action.options.content;
|
|
100
|
-
await batchSave(namespaces, sessionStorage);
|
|
101
|
-
// TODO: Add support for ownershipKey and ownershipNamespace
|
|
102
|
-
|
|
103
|
-
return ActionResult.Success;
|
|
104
|
-
});
|
|
66
|
+
actionExecutor.registerAction("localStorageSet", localStorageSetAction);
|
|
67
|
+
actionExecutor.registerAction("sessionStorageSet", sessionStorageSetAction);
|
|
68
|
+
actionExecutor.registerAction("localStorageRemove", localStorageRemoveAction);
|
|
105
69
|
|
|
106
70
|
actionExecutor.registerAction(
|
|
107
|
-
"
|
|
108
|
-
|
|
109
|
-
const dispatch = appStore.getDispatch();
|
|
110
|
-
|
|
111
|
-
const parentComponent = findParentComponent(
|
|
112
|
-
context?.component?.id,
|
|
113
|
-
context?.screenData
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
const componentSource = context?.component?.data?.source;
|
|
117
|
-
|
|
118
|
-
const componentData = componentSource
|
|
119
|
-
? context.component.data
|
|
120
|
-
: parentComponent?.data;
|
|
121
|
-
|
|
122
|
-
const source = componentData?.source;
|
|
123
|
-
const mapping = componentData?.mapping;
|
|
124
|
-
|
|
125
|
-
let dataSource = source;
|
|
126
|
-
|
|
127
|
-
if (source && mapping) {
|
|
128
|
-
dataSource =
|
|
129
|
-
getInflatedDataSourceUrl({
|
|
130
|
-
source,
|
|
131
|
-
contexts: {
|
|
132
|
-
entry: context?.entryContext,
|
|
133
|
-
screen: context?.screenData,
|
|
134
|
-
search: getSearchContext(null, mapping),
|
|
135
|
-
},
|
|
136
|
-
mapping,
|
|
137
|
-
}) || source;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
log_info(`handleAction: refreshComponent for dataSource:${dataSource}`, {
|
|
141
|
-
source,
|
|
142
|
-
inflatedUrl: dataSource,
|
|
143
|
-
mapping,
|
|
144
|
-
entryContextId: context?.entryContext?.id,
|
|
145
|
-
entryId: context?.entry?.id,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// TODO: In theory we should wait callback to complete, before completing the action, but now it's not needed
|
|
149
|
-
// TODO: handle focused item removal
|
|
150
|
-
dispatch(
|
|
151
|
-
loadPipesData(dataSource, {
|
|
152
|
-
silentRefresh: false,
|
|
153
|
-
clearCache: true,
|
|
154
|
-
riverId: context?.screenData?.id,
|
|
155
|
-
})
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
return ActionResult.Success;
|
|
159
|
-
}
|
|
71
|
+
"sessionStorageRemove",
|
|
72
|
+
sessionStorageRemoveAction
|
|
160
73
|
);
|
|
161
74
|
|
|
162
|
-
actionExecutor.registerAction("
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
action.options.layoutId
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
QuickBrickManager.sendQuickBrickEvent(QUICK_BRICK_EVENTS.FORCE_APP_RELOAD);
|
|
171
|
-
|
|
172
|
-
return ActionResult.Success;
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
actionExecutor.registerAction("appRestart", async () => {
|
|
176
|
-
log_info(`handleAction: ${QUICK_BRICK_EVENTS.FORCE_APP_RELOAD} event`);
|
|
177
|
-
|
|
178
|
-
QuickBrickManager.sendQuickBrickEvent(QUICK_BRICK_EVENTS.FORCE_APP_RELOAD);
|
|
179
|
-
|
|
180
|
-
return ActionResult.Success;
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
actionExecutor.registerAction("confirmDialog", async (action) => {
|
|
184
|
-
log_info("handleAction: confirmDialog event");
|
|
185
|
-
|
|
186
|
-
return new Promise<ActionResult>((resolve) => {
|
|
187
|
-
showConfirmationDialog({
|
|
188
|
-
...action.options,
|
|
189
|
-
confirmCompletion: () => resolve(ActionResult.Success),
|
|
190
|
-
cancelCompletion: () => resolve(ActionResult.Cancel),
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
actionExecutor.registerAction("sendCloudEvent", async (action, context) => {
|
|
196
|
-
try {
|
|
197
|
-
const options = action.options;
|
|
198
|
-
|
|
199
|
-
const entry = context?.entry || {};
|
|
200
|
-
const entryResolver = new EntryResolver(entry);
|
|
201
|
-
const screenData = context?.screenStateStore.getState().data || {};
|
|
202
|
-
const screenResolver = new EntryResolver(screenData || {});
|
|
203
|
-
|
|
204
|
-
const data =
|
|
205
|
-
options?.data && options.inflateData
|
|
206
|
-
? await resolveObjectValues(options.data, {
|
|
207
|
-
entry: entryResolver,
|
|
208
|
-
screen: screenResolver,
|
|
209
|
-
})
|
|
210
|
-
: options?.data || entry;
|
|
211
|
-
|
|
212
|
-
const cloudEvent = await createCloudEvent({
|
|
213
|
-
type: options.type || "com.applicaster.selector.action.v1",
|
|
214
|
-
data,
|
|
215
|
-
subject: options.subject || entry?.id,
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
log_info("handleAction: sendCloudEvent event", { cloudEvent });
|
|
219
|
-
|
|
220
|
-
const { error, code } = await sendCloudEvent(cloudEvent, options.url);
|
|
221
|
-
|
|
222
|
-
if (error) {
|
|
223
|
-
log_error("sendCloudEvent: error sending cloud event", { error });
|
|
224
|
-
|
|
225
|
-
return ActionResult.Error;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (code && code >= 200 && code < 300 && !error) {
|
|
229
|
-
log_info("sendCloudEvent: cloud event sent successfully");
|
|
230
|
-
|
|
231
|
-
return ActionResult.Success;
|
|
232
|
-
}
|
|
233
|
-
} catch (error) {
|
|
234
|
-
log_error("sendCloudEvent: error sending cloud event", {
|
|
235
|
-
action,
|
|
236
|
-
error,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return ActionResult.Error;
|
|
241
|
-
});
|
|
75
|
+
actionExecutor.registerAction("refreshComponent", refreshComponentAction);
|
|
76
|
+
actionExecutor.registerAction("switchLayout", switchLayoutAction);
|
|
77
|
+
actionExecutor.registerAction("appRestart", appRestartAction);
|
|
78
|
+
actionExecutor.registerAction("confirmDialog", confirmDialogAction);
|
|
79
|
+
actionExecutor.registerAction("sendCloudEvent", sendCloudEventAction);
|
|
242
80
|
|
|
243
81
|
actionExecutor.registerAction(
|
|
244
82
|
"sessionStorageToggleFlag",
|
|
245
|
-
|
|
246
|
-
action: ActionType,
|
|
247
|
-
context?: Record<string, any>
|
|
248
|
-
): Promise<ActionResult> => {
|
|
249
|
-
return await sessionStorageToggleFlag(context, action);
|
|
250
|
-
}
|
|
83
|
+
sessionStorageToggleFlagAction
|
|
251
84
|
);
|
|
252
85
|
|
|
253
86
|
actionExecutor.registerAction(
|
|
254
87
|
"localStorageToggleFlag",
|
|
255
|
-
|
|
256
|
-
action: ActionType,
|
|
257
|
-
context?: Record<string, any>
|
|
258
|
-
): Promise<ActionResult> => {
|
|
259
|
-
return await localStorageToggleFlag(context, action);
|
|
260
|
-
}
|
|
261
|
-
);
|
|
262
|
-
|
|
263
|
-
actionExecutor.registerAction(
|
|
264
|
-
"screenSetVariable",
|
|
265
|
-
async (
|
|
266
|
-
action: ActionType,
|
|
267
|
-
context?: Record<string, any>
|
|
268
|
-
): Promise<ActionResult> => {
|
|
269
|
-
const route = context?.screenRoute;
|
|
270
|
-
const screenStateStore = context?.screenStateStore;
|
|
271
|
-
|
|
272
|
-
await screenSetVariable(
|
|
273
|
-
route,
|
|
274
|
-
screenStateStore,
|
|
275
|
-
{ entry: context?.entry, options: action.options },
|
|
276
|
-
action
|
|
277
|
-
);
|
|
278
|
-
|
|
279
|
-
return Promise.resolve(ActionResult.Success);
|
|
280
|
-
}
|
|
88
|
+
localStorageToggleFlagAction
|
|
281
89
|
);
|
|
282
90
|
|
|
283
|
-
actionExecutor.registerAction(
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
action: ActionType,
|
|
287
|
-
context?: Record<string, any>
|
|
288
|
-
): Promise<ActionResult> => {
|
|
289
|
-
const screenRoute = context?.screenRoute;
|
|
290
|
-
const screenStateStore = context?.screenStateStore;
|
|
291
|
-
|
|
292
|
-
await screenToggleFlag(
|
|
293
|
-
screenRoute,
|
|
294
|
-
screenStateStore,
|
|
295
|
-
{ entry: context?.entry, options: action.options },
|
|
296
|
-
action
|
|
297
|
-
);
|
|
298
|
-
|
|
299
|
-
return Promise.resolve(ActionResult.Success);
|
|
300
|
-
}
|
|
301
|
-
);
|
|
91
|
+
actionExecutor.registerAction("screenSetVariable", screenSetVariableAction);
|
|
92
|
+
actionExecutor.registerAction("screenToggleFlag", screenToggleFlagAction);
|
|
93
|
+
actionExecutor.registerAction("showToast", showToastAction);
|
|
302
94
|
};
|
|
303
95
|
|
|
304
96
|
export const ActionExecutorContext =
|
|
@@ -339,82 +131,7 @@ export function withActionExecutor(Component) {
|
|
|
339
131
|
useEffect(() => {
|
|
340
132
|
return _actionExecutor.registerAction(
|
|
341
133
|
"navigateToScreen",
|
|
342
|
-
|
|
343
|
-
async (action: ActionType, context?: Record<string, any>) => {
|
|
344
|
-
const screenType = action.options?.typeMapping;
|
|
345
|
-
|
|
346
|
-
if (!screenType) {
|
|
347
|
-
log_error("navigateToScreen: typeMapping option is missing");
|
|
348
|
-
|
|
349
|
-
return ActionResult.Error;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
const navigationAction = action.options?.navigationAction;
|
|
353
|
-
const entrySource = action.options?.entry;
|
|
354
|
-
|
|
355
|
-
const entry = entrySource
|
|
356
|
-
? entrySource === "@{entry/}"
|
|
357
|
-
? context?.entry
|
|
358
|
-
: entrySource
|
|
359
|
-
: null;
|
|
360
|
-
|
|
361
|
-
if (entry) {
|
|
362
|
-
if (typeof entry !== "object") {
|
|
363
|
-
log_error(
|
|
364
|
-
`navigateToScreen: entry option is not an object, entry: ${entry}`
|
|
365
|
-
);
|
|
366
|
-
|
|
367
|
-
return ActionResult.Error;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
log_info(
|
|
371
|
-
`navigateToScreen: navigating to screen type: ${screenType} with entry id: ${entry.id}`
|
|
372
|
-
);
|
|
373
|
-
|
|
374
|
-
const overriddenEntry = {
|
|
375
|
-
...entry,
|
|
376
|
-
type: {
|
|
377
|
-
value: screenType,
|
|
378
|
-
},
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
if (navigationAction === "push") {
|
|
382
|
-
navigator.push(overriddenEntry);
|
|
383
|
-
} else {
|
|
384
|
-
navigator.replace(overriddenEntry);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
return ActionResult.Success;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
const screenId = contentTypes?.[screenType]?.screen_id || null;
|
|
391
|
-
|
|
392
|
-
if (!screenId) {
|
|
393
|
-
log_error(
|
|
394
|
-
`navigateToScreen: can not resolve screen type mapping: ${screenType}`
|
|
395
|
-
);
|
|
396
|
-
|
|
397
|
-
return ActionResult.Error;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
const river = rivers[screenId];
|
|
401
|
-
|
|
402
|
-
if (!river) {
|
|
403
|
-
log_error("navigateToScreen: can not resolve river");
|
|
404
|
-
|
|
405
|
-
return ActionResult.Error;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
context?.callback?.({ success: false, error: null, abort: true });
|
|
409
|
-
|
|
410
|
-
if (navigationAction === "push") {
|
|
411
|
-
navigator.push(river);
|
|
412
|
-
} else {
|
|
413
|
-
navigator.replace(river);
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
return ActionResult.Success;
|
|
417
|
-
}
|
|
134
|
+
createNavigateToScreenAction(navigator, rivers, contentTypes)
|
|
418
135
|
);
|
|
419
136
|
}, [navigator, rivers, contentTypes]);
|
|
420
137
|
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { showToastAction } from "../showToast";
|
|
2
|
+
import { postEvent } from "../../../reactHooks/useSubscriberFor";
|
|
3
|
+
import { ActionResult } from "../../ActionExecutor";
|
|
4
|
+
|
|
5
|
+
jest.mock("../../../reactHooks/useSubscriberFor", () => ({
|
|
6
|
+
postEvent: jest.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
describe("showToastAction", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
jest.clearAllMocks();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("calls postEvent with confirmation source, default timeout, and returns Success", async () => {
|
|
15
|
+
const action = {
|
|
16
|
+
type: "showToast",
|
|
17
|
+
options: {
|
|
18
|
+
id: "toast-1",
|
|
19
|
+
message: "Added to queue",
|
|
20
|
+
extraMessage: "Extra info",
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const result = await showToastAction(action);
|
|
25
|
+
|
|
26
|
+
expect(postEvent).toHaveBeenCalledTimes(1);
|
|
27
|
+
|
|
28
|
+
expect(postEvent).toHaveBeenCalledWith("showToast", [
|
|
29
|
+
{
|
|
30
|
+
id: "toast-1",
|
|
31
|
+
message: "Added to queue",
|
|
32
|
+
extraMessage: "Extra info",
|
|
33
|
+
style: undefined,
|
|
34
|
+
timeout: 1000,
|
|
35
|
+
source: "confirmation",
|
|
36
|
+
},
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
expect(result).toBe(ActionResult.Success);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("preserves an explicit timeout and style override", async () => {
|
|
43
|
+
const action = {
|
|
44
|
+
type: "showToast",
|
|
45
|
+
options: {
|
|
46
|
+
message: "Playlist created",
|
|
47
|
+
timeout: 3000,
|
|
48
|
+
style: { backgroundColor: "#00FF00" },
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
await showToastAction(action);
|
|
53
|
+
|
|
54
|
+
expect(postEvent).toHaveBeenCalledWith("showToast", [
|
|
55
|
+
{
|
|
56
|
+
id: undefined,
|
|
57
|
+
message: "Playlist created",
|
|
58
|
+
extraMessage: undefined,
|
|
59
|
+
style: { backgroundColor: "#00FF00" },
|
|
60
|
+
timeout: 3000,
|
|
61
|
+
source: "confirmation",
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("handles missing or empty options without throwing", async () => {
|
|
67
|
+
const action = {
|
|
68
|
+
type: "showToast",
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const result = await showToastAction(action);
|
|
72
|
+
|
|
73
|
+
expect(postEvent).toHaveBeenCalledTimes(1);
|
|
74
|
+
|
|
75
|
+
expect(postEvent).toHaveBeenCalledWith("showToast", [
|
|
76
|
+
{
|
|
77
|
+
id: undefined,
|
|
78
|
+
message: undefined,
|
|
79
|
+
extraMessage: undefined,
|
|
80
|
+
style: undefined,
|
|
81
|
+
timeout: 1000,
|
|
82
|
+
source: "confirmation",
|
|
83
|
+
},
|
|
84
|
+
]);
|
|
85
|
+
|
|
86
|
+
expect(result).toBe(ActionResult.Success);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import * as QuickBrickManager from "@applicaster/zapp-react-native-bridge/QuickBrick";
|
|
3
|
+
import { QUICK_BRICK_EVENTS } from "@applicaster/zapp-react-native-bridge/QuickBrick";
|
|
4
|
+
import { ActionResult } from "../ActionExecutor";
|
|
5
|
+
import { ActionHandler } from "../types";
|
|
6
|
+
import { createLogger } from "../../logger";
|
|
7
|
+
|
|
8
|
+
const { log_info } = createLogger({
|
|
9
|
+
subsystem: "ActionExecutorContext",
|
|
10
|
+
category: "General",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Restarts the application by triggering a force reload event.
|
|
15
|
+
* This action does not require any options or context.
|
|
16
|
+
*/
|
|
17
|
+
export const appRestartAction: ActionHandler =
|
|
18
|
+
async (): Promise<ActionResult> => {
|
|
19
|
+
log_info(`handleAction: ${QUICK_BRICK_EVENTS.FORCE_APP_RELOAD} event`);
|
|
20
|
+
|
|
21
|
+
QuickBrickManager.sendQuickBrickEvent(QUICK_BRICK_EVENTS.FORCE_APP_RELOAD);
|
|
22
|
+
|
|
23
|
+
return ActionResult.Success;
|
|
24
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import { showConfirmationDialog } from "../../alertUtils";
|
|
3
|
+
import { ActionResult } from "../ActionExecutor";
|
|
4
|
+
import { ActionHandler } from "../types";
|
|
5
|
+
import { createLogger } from "../../logger";
|
|
6
|
+
|
|
7
|
+
const { log_info } = createLogger({
|
|
8
|
+
subsystem: "ActionExecutorContext",
|
|
9
|
+
category: "General",
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Options for the confirmDialog action.
|
|
14
|
+
*/
|
|
15
|
+
export interface ConfirmDialogOptions {
|
|
16
|
+
/** Dialog title (required) */
|
|
17
|
+
title: string;
|
|
18
|
+
|
|
19
|
+
/** Dialog message */
|
|
20
|
+
message?: string;
|
|
21
|
+
|
|
22
|
+
/** Confirm button text */
|
|
23
|
+
okButtonText?: string;
|
|
24
|
+
|
|
25
|
+
/** Cancel button text */
|
|
26
|
+
cancelButtonText?: string;
|
|
27
|
+
|
|
28
|
+
/** Callback when confirmed (deprecated - use action result) */
|
|
29
|
+
confirmCompletion?: () => void;
|
|
30
|
+
|
|
31
|
+
/** Callback when cancelled (deprecated - use action result) */
|
|
32
|
+
cancelCompletion?: () => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Shows a confirmation dialog to the user.
|
|
37
|
+
* Resolves to Success if user confirms, Cancel if user dismisses.
|
|
38
|
+
*/
|
|
39
|
+
export const confirmDialogAction: ActionHandler<ConfirmDialogOptions> = async (
|
|
40
|
+
action
|
|
41
|
+
): Promise<ActionResult> => {
|
|
42
|
+
log_info("handleAction: confirmDialog event");
|
|
43
|
+
|
|
44
|
+
const options = action.options as ConfirmDialogOptions;
|
|
45
|
+
|
|
46
|
+
return new Promise<ActionResult>((resolve) => {
|
|
47
|
+
showConfirmationDialog({
|
|
48
|
+
...options,
|
|
49
|
+
confirmCompletion: () => resolve(ActionResult.Success),
|
|
50
|
+
cancelCompletion: () => resolve(ActionResult.Cancel),
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Export action handlers
|
|
2
|
+
export { localStorageSetAction } from "./localStorageSet";
|
|
3
|
+
|
|
4
|
+
export { sessionStorageSetAction } from "./sessionStorageSet";
|
|
5
|
+
|
|
6
|
+
export { localStorageRemoveAction } from "./localStorageRemove";
|
|
7
|
+
|
|
8
|
+
export { sessionStorageRemoveAction } from "./sessionStorageRemove";
|
|
9
|
+
|
|
10
|
+
export { refreshComponentAction } from "./refreshComponent";
|
|
11
|
+
|
|
12
|
+
export { switchLayoutAction } from "./switchLayout";
|
|
13
|
+
|
|
14
|
+
export { appRestartAction } from "./appRestart";
|
|
15
|
+
|
|
16
|
+
export { confirmDialogAction } from "./confirmDialog";
|
|
17
|
+
|
|
18
|
+
export { sendCloudEventAction } from "./sendCloudEvent";
|
|
19
|
+
|
|
20
|
+
export { sessionStorageToggleFlagAction } from "./sessionStorageToggleFlag";
|
|
21
|
+
|
|
22
|
+
export { localStorageToggleFlagAction } from "./localStorageToggleFlag";
|
|
23
|
+
|
|
24
|
+
export { screenSetVariableAction } from "./screenSetVariable";
|
|
25
|
+
|
|
26
|
+
export { screenToggleFlagAction } from "./screenToggleFlag";
|
|
27
|
+
|
|
28
|
+
export { createNavigateToScreenAction } from "./navigateToScreen";
|
|
29
|
+
|
|
30
|
+
export { showToastAction } from "./showToast";
|