@applicaster/zapp-react-native-utils 16.0.0-rc.8 → 16.0.0-rc.80

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.
Files changed (189) hide show
  1. package/actionsExecutor/ActionExecutor.ts +47 -11
  2. package/actionsExecutor/ActionExecutorContext.tsx +102 -315
  3. package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
  4. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
  5. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  6. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  7. package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
  8. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +133 -0
  9. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
  10. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +212 -0
  11. package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
  12. package/actionsExecutor/actions/appRestart.ts +24 -0
  13. package/actionsExecutor/actions/confirmDialog.ts +53 -0
  14. package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
  15. package/actionsExecutor/actions/goBack.ts +60 -0
  16. package/actionsExecutor/actions/goHome.ts +31 -0
  17. package/actionsExecutor/actions/index.ts +38 -0
  18. package/actionsExecutor/actions/localStorageRemove.ts +27 -0
  19. package/actionsExecutor/actions/localStorageSet.ts +28 -0
  20. package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
  21. package/actionsExecutor/actions/navigateToScreen.ts +137 -0
  22. package/actionsExecutor/actions/openBottomSheet.ts +325 -0
  23. package/actionsExecutor/actions/refreshComponent.ts +85 -0
  24. package/actionsExecutor/actions/screenSetVariable.ts +35 -0
  25. package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
  26. package/actionsExecutor/actions/sendCloudEvent.ts +93 -0
  27. package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
  28. package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
  29. package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
  30. package/actionsExecutor/actions/showToast.ts +87 -0
  31. package/actionsExecutor/actions/switchLayout.ts +40 -0
  32. package/actionsExecutor/consts.ts +25 -0
  33. package/actionsExecutor/feedDecorator.ts +6 -6
  34. package/actionsExecutor/types.ts +59 -0
  35. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -2
  36. package/analyticsUtils/PlayerAnalyticsManager.ts +12 -2
  37. package/analyticsUtils/__tests__/analyticsMapper.test.ts +35 -0
  38. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testACP_events.json +1 -1
  39. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testBlockUnlistedParams_rules.json +1 -1
  40. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_events.json +4 -0
  41. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_rules.json +6 -0
  42. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEventRegex_events.json +3 -9
  43. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_events.json +18 -0
  44. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_rules.json +16 -0
  45. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_events.json +4 -0
  46. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_rules.json +6 -0
  47. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_events.json +4 -0
  48. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_rules.json +6 -0
  49. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_events.json +4 -0
  50. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_rules.json +6 -0
  51. package/analyticsUtils/__tests__/fixtures/index.js +20 -0
  52. package/analyticsUtils/analyticsMapper.ts +4 -1
  53. package/analyticsUtils/playerAnalyticsTracker.ts +26 -3
  54. package/appUtils/HooksManager/index.ts +12 -8
  55. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -1
  56. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -1
  57. package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
  58. package/appUtils/contextKeysManager/index.ts +1 -1
  59. package/appUtils/contextKeysManager/utils/index.ts +38 -25
  60. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +143 -53
  61. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  62. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +49 -0
  63. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  64. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  65. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +11 -0
  66. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  67. package/appUtils/playerManager/OverlayObserver/utils.ts +54 -20
  68. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  69. package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
  70. package/appUtils/playerManager/__tests__/playerNative.test.ts +38 -0
  71. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  72. package/appUtils/playerManager/{conts.ts → const.ts} +20 -0
  73. package/appUtils/playerManager/index.ts +1 -1
  74. package/appUtils/playerManager/player.ts +115 -3
  75. package/appUtils/playerManager/playerFactory.ts +1 -1
  76. package/appUtils/playerManager/playerNative.ts +6 -4
  77. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  78. package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
  79. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  80. package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
  81. package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
  82. package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
  83. package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
  84. package/arrayUtils/__tests__/isFirst.test.ts +17 -0
  85. package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
  86. package/arrayUtils/__tests__/isLast.test.ts +31 -0
  87. package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
  88. package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
  89. package/arrayUtils/__tests__/reorderByIds.test.ts +50 -0
  90. package/arrayUtils/__tests__/sample.test.ts +61 -0
  91. package/arrayUtils/index.ts +136 -20
  92. package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
  93. package/bottomSheet/index.ts +17 -0
  94. package/cellUtils/index.ts +33 -8
  95. package/colorUtils/__tests__/isTransparentColor.test.ts +76 -0
  96. package/colorUtils/__tests__/isValidColor.test.ts +70 -0
  97. package/colorUtils/index.ts +50 -0
  98. package/configurationUtils/__tests__/modalBlocksParser.test.ts +107 -0
  99. package/configurationUtils/manifestKeyParser.ts +38 -9
  100. package/configurationUtils/modalBlocksParser.ts +178 -0
  101. package/entryActions/__tests__/buildEntryActions.test.ts +156 -0
  102. package/entryActions/aliasPresentation.ts +124 -0
  103. package/entryActions/buildEntryActions.ts +166 -0
  104. package/entryActions/index.ts +17 -0
  105. package/entryActions/types.ts +39 -0
  106. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  107. package/manifestUtils/_internals/index.js +14 -3
  108. package/manifestUtils/defaultManifestConfigurations/generalContent.js +35 -0
  109. package/manifestUtils/defaultManifestConfigurations/player.js +349 -20
  110. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
  111. package/manifestUtils/fieldUtils/index.js +125 -0
  112. package/manifestUtils/index.js +3 -0
  113. package/manifestUtils/keys.js +9 -0
  114. package/manifestUtils/mobileAction/button/index.js +16 -0
  115. package/manifestUtils/mobileAction/container/index.js +3 -1
  116. package/manifestUtils/mobileAction/groups/defaults.js +3 -1
  117. package/manifestUtils/modalBlocks.js +304 -0
  118. package/manifestUtils/platformIsTV.js +1 -0
  119. package/modalState/ContentViewModel.ts +113 -0
  120. package/modalState/EditableCollection.ts +17 -0
  121. package/modalState/EditableCollectionRegistry.ts +51 -0
  122. package/modalState/ModalOrchestrator.ts +211 -0
  123. package/modalState/RemoteEditableCollection.ts +227 -0
  124. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  125. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  126. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  127. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +47 -0
  128. package/modalState/__tests__/RemoteEditableCollection.test.ts +326 -0
  129. package/modalState/__tests__/index.test.ts +30 -1
  130. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  131. package/modalState/index.ts +35 -83
  132. package/modalState/store.ts +102 -0
  133. package/modalState/types.ts +159 -0
  134. package/modalState/useBottomSheetContent.ts +104 -0
  135. package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
  136. package/numberUtils/__tests__/isZero.test.ts +27 -0
  137. package/numberUtils/__tests__/requireNumber.test.ts +50 -0
  138. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  139. package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
  140. package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
  141. package/numberUtils/index.ts +27 -8
  142. package/package.json +2 -2
  143. package/pipesUtils/__tests__/buildUrlWithQuery.test.ts +33 -0
  144. package/pipesUtils/__tests__/withPipesEndpoint.test.tsx +56 -0
  145. package/pipesUtils/index.ts +1 -0
  146. package/pipesUtils/withPipesEndpoint.tsx +54 -0
  147. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  148. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  149. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  150. package/playerUtils/contentDataKeys.ts +134 -0
  151. package/playerUtils/index.ts +58 -15
  152. package/playerUtils/isAudioItem.ts +26 -0
  153. package/playerUtils/resolvePlayerActions.ts +71 -0
  154. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  155. package/reactHooks/actions/index.ts +117 -2
  156. package/reactHooks/cell-click/index.ts +18 -10
  157. package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
  158. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
  159. package/reactHooks/feed/index.ts +5 -1
  160. package/reactHooks/feed/useBatchLoading.ts +9 -1
  161. package/reactHooks/feed/{usePipesCacheReset.ts → useMarkPipesDataStale.ts} +12 -4
  162. package/reactHooks/index.ts +2 -0
  163. package/reactHooks/layout/index.ts +1 -1
  164. package/reactHooks/navigation/__mocks__/index.ts +4 -0
  165. package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
  166. package/reactHooks/navigation/index.ts +1 -1
  167. package/reactHooks/navigation/useIsScreenActive.ts +29 -8
  168. package/reactHooks/state/useComponentScreenState.ts +1 -1
  169. package/reactHooks/usePluginConfiguration.ts +4 -1
  170. package/reactHooks/utils/__tests__/index.test.js +22 -2
  171. package/reactHooks/utils/index.ts +13 -2
  172. package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +22 -4
  173. package/riverComponetsMeasurementProvider/index.tsx +12 -8
  174. package/stringUtils/__tests__/stringUtils.test.js +42 -0
  175. package/stringUtils/index.ts +2 -2
  176. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  177. package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
  178. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  179. package/uiActionsRegistrator/index.ts +25 -0
  180. package/uiActionsRegistrator/registry.ts +335 -0
  181. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  182. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  183. package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
  184. package/zappFrameworkUtils/localStorageHelper.ts +19 -15
  185. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  186. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  187. package/playerUtils/getPlayerActionButtons.ts +0 -17
  188. package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
  189. /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, any> = {};
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?: Record<string, any>
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?: Record<string, any>
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?: Record<string, any>
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
- action: ActionType,
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,300 +5,146 @@ import {
5
5
  actionExecutor as _actionExecutor,
6
6
  ActionResult,
7
7
  } from "./ActionExecutor";
