@applicaster/zapp-react-native-utils 16.0.0-alpha.4880104344 → 16.0.0-alpha.4909430115
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 +47 -11
- package/actionsExecutor/ActionExecutorContext.tsx +99 -334
- package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
- package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +22 -0
- package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
- package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
- package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
- package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +133 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +100 -0
- 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/dismissBottomSheet.ts +22 -0
- package/actionsExecutor/actions/goBack.ts +60 -0
- package/actionsExecutor/actions/goHome.ts +31 -0
- package/actionsExecutor/actions/index.ts +38 -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 +137 -0
- package/actionsExecutor/actions/openBottomSheet.ts +320 -0
- package/actionsExecutor/actions/refreshComponent.ts +85 -0
- package/actionsExecutor/actions/screenSetVariable.ts +35 -0
- package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
- package/actionsExecutor/actions/sendCloudEvent.ts +93 -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/consts.ts +25 -0
- package/actionsExecutor/feedDecorator.ts +6 -6
- package/actionsExecutor/types.ts +59 -0
- package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
- package/appUtils/HooksManager/index.ts +9 -0
- 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/playerManager/OverlayObserver/OverlaysObserver.ts +143 -53
- package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
- package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +49 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +11 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/utils.ts +54 -20
- package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
- package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
- package/appUtils/playerManager/__tests__/playerNative.test.ts +38 -0
- 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 +6 -4
- 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__/reorderByIds.test.ts +50 -0
- package/arrayUtils/__tests__/sample.test.ts +61 -0
- package/arrayUtils/index.ts +136 -20
- package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
- package/bottomSheet/index.ts +17 -0
- package/cellUtils/index.ts +30 -3
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +107 -0
- package/configurationUtils/manifestKeyParser.ts +38 -9
- package/configurationUtils/modalBlocksParser.ts +178 -0
- package/entryActions/__tests__/buildEntryActions.test.ts +156 -0
- package/entryActions/aliasPresentation.ts +124 -0
- package/entryActions/buildEntryActions.ts +166 -0
- package/entryActions/index.ts +17 -0
- package/entryActions/types.ts +39 -0
- package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
- package/manifestUtils/_internals/index.js +14 -3
- package/manifestUtils/defaultManifestConfigurations/player.js +349 -20
- package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
- package/manifestUtils/fieldUtils/index.js +125 -0
- package/manifestUtils/index.js +3 -0
- package/manifestUtils/keys.js +8 -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/modalBlocks.js +304 -0
- package/modalState/ContentViewModel.ts +113 -0
- package/modalState/EditableCollection.ts +17 -0
- package/modalState/EditableCollectionRegistry.ts +51 -0
- package/modalState/ModalOrchestrator.ts +199 -0
- package/modalState/RemoteEditableCollection.ts +227 -0
- package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
- package/modalState/__tests__/ContentViewModel.test.ts +165 -0
- package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +47 -0
- package/modalState/__tests__/RemoteEditableCollection.test.ts +326 -0
- package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
- package/modalState/index.ts +30 -83
- package/modalState/store.ts +102 -0
- package/modalState/types.ts +133 -0
- package/modalState/useBottomSheetContent.ts +102 -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/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
- package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
- package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
- package/playerUtils/contentDataKeys.ts +134 -0
- package/playerUtils/index.ts +37 -16
- package/playerUtils/isAudioItem.ts +26 -0
- package/playerUtils/resolvePlayerActions.ts +71 -0
- package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
- package/reactHooks/actions/index.ts +117 -2
- package/reactHooks/cell-click/index.ts +3 -3
- package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
- package/reactHooks/index.ts +2 -0
- package/reactHooks/layout/index.ts +1 -1
- package/reactHooks/navigation/__mocks__/index.ts +4 -0
- package/reactHooks/navigation/__tests__/index.test.tsx +47 -0
- package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
- package/reactHooks/navigation/index.ts +17 -4
- package/reactHooks/navigation/useIsScreenActive.ts +29 -8
- package/reactHooks/state/useComponentScreenState.ts +1 -1
- package/reactHooks/usePluginConfiguration.ts +4 -1
- package/reactHooks/utils/__tests__/index.test.js +22 -2
- package/reactHooks/utils/index.ts +11 -1
- package/stringUtils/__tests__/stringUtils.test.js +42 -0
- package/stringUtils/index.ts +2 -2
- package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
- package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
- package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
- package/uiActionsRegistrator/index.ts +25 -0
- package/uiActionsRegistrator/registry.ts +335 -0
- package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
- package/uiActionsRegistrator/usableActionItems.ts +66 -0
- package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
- package/zappFrameworkUtils/localStorageHelper.ts +19 -15
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
- package/playerUtils/getPlayerActionButtons.ts +0 -17
- /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
|
@@ -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",
|
|
@@ -11,13 +12,13 @@ const { log_error, log_debug, log_info } = createLogger({
|
|
|
11
12
|
category: "General",
|
|
12
13
|
});
|
|
13
14
|
|
|
14
|
-
class ActionExecutor {
|
|
15
|
-
private registeredActions: Record<string,
|
|
16
|
-
// TODO: Remove context
|
|
15
|
+
export class ActionExecutor {
|
|
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,10 @@ 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
|
-
|
|
105
|
-
context?: Record<string, any>
|
|
106
|
-
) => Promise<ActionResult>
|
|
104
|
+
handler: ActionHandler<TOptions>,
|
|
105
|
+
stateResolver?: (entry?: ZappEntry) => any
|
|
107
106
|
) => {
|
|
108
107
|
if (this.registeredActions[type]) {
|
|
109
108
|
log_error(`registerAction: action type: ${type} already registered`);
|
|
@@ -114,11 +113,48 @@ class ActionExecutor {
|
|
|
114
113
|
this.registeredActions[type] = handler;
|
|
115
114
|
log_debug(`registerAction: action type: ${type} registered`);
|
|
116
115
|
|
|
116
|
+
let unregisterState = () => {};
|
|
117
|
+
|
|
118
|
+
if (stateResolver) {
|
|
119
|
+
unregisterState = this.registerActionState(type, stateResolver);
|
|
120
|
+
}
|
|
121
|
+
|
|
117
122
|
return () => {
|
|
118
123
|
this.unregisterAction(type);
|
|
124
|
+
unregisterState();
|
|
119
125
|
log_debug(`registerAction: action type: ${type} un-registered`);
|
|
120
126
|
};
|
|
121
127
|
};
|
|
128
|
+
|
|
129
|
+
private actionStates: Record<string, (entry?: ZappEntry) => any> = {};
|
|
130
|
+
|
|
131
|
+
registerActionState = (
|
|
132
|
+
type: string,
|
|
133
|
+
stateResolver: (entry?: ZappEntry) => any
|
|
134
|
+
) => {
|
|
135
|
+
if (this.actionStates[type]) {
|
|
136
|
+
log_error(
|
|
137
|
+
`registerActionState: action type state: ${type} already registered`
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
return () => {};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
this.actionStates[type] = stateResolver;
|
|
144
|
+
log_debug(`registerActionState: action type state: ${type} registered`);
|
|
145
|
+
|
|
146
|
+
return () => {
|
|
147
|
+
delete this.actionStates[type];
|
|
148
|
+
|
|
149
|
+
log_debug(
|
|
150
|
+
`registerActionState: action type state: ${type} un-registered`
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
getActionState = (type: string, entry?: ZappEntry) => {
|
|
156
|
+
return this.actionStates[type]?.(entry);
|
|
157
|
+
};
|
|
122
158
|
}
|
|
123
159
|
|
|
124
160
|
export const actionExecutor = new ActionExecutor();
|
|
@@ -5,44 +5,39 @@ import {
|
|
|
5
5
|
actionExecutor as _actionExecutor,
|
|
6
6
|
ActionResult,
|
|
7
7
|
} from "./ActionExecutor";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
batchRemoveFromStorage,
|
|
11
|
-
batchSave,
|
|
12
|
-
} from "../zappFrameworkUtils/localStorageHelper";
|
|
8
|
+
import { ActionExecutionContext, ActionHandler } from "./types";
|
|
9
|
+
import { batchRemoveAllFromNamespaceForStorage } from "../zappFrameworkUtils/localStorageHelper";
|
|
13
10
|
import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
|
|
14
11
|
|
|
15
|
-
import * as QuickBrickManager from "@applicaster/zapp-react-native-bridge/QuickBrick";
|
|
16
|
-
import { QUICK_BRICK_EVENTS } from "@applicaster/zapp-react-native-bridge/QuickBrick";
|
|
17
|
-
import { showConfirmationDialog } from "../alertUtils";
|
|
18
|
-
import { createCloudEvent, sendCloudEvent } from "../cloudEventsUtils";
|
|
19
|
-
import { createLogger } from "../logger";
|
|
20
|
-
import { ACTIVE_LAYOUT_ID_STORAGE_KEY } from "@applicaster/quick-brick-core/App/remoteContextReloader/consts";
|
|
21
|
-
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
22
|
-
import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
|
|
23
|
-
import {
|
|
24
|
-
EntryResolver,
|
|
25
|
-
resolveObjectValues,
|
|
26
|
-
} from "../appUtils/contextKeysManager/contextResolver";
|
|
27
12
|
import { useNavigation, useRivers } from "../reactHooks";
|
|
28
|
-
import {
|
|
29
|
-
getInflatedDataSourceUrl,
|
|
30
|
-
getSearchContext,
|
|
31
|
-
} from "../reactHooks/feed/useInflatedUrl";
|
|
32
|
-
|
|
33
13
|
import { useContentTypes } from "@applicaster/zapp-react-native-redux/hooks";
|
|
34
14
|
import { useSubscriberFor } from "../reactHooks/useSubscriberFor";
|
|
35
15
|
import { APP_EVENTS } from "../appUtils/events";
|
|
36
|
-
import {
|
|
37
|
-
localStorageToggleFlag,
|
|
38
|
-
sessionStorageToggleFlag,
|
|
39
|
-
} from "./StorageActions";
|
|
16
|
+
import { createLogger } from "../logger";
|
|
40
17
|
|
|
41
|
-
import { screenSetVariable, screenToggleFlag } from "./ScreenActions";
|
|
42
18
|
import {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
19
|
+
appRestartAction,
|
|
20
|
+
confirmDialogAction,
|
|
21
|
+
createGoBackAction,
|
|
22
|
+
createGoHomeAction,
|
|
23
|
+
createNavigateToScreenAction,
|
|
24
|
+
dismissBottomSheetAction,
|
|
25
|
+
localStorageRemoveAction,
|
|
26
|
+
localStorageSetAction,
|
|
27
|
+
localStorageToggleFlagAction,
|
|
28
|
+
openBottomSheetAction,
|
|
29
|
+
refreshComponentAction,
|
|
30
|
+
screenSetVariableAction,
|
|
31
|
+
screenToggleFlagAction,
|
|
32
|
+
sendCloudEventAction,
|
|
33
|
+
sessionStorageRemoveAction,
|
|
34
|
+
sessionStorageSetAction,
|
|
35
|
+
sessionStorageToggleFlagAction,
|
|
36
|
+
switchLayoutAction,
|
|
37
|
+
showToastAction,
|
|
38
|
+
} from "./actions";
|
|
39
|
+
|
|
40
|
+
import { ACTION_TYPES } from "./consts";
|
|
46
41
|
|
|
47
42
|
export const { log_error, log_info, log_debug } = createLogger({
|
|
48
43
|
subsystem: "ActionExecutorContext",
|
|
@@ -50,25 +45,28 @@ export const { log_error, log_info, log_debug } = createLogger({
|
|
|
50
45
|
});
|
|
51
46
|
|
|
52
47
|
export type ActionExecutorContextType = {
|
|
53
|
-
registerAction: (
|
|
48
|
+
registerAction: <TOptions = Record<string, any>>(
|
|
54
49
|
type: string,
|
|
55
|
-
handler:
|
|
56
|
-
|
|
57
|
-
context?: Record<string, any>
|
|
58
|
-
) => Promise<ActionResult>
|
|
50
|
+
handler: ActionHandler<TOptions>,
|
|
51
|
+
stateResolver?: (entry?: ZappEntry) => any
|
|
59
52
|
) => void;
|
|
60
53
|
unregisterAction: (type: string) => void;
|
|
54
|
+
registerActionState: (
|
|
55
|
+
type: string,
|
|
56
|
+
stateResolver: (entry?: ZappEntry) => any
|
|
57
|
+
) => () => void;
|
|
58
|
+
getActionState: (type: string, entry?: ZappEntry) => any;
|
|
61
59
|
handleAction: (
|
|
62
60
|
action: ActionType,
|
|
63
|
-
context?:
|
|
61
|
+
context?: ActionExecutionContext
|
|
64
62
|
) => Promise<ActionResult>;
|
|
65
63
|
handleActions: (
|
|
66
64
|
actions: ActionType[],
|
|
67
|
-
context
|
|
65
|
+
context?: ActionExecutionContext
|
|
68
66
|
) => Promise<ActionResult>;
|
|
69
67
|
handleEntryActions: (
|
|
70
68
|
entry: ZappEntry,
|
|
71
|
-
context?:
|
|
69
|
+
context?: ActionExecutionContext
|
|
72
70
|
) => Promise<ActionResult>;
|
|
73
71
|
};
|
|
74
72
|
|
|
@@ -76,251 +74,77 @@ type Props = {
|
|
|
76
74
|
children: React.ReactNode;
|
|
77
75
|
};
|
|
78
76
|
|
|
79
|
-
function findParentComponent(
|
|
80
|
-
childId: string,
|
|
81
|
-
parent: ZappRiver | ZappUIComponent
|
|
82
|
-
): ZappRiver | ZappUIComponent | null {
|
|
83
|
-
for (const child of parent.ui_components) {
|
|
84
|
-
if (child.id === childId) return parent;
|
|
85
|
-
|
|
86
|
-
if (child.ui_components) {
|
|
87
|
-
const found = findParentComponent(childId, child);
|
|
88
|
-
if (found) return found;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
77
|
const prepareDefaultActions = (actionExecutor) => {
|
|
96
|
-
actionExecutor.registerAction("localStorageSet", async (action) => {
|
|
97
|
-
const namespaces: StorageValuesToAdd = action.options.content;
|
|
98
|
-
await batchSave(namespaces, localStorage);
|
|
99
|
-
// TODO: Add support for ownershipKey and ownershipNamespace
|
|
100
|
-
|
|
101
|
-
return ActionResult.Success;
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
actionExecutor.registerAction("sessionStorageSet", async (action) => {
|
|
105
|
-
const namespaces: StorageValuesToAdd = action.options.content;
|
|
106
|
-
await batchSave(namespaces, sessionStorage);
|
|
107
|
-
// TODO: Add support for ownershipKey and ownershipNamespace
|
|
108
|
-
|
|
109
|
-
return ActionResult.Success;
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
actionExecutor.registerAction("localStorageRemove", async (action) => {
|
|
113
|
-
const namespaces: StorageValuesToRemove = action.options.content;
|
|
114
|
-
await batchRemoveFromStorage(namespaces, localStorage);
|
|
115
|
-
// TODO: Add support for ownershipKey and ownershipNamespace
|
|
116
|
-
|
|
117
|
-
return ActionResult.Success;
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
actionExecutor.registerAction("sessionStorageRemove", async (action) => {
|
|
121
|
-
const namespaces: StorageValuesToRemove = action.options.content;
|
|
122
|
-
await batchRemoveFromStorage(namespaces, sessionStorage);
|
|
123
|
-
// TODO: Add support for ownershipKey and ownershipNamespace
|
|
124
|
-
|
|
125
|
-
return ActionResult.Success;
|
|
126
|
-
});
|
|
127
|
-
|
|
128
78
|
actionExecutor.registerAction(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const dispatch = appStore.getDispatch();
|
|
132
|
-
|
|
133
|
-
const parentComponent = findParentComponent(
|
|
134
|
-
context?.component?.id,
|
|
135
|
-
context?.screenData
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
const componentSource = context?.component?.data?.source;
|
|
139
|
-
|
|
140
|
-
const componentData = componentSource
|
|
141
|
-
? context.component.data
|
|
142
|
-
: parentComponent?.data;
|
|
143
|
-
|
|
144
|
-
const source = componentData?.source;
|
|
145
|
-
const mapping = componentData?.mapping;
|
|
146
|
-
|
|
147
|
-
let dataSource = source;
|
|
148
|
-
|
|
149
|
-
if (source && mapping) {
|
|
150
|
-
dataSource =
|
|
151
|
-
getInflatedDataSourceUrl({
|
|
152
|
-
source,
|
|
153
|
-
contexts: {
|
|
154
|
-
entry: context?.screenEntry,
|
|
155
|
-
screen: context?.screenData,
|
|
156
|
-
search: getSearchContext(null, mapping),
|
|
157
|
-
},
|
|
158
|
-
mapping,
|
|
159
|
-
}) || source;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
log_info(`handleAction: refreshComponent for dataSource:${dataSource}`, {
|
|
163
|
-
source,
|
|
164
|
-
inflatedUrl: dataSource,
|
|
165
|
-
mapping,
|
|
166
|
-
entryContextId: context?.entryContext?.id,
|
|
167
|
-
entryId: context?.entry?.id,
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
// TODO: In theory we should wait callback to complete, before completing the action, but now it's not needed
|
|
171
|
-
// TODO: handle focused item removal
|
|
172
|
-
dispatch(
|
|
173
|
-
loadPipesData(dataSource, {
|
|
174
|
-
silentRefresh: false,
|
|
175
|
-
clearCache: true,
|
|
176
|
-
riverId: context?.screenData?.id,
|
|
177
|
-
})
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
return ActionResult.Success;
|
|
181
|
-
}
|
|
79
|
+
ACTION_TYPES.LOCAL_STORAGE_SET,
|
|
80
|
+
localStorageSetAction
|
|
182
81
|
);
|
|
183
82
|
|
|
184
|
-
actionExecutor.registerAction(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
ACTIVE_LAYOUT_ID_STORAGE_KEY,
|
|
189
|
-
action.options.layoutId
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
QuickBrickManager.sendQuickBrickEvent(QUICK_BRICK_EVENTS.FORCE_APP_RELOAD);
|
|
193
|
-
|
|
194
|
-
return ActionResult.Success;
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
actionExecutor.registerAction("appRestart", async () => {
|
|
198
|
-
log_info(`handleAction: ${QUICK_BRICK_EVENTS.FORCE_APP_RELOAD} event`);
|
|
199
|
-
|
|
200
|
-
QuickBrickManager.sendQuickBrickEvent(QUICK_BRICK_EVENTS.FORCE_APP_RELOAD);
|
|
201
|
-
|
|
202
|
-
return ActionResult.Success;
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
actionExecutor.registerAction("confirmDialog", async (action) => {
|
|
206
|
-
log_info("handleAction: confirmDialog event");
|
|
207
|
-
|
|
208
|
-
return new Promise<ActionResult>((resolve) => {
|
|
209
|
-
showConfirmationDialog({
|
|
210
|
-
...action.options,
|
|
211
|
-
confirmCompletion: () => resolve(ActionResult.Success),
|
|
212
|
-
cancelCompletion: () => resolve(ActionResult.Cancel),
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
actionExecutor.registerAction("sendCloudEvent", async (action, context) => {
|
|
218
|
-
try {
|
|
219
|
-
const options = action.options;
|
|
220
|
-
|
|
221
|
-
const entry = context?.entry || {};
|
|
222
|
-
const entryResolver = new EntryResolver(entry);
|
|
223
|
-
const screenData = context?.screenStateStore?.getState().data || {};
|
|
224
|
-
const screenResolver = new EntryResolver(screenData || {});
|
|
225
|
-
|
|
226
|
-
const data =
|
|
227
|
-
options?.data && options.inflateData
|
|
228
|
-
? await resolveObjectValues(options.data, {
|
|
229
|
-
entry: entryResolver,
|
|
230
|
-
screen: screenResolver,
|
|
231
|
-
})
|
|
232
|
-
: options?.data || entry;
|
|
233
|
-
|
|
234
|
-
const cloudEvent = await createCloudEvent({
|
|
235
|
-
type: options.type || "com.applicaster.selector.action.v1",
|
|
236
|
-
data,
|
|
237
|
-
subject: options.subject || entry?.id,
|
|
238
|
-
});
|
|
83
|
+
actionExecutor.registerAction(
|
|
84
|
+
ACTION_TYPES.SESSION_STORAGE_SET,
|
|
85
|
+
sessionStorageSetAction
|
|
86
|
+
);
|
|
239
87
|
|
|
240
|
-
|
|
88
|
+
actionExecutor.registerAction(
|
|
89
|
+
ACTION_TYPES.LOCAL_STORAGE_REMOVE,
|
|
90
|
+
localStorageRemoveAction
|
|
91
|
+
);
|
|
241
92
|
|
|
242
|
-
|
|
93
|
+
actionExecutor.registerAction(
|
|
94
|
+
ACTION_TYPES.SESSION_STORAGE_REMOVE,
|
|
95
|
+
sessionStorageRemoveAction
|
|
96
|
+
);
|
|
243
97
|
|
|
244
|
-
|
|
245
|
-
|
|
98
|
+
actionExecutor.registerAction(
|
|
99
|
+
ACTION_TYPES.REFRESH_COMPONENT,
|
|
100
|
+
refreshComponentAction
|
|
101
|
+
);
|
|
246
102
|
|
|
247
|
-
|
|
248
|
-
}
|
|
103
|
+
actionExecutor.registerAction(ACTION_TYPES.SWITCH_LAYOUT, switchLayoutAction);
|
|
249
104
|
|
|
250
|
-
|
|
251
|
-
log_info("sendCloudEvent: cloud event sent successfully");
|
|
105
|
+
actionExecutor.registerAction(ACTION_TYPES.APP_RESTART, appRestartAction);
|
|
252
106
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
action,
|
|
258
|
-
error,
|
|
259
|
-
});
|
|
260
|
-
}
|
|
107
|
+
actionExecutor.registerAction(
|
|
108
|
+
ACTION_TYPES.CONFIRM_DIALOG,
|
|
109
|
+
confirmDialogAction
|
|
110
|
+
);
|
|
261
111
|
|
|
262
|
-
|
|
263
|
-
|
|
112
|
+
actionExecutor.registerAction(
|
|
113
|
+
ACTION_TYPES.SEND_CLOUD_EVENT,
|
|
114
|
+
sendCloudEventAction
|
|
115
|
+
);
|
|
264
116
|
|
|
265
117
|
actionExecutor.registerAction(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
action: ActionType,
|
|
269
|
-
context?: Record<string, any>
|
|
270
|
-
): Promise<ActionResult> => {
|
|
271
|
-
return await sessionStorageToggleFlag(context, action);
|
|
272
|
-
}
|
|
118
|
+
ACTION_TYPES.SESSION_STORAGE_TOGGLE_FLAG,
|
|
119
|
+
sessionStorageToggleFlagAction
|
|
273
120
|
);
|
|
274
121
|
|
|
275
122
|
actionExecutor.registerAction(
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
action: ActionType,
|
|
279
|
-
context?: Record<string, any>
|
|
280
|
-
): Promise<ActionResult> => {
|
|
281
|
-
return await localStorageToggleFlag(context, action);
|
|
282
|
-
}
|
|
123
|
+
ACTION_TYPES.LOCAL_STORAGE_TOGGLE_FLAG,
|
|
124
|
+
localStorageToggleFlagAction
|
|
283
125
|
);
|
|
284
126
|
|
|
285
127
|
actionExecutor.registerAction(
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
context?: Record<string, any>
|
|
290
|
-
): Promise<ActionResult> => {
|
|
291
|
-
const route = context?.screenRoute;
|
|
292
|
-
const screenStateStore = context?.screenStateStore;
|
|
293
|
-
|
|
294
|
-
await screenSetVariable(
|
|
295
|
-
route,
|
|
296
|
-
screenStateStore,
|
|
297
|
-
{ entry: context?.entry, options: action.options },
|
|
298
|
-
action
|
|
299
|
-
);
|
|
128
|
+
ACTION_TYPES.SCREEN_SET_VARIABLE,
|
|
129
|
+
screenSetVariableAction
|
|
130
|
+
);
|
|
300
131
|
|
|
301
|
-
|
|
302
|
-
|
|
132
|
+
actionExecutor.registerAction(
|
|
133
|
+
ACTION_TYPES.SCREEN_TOGGLE_FLAG,
|
|
134
|
+
screenToggleFlagAction
|
|
303
135
|
);
|
|
304
136
|
|
|
305
137
|
actionExecutor.registerAction(
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
context?: Record<string, any>
|
|
310
|
-
): Promise<ActionResult> => {
|
|
311
|
-
const screenRoute = context?.screenRoute;
|
|
312
|
-
const screenStateStore = context?.screenStateStore;
|
|
313
|
-
|
|
314
|
-
await screenToggleFlag(
|
|
315
|
-
screenRoute,
|
|
316
|
-
screenStateStore,
|
|
317
|
-
{ entry: context?.entry, options: action.options },
|
|
318
|
-
action
|
|
319
|
-
);
|
|
138
|
+
ACTION_TYPES.OPEN_BOTTOM_SHEET,
|
|
139
|
+
openBottomSheetAction
|
|
140
|
+
);
|
|
320
141
|
|
|
321
|
-
|
|
322
|
-
|
|
142
|
+
actionExecutor.registerAction(
|
|
143
|
+
ACTION_TYPES.DISMISS_BOTTOM_SHEET,
|
|
144
|
+
dismissBottomSheetAction
|
|
323
145
|
);
|
|
146
|
+
|
|
147
|
+
actionExecutor.registerAction(ACTION_TYPES.SHOW_TOAST, showToastAction);
|
|
324
148
|
};
|
|
325
149
|
|
|
326
150
|
export const ActionExecutorContext =
|
|
@@ -338,6 +162,8 @@ export function withActionExecutor(Component) {
|
|
|
338
162
|
return {
|
|
339
163
|
unregisterAction: _actionExecutor.unregisterAction,
|
|
340
164
|
registerAction: _actionExecutor.registerAction,
|
|
165
|
+
registerActionState: _actionExecutor.registerActionState,
|
|
166
|
+
getActionState: _actionExecutor.getActionState,
|
|
341
167
|
handleAction: _actionExecutor.handleAction,
|
|
342
168
|
handleActions: _actionExecutor.handleActions,
|
|
343
169
|
handleEntryActions: _actionExecutor.handleEntryActions,
|
|
@@ -360,85 +186,24 @@ export function withActionExecutor(Component) {
|
|
|
360
186
|
|
|
361
187
|
useEffect(() => {
|
|
362
188
|
return _actionExecutor.registerAction(
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
if (!screenType) {
|
|
369
|
-
log_error("navigateToScreen: typeMapping option is missing");
|
|
370
|
-
|
|
371
|
-
return ActionResult.Error;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
const navigationAction = action.options?.navigationAction;
|
|
375
|
-
const entrySource = action.options?.entry;
|
|
376
|
-
|
|
377
|
-
const entry = entrySource
|
|
378
|
-
? entrySource === "@{entry/}"
|
|
379
|
-
? context?.entry
|
|
380
|
-
: entrySource
|
|
381
|
-
: null;
|
|
382
|
-
|
|
383
|
-
if (entry) {
|
|
384
|
-
if (typeof entry !== "object") {
|
|
385
|
-
log_error(
|
|
386
|
-
`navigateToScreen: entry option is not an object, entry: ${entry}`
|
|
387
|
-
);
|
|
388
|
-
|
|
389
|
-
return ActionResult.Error;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
log_info(
|
|
393
|
-
`navigateToScreen: navigating to screen type: ${screenType} with entry id: ${entry.id}`
|
|
394
|
-
);
|
|
395
|
-
|
|
396
|
-
const overriddenEntry = {
|
|
397
|
-
...entry,
|
|
398
|
-
type: {
|
|
399
|
-
value: screenType,
|
|
400
|
-
},
|
|
401
|
-
};
|
|
402
|
-
|
|
403
|
-
if (navigationAction === "push") {
|
|
404
|
-
navigator.push(overriddenEntry);
|
|
405
|
-
} else {
|
|
406
|
-
navigator.replace(overriddenEntry);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
return ActionResult.Success;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
const screenId = contentTypes?.[screenType]?.screen_id || null;
|
|
413
|
-
|
|
414
|
-
if (!screenId) {
|
|
415
|
-
log_error(
|
|
416
|
-
`navigateToScreen: can not resolve screen type mapping: ${screenType}`
|
|
417
|
-
);
|
|
418
|
-
|
|
419
|
-
return ActionResult.Error;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
const river = rivers[screenId];
|
|
423
|
-
|
|
424
|
-
if (!river) {
|
|
425
|
-
log_error("navigateToScreen: can not resolve river");
|
|
426
|
-
|
|
427
|
-
return ActionResult.Error;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
context?.callback?.({ success: false, error: null, abort: true });
|
|
189
|
+
ACTION_TYPES.NAVIGATE_TO_SCREEN,
|
|
190
|
+
createNavigateToScreenAction(navigator, rivers, contentTypes)
|
|
191
|
+
);
|
|
192
|
+
}, [navigator, rivers, contentTypes]);
|
|
431
193
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
return _actionExecutor.registerAction(
|
|
196
|
+
ACTION_TYPES.GO_BACK,
|
|
197
|
+
createGoBackAction(navigator)
|
|
198
|
+
);
|
|
199
|
+
}, [navigator]);
|
|
437
200
|
|
|
438
|
-
|
|
439
|
-
|
|
201
|
+
useEffect(() => {
|
|
202
|
+
return _actionExecutor.registerAction(
|
|
203
|
+
ACTION_TYPES.GO_HOME,
|
|
204
|
+
createGoHomeAction(navigator)
|
|
440
205
|
);
|
|
441
|
-
}, [navigator
|
|
206
|
+
}, [navigator]);
|
|
442
207
|
|
|
443
208
|
return (
|
|
444
209
|
<ActionExecutorContext.Provider value={handlers}>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { decorateFeed } from "../feedDecorator";
|
|
2
|
+
|
|
3
|
+
const preferenceFeed = (selectMode: string) =>
|
|
4
|
+
({
|
|
5
|
+
id: "agree-component",
|
|
6
|
+
title: "I agree to the terms",
|
|
7
|
+
type: { value: "feed" },
|
|
8
|
+
extensions: {
|
|
9
|
+
role: "preference_editor",
|
|
10
|
+
preference_editor_options: {
|
|
11
|
+
key: "agree",
|
|
12
|
+
scope: "screen",
|
|
13
|
+
select_mode: selectMode,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
entry: [
|
|
17
|
+
{
|
|
18
|
+
id: "I agree to the terms-agree",
|
|
19
|
+
title: "I agree to the terms",
|
|
20
|
+
type: { value: "action" },
|
|
21
|
+
extensions: { tag: "true" },
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
}) as unknown as ZappFeed;
|
|
25
|
+
|
|
26
|
+
describe("decorateFeed", () => {
|
|
27
|
+
it("decorates single select feeds with screenSetVariable", () => {
|
|
28
|
+
const decorated = decorateFeed(preferenceFeed("single"));
|
|
29
|
+
|
|
30
|
+
expect(decorated.extensions.behavior).toEqual(
|
|
31
|
+
expect.objectContaining({
|
|
32
|
+
select_mode: "single",
|
|
33
|
+
current_selection: "@{screen/agree}",
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
expect(decorated.entry[0].extensions.tap_actions.actions[0].type).toBe(
|
|
38
|
+
"screenSetVariable"
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("decorates multi select feeds with screenToggleFlag", () => {
|
|
43
|
+
const decorated = decorateFeed(preferenceFeed("multi"));
|
|
44
|
+
|
|
45
|
+
expect(decorated.extensions.behavior.select_mode).toBe("multi");
|
|
46
|
+
|
|
47
|
+
expect(decorated.entry[0].extensions.tap_actions.actions[0].type).toBe(
|
|
48
|
+
"screenToggleFlag"
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("leaves a feed without the preference_editor role untouched", () => {
|
|
53
|
+
const feed = preferenceFeed("single");
|
|
54
|
+
feed.extensions.role = undefined;
|
|
55
|
+
|
|
56
|
+
const decorated = decorateFeed(feed);
|
|
57
|
+
|
|
58
|
+
expect(decorated.extensions.behavior).toBeUndefined();
|
|
59
|
+
expect(decorated.entry[0].extensions.tap_actions).toBeUndefined();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { dismissBottomSheetAction } from "../dismissBottomSheet";
|
|
2
|
+
import { dismissModal } from "../../../modalState";
|
|
3
|
+
import { ActionResult } from "../../ActionExecutor";
|
|
4
|
+
|
|
5
|
+
jest.mock("../../../modalState", () => ({
|
|
6
|
+
dismissModal: jest.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
describe("dismissBottomSheetAction", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
jest.clearAllMocks();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("calls dismissModal and returns ActionResult.Success", async () => {
|
|
15
|
+
const result = await dismissBottomSheetAction({
|
|
16
|
+
type: "dismissBottomSheet",
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(dismissModal).toHaveBeenCalledTimes(1);
|
|
20
|
+
expect(result).toBe(ActionResult.Success);
|
|
21
|
+
});
|
|
22
|
+
});
|