@applicaster/zapp-react-native-utils 14.0.0-alpha.5974411329 → 14.0.0-alpha.6240202185
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/ActionExecutorContext.tsx +83 -60
- package/analyticsUtils/AnalyticsEvents/helper.ts +1 -1
- package/appUtils/contextKeysManager/contextResolver.ts +1 -31
- package/package.json +2 -2
- package/reactHooks/cell-click/index.ts +1 -8
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +0 -20
- package/reactHooks/feed/useFeedLoader.tsx +5 -14
- package/reactHooks/navigation/useRoute.ts +2 -7
- package/actionsExecutor/ScreenActions.ts +0 -163
- package/actionsExecutor/StorageActions.ts +0 -110
- package/actionsExecutor/feedDecorator.ts +0 -171
- package/actionsExecutor/screenResolver.ts +0 -11
- package/reactHooks/navigation/useScreenStateStore.ts +0 -8
- package/storage/ScreenSingleValueProvider.ts +0 -201
- package/storage/ScreenStateMultiSelectProvider.ts +0 -290
- package/storage/StorageMultiSelectProvider.ts +0 -192
- package/storage/StorageSingleSelectProvider.ts +0 -108
|
@@ -16,6 +16,7 @@ import { QUICK_BRICK_EVENTS } from "@applicaster/zapp-react-native-bridge/QuickB
|
|
|
16
16
|
import { showConfirmationDialog } from "../alertUtils";
|
|
17
17
|
import { createCloudEvent, sendCloudEvent } from "../cloudEventsUtils";
|
|
18
18
|
import { createLogger } from "../logger";
|
|
19
|
+
import { StorageMultiSelectProvider } from "@applicaster/zapp-react-native-bridge/ZappStorage/StorageMultiSelectProvider";
|
|
19
20
|
import { ACTIVE_LAYOUT_ID_STORAGE_KEY } from "@applicaster/quick-brick-core/App/remoteContextReloader/consts";
|
|
20
21
|
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
21
22
|
import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
|
|
@@ -24,19 +25,15 @@ import {
|
|
|
24
25
|
resolveObjectValues,
|
|
25
26
|
} from "../appUtils/contextKeysManager/contextResolver";
|
|
26
27
|
import { useNavigation } from "../reactHooks";
|
|
28
|
+
import { get } from "../utils";
|
|
27
29
|
|
|
28
30
|
import {
|
|
29
31
|
useContentTypes,
|
|
30
32
|
usePickFromState,
|
|
31
33
|
} from "@applicaster/zapp-react-native-redux/hooks";
|
|
32
|
-
import {
|
|
34
|
+
import { TOGGLE_FLAG_MAX_ITEMS_REACHED_EVENT } from "./consts";
|
|
35
|
+
import { postEvent, useSubscriberFor } from "../reactHooks/useSubscriberFor";
|
|
33
36
|
import { APP_EVENTS } from "../appUtils/events";
|
|
34
|
-
import {
|
|
35
|
-
localStorageToggleFlag,
|
|
36
|
-
sessionStorageToggleFlag,
|
|
37
|
-
} from "./StorageActions";
|
|
38
|
-
|
|
39
|
-
import { screenSetVariable, screenToggleFlag } from "./ScreenActions";
|
|
40
37
|
|
|
41
38
|
export const { log_error, log_info, log_debug } = createLogger({
|
|
42
39
|
subsystem: "ActionExecutorContext",
|
|
@@ -85,6 +82,19 @@ function findParentComponent(
|
|
|
85
82
|
return null;
|
|
86
83
|
}
|
|
87
84
|
|
|
85
|
+
// send all data just in case (like for message string formatting)
|
|
86
|
+
// Type is not exported for now
|
|
87
|
+
type MaxTagsReachedEvent = {
|
|
88
|
+
selectedItems: string[];
|
|
89
|
+
maxItems: number;
|
|
90
|
+
tag: string;
|
|
91
|
+
keyNamespace: string;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
async function onMaxTagsReached(data: MaxTagsReachedEvent) {
|
|
95
|
+
postEvent(TOGGLE_FLAG_MAX_ITEMS_REACHED_EVENT, [data]);
|
|
96
|
+
}
|
|
97
|
+
|
|
88
98
|
const prepareDefaultActions = (actionExecutor) => {
|
|
89
99
|
actionExecutor.registerAction("localStorageSet", async (action) => {
|
|
90
100
|
const namespaces = action.options.content;
|
|
@@ -168,15 +178,10 @@ const prepareDefaultActions = (actionExecutor) => {
|
|
|
168
178
|
|
|
169
179
|
const entry = context?.entry || {};
|
|
170
180
|
const entryResolver = new EntryResolver(entry);
|
|
171
|
-
const screenData = context?.screenStateStore.getState().data || {};
|
|
172
|
-
const screenResolver = new EntryResolver(screenData || {});
|
|
173
181
|
|
|
174
182
|
const data =
|
|
175
183
|
options?.data && options.inflateData
|
|
176
|
-
? await resolveObjectValues(options.data, {
|
|
177
|
-
entry: entryResolver,
|
|
178
|
-
screen: screenResolver,
|
|
179
|
-
})
|
|
184
|
+
? await resolveObjectValues(options.data, { entry: entryResolver })
|
|
180
185
|
: options?.data || entry;
|
|
181
186
|
|
|
182
187
|
const cloudEvent = await createCloudEvent({
|
|
@@ -210,63 +215,81 @@ const prepareDefaultActions = (actionExecutor) => {
|
|
|
210
215
|
return ActionResult.Error;
|
|
211
216
|
});
|
|
212
217
|
|
|
213
|
-
actionExecutor.registerAction(
|
|
214
|
-
"sessionStorageToggleFlag",
|
|
215
|
-
async (
|
|
216
|
-
action: ActionType,
|
|
217
|
-
context?: Record<string, any>
|
|
218
|
-
): Promise<ActionResult> => {
|
|
219
|
-
return await sessionStorageToggleFlag(context, action);
|
|
220
|
-
}
|
|
221
|
-
);
|
|
222
|
-
|
|
223
218
|
actionExecutor.registerAction(
|
|
224
219
|
"localStorageToggleFlag",
|
|
225
220
|
async (
|
|
226
221
|
action: ActionType,
|
|
227
222
|
context?: Record<string, any>
|
|
228
223
|
): Promise<ActionResult> => {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
224
|
+
if (!context) {
|
|
225
|
+
log_error(
|
|
226
|
+
"handleAction: localStorageToggleFlag action missing context"
|
|
227
|
+
);
|
|
232
228
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
async (
|
|
236
|
-
action: ActionType,
|
|
237
|
-
context?: Record<string, any>
|
|
238
|
-
): Promise<ActionResult> => {
|
|
239
|
-
const route = context?.screenRoute;
|
|
240
|
-
const screenStateStore = context?.screenStateStore;
|
|
241
|
-
|
|
242
|
-
await screenSetVariable(
|
|
243
|
-
route,
|
|
244
|
-
screenStateStore,
|
|
245
|
-
{ entry: context?.entry, options: action.options },
|
|
246
|
-
action
|
|
247
|
-
);
|
|
229
|
+
return ActionResult.Error;
|
|
230
|
+
}
|
|
248
231
|
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
);
|
|
232
|
+
const entry = context?.entry as ZappEntry;
|
|
252
233
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
)
|
|
234
|
+
if (!entry) {
|
|
235
|
+
log_error(
|
|
236
|
+
"handleAction: localStorageToggleFlag action missing entry. Entry is required to get the tag."
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
return ActionResult.Error;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const tag = action.options?.selector
|
|
243
|
+
? get(entry, action.options.selector)
|
|
244
|
+
: (entry.extensions?.tag ?? entry.id);
|
|
245
|
+
|
|
246
|
+
const keyNamespace = action.options?.key;
|
|
247
|
+
|
|
248
|
+
if (keyNamespace && tag) {
|
|
249
|
+
const multiSelectProvider =
|
|
250
|
+
StorageMultiSelectProvider.getProvider(keyNamespace);
|
|
251
|
+
|
|
252
|
+
const selectedItems = await multiSelectProvider.getSelectedAsync();
|
|
253
|
+
const isTagInSelectedItems = selectedItems.includes(tag);
|
|
268
254
|
|
|
269
|
-
|
|
255
|
+
log_info(
|
|
256
|
+
`handleAction: localStorageToggleFlag event will ${
|
|
257
|
+
isTagInSelectedItems ? "remove" : "add"
|
|
258
|
+
} tag: ${tag} for keyNamespace: ${keyNamespace}, current selectedItems: ${selectedItems}`
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
if (selectedItems.includes(tag)) {
|
|
262
|
+
await multiSelectProvider.removeItem(tag);
|
|
263
|
+
} else {
|
|
264
|
+
const maxItems = action.options?.max_items;
|
|
265
|
+
|
|
266
|
+
if (maxItems && selectedItems.length >= maxItems) {
|
|
267
|
+
log_info(
|
|
268
|
+
`handleAction: localStorageToggleFlag event reached max items limit: ${maxItems}, cannot add tag: ${tag}`
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
await onMaxTagsReached({
|
|
272
|
+
selectedItems,
|
|
273
|
+
maxItems,
|
|
274
|
+
tag,
|
|
275
|
+
keyNamespace,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
return ActionResult.Cancel;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
await multiSelectProvider.addItem(tag);
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
log_error(
|
|
285
|
+
"handleAction: localStorageToggleFlag event missing keyNamespace or tag",
|
|
286
|
+
{ keyNamespace, tag }
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
return ActionResult.Error;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return ActionResult.Success;
|
|
270
293
|
}
|
|
271
294
|
);
|
|
272
295
|
};
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from "../events";
|
|
10
10
|
import { isEmptyOrNil } from "../../cellUtils";
|
|
11
11
|
import { get } from "lodash";
|
|
12
|
-
import { StorageMultiSelectProvider } from "@applicaster/zapp-react-native-
|
|
12
|
+
import { StorageMultiSelectProvider } from "@applicaster/zapp-react-native-bridge/ZappStorage/StorageMultiSelectProvider";
|
|
13
13
|
|
|
14
14
|
export enum OfflineItemState {
|
|
15
15
|
notExist = "NOT_EXISTS",
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { ContextKeysManager } from "./index";
|
|
2
2
|
import * as R from "ramda";
|
|
3
|
-
import * as _ from "lodash";
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
interface IResolver {
|
|
6
5
|
resolve: (string) => Promise<string | number | object>;
|
|
7
6
|
}
|
|
8
7
|
|
|
9
|
-
// TODO: Rename to ObjectKeyResolver or similar
|
|
10
8
|
export class EntryResolver implements IResolver {
|
|
11
9
|
entry: ZappEntry;
|
|
12
10
|
|
|
@@ -23,18 +21,6 @@ export class EntryResolver implements IResolver {
|
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
// TODO: Move to proper place
|
|
27
|
-
|
|
28
|
-
export class ScreenStateResolver implements IResolver {
|
|
29
|
-
constructor(private screenStateStore: ScreenStateStore) {}
|
|
30
|
-
|
|
31
|
-
async resolve(key: string) {
|
|
32
|
-
const screenState = this.screenStateStore.getState().data;
|
|
33
|
-
|
|
34
|
-
return screenState?.[key];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
24
|
export class ContextResolver implements IResolver {
|
|
39
25
|
resolve = async (compositeKey: string) =>
|
|
40
26
|
ContextKeysManager.instance.getKey(compositeKey);
|
|
@@ -78,19 +64,3 @@ export const resolveObjectValues = async (
|
|
|
78
64
|
|
|
79
65
|
return Object.fromEntries(resolvedEntries);
|
|
80
66
|
};
|
|
81
|
-
|
|
82
|
-
export const extractAtValues = _.memoize((input: any): string[] => {
|
|
83
|
-
return _.flatMapDeep(input, (value: any) => {
|
|
84
|
-
if (_.isString(value)) {
|
|
85
|
-
const matches = value.match(/@\{([^}]*)\}/g);
|
|
86
|
-
|
|
87
|
-
return matches ? matches.map((match) => match.slice(2, -1)) : [];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (_.isObject(value)) {
|
|
91
|
-
return extractAtValues(_.values(value));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return [];
|
|
95
|
-
});
|
|
96
|
-
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "14.0.0-alpha.
|
|
3
|
+
"version": "14.0.0-alpha.6240202185",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@applicaster/applicaster-types": "14.0.0-alpha.
|
|
30
|
+
"@applicaster/applicaster-types": "14.0.0-alpha.6240202185",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|
|
@@ -16,8 +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
|
|
20
|
-
import { useScreenStateStore } from "../navigation/useScreenStateStore";
|
|
19
|
+
import { useCurrentScreenData } from "../screen";
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
22
|
* If onCellTap is defined execute the function and
|
|
@@ -43,12 +42,10 @@ export const useCellClick = ({
|
|
|
43
42
|
}: Props): onPressReturnFn => {
|
|
44
43
|
const { push, currentRoute } = useNavigation();
|
|
45
44
|
const { pathname } = useRoute();
|
|
46
|
-
const screenStateStore = useScreenStateStore();
|
|
47
45
|
|
|
48
46
|
const onCellTap: Option<Function> = React.useContext(CellTapContext);
|
|
49
47
|
const actionExecutor = React.useContext(ActionExecutorContext);
|
|
50
48
|
const screenData = useCurrentScreenData();
|
|
51
|
-
const screenState = useScreenContext()?.options;
|
|
52
49
|
|
|
53
50
|
const cellSelectable = toBooleanWithDefaultTrue(
|
|
54
51
|
component?.rules?.component_cells_selectable
|
|
@@ -86,9 +83,6 @@ export const useCellClick = ({
|
|
|
86
83
|
await actionExecutor?.handleEntryActions(selectedItem, {
|
|
87
84
|
component,
|
|
88
85
|
screenData,
|
|
89
|
-
screenState,
|
|
90
|
-
screenRoute: pathname,
|
|
91
|
-
screenStateStore,
|
|
92
86
|
});
|
|
93
87
|
}
|
|
94
88
|
|
|
@@ -123,7 +117,6 @@ export const useCellClick = ({
|
|
|
123
117
|
push,
|
|
124
118
|
sendAnalyticsOnPress,
|
|
125
119
|
screenData,
|
|
126
|
-
screenState,
|
|
127
120
|
]
|
|
128
121
|
);
|
|
129
122
|
|
|
@@ -138,11 +138,6 @@ describe("useFeedLoader", () => {
|
|
|
138
138
|
expect(loadPipesDataSpy).toBeCalledWith(feedUrl, {
|
|
139
139
|
clearCache: true,
|
|
140
140
|
riverId: undefined,
|
|
141
|
-
resolvers: {
|
|
142
|
-
screen: {
|
|
143
|
-
screenStateStore: undefined,
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
141
|
});
|
|
147
142
|
|
|
148
143
|
const store2 = mockStore({
|
|
@@ -184,11 +179,6 @@ describe("useFeedLoader", () => {
|
|
|
184
179
|
expect(loadPipesDataSpy).toBeCalledWith(feedUrl, {
|
|
185
180
|
clearCache: true,
|
|
186
181
|
riverId: undefined,
|
|
187
|
-
resolvers: {
|
|
188
|
-
screen: {
|
|
189
|
-
screenStateStore: undefined,
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
182
|
});
|
|
193
183
|
|
|
194
184
|
const store2 = mockStore({
|
|
@@ -238,11 +228,6 @@ describe("useFeedLoader", () => {
|
|
|
238
228
|
expect(loadPipesDataSpy).toBeCalledWith(feedUrl, {
|
|
239
229
|
clearCache: true,
|
|
240
230
|
silentRefresh: true,
|
|
241
|
-
resolvers: {
|
|
242
|
-
screen: {
|
|
243
|
-
screenStateStore: undefined,
|
|
244
|
-
},
|
|
245
|
-
},
|
|
246
231
|
});
|
|
247
232
|
|
|
248
233
|
loadPipesDataSpy.mockRestore();
|
|
@@ -282,11 +267,6 @@ describe("useFeedLoader", () => {
|
|
|
282
267
|
expect(loadPipesDataSpy).toBeCalledWith(nextUrl, {
|
|
283
268
|
parentFeed: feedUrlWithNext,
|
|
284
269
|
silentRefresh: true,
|
|
285
|
-
resolvers: {
|
|
286
|
-
screen: {
|
|
287
|
-
screenStateStore: undefined,
|
|
288
|
-
},
|
|
289
|
-
},
|
|
290
270
|
});
|
|
291
271
|
|
|
292
272
|
loadPipesDataSpy.mockRestore();
|
|
@@ -10,7 +10,6 @@ import { reactHooksLogger } from "../logger";
|
|
|
10
10
|
import { shouldDispatchData, useIsInitialRender } from "../utils";
|
|
11
11
|
import { useInflatedUrl } from "./useInflatedUrl";
|
|
12
12
|
import { useRoute } from "../navigation";
|
|
13
|
-
import { useScreenResolvers } from "@applicaster/zapp-react-native-utils/actionsExecutor/screenResolver";
|
|
14
13
|
|
|
15
14
|
const logger = reactHooksLogger.addSubsystem("useFeedLoader");
|
|
16
15
|
|
|
@@ -54,7 +53,6 @@ export const useFeedLoader = ({
|
|
|
54
53
|
const isInitialRender = useIsInitialRender();
|
|
55
54
|
const dispatch = useAppDispatch();
|
|
56
55
|
const { screenData } = useRoute();
|
|
57
|
-
const resolvers = useScreenResolvers();
|
|
58
56
|
|
|
59
57
|
const callableFeedUrl = useInflatedUrl({ feedUrl, mapping });
|
|
60
58
|
|
|
@@ -73,12 +71,11 @@ export const useFeedLoader = ({
|
|
|
73
71
|
silentRefresh,
|
|
74
72
|
callback,
|
|
75
73
|
riverId,
|
|
76
|
-
resolvers,
|
|
77
74
|
})
|
|
78
75
|
);
|
|
79
76
|
}
|
|
80
77
|
},
|
|
81
|
-
[callableFeedUrl
|
|
78
|
+
[callableFeedUrl]
|
|
82
79
|
);
|
|
83
80
|
|
|
84
81
|
const loadNext: FeedLoaderResponse["loadNext"] = React.useCallback(() => {
|
|
@@ -91,12 +88,11 @@ export const useFeedLoader = ({
|
|
|
91
88
|
silentRefresh: true,
|
|
92
89
|
parentFeed: callableFeedUrl,
|
|
93
90
|
riverId,
|
|
94
|
-
resolvers,
|
|
95
91
|
})
|
|
96
92
|
);
|
|
97
93
|
}
|
|
98
94
|
}
|
|
99
|
-
}, [callableFeedUrl, currentFeed?.data?.next
|
|
95
|
+
}, [callableFeedUrl, currentFeed?.data?.next]);
|
|
100
96
|
|
|
101
97
|
useEffect(() => {
|
|
102
98
|
if (
|
|
@@ -108,7 +104,6 @@ export const useFeedLoader = ({
|
|
|
108
104
|
...pipesOptions,
|
|
109
105
|
clearCache: true,
|
|
110
106
|
riverId,
|
|
111
|
-
resolvers,
|
|
112
107
|
})
|
|
113
108
|
);
|
|
114
109
|
} else if (!callableFeedUrl) {
|
|
@@ -133,20 +128,16 @@ export const useFeedLoader = ({
|
|
|
133
128
|
jsOnly: true,
|
|
134
129
|
});
|
|
135
130
|
}
|
|
136
|
-
}, [
|
|
131
|
+
}, []);
|
|
137
132
|
|
|
138
133
|
// Reload feed when feedUrl changes, unless skipLoading is true
|
|
139
134
|
useEffect(() => {
|
|
140
135
|
if (!isInitialRender && callableFeedUrl && !pipesOptions.skipLoading) {
|
|
141
136
|
dispatch(
|
|
142
|
-
ZappPipes.loadPipesData(callableFeedUrl, {
|
|
143
|
-
...pipesOptions,
|
|
144
|
-
riverId,
|
|
145
|
-
resolvers,
|
|
146
|
-
})
|
|
137
|
+
ZappPipes.loadPipesData(callableFeedUrl, { ...pipesOptions, riverId })
|
|
147
138
|
);
|
|
148
139
|
}
|
|
149
|
-
}, [callableFeedUrl
|
|
140
|
+
}, [callableFeedUrl]);
|
|
150
141
|
|
|
151
142
|
return React.useMemo(() => {
|
|
152
143
|
if (!callableFeedUrl || !feedUrl) {
|
|
@@ -28,19 +28,14 @@ const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
|
|
|
28
28
|
|
|
29
29
|
type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
|
|
30
30
|
|
|
31
|
-
export const useRoute = (
|
|
32
|
-
useLegacy = true
|
|
33
|
-
): {
|
|
31
|
+
export const useRoute = (): {
|
|
34
32
|
screenData: VariousScreenData;
|
|
35
33
|
pathname: string;
|
|
36
34
|
} => {
|
|
37
35
|
const pathname = usePathname() || "";
|
|
38
36
|
const navigator = useNavigation();
|
|
39
|
-
const screenContext = useContext(ScreenDataContext);
|
|
40
37
|
|
|
41
|
-
const screenDataContext =
|
|
42
|
-
? legacyScreenData(screenContext)
|
|
43
|
-
: screenContext;
|
|
38
|
+
const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
|
|
44
39
|
|
|
45
40
|
const { plugins, contentTypes, rivers } = usePickFromState([
|
|
46
41
|
"plugins",
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
// import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
2
|
-
|
|
3
|
-
import { log_error, log_info } from "./ActionExecutorContext";
|
|
4
|
-
import { ActionResult } from "./ActionExecutor";
|
|
5
|
-
import { get } from "lodash";
|
|
6
|
-
|
|
7
|
-
import { onMaxTagsReached } from "./StorageActions";
|
|
8
|
-
import { ScreenMultiSelectProvider } from "../storage/ScreenStateMultiSelectProvider";
|
|
9
|
-
import { ScreenSingleValueProvider } from "../storage/ScreenSingleValueProvider";
|
|
10
|
-
|
|
11
|
-
export const screenSetVariable = async (
|
|
12
|
-
screenRoute: string,
|
|
13
|
-
screenStateStore: ScreenStateStore,
|
|
14
|
-
context: Record<string, any>,
|
|
15
|
-
action: ActionType
|
|
16
|
-
): Promise<ActionResult> => {
|
|
17
|
-
if (!context) {
|
|
18
|
-
log_error("handleAction: screenSetVariable action missing context");
|
|
19
|
-
|
|
20
|
-
return ActionResult.Error;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const entry = context?.entry as ZappEntry;
|
|
24
|
-
|
|
25
|
-
if (!entry) {
|
|
26
|
-
log_error(
|
|
27
|
-
"handleAction: screenSetVariable action missing entry. Entry is required to get the value."
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
return ActionResult.Error;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const tag = action.options?.selector
|
|
34
|
-
? get(entry, action.options.selector)
|
|
35
|
-
: (entry.extensions?.tag ?? entry.id);
|
|
36
|
-
|
|
37
|
-
const keyNamespace = action.options?.key;
|
|
38
|
-
|
|
39
|
-
if (!keyNamespace) {
|
|
40
|
-
log_error("handleAction: screenSetVariable action missing key namespace", {
|
|
41
|
-
keyNamespace,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return ActionResult.Error;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (!tag) {
|
|
48
|
-
log_error(
|
|
49
|
-
"handleAction: screenSetVariable action could not determine tag",
|
|
50
|
-
{ selector: action.options?.selector, value: action.options?.value }
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
return ActionResult.Error;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
const singleValueProvider = ScreenSingleValueProvider.getProvider(
|
|
58
|
-
keyNamespace,
|
|
59
|
-
screenRoute,
|
|
60
|
-
screenStateStore
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
const currentValue = await singleValueProvider.getValueAsync();
|
|
64
|
-
|
|
65
|
-
log_info(
|
|
66
|
-
`handleAction: screenSetVariable setting value: ${tag} for keyNamespace: ${keyNamespace}, previous value: ${currentValue}`
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
await singleValueProvider.setValue(String(tag));
|
|
70
|
-
|
|
71
|
-
log_info(
|
|
72
|
-
`handleAction: screenSetVariable successfully set value: ${tag} for keyNamespace: ${keyNamespace}`
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
return ActionResult.Success;
|
|
76
|
-
} catch (error) {
|
|
77
|
-
log_error("handleAction: screenSetVariable failed to set value", {
|
|
78
|
-
keyNamespace,
|
|
79
|
-
tag,
|
|
80
|
-
error,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
return ActionResult.Error;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export const screenToggleFlag = async (
|
|
88
|
-
screenRoute: string,
|
|
89
|
-
screenStateStore: ScreenStateStore,
|
|
90
|
-
context: Record<string, any>,
|
|
91
|
-
action: ActionType
|
|
92
|
-
) => {
|
|
93
|
-
if (!context) {
|
|
94
|
-
log_error("handleAction: screenToggleFlag action missing context");
|
|
95
|
-
|
|
96
|
-
return ActionResult.Error;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const entry = context?.entry as ZappEntry;
|
|
100
|
-
|
|
101
|
-
if (!entry) {
|
|
102
|
-
log_error(
|
|
103
|
-
"handleAction: screenToggleFlag action missing entry. Entry is required to get the tag."
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
return ActionResult.Error;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const tag = action.options?.selector
|
|
110
|
-
? get(entry, action.options.selector)
|
|
111
|
-
: (entry.extensions?.tag ?? entry.id);
|
|
112
|
-
|
|
113
|
-
const keyNamespace = action.options?.key;
|
|
114
|
-
|
|
115
|
-
if (keyNamespace && tag) {
|
|
116
|
-
const multiSelectProvider = ScreenMultiSelectProvider.getProvider(
|
|
117
|
-
keyNamespace,
|
|
118
|
-
screenRoute,
|
|
119
|
-
screenStateStore
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
const selectedItems = await multiSelectProvider.getSelectedAsync();
|
|
123
|
-
const isTagInSelectedItems = selectedItems.includes(tag);
|
|
124
|
-
|
|
125
|
-
log_info(
|
|
126
|
-
`handleAction: screenToggleFlag event will ${
|
|
127
|
-
isTagInSelectedItems ? "remove" : "add"
|
|
128
|
-
} tag: ${tag} for keyNamespace: ${keyNamespace}, current selectedItems: ${selectedItems}`
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
if (selectedItems.includes(tag)) {
|
|
132
|
-
await multiSelectProvider.removeItem(tag);
|
|
133
|
-
} else {
|
|
134
|
-
const maxItems = action.options?.max_items;
|
|
135
|
-
|
|
136
|
-
if (maxItems && selectedItems.length >= maxItems) {
|
|
137
|
-
log_info(
|
|
138
|
-
`handleAction: screenToggleFlag event reached max items limit: ${maxItems}, cannot add tag: ${tag}`
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
await onMaxTagsReached({
|
|
142
|
-
selectedItems,
|
|
143
|
-
maxItems,
|
|
144
|
-
tag,
|
|
145
|
-
keyNamespace,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
return ActionResult.Cancel;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
await multiSelectProvider.addItem(tag);
|
|
152
|
-
}
|
|
153
|
-
} else {
|
|
154
|
-
log_error(
|
|
155
|
-
"handleAction: screenToggleFlag event missing keyNamespace or tag",
|
|
156
|
-
{ keyNamespace, tag }
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
return ActionResult.Error;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return ActionResult.Success;
|
|
163
|
-
};
|