@applicaster/zapp-react-native-utils 16.0.0-alpha.9534912292 → 16.0.0-alpha.9953202182
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actionsExecutor/ActionExecutor.ts +8 -10
- package/actionsExecutor/ActionExecutorContext.tsx +38 -345
- package/actionsExecutor/actions/appRestart.ts +24 -0
- package/actionsExecutor/actions/confirmDialog.ts +53 -0
- package/actionsExecutor/actions/index.ts +28 -0
- package/actionsExecutor/actions/localStorageRemove.ts +27 -0
- package/actionsExecutor/actions/localStorageSet.ts +28 -0
- package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
- package/actionsExecutor/actions/navigateToScreen.ts +123 -0
- package/actionsExecutor/actions/refreshComponent.ts +94 -0
- package/actionsExecutor/actions/screenSetVariable.ts +35 -0
- package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
- package/actionsExecutor/actions/sendCloudEvent.ts +88 -0
- package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
- package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
- package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
- package/actionsExecutor/actions/switchLayout.ts +40 -0
- package/actionsExecutor/types.ts +57 -0
- package/manifestUtils/_internals/index.js +6 -0
- package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
- package/manifestUtils/fieldUtils/index.js +125 -0
- package/manifestUtils/keys.js +8 -0
- package/manifestUtils/mobileAction/button/index.js +16 -0
- package/manifestUtils/mobileAction/container/index.js +3 -1
- package/manifestUtils/mobileAction/groups/defaults.js +3 -1
- package/package.json +2 -2
- package/reactHooks/actions/index.ts +51 -1
- package/riverComponetsMeasurementProvider/index.tsx +5 -1
- package/uiActionsRegistrator/index.ts +203 -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",
|
|
@@ -12,12 +13,12 @@ const { log_error, log_debug, log_info } = createLogger({
|
|
|
12
13
|
});
|
|
13
14
|
|
|
14
15
|
class ActionExecutor {
|
|
15
|
-
private registeredActions: Record<string,
|
|
16
|
-
// TODO: Remove context
|
|
16
|
+
private registeredActions: Record<string, ActionHandler> = {};
|
|
17
17
|
|
|
18
|
+
// TODO: Remove context
|
|
18
19
|
handleAction = async (
|
|
19
20
|
action: ActionType,
|
|
20
|
-
context?:
|
|
21
|
+
context?: ActionExecutionContext
|
|
21
22
|
): Promise<ActionResult> => {
|
|
22
23
|
const handler = this.registeredActions[action.type];
|
|
23
24
|
const entry = context?.entry as ZappEntry;
|
|
@@ -52,7 +53,7 @@ class ActionExecutor {
|
|
|
52
53
|
|
|
53
54
|
handleActions = async (
|
|
54
55
|
actionTypes: ActionType[],
|
|
55
|
-
context?:
|
|
56
|
+
context?: ActionExecutionContext
|
|
56
57
|
): Promise<ActionResult> => {
|
|
57
58
|
for (const action of actionTypes) {
|
|
58
59
|
// TODO: Handle action result error
|
|
@@ -70,7 +71,7 @@ class ActionExecutor {
|
|
|
70
71
|
|
|
71
72
|
handleEntryActions = async (
|
|
72
73
|
entry: ZappEntry,
|
|
73
|
-
context?:
|
|
74
|
+
context?: ActionExecutionContext
|
|
74
75
|
): Promise<ActionResult> => {
|
|
75
76
|
const tapActions = entry.extensions?.tap_actions?.actions;
|
|
76
77
|
|
|
@@ -98,12 +99,9 @@ class ActionExecutor {
|
|
|
98
99
|
delete this.registeredActions[actionType];
|
|
99
100
|
};
|
|
100
101
|
|
|
101
|
-
registerAction = (
|
|
102
|
+
registerAction = <TOptions = Record<string, any>>(
|
|
102
103
|
type: string,
|
|
103
|
-
handler:
|
|
104
|
-
action: ActionType,
|
|
105
|
-
context?: Record<string, any>
|
|
106
|
-
) => Promise<ActionResult>
|
|
104
|
+
handler: ActionHandler<TOptions>
|
|
107
105
|
) => {
|
|
108
106
|
if (this.registeredActions[type]) {
|
|
109
107
|
log_error(`registerAction: action type: ${type} already registered`);
|
|
@@ -5,44 +5,32 @@ import {
|
|
|
5
5
|
actionExecutor as _actionExecutor,
|
|
6
6
|
ActionResult,
|
|
7
7
|
} from "./ActionExecutor";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
batchRemoveFromStorage,
|
|
11
|
-
batchSave,
|
|
12
|
-
} from "../zappFrameworkUtils/localStorageHelper";
|
|
8
|
+
import { ActionExecutionContext, ActionHandler } from "./types";
|
|
9
|
+
import { batchRemoveAllFromNamespaceForStorage } from "../zappFrameworkUtils/localStorageHelper";
|
|
13
10
|
import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
|
|
14
11
|
|
|
15
|
-
import * as QuickBrickManager from "@applicaster/zapp-react-native-bridge/QuickBrick";
|
|
16
|
-
import { QUICK_BRICK_EVENTS } from "@applicaster/zapp-react-native-bridge/QuickBrick";
|
|
17
|
-
import { showConfirmationDialog } from "../alertUtils";
|
|
18
|
-
import { createCloudEvent, sendCloudEvent } from "../cloudEventsUtils";
|
|
19
|
-
import { createLogger } from "../logger";
|
|
20
|
-
import { ACTIVE_LAYOUT_ID_STORAGE_KEY } from "@applicaster/quick-brick-core/App/remoteContextReloader/consts";
|
|
21
|
-
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
22
|
-
import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
|
|
23
|
-
import {
|
|
24
|
-
EntryResolver,
|
|
25
|
-
resolveObjectValues,
|
|
26
|
-
} from "../appUtils/contextKeysManager/contextResolver";
|
|
27
12
|
import { useNavigation, useRivers } from "../reactHooks";
|
|
28
|
-
import {
|
|
29
|
-
getInflatedDataSourceUrl,
|
|
30
|
-
getSearchContext,
|
|
31
|
-
} from "../reactHooks/feed/useInflatedUrl";
|
|
32
|
-
|
|
33
13
|
import { useContentTypes } from "@applicaster/zapp-react-native-redux/hooks";
|
|
34
14
|
import { useSubscriberFor } from "../reactHooks/useSubscriberFor";
|
|
35
15
|
import { APP_EVENTS } from "../appUtils/events";
|
|
36
|
-
import {
|
|
37
|
-
localStorageToggleFlag,
|
|
38
|
-
sessionStorageToggleFlag,
|
|
39
|
-
} from "./StorageActions";
|
|
16
|
+
import { createLogger } from "../logger";
|
|
40
17
|
|
|
41
|
-
import { screenSetVariable, screenToggleFlag } from "./ScreenActions";
|
|
42
18
|
import {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
19
|
+
appRestartAction,
|
|
20
|
+
confirmDialogAction,
|
|
21
|
+
createNavigateToScreenAction,
|
|
22
|
+
localStorageRemoveAction,
|
|
23
|
+
localStorageSetAction,
|
|
24
|
+
localStorageToggleFlagAction,
|
|
25
|
+
refreshComponentAction,
|
|
26
|
+
screenSetVariableAction,
|
|
27
|
+
screenToggleFlagAction,
|
|
28
|
+
sendCloudEventAction,
|
|
29
|
+
sessionStorageRemoveAction,
|
|
30
|
+
sessionStorageSetAction,
|
|
31
|
+
sessionStorageToggleFlagAction,
|
|
32
|
+
switchLayoutAction,
|
|
33
|
+
} from "./actions";
|
|
46
34
|
|
|
47
35
|
export const { log_error, log_info, log_debug } = createLogger({
|
|
48
36
|
subsystem: "ActionExecutorContext",
|
|
@@ -50,25 +38,22 @@ export const { log_error, log_info, log_debug } = createLogger({
|
|
|
50
38
|
});
|
|
51
39
|
|
|
52
40
|
export type ActionExecutorContextType = {
|
|
53
|
-
registerAction: (
|
|
41
|
+
registerAction: <TOptions = Record<string, any>>(
|
|
54
42
|
type: string,
|
|
55
|
-
handler:
|
|
56
|
-
action: ActionType,
|
|
57
|
-
context?: Record<string, any>
|
|
58
|
-
) => Promise<ActionResult>
|
|
43
|
+
handler: ActionHandler<TOptions>
|
|
59
44
|
) => void;
|
|
60
45
|
unregisterAction: (type: string) => void;
|
|
61
46
|
handleAction: (
|
|
62
47
|
action: ActionType,
|
|
63
|
-
context?:
|
|
48
|
+
context?: ActionExecutionContext
|
|
64
49
|
) => Promise<ActionResult>;
|
|
65
50
|
handleActions: (
|
|
66
51
|
actions: ActionType[],
|
|
67
|
-
context
|
|
52
|
+
context?: ActionExecutionContext
|
|
68
53
|
) => Promise<ActionResult>;
|
|
69
54
|
handleEntryActions: (
|
|
70
55
|
entry: ZappEntry,
|
|
71
|
-
context?:
|
|
56
|
+
context?: ActionExecutionContext
|
|
72
57
|
) => Promise<ActionResult>;
|
|
73
58
|
};
|
|
74
59
|
|
|
@@ -76,251 +61,34 @@ type Props = {
|
|
|
76
61
|
children: React.ReactNode;
|
|
77
62
|
};
|
|
78
63
|
|
|
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
64
|
const prepareDefaultActions = (actionExecutor) => {
|
|
96
|
-
actionExecutor.registerAction("localStorageSet",
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
});
|
|
65
|
+
actionExecutor.registerAction("localStorageSet", localStorageSetAction);
|
|
66
|
+
actionExecutor.registerAction("sessionStorageSet", sessionStorageSetAction);
|
|
67
|
+
actionExecutor.registerAction("localStorageRemove", localStorageRemoveAction);
|
|
127
68
|
|
|
128
69
|
actionExecutor.registerAction(
|
|
129
|
-
"
|
|
130
|
-
|
|
131
|
-
const dispatch = appStore.getDispatch();
|
|
132
|
-
|
|
133
|
-
const parentComponent = findParentComponent(
|
|
134
|
-
context?.component?.id,
|
|
135
|
-
context?.screenData
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
const componentSource = context?.component?.data?.source;
|
|
139
|
-
|
|
140
|
-
const componentData = componentSource
|
|
141
|
-
? context.component.data
|
|
142
|
-
: parentComponent?.data;
|
|
143
|
-
|
|
144
|
-
const source = componentData?.source;
|
|
145
|
-
const mapping = componentData?.mapping;
|
|
146
|
-
|
|
147
|
-
let dataSource = source;
|
|
148
|
-
|
|
149
|
-
if (source && mapping) {
|
|
150
|
-
dataSource =
|
|
151
|
-
getInflatedDataSourceUrl({
|
|
152
|
-
source,
|
|
153
|
-
contexts: {
|
|
154
|
-
entry: context?.screenEntry,
|
|
155
|
-
screen: context?.screenData,
|
|
156
|
-
search: getSearchContext(null, mapping),
|
|
157
|
-
},
|
|
158
|
-
mapping,
|
|
159
|
-
}) || source;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
log_info(`handleAction: refreshComponent for dataSource:${dataSource}`, {
|
|
163
|
-
source,
|
|
164
|
-
inflatedUrl: dataSource,
|
|
165
|
-
mapping,
|
|
166
|
-
entryContextId: context?.entryContext?.id,
|
|
167
|
-
entryId: context?.entry?.id,
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
// TODO: In theory we should wait callback to complete, before completing the action, but now it's not needed
|
|
171
|
-
// TODO: handle focused item removal
|
|
172
|
-
dispatch(
|
|
173
|
-
loadPipesData(dataSource, {
|
|
174
|
-
silentRefresh: false,
|
|
175
|
-
clearCache: true,
|
|
176
|
-
riverId: context?.screenData?.id,
|
|
177
|
-
})
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
return ActionResult.Success;
|
|
181
|
-
}
|
|
70
|
+
"sessionStorageRemove",
|
|
71
|
+
sessionStorageRemoveAction
|
|
182
72
|
);
|
|
183
73
|
|
|
184
|
-
actionExecutor.registerAction("
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
action.options.layoutId
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
QuickBrickManager.sendQuickBrickEvent(QUICK_BRICK_EVENTS.FORCE_APP_RELOAD);
|
|
193
|
-
|
|
194
|
-
return ActionResult.Success;
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
actionExecutor.registerAction("appRestart", async () => {
|
|
198
|
-
log_info(`handleAction: ${QUICK_BRICK_EVENTS.FORCE_APP_RELOAD} event`);
|
|
199
|
-
|
|
200
|
-
QuickBrickManager.sendQuickBrickEvent(QUICK_BRICK_EVENTS.FORCE_APP_RELOAD);
|
|
201
|
-
|
|
202
|
-
return ActionResult.Success;
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
actionExecutor.registerAction("confirmDialog", async (action) => {
|
|
206
|
-
log_info("handleAction: confirmDialog event");
|
|
207
|
-
|
|
208
|
-
return new Promise<ActionResult>((resolve) => {
|
|
209
|
-
showConfirmationDialog({
|
|
210
|
-
...action.options,
|
|
211
|
-
confirmCompletion: () => resolve(ActionResult.Success),
|
|
212
|
-
cancelCompletion: () => resolve(ActionResult.Cancel),
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
actionExecutor.registerAction("sendCloudEvent", async (action, context) => {
|
|
218
|
-
try {
|
|
219
|
-
const options = action.options;
|
|
220
|
-
|
|
221
|
-
const entry = context?.entry || {};
|
|
222
|
-
const entryResolver = new EntryResolver(entry);
|
|
223
|
-
const screenData = context?.screenStateStore?.getState().data || {};
|
|
224
|
-
const screenResolver = new EntryResolver(screenData || {});
|
|
225
|
-
|
|
226
|
-
const data =
|
|
227
|
-
options?.data && options.inflateData
|
|
228
|
-
? await resolveObjectValues(options.data, {
|
|
229
|
-
entry: entryResolver,
|
|
230
|
-
screen: screenResolver,
|
|
231
|
-
})
|
|
232
|
-
: options?.data || entry;
|
|
233
|
-
|
|
234
|
-
const cloudEvent = await createCloudEvent({
|
|
235
|
-
type: options.type || "com.applicaster.selector.action.v1",
|
|
236
|
-
data,
|
|
237
|
-
subject: options.subject || entry?.id,
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
log_info("handleAction: sendCloudEvent event", { cloudEvent });
|
|
241
|
-
|
|
242
|
-
const { error, code } = await sendCloudEvent(cloudEvent, options.url);
|
|
243
|
-
|
|
244
|
-
if (error) {
|
|
245
|
-
log_error("sendCloudEvent: error sending cloud event", { error });
|
|
246
|
-
|
|
247
|
-
return ActionResult.Error;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (code && code >= 200 && code < 300 && !error) {
|
|
251
|
-
log_info("sendCloudEvent: cloud event sent successfully");
|
|
252
|
-
|
|
253
|
-
return ActionResult.Success;
|
|
254
|
-
}
|
|
255
|
-
} catch (error) {
|
|
256
|
-
log_error("sendCloudEvent: error sending cloud event", {
|
|
257
|
-
action,
|
|
258
|
-
error,
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
return ActionResult.Error;
|
|
263
|
-
});
|
|
74
|
+
actionExecutor.registerAction("refreshComponent", refreshComponentAction);
|
|
75
|
+
actionExecutor.registerAction("switchLayout", switchLayoutAction);
|
|
76
|
+
actionExecutor.registerAction("appRestart", appRestartAction);
|
|
77
|
+
actionExecutor.registerAction("confirmDialog", confirmDialogAction);
|
|
78
|
+
actionExecutor.registerAction("sendCloudEvent", sendCloudEventAction);
|
|
264
79
|
|
|
265
80
|
actionExecutor.registerAction(
|
|
266
81
|
"sessionStorageToggleFlag",
|
|
267
|
-
|
|
268
|
-
action: ActionType,
|
|
269
|
-
context?: Record<string, any>
|
|
270
|
-
): Promise<ActionResult> => {
|
|
271
|
-
return await sessionStorageToggleFlag(context, action);
|
|
272
|
-
}
|
|
82
|
+
sessionStorageToggleFlagAction
|
|
273
83
|
);
|
|
274
84
|
|
|
275
85
|
actionExecutor.registerAction(
|
|
276
86
|
"localStorageToggleFlag",
|
|
277
|
-
|
|
278
|
-
action: ActionType,
|
|
279
|
-
context?: Record<string, any>
|
|
280
|
-
): Promise<ActionResult> => {
|
|
281
|
-
return await localStorageToggleFlag(context, action);
|
|
282
|
-
}
|
|
283
|
-
);
|
|
284
|
-
|
|
285
|
-
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
|
-
);
|
|
300
|
-
|
|
301
|
-
return Promise.resolve(ActionResult.Success);
|
|
302
|
-
}
|
|
87
|
+
localStorageToggleFlagAction
|
|
303
88
|
);
|
|
304
89
|
|
|
305
|
-
actionExecutor.registerAction(
|
|
306
|
-
|
|
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
|
-
);
|
|
320
|
-
|
|
321
|
-
return Promise.resolve(ActionResult.Success);
|
|
322
|
-
}
|
|
323
|
-
);
|
|
90
|
+
actionExecutor.registerAction("screenSetVariable", screenSetVariableAction);
|
|
91
|
+
actionExecutor.registerAction("screenToggleFlag", screenToggleFlagAction);
|
|
324
92
|
};
|
|
325
93
|
|
|
326
94
|
export const ActionExecutorContext =
|
|
@@ -361,82 +129,7 @@ export function withActionExecutor(Component) {
|
|
|
361
129
|
useEffect(() => {
|
|
362
130
|
return _actionExecutor.registerAction(
|
|
363
131
|
"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
|
-
}
|
|
429
|
-
|
|
430
|
-
context?.callback?.({ success: false, error: null, abort: true });
|
|
431
|
-
|
|
432
|
-
if (navigationAction === "push") {
|
|
433
|
-
navigator.push(river);
|
|
434
|
-
} else {
|
|
435
|
-
navigator.replace(river);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
return ActionResult.Success;
|
|
439
|
-
}
|
|
132
|
+
createNavigateToScreenAction(navigator, rivers, contentTypes)
|
|
440
133
|
);
|
|
441
134
|
}, [navigator, rivers, contentTypes]);
|
|
442
135
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import * as QuickBrickManager from "@applicaster/zapp-react-native-bridge/QuickBrick";
|
|
3
|
+
import { QUICK_BRICK_EVENTS } from "@applicaster/zapp-react-native-bridge/QuickBrick";
|
|
4
|
+
import { ActionResult } from "../ActionExecutor";
|
|
5
|
+
import { ActionHandler } from "../types";
|
|
6
|
+
import { createLogger } from "../../logger";
|
|
7
|
+
|
|
8
|
+
const { log_info } = createLogger({
|
|
9
|
+
subsystem: "ActionExecutorContext",
|
|
10
|
+
category: "General",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Restarts the application by triggering a force reload event.
|
|
15
|
+
* This action does not require any options or context.
|
|
16
|
+
*/
|
|
17
|
+
export const appRestartAction: ActionHandler =
|
|
18
|
+
async (): Promise<ActionResult> => {
|
|
19
|
+
log_info(`handleAction: ${QUICK_BRICK_EVENTS.FORCE_APP_RELOAD} event`);
|
|
20
|
+
|
|
21
|
+
QuickBrickManager.sendQuickBrickEvent(QUICK_BRICK_EVENTS.FORCE_APP_RELOAD);
|
|
22
|
+
|
|
23
|
+
return ActionResult.Success;
|
|
24
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import { showConfirmationDialog } from "../../alertUtils";
|
|
3
|
+
import { ActionResult } from "../ActionExecutor";
|
|
4
|
+
import { ActionHandler } from "../types";
|
|
5
|
+
import { createLogger } from "../../logger";
|
|
6
|
+
|
|
7
|
+
const { log_info } = createLogger({
|
|
8
|
+
subsystem: "ActionExecutorContext",
|
|
9
|
+
category: "General",
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Options for the confirmDialog action.
|
|
14
|
+
*/
|
|
15
|
+
export interface ConfirmDialogOptions {
|
|
16
|
+
/** Dialog title (required) */
|
|
17
|
+
title: string;
|
|
18
|
+
|
|
19
|
+
/** Dialog message */
|
|
20
|
+
message?: string;
|
|
21
|
+
|
|
22
|
+
/** Confirm button text */
|
|
23
|
+
okButtonText?: string;
|
|
24
|
+
|
|
25
|
+
/** Cancel button text */
|
|
26
|
+
cancelButtonText?: string;
|
|
27
|
+
|
|
28
|
+
/** Callback when confirmed (deprecated - use action result) */
|
|
29
|
+
confirmCompletion?: () => void;
|
|
30
|
+
|
|
31
|
+
/** Callback when cancelled (deprecated - use action result) */
|
|
32
|
+
cancelCompletion?: () => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Shows a confirmation dialog to the user.
|
|
37
|
+
* Resolves to Success if user confirms, Cancel if user dismisses.
|
|
38
|
+
*/
|
|
39
|
+
export const confirmDialogAction: ActionHandler<ConfirmDialogOptions> = async (
|
|
40
|
+
action
|
|
41
|
+
): Promise<ActionResult> => {
|
|
42
|
+
log_info("handleAction: confirmDialog event");
|
|
43
|
+
|
|
44
|
+
const options = action.options as ConfirmDialogOptions;
|
|
45
|
+
|
|
46
|
+
return new Promise<ActionResult>((resolve) => {
|
|
47
|
+
showConfirmationDialog({
|
|
48
|
+
...options,
|
|
49
|
+
confirmCompletion: () => resolve(ActionResult.Success),
|
|
50
|
+
cancelCompletion: () => resolve(ActionResult.Cancel),
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Export action handlers
|
|
2
|
+
export { localStorageSetAction } from "./localStorageSet";
|
|
3
|
+
|
|
4
|
+
export { sessionStorageSetAction } from "./sessionStorageSet";
|
|
5
|
+
|
|
6
|
+
export { localStorageRemoveAction } from "./localStorageRemove";
|
|
7
|
+
|
|
8
|
+
export { sessionStorageRemoveAction } from "./sessionStorageRemove";
|
|
9
|
+
|
|
10
|
+
export { refreshComponentAction } from "./refreshComponent";
|
|
11
|
+
|
|
12
|
+
export { switchLayoutAction } from "./switchLayout";
|
|
13
|
+
|
|
14
|
+
export { appRestartAction } from "./appRestart";
|
|
15
|
+
|
|
16
|
+
export { confirmDialogAction } from "./confirmDialog";
|
|
17
|
+
|
|
18
|
+
export { sendCloudEventAction } from "./sendCloudEvent";
|
|
19
|
+
|
|
20
|
+
export { sessionStorageToggleFlagAction } from "./sessionStorageToggleFlag";
|
|
21
|
+
|
|
22
|
+
export { localStorageToggleFlagAction } from "./localStorageToggleFlag";
|
|
23
|
+
|
|
24
|
+
export { screenSetVariableAction } from "./screenSetVariable";
|
|
25
|
+
|
|
26
|
+
export { screenToggleFlagAction } from "./screenToggleFlag";
|
|
27
|
+
|
|
28
|
+
export { createNavigateToScreenAction } from "./navigateToScreen";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
3
|
+
import { batchRemoveFromStorage } from "../../zappFrameworkUtils/localStorageHelper";
|
|
4
|
+
import { ActionResult } from "../ActionExecutor";
|
|
5
|
+
import { ActionHandler } from "../types";
|
|
6
|
+
import { StorageValuesToRemove } from "../../zappFrameworkUtils/types";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Options for localStorage/sessionStorage remove actions.
|
|
10
|
+
*/
|
|
11
|
+
export interface StorageRemoveOptions {
|
|
12
|
+
/** The keys to remove, organized by namespace */
|
|
13
|
+
content: StorageValuesToRemove;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Removes values from local storage organized by namespaces.
|
|
18
|
+
*/
|
|
19
|
+
export const localStorageRemoveAction: ActionHandler<
|
|
20
|
+
StorageRemoveOptions
|
|
21
|
+
> = async (action): Promise<ActionResult> => {
|
|
22
|
+
const namespaces = action.options.content;
|
|
23
|
+
await batchRemoveFromStorage(namespaces, localStorage);
|
|
24
|
+
// TODO: Add support for ownershipKey and ownershipNamespace
|
|
25
|
+
|
|
26
|
+
return ActionResult.Success;
|
|
27
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
3
|
+
import { batchSave } from "../../zappFrameworkUtils/localStorageHelper";
|
|
4
|
+
import { ActionResult } from "../ActionExecutor";
|
|
5
|
+
import { ActionHandler } from "../types";
|
|
6
|
+
import { StorageValuesToAdd } from "../../zappFrameworkUtils/types";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Options for localStorage/sessionStorage set actions.
|
|
10
|
+
*/
|
|
11
|
+
export interface StorageSetOptions {
|
|
12
|
+
/** The values to save, organized by namespace */
|
|
13
|
+
content: StorageValuesToAdd;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Saves values to local storage organized by namespaces.
|
|
18
|
+
* The values persist across app sessions.
|
|
19
|
+
*/
|
|
20
|
+
export const localStorageSetAction: ActionHandler<StorageSetOptions> = async (
|
|
21
|
+
action
|
|
22
|
+
): Promise<ActionResult> => {
|
|
23
|
+
const namespaces = action.options.content;
|
|
24
|
+
await batchSave(namespaces, localStorage);
|
|
25
|
+
// TODO: Add support for ownershipKey and ownershipNamespace
|
|
26
|
+
|
|
27
|
+
return ActionResult.Success;
|
|
28
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import { localStorageToggleFlag } from "../StorageActions";
|
|
3
|
+
import { ActionResult } from "../ActionExecutor";
|
|
4
|
+
import { ActionHandler, ActionExecutionContext } from "../types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Options for storage toggle flag actions (localStorage/sessionStorage).
|
|
8
|
+
*/
|
|
9
|
+
export interface StorageToggleFlagOptions {
|
|
10
|
+
/** The key/namespace for storing the flag */
|
|
11
|
+
key: string;
|
|
12
|
+
|
|
13
|
+
/** Path to extract the tag from entry */
|
|
14
|
+
selector?: string;
|
|
15
|
+
|
|
16
|
+
/** Maximum number of items that can be selected */
|
|
17
|
+
max_items?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Toggles a flag in local storage (adds or removes an item from a collection).
|
|
22
|
+
* Used for features like favorites, watchlists, etc.
|
|
23
|
+
*/
|
|
24
|
+
export const localStorageToggleFlagAction: ActionHandler<
|
|
25
|
+
StorageToggleFlagOptions
|
|
26
|
+
> = async (action, context?: ActionExecutionContext): Promise<ActionResult> => {
|
|
27
|
+
return await localStorageToggleFlag(context, action);
|
|
28
|
+
};
|