@applicaster/zapp-react-native-utils 13.0.0-rc.19 → 13.0.0-rc.20
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.
|
@@ -17,9 +17,10 @@ class ActionExecutor {
|
|
|
17
17
|
|
|
18
18
|
handleAction = async (
|
|
19
19
|
action: ActionType,
|
|
20
|
-
|
|
20
|
+
context?: Record<string, any>
|
|
21
21
|
): Promise<ActionResult> => {
|
|
22
22
|
const handler = this.registeredActions[action.type];
|
|
23
|
+
const entry = context?.entry as ZappEntry;
|
|
23
24
|
|
|
24
25
|
if (!handler) {
|
|
25
26
|
log_error(
|
|
@@ -38,11 +39,11 @@ class ActionExecutor {
|
|
|
38
39
|
);
|
|
39
40
|
|
|
40
41
|
try {
|
|
41
|
-
return handler(action,
|
|
42
|
+
return handler(action, context);
|
|
42
43
|
} catch (error) {
|
|
43
44
|
log_error(
|
|
44
45
|
`handleAction: error handling action type: ${action.type}, message: ${error.message}`,
|
|
45
|
-
{ action,
|
|
46
|
+
{ action, context, error }
|
|
46
47
|
);
|
|
47
48
|
|
|
48
49
|
throw error;
|
|
@@ -51,11 +52,11 @@ class ActionExecutor {
|
|
|
51
52
|
|
|
52
53
|
handleActions = async (
|
|
53
54
|
actionTypes: ActionType[],
|
|
54
|
-
|
|
55
|
+
context?: Record<string, any>
|
|
55
56
|
): Promise<ActionResult> => {
|
|
56
57
|
for (const action of actionTypes) {
|
|
57
58
|
// TODO: Handle action result error
|
|
58
|
-
const result = await this.handleAction(action,
|
|
59
|
+
const result = await this.handleAction(action, context);
|
|
59
60
|
|
|
60
61
|
if (result === ActionResult.Cancel) {
|
|
61
62
|
log_info(`handleActions: action: ${action.type} canceled`);
|
|
@@ -67,7 +68,10 @@ class ActionExecutor {
|
|
|
67
68
|
return ActionResult.Success;
|
|
68
69
|
};
|
|
69
70
|
|
|
70
|
-
handleEntryActions = async (
|
|
71
|
+
handleEntryActions = async (
|
|
72
|
+
entry: ZappEntry,
|
|
73
|
+
context?: Record<string, any>
|
|
74
|
+
): Promise<ActionResult> => {
|
|
71
75
|
const tapActions = entry.extensions?.tap_actions?.actions;
|
|
72
76
|
|
|
73
77
|
if (!tapActions) {
|
|
@@ -77,7 +81,7 @@ class ActionExecutor {
|
|
|
77
81
|
if (!Array.isArray(tapActions)) {
|
|
78
82
|
log_error(
|
|
79
83
|
`handleEntryActions: tapActions is not an array for id: ${entry.id} title: ${entry.title}`,
|
|
80
|
-
{ entry }
|
|
84
|
+
{ context, entry }
|
|
81
85
|
);
|
|
82
86
|
|
|
83
87
|
return;
|
|
@@ -87,7 +91,7 @@ class ActionExecutor {
|
|
|
87
91
|
return;
|
|
88
92
|
}
|
|
89
93
|
|
|
90
|
-
await this.handleActions(tapActions, entry);
|
|
94
|
+
await this.handleActions(tapActions, { ...context, entry });
|
|
91
95
|
};
|
|
92
96
|
|
|
93
97
|
unregisterAction = (actionType: string) => {
|
|
@@ -96,7 +100,10 @@ class ActionExecutor {
|
|
|
96
100
|
|
|
97
101
|
registerAction = (
|
|
98
102
|
type: string,
|
|
99
|
-
handler: (
|
|
103
|
+
handler: (
|
|
104
|
+
action: ActionType,
|
|
105
|
+
context?: Record<string, any>
|
|
106
|
+
) => Promise<ActionResult>
|
|
100
107
|
) => {
|
|
101
108
|
if (this.registeredActions[type]) {
|
|
102
109
|
log_error(`registerAction: action type: ${type} already registered`);
|
|
@@ -13,6 +13,8 @@ import { createCloudEvent, sendCloudEvent } from "../cloudEventsUtils";
|
|
|
13
13
|
import { createLogger } from "../logger";
|
|
14
14
|
import { StorageMultiSelectProvider } from "@applicaster/zapp-react-native-bridge/ZappStorage/StorageMultiSelectProvider";
|
|
15
15
|
import { ACTIVE_LAYOUT_ID_STORAGE_KEY } from "@applicaster/quick-brick-core/App/remoteContextReloader/consts";
|
|
16
|
+
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
17
|
+
import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
|
|
16
18
|
import {
|
|
17
19
|
EntryResolver,
|
|
18
20
|
resolveObjectValues,
|
|
@@ -26,15 +28,24 @@ const { log_error, log_info } = createLogger({
|
|
|
26
28
|
type ActionExecutorContextType = {
|
|
27
29
|
registerAction: (
|
|
28
30
|
type: string,
|
|
29
|
-
handler: (
|
|
31
|
+
handler: (
|
|
32
|
+
action: ActionType,
|
|
33
|
+
context?: Record<string, any>
|
|
34
|
+
) => Promise<ActionResult>
|
|
30
35
|
) => void;
|
|
31
36
|
unregisterAction: (type: string) => void;
|
|
32
|
-
handleAction: (
|
|
37
|
+
handleAction: (
|
|
38
|
+
action: ActionType,
|
|
39
|
+
context?: Record<string, any>
|
|
40
|
+
) => Promise<ActionResult>;
|
|
33
41
|
handleActions: (
|
|
34
42
|
actions: ActionType[],
|
|
35
|
-
|
|
43
|
+
context: Record<string, any>
|
|
44
|
+
) => Promise<ActionResult>;
|
|
45
|
+
handleEntryActions: (
|
|
46
|
+
entry: ZappEntry,
|
|
47
|
+
context?: Record<string, any>
|
|
36
48
|
) => Promise<ActionResult>;
|
|
37
|
-
handleEntryActions: (entry: ZappEntry) => Promise<ActionResult>;
|
|
38
49
|
};
|
|
39
50
|
type Props = {
|
|
40
51
|
children: React.ReactNode;
|
|
@@ -49,6 +60,31 @@ const prepareDefaultActions = (actionExecutor) => {
|
|
|
49
60
|
return ActionResult.Success;
|
|
50
61
|
});
|
|
51
62
|
|
|
63
|
+
actionExecutor.registerAction(
|
|
64
|
+
"refreshComponent",
|
|
65
|
+
async (_action, context) => {
|
|
66
|
+
const dispatch = appStore.getDispatch();
|
|
67
|
+
|
|
68
|
+
log_info("handleAction: refreshComponent event");
|
|
69
|
+
|
|
70
|
+
const dataSource = context?.component?.data?.source;
|
|
71
|
+
|
|
72
|
+
// TODO: Later we can pass component ids to do refresh instead of current one
|
|
73
|
+
// TODO: In theory we should wait callback to complete, before completing the action, but now it's not needed
|
|
74
|
+
// TODO: handle focused item removal
|
|
75
|
+
dispatch(
|
|
76
|
+
loadPipesData(dataSource, {
|
|
77
|
+
silentRefresh: false,
|
|
78
|
+
clearCache: true,
|
|
79
|
+
callback: (_data) => {},
|
|
80
|
+
riverId: context?.screenData?.id,
|
|
81
|
+
})
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
return ActionResult.Success;
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
|
|
52
88
|
actionExecutor.registerAction("switchLayout", async (action) => {
|
|
53
89
|
log_info("handleAction: switchLayout event");
|
|
54
90
|
|
|
@@ -84,10 +120,11 @@ const prepareDefaultActions = (actionExecutor) => {
|
|
|
84
120
|
return confirmationPromise;
|
|
85
121
|
});
|
|
86
122
|
|
|
87
|
-
actionExecutor.registerAction("sendCloudEvent", async (action,
|
|
123
|
+
actionExecutor.registerAction("sendCloudEvent", async (action, context) => {
|
|
88
124
|
try {
|
|
89
125
|
const options = action.options;
|
|
90
126
|
|
|
127
|
+
const entry = context?.entry || {};
|
|
91
128
|
const entryResolver = new EntryResolver(entry);
|
|
92
129
|
|
|
93
130
|
const data =
|
|
@@ -128,9 +165,12 @@ const prepareDefaultActions = (actionExecutor) => {
|
|
|
128
165
|
|
|
129
166
|
actionExecutor.registerAction(
|
|
130
167
|
"localStorageToggleFlag",
|
|
131
|
-
async (
|
|
168
|
+
async (
|
|
169
|
+
action: ActionType,
|
|
170
|
+
context?: Record<string, any>
|
|
171
|
+
): Promise<ActionResult> => {
|
|
132
172
|
const keyNamespace = action.options?.key;
|
|
133
|
-
const tag = entry?.extensions?.tag;
|
|
173
|
+
const tag = context?.entry?.extensions?.tag;
|
|
134
174
|
|
|
135
175
|
if (keyNamespace && tag) {
|
|
136
176
|
const multiSelectProvider =
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "13.0.0-rc.
|
|
3
|
+
"version": "13.0.0-rc.20",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "13.0.0-rc.
|
|
31
|
+
"@applicaster/applicaster-types": "13.0.0-rc.20",
|
|
32
32
|
"buffer": "^5.2.1",
|
|
33
33
|
"camelize": "^1.0.0",
|
|
34
34
|
"create-react-context": "^0.2.3",
|
|
@@ -25,6 +25,11 @@ jest.mock("@applicaster/zapp-react-native-utils/analyticsUtils/", () => ({
|
|
|
25
25
|
}),
|
|
26
26
|
}));
|
|
27
27
|
|
|
28
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/screen", () => ({
|
|
29
|
+
useTargetScreenData: jest.fn(() => ({})),
|
|
30
|
+
useCurrentScreenData: jest.fn(() => ({})),
|
|
31
|
+
}));
|
|
32
|
+
|
|
28
33
|
jest.mock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
|
|
29
34
|
...jest.requireActual(
|
|
30
35
|
"@applicaster/zapp-react-native-ui-components/Contexts"
|
|
@@ -16,6 +16,7 @@ import { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/acti
|
|
|
16
16
|
import { isFunction, noop } from "../../functionUtils";
|
|
17
17
|
import { useSendAnalyticsOnPress } from "../analytics";
|
|
18
18
|
import { logOnPress, warnEmptyContentType } from "./helpers";
|
|
19
|
+
import { useCurrentScreenData } from "../screen";
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* If onCellTap is defined execute the function and
|
|
@@ -44,6 +45,7 @@ export const useCellClick = ({
|
|
|
44
45
|
|
|
45
46
|
const onCellTap: Option<Function> = React.useContext(CellTapContext);
|
|
46
47
|
const actionExecutor = React.useContext(ActionExecutorContext);
|
|
48
|
+
const screenData = useCurrentScreenData();
|
|
47
49
|
|
|
48
50
|
const cellSelectable = toBooleanWithDefaultTrue(
|
|
49
51
|
component?.rules?.component_cells_selectable
|
|
@@ -78,7 +80,10 @@ export const useCellClick = ({
|
|
|
78
80
|
logOnPress(selectedItem, pathname, component, onCellTap);
|
|
79
81
|
|
|
80
82
|
if (selectedItem) {
|
|
81
|
-
await actionExecutor?.handleEntryActions(selectedItem
|
|
83
|
+
await actionExecutor?.handleEntryActions(selectedItem, {
|
|
84
|
+
component,
|
|
85
|
+
screenData,
|
|
86
|
+
});
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
if (selectedItem?.type?.value === "action") {
|
|
@@ -111,6 +116,7 @@ export const useCellClick = ({
|
|
|
111
116
|
pathname,
|
|
112
117
|
push,
|
|
113
118
|
sendAnalyticsOnPress,
|
|
119
|
+
screenData,
|
|
114
120
|
]
|
|
115
121
|
);
|
|
116
122
|
|