@applicaster/zapp-react-native-utils 16.0.0-alpha.1745039402 → 16.0.0-alpha.1774022213

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 (168) hide show
  1. package/actionsExecutor/ActionExecutor.ts +57 -12
  2. package/actionsExecutor/ActionExecutorContext.tsx +110 -333
  3. package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
  4. package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
  5. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
  6. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  7. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  8. package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
  9. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +133 -0
  10. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
  11. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +300 -0
  12. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  13. package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
  14. package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
  15. package/actionsExecutor/actions/appRestart.ts +24 -0
  16. package/actionsExecutor/actions/confirmDialog.ts +53 -0
  17. package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
  18. package/actionsExecutor/actions/goBack.ts +60 -0
  19. package/actionsExecutor/actions/goHome.ts +31 -0
  20. package/actionsExecutor/actions/index.ts +42 -0
  21. package/actionsExecutor/actions/localStorageRemove.ts +27 -0
  22. package/actionsExecutor/actions/localStorageSet.ts +28 -0
  23. package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
  24. package/actionsExecutor/actions/navigateToScreen.ts +137 -0
  25. package/actionsExecutor/actions/openBottomSheet.ts +338 -0
  26. package/actionsExecutor/actions/presentScreen.ts +78 -0
  27. package/actionsExecutor/actions/refreshComponent.ts +85 -0
  28. package/actionsExecutor/actions/screenSetVariable.ts +35 -0
  29. package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
  30. package/actionsExecutor/actions/sendCloudEvent.ts +93 -0
  31. package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
  32. package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
  33. package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
  34. package/actionsExecutor/actions/showAlert.ts +51 -0
  35. package/actionsExecutor/actions/showToast.ts +87 -0
  36. package/actionsExecutor/actions/switchLayout.ts +40 -0
  37. package/actionsExecutor/consts.ts +27 -0
  38. package/actionsExecutor/feedDecorator.ts +6 -6
  39. package/actionsExecutor/types.ts +59 -0
  40. package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
  41. package/appUtils/HooksManager/index.ts +9 -0
  42. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -1
  43. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -1
  44. package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
  45. package/appUtils/contextKeysManager/index.ts +1 -1
  46. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +142 -59
  47. package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
  48. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  49. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +56 -0
  50. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  51. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  52. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +24 -0
  53. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  54. package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
  55. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  56. package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
  57. package/appUtils/playerManager/__tests__/playerNative.test.ts +38 -0
  58. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  59. package/appUtils/playerManager/{conts.ts → const.ts} +20 -0
  60. package/appUtils/playerManager/index.ts +1 -1
  61. package/appUtils/playerManager/player.ts +115 -3
  62. package/appUtils/playerManager/playerFactory.ts +1 -1
  63. package/appUtils/playerManager/playerNative.ts +6 -4
  64. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  65. package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
  66. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  67. package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
  68. package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
  69. package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
  70. package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
  71. package/arrayUtils/__tests__/isFirst.test.ts +17 -0
  72. package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
  73. package/arrayUtils/__tests__/isLast.test.ts +31 -0
  74. package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
  75. package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
  76. package/arrayUtils/__tests__/reorderByIds.test.ts +63 -0
  77. package/arrayUtils/__tests__/sample.test.ts +61 -0
  78. package/arrayUtils/index.ts +119 -20
  79. package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
  80. package/bottomSheet/index.ts +17 -0
  81. package/cellUtils/index.ts +30 -3
  82. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  83. package/configurationUtils/__tests__/modalBlocksParser.test.ts +269 -0
  84. package/configurationUtils/manifestKeyParser.ts +50 -10
  85. package/configurationUtils/modalBlocksParser.ts +214 -0
  86. package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
  87. package/entryActions/aliasPresentation.ts +108 -0
  88. package/entryActions/buildEntryActions.ts +167 -0
  89. package/entryActions/index.ts +15 -0
  90. package/entryActions/types.ts +39 -0
  91. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  92. package/manifestUtils/_internals/index.js +8 -3
  93. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  94. package/manifestUtils/defaultManifestConfigurations/player.js +349 -20
  95. package/manifestUtils/index.js +3 -0
  96. package/manifestUtils/keys.js +8 -0
  97. package/manifestUtils/mobileAction/button/index.js +16 -0
  98. package/manifestUtils/mobileAction/container/index.js +3 -1
  99. package/manifestUtils/mobileAction/groups/defaults.js +3 -1
  100. package/manifestUtils/modalBlocks.js +304 -0
  101. package/modalState/ContentViewModel.ts +113 -0
  102. package/modalState/EditableCollection.ts +17 -0
  103. package/modalState/EditableCollectionRegistry.ts +51 -0
  104. package/modalState/ModalOrchestrator.ts +212 -0
  105. package/modalState/RemoteEditableCollection.ts +235 -0
  106. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  107. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  108. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  109. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +63 -0
  110. package/modalState/__tests__/RemoteEditableCollection.test.ts +415 -0
  111. package/modalState/__tests__/index.test.ts +30 -1
  112. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  113. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  114. package/modalState/index.ts +35 -83
  115. package/modalState/store.ts +109 -0
  116. package/modalState/types.ts +162 -0
  117. package/modalState/useBottomSheetContent.ts +109 -0
  118. package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
  119. package/numberUtils/__tests__/isZero.test.ts +27 -0
  120. package/numberUtils/__tests__/requireNumber.test.ts +50 -0
  121. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  122. package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
  123. package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
  124. package/numberUtils/index.ts +27 -8
  125. package/package.json +2 -2
  126. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  127. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  128. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  129. package/playerUtils/contentDataKeys.ts +134 -0
  130. package/playerUtils/index.ts +37 -16
  131. package/playerUtils/isAudioItem.ts +26 -0
  132. package/playerUtils/resolvePlayerActions.ts +71 -0
  133. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  134. package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
  135. package/pluginUtils/index.ts +29 -0
  136. package/reactHooks/actions/index.ts +117 -2
  137. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  138. package/reactHooks/cell-click/index.ts +24 -17
  139. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
  140. package/reactHooks/index.ts +2 -0
  141. package/reactHooks/layout/index.ts +1 -1
  142. package/reactHooks/navigation/__mocks__/index.ts +4 -0
  143. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  144. package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
  145. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  146. package/reactHooks/navigation/index.ts +3 -1
  147. package/reactHooks/navigation/useIsScreenActive.ts +29 -8
  148. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  149. package/reactHooks/navigation/useRoute.ts +22 -5
  150. package/reactHooks/state/useComponentScreenState.ts +1 -1
  151. package/reactHooks/usePluginConfiguration.ts +4 -1
  152. package/reactHooks/utils/__tests__/index.test.js +22 -2
  153. package/reactHooks/utils/index.ts +11 -1
  154. package/stringUtils/__tests__/stringUtils.test.js +42 -0
  155. package/stringUtils/index.ts +2 -2
  156. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  157. package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
  158. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  159. package/uiActionsRegistrator/index.ts +25 -0
  160. package/uiActionsRegistrator/registry.ts +335 -0
  161. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  162. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  163. package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
  164. package/zappFrameworkUtils/localStorageHelper.ts +19 -15
  165. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  166. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  167. package/playerUtils/getPlayerActionButtons.ts +0 -17
  168. /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,10 +53,9 @@ 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