8
- import {
9
- batchRemoveAllFromNamespaceForStorage,
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 { screenSetVariable, screenToggleFlag } from "./ScreenActions";
18
+ import {
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";
41
41
 
42
42
  export const { log_error, log_info, log_debug } = createLogger({
43
43
  subsystem: "ActionExecutorContext",
44
44
  category: "General",
45
45
  });
46
46
 
47
- type ActionExecutorContextType = {
48
- registerAction: (
47
+ export type ActionExecutorContextType = {
48
+ registerAction: <TOptions = Record<string, any>>(
49
49
  type: string,
50
- handler: (
51
- action: ActionType,
52
- context?: Record<string, any>
53
- ) => Promise<ActionResult>
50
+ handler: ActionHandler<TOptions>,
51
+ stateResolver?: (entry?: ZappEntry) => any
54
52
  ) => void;
55
53
  unregisterAction: (type: string) => void;
54
+ registerActionState: (
55
+ type: string,
56
+ stateResolver: (entry?: ZappEntry) => any
57
+ ) => () => void;
58
+ getActionState: (type: string, entry?: ZappEntry) => any;
56
59
  handleAction: (
57
60
  action: ActionType,
58
- context?: Record<string, any>
61
+ context?: ActionExecutionContext
59
62
  ) => Promise<ActionResult>;
60
63
  handleActions: (
61
64
  actions: ActionType[],
62
- context: Record<string, any>
65
+ context?: ActionExecutionContext
63
66
  ) => Promise<ActionResult>;
64
67
  handleEntryActions: (
65
68
  entry: ZappEntry,
66
- context?: Record<string, any>
69
+ context?: ActionExecutionContext
67
70
  ) => Promise<ActionResult>;
68
71
  };
72
+
69
73
  type Props = {
70
74
  children: React.ReactNode;
71
75
  };
72
76
 
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
77
  const prepareDefaultActions = (actionExecutor) => {
90
- actionExecutor.registerAction("localStorageSet", async (action) => {
91
- const namespaces = action.options.content;
92
- await batchSave(namespaces, localStorage);
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
- });
105
-
106
78
  actionExecutor.registerAction(
107
- "refreshComponent",
108
- async (_action, context) => {
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
- }
79
+ ACTION_TYPES.LOCAL_STORAGE_SET,
80
+ localStorageSetAction
160
81
  );
161
82
 
162
- actionExecutor.registerAction("switchLayout", async (action) => {
163
- log_info("handleAction: switchLayout event");
164
-
165
- await localStorage.setItem(
166
- ACTIVE_LAYOUT_ID_STORAGE_KEY,
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
- });
83
+ actionExecutor.registerAction(
84
+ ACTION_TYPES.SESSION_STORAGE_SET,
85
+ sessionStorageSetAction
86
+ );
217
87
 
218
- log_info("handleAction: sendCloudEvent event", { cloudEvent });
88
+ actionExecutor.registerAction(
89
+ ACTION_TYPES.LOCAL_STORAGE_REMOVE,
90
+ localStorageRemoveAction
91
+ );
219
92
 
220
- const { error, code } = await sendCloudEvent(cloudEvent, options.url);
93
+ actionExecutor.registerAction(
94
+ ACTION_TYPES.SESSION_STORAGE_REMOVE,
95
+ sessionStorageRemoveAction
96
+ );
221
97
 
222
- if (error) {
223
- log_error("sendCloudEvent: error sending cloud event", { error });
98
+ actionExecutor.registerAction(
99
+ ACTION_TYPES.REFRESH_COMPONENT,
100
+ refreshComponentAction
101
+ );
224
102
 
225
- return ActionResult.Error;
226
- }
103
+ actionExecutor.registerAction(ACTION_TYPES.SWITCH_LAYOUT, switchLayoutAction);
227
104
 
228
- if (code && code >= 200 && code < 300 && !error) {
229
- log_info("sendCloudEvent: cloud event sent successfully");
105
+ actionExecutor.registerAction(ACTION_TYPES.APP_RESTART, appRestartAction);
230
106
 
231
- return ActionResult.Success;
232
- }
233
- } catch (error) {
234
- log_error("sendCloudEvent: error sending cloud event", {
235
- action,
236
- error,
237
- });
238
- }
107
+ actionExecutor.registerAction(
108
+ ACTION_TYPES.CONFIRM_DIALOG,
109
+ confirmDialogAction
110
+ );
239
111
 
240
- return ActionResult.Error;
241
- });
112
+ actionExecutor.registerAction(
113
+ ACTION_TYPES.SEND_CLOUD_EVENT,
114
+ sendCloudEventAction
115
+ );
242
116
 
243
117
  actionExecutor.registerAction(
244
- "sessionStorageToggleFlag",
245
- async (
246
- action: ActionType,
247
- context?: Record<string, any>
248
- ): Promise<ActionResult> => {
249
- return await sessionStorageToggleFlag(context, action);
250
- }
118
+ ACTION_TYPES.SESSION_STORAGE_TOGGLE_FLAG,
119
+ sessionStorageToggleFlagAction
251
120
  );
252
121
 
253
122
  actionExecutor.registerAction(
254
- "localStorageToggleFlag",
255
- async (
256
- action: ActionType,
257
- context?: Record<string, any>
258
- ): Promise<ActionResult> => {
259
- return await localStorageToggleFlag(context, action);
260
- }
123
+ ACTION_TYPES.LOCAL_STORAGE_TOGGLE_FLAG,
124
+ localStorageToggleFlagAction
261
125
  );
262
126
 
263
127
  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
- );
128
+ ACTION_TYPES.SCREEN_SET_VARIABLE,
129
+ screenSetVariableAction
130
+ );
278
131
 
279
- return Promise.resolve(ActionResult.Success);
280
- }
132
+ actionExecutor.registerAction(
133
+ ACTION_TYPES.SCREEN_TOGGLE_FLAG,
134
+ screenToggleFlagAction
281
135
  );
