@applicaster/zapp-react-native-utils 16.0.0-alpha.5402127570 → 16.0.0-alpha.5530459253
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 +85 -315
- package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
- package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +22 -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/index.ts +34 -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 +23 -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__/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__/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 +33 -8
- package/colorUtils/__tests__/isTransparentColor.test.ts +76 -0
- package/colorUtils/__tests__/isValidColor.test.ts +70 -0
- package/colorUtils/index.ts +50 -0
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +107 -0
- package/configurationUtils/manifestKeyParser.ts +38 -9
- package/configurationUtils/modalBlocksParser.ts +178 -0
- package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
- package/manifestUtils/_internals/index.js +6 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +327 -19
- 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 +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/modalBlocks.js +304 -0
- package/manifestUtils/platformIsTV.js +1 -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/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 +20 -15
- 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 +3 -3
- 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/index.ts +2 -0
- 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/usePluginConfiguration.ts +4 -1
- package/reactHooks/utils/__tests__/index.test.js +22 -2
- package/reactHooks/utils/index.ts +13 -2
- 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
- /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,39 +5,37 @@ 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
|
+
dismissBottomSheetAction,
|
|
23
|
+
localStorageRemoveAction,
|
|
24
|
+
localStorageSetAction,
|
|
25
|
+
localStorageToggleFlagAction,
|
|
26
|
+
openBottomSheetAction,
|
|
27
|
+
refreshComponentAction,
|
|
28
|
+
screenSetVariableAction,
|
|
29
|
+
screenToggleFlagAction,
|
|
30
|
+
sendCloudEventAction,
|
|
31
|
+
sessionStorageRemoveAction,
|
|
32
|
+
sessionStorageSetAction,
|
|
33
|
+
sessionStorageToggleFlagAction,
|
|
34
|
+
switchLayoutAction,
|
|
35
|
+
showToastAction,
|
|
36
|
+
} from "./actions";
|
|
37
|
+
|
|
38
|
+
import { ACTION_TYPES } from "./consts";
|
|
41
39
|
|
|
42
40
|
export const { log_error, log_info, log_debug } = createLogger({
|
|
43
41
|
subsystem: "ActionExecutorContext",
|
|
@@ -45,25 +43,28 @@ export const { log_error, log_info, log_debug } = createLogger({
|
|
|
45
43
|
});
|
|
46
44
|
|
|
47
45
|
export type ActionExecutorContextType = {
|
|
48
|
-
registerAction: (
|
|
46
|
+
registerAction: <TOptions = Record<string, any>>(
|
|
49
47
|
type: string,
|
|
50
|
-
handler:
|
|
51
|
-
|
|
52
|
-
context?: Record<string, any>
|
|
53
|
-
) => Promise<ActionResult>
|
|
48
|
+
handler: ActionHandler<TOptions>,
|
|
49
|
+
stateResolver?: (entry?: ZappEntry) => any
|
|
54
50
|
) => void;
|
|
55
51
|
unregisterAction: (type: string) => void;
|
|
52
|
+
registerActionState: (
|
|
53
|
+
type: string,
|
|
54
|
+
stateResolver: (entry?: ZappEntry) => any
|
|
55
|
+
) => () => void;
|
|
56
|
+
getActionState: (type: string, entry?: ZappEntry) => any;
|
|
56
57
|
handleAction: (
|
|
57
58
|
action: ActionType,
|
|
58
|
-
context?:
|
|
59
|
+
context?: ActionExecutionContext
|
|
59
60
|
) => Promise<ActionResult>;
|
|
60
61
|
handleActions: (
|
|
61
62
|
actions: ActionType[],
|
|
62
|
-
context
|
|
63
|
+
context?: ActionExecutionContext
|
|
63
64
|
) => Promise<ActionResult>;
|
|
64
65
|
handleEntryActions: (
|
|
65
66
|
entry: ZappEntry,
|
|
66
|
-
context?:
|
|
67
|
+
context?: ActionExecutionContext
|
|
67
68
|
) => Promise<ActionResult>;
|
|
68
69
|
};
|
|
69
70
|
|
|
@@ -71,235 +72,77 @@ type Props = {
|
|
|
71
72
|
children: React.ReactNode;
|
|
72
73
|
};
|
|
73
74
|
|
|
74
|
-
function findParentComponent(
|
|
75
|
-
childId: string,
|
|
76
|
-
parent: ZappRiver | ZappUIComponent
|
|
77
|
-
): ZappRiver | ZappUIComponent | null {
|
|
78
|
-
for (const child of parent.ui_components) {
|
|
79
|
-
if (child.id === childId) return parent;
|
|
80
|
-
|
|
81
|
-
if (child.ui_components) {
|
|
82
|
-
const found = findParentComponent(childId, child);
|
|
83
|
-
if (found) return found;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
75
|
const prepareDefaultActions = (actionExecutor) => {
|
|
91
|
-
actionExecutor.registerAction("localStorageSet", async (action) => {
|
|
92
|
-
const namespaces = action.options.content;
|
|
93
|
-
await batchSave(namespaces, localStorage);
|
|
94
|
-
// TODO: Add support for ownershipKey and ownershipNamespace
|
|
95
|
-
|
|
96
|
-
return ActionResult.Success;
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
actionExecutor.registerAction("sessionStorageSet", async (action) => {
|
|
100
|
-
const namespaces = action.options.content;
|
|
101
|
-
await batchSave(namespaces, sessionStorage);
|
|
102
|
-
// TODO: Add support for ownershipKey and ownershipNamespace
|
|
103
|
-
|
|
104
|
-
return ActionResult.Success;
|
|
105
|
-
});
|
|
106
|
-
|
|
107
76
|
actionExecutor.registerAction(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const dispatch = appStore.getDispatch();
|
|
111
|
-
|
|
112
|
-
const parentComponent = findParentComponent(
|
|
113
|
-
context?.component?.id,
|
|
114
|
-
context?.screenData
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
const componentSource = context?.component?.data?.source;
|
|
118
|
-
|
|
119
|
-
const componentData = componentSource
|
|
120
|
-
? context.component.data
|
|
121
|
-
: parentComponent?.data;
|
|
122
|
-
|
|
123
|
-
const source = componentData?.source;
|
|
124
|
-
const mapping = componentData?.mapping;
|
|
125
|
-
|
|
126
|
-
let dataSource = source;
|
|
127
|
-
|
|
128
|
-
if (source && mapping) {
|
|
129
|
-
dataSource =
|
|
130
|
-
getInflatedDataSourceUrl({
|
|
131
|
-
source,
|
|
132
|
-
contexts: {
|
|
133
|
-
entry: context?.screenEntry,
|
|
134
|
-
screen: context?.screenData,
|
|
135
|
-
search: getSearchContext(null, mapping),
|
|
136
|
-
},
|
|
137
|
-
mapping,
|
|
138
|
-
}) || source;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
log_info(`handleAction: refreshComponent for dataSource:${dataSource}`, {
|
|
142
|
-
source,
|
|
143
|
-
inflatedUrl: dataSource,
|
|
144
|
-
mapping,
|
|
145
|
-
entryContextId: context?.entryContext?.id,
|
|
146
|
-
entryId: context?.entry?.id,
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
// TODO: In theory we should wait callback to complete, before completing the action, but now it's not needed
|
|
150
|
-
// TODO: handle focused item removal
|
|
151
|
-
dispatch(
|
|
152
|
-
loadPipesData(dataSource, {
|
|
153
|
-
silentRefresh: false,
|
|
154
|
-
clearCache: true,
|
|
155
|
-
riverId: context?.screenData?.id,
|
|
156
|
-
})
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
return ActionResult.Success;
|
|
160
|
-
}
|
|
77
|
+
ACTION_TYPES.LOCAL_STORAGE_SET,
|
|
78
|
+
localStorageSetAction
|
|
161
79
|
);
|
|
162
80
|
|
|
163
|
-
actionExecutor.registerAction(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
ACTIVE_LAYOUT_ID_STORAGE_KEY,
|
|
168
|
-
action.options.layoutId
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
QuickBrickManager.sendQuickBrickEvent(QUICK_BRICK_EVENTS.FORCE_APP_RELOAD);
|
|
172
|
-
|
|
173
|
-
return ActionResult.Success;
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
actionExecutor.registerAction("appRestart", async () => {
|
|
177
|
-
log_info(`handleAction: ${QUICK_BRICK_EVENTS.FORCE_APP_RELOAD} event`);
|
|
178
|
-
|
|
179
|
-
QuickBrickManager.sendQuickBrickEvent(QUICK_BRICK_EVENTS.FORCE_APP_RELOAD);
|
|
180
|
-
|
|
181
|
-
return ActionResult.Success;
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
actionExecutor.registerAction("confirmDialog", async (action) => {
|
|
185
|
-
log_info("handleAction: confirmDialog event");
|
|
186
|
-
|
|
187
|
-
return new Promise<ActionResult>((resolve) => {
|
|
188
|
-
showConfirmationDialog({
|
|
189
|
-
...action.options,
|
|
190
|
-
confirmCompletion: () => resolve(ActionResult.Success),
|
|
191
|
-
cancelCompletion: () => resolve(ActionResult.Cancel),
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
actionExecutor.registerAction("sendCloudEvent", async (action, context) => {
|
|
197
|
-
try {
|
|
198
|
-
const options = action.options;
|
|
199
|
-
|
|
200
|
-
const entry = context?.entry || {};
|
|
201
|
-
const entryResolver = new EntryResolver(entry);
|
|
202
|
-
const screenData = context?.screenStateStore?.getState().data || {};
|
|
203
|
-
const screenResolver = new EntryResolver(screenData || {});
|
|
204
|
-
|
|
205
|
-
const data =
|
|
206
|
-
options?.data && options.inflateData
|
|
207
|
-
? await resolveObjectValues(options.data, {
|
|
208
|
-
entry: entryResolver,
|
|
209
|
-
screen: screenResolver,
|
|
210
|
-
})
|
|
211
|
-
: options?.data || entry;
|
|
212
|
-
|
|
213
|
-
const cloudEvent = await createCloudEvent({
|
|
214
|
-
type: options.type || "com.applicaster.selector.action.v1",
|
|
215
|
-
data,
|
|
216
|
-
subject: options.subject || entry?.id,
|
|
217
|
-
});
|
|
81
|
+
actionExecutor.registerAction(
|
|
82
|
+
ACTION_TYPES.SESSION_STORAGE_SET,
|
|
83
|
+
sessionStorageSetAction
|
|
84
|
+
);
|
|
218
85
|
|
|
219
|
-
|
|
86
|
+
actionExecutor.registerAction(
|
|
87
|
+
ACTION_TYPES.LOCAL_STORAGE_REMOVE,
|
|
88
|
+
localStorageRemoveAction
|
|
89
|
+
);
|
|
220
90
|
|
|
221
|
-
|
|
91
|
+
actionExecutor.registerAction(
|
|
92
|
+
ACTION_TYPES.SESSION_STORAGE_REMOVE,
|
|
93
|
+
sessionStorageRemoveAction
|
|
94
|
+
);
|
|
222
95
|
|
|
223
|
-
|
|
224
|
-
|
|
96
|
+
actionExecutor.registerAction(
|
|
97
|
+
ACTION_TYPES.REFRESH_COMPONENT,
|
|
98
|
+
refreshComponentAction
|
|
99
|
+
);
|
|
225
100
|
|
|
226
|
-
|
|
227
|
-
}
|
|
101
|
+
actionExecutor.registerAction(ACTION_TYPES.SWITCH_LAYOUT, switchLayoutAction);
|
|
228
102
|
|
|
229
|
-
|
|
230
|
-
log_info("sendCloudEvent: cloud event sent successfully");
|
|
103
|
+
actionExecutor.registerAction(ACTION_TYPES.APP_RESTART, appRestartAction);
|
|
231
104
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
action,
|
|
237
|
-
error,
|
|
238
|
-
});
|
|
239
|
-
}
|
|
105
|
+
actionExecutor.registerAction(
|
|
106
|
+
ACTION_TYPES.CONFIRM_DIALOG,
|
|
107
|
+
confirmDialogAction
|
|
108
|
+
);
|
|
240
109
|
|
|
241
|
-
|
|
242
|
-
|
|
110
|
+
actionExecutor.registerAction(
|
|
111
|
+
ACTION_TYPES.SEND_CLOUD_EVENT,
|
|
112
|
+
sendCloudEventAction
|
|
113
|
+
);
|
|
243
114
|
|
|
244
115
|
actionExecutor.registerAction(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
action: ActionType,
|
|
248
|
-
context?: Record<string, any>
|
|
249
|
-
): Promise<ActionResult> => {
|
|
250
|
-
return await sessionStorageToggleFlag(context, action);
|
|
251
|
-
}
|
|
116
|
+
ACTION_TYPES.SESSION_STORAGE_TOGGLE_FLAG,
|
|
117
|
+
sessionStorageToggleFlagAction
|
|
252
118
|
);
|
|
253
119
|
|
|
254
120
|
actionExecutor.registerAction(
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
action: ActionType,
|
|
258
|
-
context?: Record<string, any>
|
|
259
|
-
): Promise<ActionResult> => {
|
|
260
|
-
return await localStorageToggleFlag(context, action);
|
|
261
|
-
}
|
|
121
|
+
ACTION_TYPES.LOCAL_STORAGE_TOGGLE_FLAG,
|
|
122
|
+
localStorageToggleFlagAction
|
|
262
123
|
);
|
|
263
124
|
|
|
264
125
|
actionExecutor.registerAction(
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
context?: Record<string, any>
|
|
269
|
-
): Promise<ActionResult> => {
|
|
270
|
-
const route = context?.screenRoute;
|
|
271
|
-
const screenStateStore = context?.screenStateStore;
|
|
272
|
-
|
|
273
|
-
await screenSetVariable(
|
|
274
|
-
route,
|
|
275
|
-
screenStateStore,
|
|
276
|
-
{ entry: context?.entry, options: action.options },
|
|
277
|
-
action
|
|
278
|
-
);
|
|
126
|
+
ACTION_TYPES.SCREEN_SET_VARIABLE,
|
|
127
|
+
screenSetVariableAction
|
|
128
|
+
);
|
|
279
129
|
|
|
280
|
-
|
|
281
|
-
|
|
130
|
+
actionExecutor.registerAction(
|
|
131
|
+
ACTION_TYPES.SCREEN_TOGGLE_FLAG,
|
|
132
|
+
screenToggleFlagAction
|
|
282
133
|
);
|
|
283
134
|
|
|
284
135
|
actionExecutor.registerAction(
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
context?: Record<string, any>
|
|
289
|
-
): Promise<ActionResult> => {
|
|
290
|
-
const screenRoute = context?.screenRoute;
|
|
291
|
-
const screenStateStore = context?.screenStateStore;
|
|
292
|
-
|
|
293
|
-
await screenToggleFlag(
|
|
294
|
-
screenRoute,
|
|
295
|
-
screenStateStore,
|
|
296
|
-
{ entry: context?.entry, options: action.options },
|
|
297
|
-
action
|
|
298
|
-
);
|
|
136
|
+
ACTION_TYPES.OPEN_BOTTOM_SHEET,
|
|
137
|
+
openBottomSheetAction
|
|
138
|
+
);
|
|
299
139
|
|
|
300
|
-
|
|
301
|
-
|
|
140
|
+
actionExecutor.registerAction(
|
|
141
|
+
ACTION_TYPES.DISMISS_BOTTOM_SHEET,
|
|
142
|
+
dismissBottomSheetAction
|
|
302
143
|
);
|
|
144
|
+
|
|
145
|
+
actionExecutor.registerAction(ACTION_TYPES.SHOW_TOAST, showToastAction);
|
|
303
146
|
};
|
|
304
147
|
|
|
305
148
|
export const ActionExecutorContext =
|
|
@@ -317,6 +160,8 @@ export function withActionExecutor(Component) {
|
|
|
317
160
|
return {
|
|
318
161
|
unregisterAction: _actionExecutor.unregisterAction,
|
|
319
162
|
registerAction: _actionExecutor.registerAction,
|
|
163
|
+
registerActionState: _actionExecutor.registerActionState,
|
|
164
|
+
getActionState: _actionExecutor.getActionState,
|
|
320
165
|
handleAction: _actionExecutor.handleAction,
|
|
321
166
|
handleActions: _actionExecutor.handleActions,
|
|
322
167
|
handleEntryActions: _actionExecutor.handleEntryActions,
|
|
@@ -339,83 +184,8 @@ export function withActionExecutor(Component) {
|
|
|
339
184
|
|
|
340
185
|
useEffect(() => {
|
|
341
186
|
return _actionExecutor.registerAction(
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
async (action: ActionType, context?: Record<string, any>) => {
|
|
345
|
-
const screenType = action.options?.typeMapping;
|
|
346
|
-
|
|
347
|
-
if (!screenType) {
|
|
348
|
-
log_error("navigateToScreen: typeMapping option is missing");
|
|
349
|
-
|
|
350
|
-
return ActionResult.Error;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
const navigationAction = action.options?.navigationAction;
|
|
354
|
-
const entrySource = action.options?.entry;
|
|
355
|
-
|
|
356
|
-
const entry = entrySource
|
|
357
|
-
? entrySource === "@{entry/}"
|
|
358
|
-
? context?.entry
|
|
359
|
-
: entrySource
|
|
360
|
-
: null;
|
|
361
|
-
|
|
362
|
-
if (entry) {
|
|
363
|
-
if (typeof entry !== "object") {
|
|
364
|
-
log_error(
|
|
365
|
-
`navigateToScreen: entry option is not an object, entry: ${entry}`
|
|
366
|
-
);
|
|
367
|
-
|
|
368
|
-
return ActionResult.Error;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
log_info(
|
|
372
|
-
`navigateToScreen: navigating to screen type: ${screenType} with entry id: ${entry.id}`
|
|
373
|
-
);
|
|
374
|
-
|
|
375
|
-
const overriddenEntry = {
|
|
376
|
-
...entry,
|
|
377
|
-
type: {
|
|
378
|
-
value: screenType,
|
|
379
|
-
},
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
if (navigationAction === "push") {
|
|
383
|
-
navigator.push(overriddenEntry);
|
|
384
|
-
} else {
|
|
385
|
-
navigator.replace(overriddenEntry);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
return ActionResult.Success;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
const screenId = contentTypes?.[screenType]?.screen_id || null;
|
|
392
|
-
|
|
393
|
-
if (!screenId) {
|
|
394
|
-
log_error(
|
|
395
|
-
`navigateToScreen: can not resolve screen type mapping: ${screenType}`
|
|
396
|
-
);
|
|
397
|
-
|
|
398
|
-
return ActionResult.Error;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
const river = rivers[screenId];
|
|
402
|
-
|
|
403
|
-
if (!river) {
|
|
404
|
-
log_error("navigateToScreen: can not resolve river");
|
|
405
|
-
|
|
406
|
-
return ActionResult.Error;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
context?.callback?.({ success: false, error: null, abort: true });
|
|
410
|
-
|
|
411
|
-
if (navigationAction === "push") {
|
|
412
|
-
navigator.push(river);
|
|
413
|
-
} else {
|
|
414
|
-
navigator.replace(river);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
return ActionResult.Success;
|
|
418
|
-
}
|
|
187
|
+
ACTION_TYPES.NAVIGATE_TO_SCREEN,
|
|
188
|
+
createNavigateToScreenAction(navigator, rivers, contentTypes)
|
|
419
189
|
);
|
|
420
190
|
}, [navigator, rivers, contentTypes]);
|
|
421
191
|
|
|
@@ -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
|
+
});
|