- // TODO: Handle action result error
59
59
  const result = await this.handleAction(action, context);
60
60
 
61
61
  if (result === ActionResult.Cancel) {
@@ -63,6 +63,16 @@ class ActionExecutor {
63
63
 
64
64
  return result;
65
65
  }
66
+
67
+ if (result === ActionResult.Error) {
68
+ // Everything after a failed step was written for a state that never
69
+ // happened — the event was refused, the screen never opened — so
70
+ // running it is how a chain ends up telling the user their mail was
71
+ // sent when it was not.
72
+ log_error(`handleActions: action: ${action.type} failed`, { action });
73
+
74
+ return result;
75
+ }
66
76
  }
67
77
 
68
78
  return ActionResult.Success;
@@ -70,7 +80,7 @@ class ActionExecutor {
70
80
 
71
81
  handleEntryActions = async (
72
82
  entry: ZappEntry,
73
- context?: Record<string, any>
83
+ context?: ActionExecutionContext
74
84
  ): Promise<ActionResult> => {
75
85
  const tapActions = entry.extensions?.tap_actions?.actions;
76
86
 
@@ -98,12 +108,10 @@ class ActionExecutor {
98
108
  delete this.registeredActions[actionType];
99
109
  };
100
110
 
101
- registerAction = (
111
+ registerAction = <TOptions = Record<string, any>>(
102
112
  type: string,
103
- handler: (
104
- action: ActionType,
105
- context?: Record<string, any>
106
- ) => Promise<ActionResult>
113
+ handler: ActionHandler<TOptions>,
114
+ stateResolver?: (entry?: ZappEntry) => any
107
115
  ) => {
108
116
  if (this.registeredActions[type]) {
109
117
  log_error(`registerAction: action type: ${type} already registered`);
@@ -114,11 +122,48 @@ class ActionExecutor {
114
122
  this.registeredActions[type] = handler;
115
123
  log_debug(`registerAction: action type: ${type} registered`);
116
124
 
125
+ let unregisterState = () => {};
126
+
127
+ if (stateResolver) {
128
+ unregisterState = this.registerActionState(type, stateResolver);
129
+ }
130
+
117
131
  return () => {
118
132
  this.unregisterAction(type);
133
+ unregisterState();
119
134
  log_debug(`registerAction: action type: ${type} un-registered`);
120
135
  };
121
136
  };
137
+
138
+ private actionStates: Record<string, (entry?: ZappEntry) => any> = {};
139
+
140
+ registerActionState = (
141
+ type: string,
142
+ stateResolver: (entry?: ZappEntry) => any
143
+ ) => {
144
+ if (this.actionStates[type]) {
145
+ log_error(
146
+ `registerActionState: action type state: ${type} already registered`
147
+ );
148
+
149
+ return () => {};
150
+ }
151
+
152
+ this.actionStates[type] = stateResolver;
153
+ log_debug(`registerActionState: action type state: ${type} registered`);
154
+
155
+ return () => {
156
+ delete this.actionStates[type];
157
+
158
+ log_debug(
159
+ `registerActionState: action type state: ${type} un-registered`
160
+ );
161
+ };
162
+ };
163
+
164
+ getActionState = (type: string, entry?: ZappEntry) => {
165
+ return this.actionStates[type]?.(entry);
166
+ };
122
167
  }
123
168
 
124
169
  export const actionExecutor = new ActionExecutor();
@@ -5,44 +5,41 @@ import {
5
5
  actionExecutor as _actionExecutor,
6
6
  ActionResult,
7
7
  } from "./ActionExecutor";
8
- import {
9
- batchRemoveAllFromNamespaceForStorage,
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
- import { useNavigation, useRivers } from "../reactHooks";
28
- import {
29
- getInflatedDataSourceUrl,
30
- getSearchContext,
31
- } from "../reactHooks/feed/useInflatedUrl";
32
-
12
+ import { useNavigation, usePresentScreen, useRivers } from "../reactHooks";
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
- StorageValuesToAdd,
44
- StorageValuesToRemove,
45
- } from "../zappFrameworkUtils/types";
19
+ appRestartAction,
20
+ confirmDialogAction,
21
+ showAlertAction,
22
+ createGoBackAction,
23
+ createGoHomeAction,
24
+ createNavigateToScreenAction,
25
+ dismissBottomSheetAction,
26
+ localStorageRemoveAction,
27
+ localStorageSetAction,
28
+ localStorageToggleFlagAction,
29
+ createPresentScreenAction,
30
+ openBottomSheetAction,
31
+ refreshComponentAction,
32
+ screenSetVariableAction,
33
+ screenToggleFlagAction,
34
+ sendCloudEventAction,
35
+ sessionStorageRemoveAction,
36
+ sessionStorageSetAction,
37
+ sessionStorageToggleFlagAction,
38
+ switchLayoutAction,
39
+ showToastAction,
40
+ } from "./actions";
41
+
42
+ import { ACTION_TYPES } from "./consts";
46
43
 
47
44
  export const { log_error, log_info, log_debug } = createLogger({
48
45
  subsystem: "ActionExecutorContext",
@@ -50,25 +47,28 @@ export const { log_error, log_info, log_debug } = createLogger({
50
47
  });
51
48
 
52
49
  export type ActionExecutorContextType = {
53
- registerAction: (
50
+ registerAction: <TOptions = Record<string, any>>(
54
51
  type: string,
55
- handler: (
56
- action: ActionType,
57
- context?: Record<string, any>
58
- ) => Promise<ActionResult>
52
+ handler: ActionHandler<TOptions>,
53
+ stateResolver?: (entry?: ZappEntry) => any
59
54
  ) => void;
60
55
  unregisterAction: (type: string) => void;
56
+ registerActionState: (
57
+ type: string,
58
+ stateResolver: (entry?: ZappEntry) => any
59
+ ) => () => void;
60
+ getActionState: (type: string, entry?: ZappEntry) => any;
61
61
  handleAction: (
62
62
  action: ActionType,
63
- context?: Record<string, any>
63
+ context?: ActionExecutionContext
64
64
  ) => Promise<ActionResult>;
65
65
  handleActions: (
66
66
  actions: ActionType[],
67
- context: Record<string, any>
67
+ context?: ActionExecutionContext
68
68
  ) => Promise<ActionResult>;
69
69
  handleEntryActions: (
70
70
  entry: ZappEntry,
71
- context?: Record<string, any>
71
+ context?: ActionExecutionContext
72
72
  ) => Promise<ActionResult>;
73
73
  };
74
74
 
@@ -76,251 +76,79 @@ type Props = {
76
76
  children: React.ReactNode;
77
77
  };
78
78
 
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
79
  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
80
  actionExecutor.registerAction(
129
- "refreshComponent",
130
- async (_action, context) => {
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
- }
81
+ ACTION_TYPES.LOCAL_STORAGE_SET,
82
+ localStorageSetAction
182
83
  );
183
84
 
184
- actionExecutor.registerAction("switchLayout", async (action) => {
185
- log_info("handleAction: switchLayout event");
186
-
187
- await localStorage.setItem(
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;
85
+ actionExecutor.registerAction(
86
+ ACTION_TYPES.SESSION_STORAGE_SET,
87
+ sessionStorageSetAction
88
+ );
233
89
 
234
- const cloudEvent = await createCloudEvent({
235
- type: options.type || "com.applicaster.selector.action.v1",
236
- data,
237
- subject: options.subject || entry?.id,
238
- });
90
+ actionExecutor.registerAction(
91
+ ACTION_TYPES.LOCAL_STORAGE_REMOVE,
92
+ localStorageRemoveAction
93
+ );
239
94
 
240
- log_info("handleAction: sendCloudEvent event", { cloudEvent });
95
+ actionExecutor.registerAction(
96
+ ACTION_TYPES.SESSION_STORAGE_REMOVE,
97
+ sessionStorageRemoveAction
98
+ );
241
99
 
242
- const { error, code } = await sendCloudEvent(cloudEvent, options.url);
100
+ actionExecutor.registerAction(
101
+ ACTION_TYPES.REFRESH_COMPONENT,
102
+ refreshComponentAction
103
+ );
243
104
 
244
- if (error) {
245
- log_error("sendCloudEvent: error sending cloud event", { error });
105
+ actionExecutor.registerAction(ACTION_TYPES.SWITCH_LAYOUT, switchLayoutAction);
246
106
 
247
- return ActionResult.Error;
248
- }
107
+ actionExecutor.registerAction(ACTION_TYPES.APP_RESTART, appRestartAction);
249
108
 
250
- if (code && code >= 200 && code < 300 && !error) {
251
- log_info("sendCloudEvent: cloud event sent successfully");
109
+ actionExecutor.registerAction(
110
+ ACTION_TYPES.CONFIRM_DIALOG,
111
+ confirmDialogAction
112
+ );
252
113
 
253
- return ActionResult.Success;
254
- }
255
- } catch (error) {
256
- log_error("sendCloudEvent: error sending cloud event", {
257
- action,
258
- error,
259
- });
260
- }
114
+ actionExecutor.registerAction(ACTION_TYPES.SHOW_ALERT, showAlertAction);
261
115
 
262
- return ActionResult.Error;
263
- });
116
+ actionExecutor.registerAction(
117
+ ACTION_TYPES.SEND_CLOUD_EVENT,
118
+ sendCloudEventAction
119
+ );
264
120
 
265
121
  actionExecutor.registerAction(
266
- "sessionStorageToggleFlag",
267
- async (
268
- action: ActionType,
269
- context?: Record<string, any>
270
- ): Promise<ActionResult> => {
271
- return await sessionStorageToggleFlag(context, action);
272
- }
122
+ ACTION_TYPES.SESSION_STORAGE_TOGGLE_FLAG,
123
+ sessionStorageToggleFlagAction
273
124
  );
274
125
 
275
126
  actionExecutor.registerAction(
276
- "localStorageToggleFlag",
277
- async (
278
- action: ActionType,
279
- context?: Record<string, any>
280
- ): Promise<ActionResult> => {
281
- return await localStorageToggleFlag(context, action);
282
- }
127
+ ACTION_TYPES.LOCAL_STORAGE_TOGGLE_FLAG,
128
+ localStorageToggleFlagAction
283
129
  );
284
130
 
285
131
  actionExecutor.registerAction(
286
- "screenSetVariable",
287
- async (
288
- action: ActionType,
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
- );
132
+ ACTION_TYPES.SCREEN_SET_VARIABLE,
133
+ screenSetVariableAction
134
+ );
300
135
 
301
- return Promise.resolve(ActionResult.Success);
302
- }
136
+ actionExecutor.registerAction(
137
+ ACTION_TYPES.SCREEN_TOGGLE_FLAG,
138
+ screenToggleFlagAction
303
139
  );
304
140
 
305
141
  actionExecutor.registerAction(
306
- "screenToggleFlag",
307
- async (
308
- action: ActionType,
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
- );
142
+ ACTION_TYPES.OPEN_BOTTOM_SHEET,
143
+ openBottomSheetAction
144
+ );
320
145
 
321
- return Promise.resolve(ActionResult.Success);
322
- }
146
+ actionExecutor.registerAction(
147
+ ACTION_TYPES.DISMISS_BOTTOM_SHEET,
148
+ dismissBottomSheetAction
323
149
  );
150
+
151
+ actionExecutor.registerAction(ACTION_TYPES.SHOW_TOAST, showToastAction);
324
152
  };
325
153
 
326
154
  export const ActionExecutorContext =
@@ -333,11 +161,14 @@ export function withActionExecutor(Component) {
333
161
  const navigator = useNavigation();
334
162
  const rivers = useRivers();
335
163
  const contentTypes = useContentTypes();
164
+ const presentScreen = usePresentScreen();
336
165
 
337
166
  const handlers = useMemo(() => {
338
167
  return {
339
168
  unregisterAction: _actionExecutor.unregisterAction,
340
169
  registerAction: _actionExecutor.registerAction,
170
+ registerActionState: _actionExecutor.registerActionState,
171
+ getActionState: _actionExecutor.getActionState,
341
172
  handleAction: _actionExecutor.handleAction,
342
173
  handleActions: _actionExecutor.handleActions,
343
174
  handleEntryActions: _actionExecutor.handleEntryActions,
@@ -360,85 +191,31 @@ export function withActionExecutor(Component) {
360
191
 
361
192
  useEffect(() => {
362
193
  return _actionExecutor.registerAction(
363
- "navigateToScreen",
364
-
365
- async (action: ActionType, context?: Record<string, any>) => {
366
- const screenType = action.options?.typeMapping;
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
- }
194
+ ACTION_TYPES.NAVIGATE_TO_SCREEN,
195
+ createNavigateToScreenAction(navigator, rivers, contentTypes)
196
+ );
197
+ }, [navigator, rivers, contentTypes]);
429
198
 
430
- context?.callback?.({ success: false, error: null, abort: true });
199
+ useEffect(() => {
200
+ return _actionExecutor.registerAction(
201
+ ACTION_TYPES.PRESENT_SCREEN,
202
+ createPresentScreenAction(presentScreen)
203
+ );
204
+ }, [presentScreen]);
431
205
 
432
- if (navigationAction === "push") {
433
- navigator.push(river);
434
- } else {
435
- navigator.replace(river);
436
- }
206
+ useEffect(() => {
207
+ return _actionExecutor.registerAction(
208
+ ACTION_TYPES.GO_BACK,
209
+ createGoBackAction(navigator)
210
+ );
211
+ }, [navigator]);
437
212
 
438
- return ActionResult.Success;
439
- }
213
+ useEffect(() => {
214
+ return _actionExecutor.registerAction(
215
+ ACTION_TYPES.GO_HOME,
216
+ createGoHomeAction(navigator)
440
217
  );
441
- }, [navigator, rivers, contentTypes]);
218
+ }, [navigator]);
442
219
 
443
220
  return (
444
221
  <ActionExecutorContext.Provider value={handlers}>