282
136
 
283
137
  actionExecutor.registerAction(
284
- "screenToggleFlag",
285
- async (
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
- );
138
+ ACTION_TYPES.OPEN_BOTTOM_SHEET,
139
+ openBottomSheetAction
140
+ );
298
141
 
299
- return Promise.resolve(ActionResult.Success);
300
- }
142
+ actionExecutor.registerAction(
143
+ ACTION_TYPES.DISMISS_BOTTOM_SHEET,
144
+ dismissBottomSheetAction
301
145
  );
146
+
147
+ actionExecutor.registerAction(ACTION_TYPES.SHOW_TOAST, showToastAction);
302
148
  };
303
149
 
304
150
  export const ActionExecutorContext =
@@ -316,6 +162,8 @@ export function withActionExecutor(Component) {
316
162
  return {
317
163
  unregisterAction: _actionExecutor.unregisterAction,
318
164
  registerAction: _actionExecutor.registerAction,
165
+ registerActionState: _actionExecutor.registerActionState,
166
+ getActionState: _actionExecutor.getActionState,
319
167
  handleAction: _actionExecutor.handleAction,
320
168
  handleActions: _actionExecutor.handleActions,
321
169
  handleEntryActions: _actionExecutor.handleEntryActions,
@@ -338,85 +186,24 @@ export function withActionExecutor(Component) {
338
186
 
339
187
  useEffect(() => {
340
188
  return _actionExecutor.registerAction(
341
- "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 });
189
+ ACTION_TYPES.NAVIGATE_TO_SCREEN,
190
+ createNavigateToScreenAction(navigator, rivers, contentTypes)
191
+ );
192
+ }, [navigator, rivers, contentTypes]);
409
193
 
410
- if (navigationAction === "push") {
411
- navigator.push(river);
412
- } else {
413
- navigator.replace(river);
414
- }
194
+ useEffect(() => {
195
+ return _actionExecutor.registerAction(
196
+ ACTION_TYPES.GO_BACK,
197
+ createGoBackAction(navigator)
198
+ );
199
+ }, [navigator]);
415
200
 
416
- return ActionResult.Success;
417
- }
201
+ useEffect(() => {
202
+ return _actionExecutor.registerAction(
203
+ ACTION_TYPES.GO_HOME,
204
+ createGoHomeAction(navigator)
418
205
  );
419
- }, [navigator, rivers, contentTypes]);
206
+ }, [navigator]);
420
207
 
421
208
  return (
422
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,25 @@
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
+ modalOrchestrator: {
8
+ close: jest.fn(),
9
+ },
10
+ }));
11
+
12
+ describe("dismissBottomSheetAction", () => {
13
+ beforeEach(() => {
14
+ jest.clearAllMocks();
15
+ });
16
+
17
+ it("calls dismissModal and returns ActionResult.Success", async () => {
18
+ const result = await dismissBottomSheetAction({
19
+ type: "dismissBottomSheet",
20
+ });
21
+
22
+ expect(dismissModal).toHaveBeenCalledTimes(1);
23
+ expect(result).toBe(ActionResult.Success);
24
+ });
25
+ });