@applicaster/zapp-react-native-utils 16.0.0-rc.84 → 16.0.0-rc.85
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/actions/openBottomSheet.ts +5 -1
- package/entryActions/__tests__/buildEntryActions.test.ts +39 -0
- package/entryActions/buildEntryActions.ts +1 -0
- package/modalState/RemoteEditableCollection.ts +9 -1
- package/modalState/__tests__/RemoteEditableCollection.test.ts +90 -1
- package/modalState/types.ts +1 -0
- package/package.json +2 -2
|
@@ -208,7 +208,10 @@ export async function openBottomSheetAction(
|
|
|
208
208
|
items: [],
|
|
209
209
|
onPress: () => {},
|
|
210
210
|
contentComponent: content.component,
|
|
211
|
-
contentComponentProps:
|
|
211
|
+
contentComponentProps: {
|
|
212
|
+
...(content.props || {}),
|
|
213
|
+
actionContext: context,
|
|
214
|
+
},
|
|
212
215
|
},
|
|
213
216
|
});
|
|
214
217
|
|
|
@@ -277,6 +280,7 @@ export async function openBottomSheetAction(
|
|
|
277
280
|
dynamicCollection,
|
|
278
281
|
themePluginId,
|
|
279
282
|
styleOverrides: styleOverrides ?? content?.styleOverrides,
|
|
283
|
+
context,
|
|
280
284
|
},
|
|
281
285
|
};
|
|
282
286
|
|
|
@@ -154,3 +154,42 @@ describe("buildEntryActions - alias & label resolution", () => {
|
|
|
154
154
|
});
|
|
155
155
|
});
|
|
156
156
|
});
|
|
157
|
+
|
|
158
|
+
describe("buildEntryActions - invokeAction execution context", () => {
|
|
159
|
+
it("forwards the List component from invoke options into handleActions", async () => {
|
|
160
|
+
const handleActions = jest.fn();
|
|
161
|
+
|
|
162
|
+
const component = {
|
|
163
|
+
id: "list-1",
|
|
164
|
+
data: { source: "https://example.com/user/collections/abc" },
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const deps = {
|
|
168
|
+
actionExecutor: { handleActions } as any,
|
|
169
|
+
actionContext: { screenData: { id: "playlist-screen" } },
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const entry = {
|
|
173
|
+
id: "entry-1",
|
|
174
|
+
extensions: {
|
|
175
|
+
entry_action: [
|
|
176
|
+
{
|
|
177
|
+
button: { title: "Edit Name" },
|
|
178
|
+
actions: [{ type: "refreshComponent" }],
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const [action] = buildEntryActions(entry as any, deps);
|
|
185
|
+
|
|
186
|
+
await action.action.invokeAction(entry as any, { component });
|
|
187
|
+
|
|
188
|
+
expect(handleActions).toHaveBeenCalledWith([{ type: "refreshComponent" }], {
|
|
189
|
+
entry,
|
|
190
|
+
entryContext: entry,
|
|
191
|
+
screenData: { id: "playlist-screen" },
|
|
192
|
+
component,
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -123,7 +123,14 @@ export class RemoteEditableCollection implements EditableCollection {
|
|
|
123
123
|
|
|
124
124
|
try {
|
|
125
125
|
for (const action of addEvents) {
|
|
126
|
-
|
|
126
|
+
if (this.content.context) {
|
|
127
|
+
await actionExecutor.handleAction(
|
|
128
|
+
action as any,
|
|
129
|
+
this.content.context
|
|
130
|
+
);
|
|
131
|
+
} else {
|
|
132
|
+
await actionExecutor.handleAction(action as any);
|
|
133
|
+
}
|
|
127
134
|
}
|
|
128
135
|
} catch (e) {
|
|
129
136
|
actionFailed = true;
|
|
@@ -219,6 +226,7 @@ export class RemoteEditableCollection implements EditableCollection {
|
|
|
219
226
|
await actionExecutor.handleAction(
|
|
220
227
|
actionToExecute as any,
|
|
221
228
|
{
|
|
229
|
+
...this.content.context,
|
|
222
230
|
entry: item as any,
|
|
223
231
|
} as any
|
|
224
232
|
);
|
|
@@ -34,16 +34,26 @@ const itemPlain: MenuItem = { id: "2", title: "B" };
|
|
|
34
34
|
function makeCollection(
|
|
35
35
|
items: MenuItem[],
|
|
36
36
|
refetch = jest.fn().mockResolvedValue(undefined),
|
|
37
|
-
operations = ["remove", "reorder"]
|
|
37
|
+
operations = ["remove", "reorder"],
|
|
38
|
+
context?: Record<string, unknown>
|
|
38
39
|
) {
|
|
39
40
|
const content = {
|
|
40
41
|
items,
|
|
42
|
+
context,
|
|
41
43
|
dynamicCollection: { operations, postUrl: "https://x/cloud-events" },
|
|
42
44
|
} as unknown as Content;
|
|
43
45
|
|
|
44
46
|
return { col: new RemoteEditableCollection(content, refetch), refetch };
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
const openingContext = {
|
|
50
|
+
component: {
|
|
51
|
+
id: "list-1",
|
|
52
|
+
data: { source: "https://example.com/user/collections/abc" },
|
|
53
|
+
},
|
|
54
|
+
screenData: { id: "playlist-screen" },
|
|
55
|
+
};
|
|
56
|
+
|
|
47
57
|
describe("RemoteEditableCollection", () => {
|
|
48
58
|
beforeEach(() => jest.clearAllMocks());
|
|
49
59
|
|
|
@@ -118,6 +128,24 @@ describe("RemoteEditableCollection", () => {
|
|
|
118
128
|
expect(refetch).toHaveBeenCalledTimes(1);
|
|
119
129
|
expect(currentItems(col)).toEqual([itemWithRemove]);
|
|
120
130
|
});
|
|
131
|
+
|
|
132
|
+
it("forwards stored sheet context plus the removed item as entry", async () => {
|
|
133
|
+
handleAction.mockResolvedValue("success");
|
|
134
|
+
|
|
135
|
+
const { col } = makeCollection(
|
|
136
|
+
[itemWithRemove, itemPlain],
|
|
137
|
+
jest.fn().mockResolvedValue(undefined),
|
|
138
|
+
["remove", "reorder"],
|
|
139
|
+
openingContext
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
await col.remove(0);
|
|
143
|
+
|
|
144
|
+
expect(handleAction).toHaveBeenCalledWith(removeAction, {
|
|
145
|
+
...openingContext,
|
|
146
|
+
entry: itemWithRemove,
|
|
147
|
+
});
|
|
148
|
+
});
|
|
121
149
|
});
|
|
122
150
|
|
|
123
151
|
describe("move", () => {
|
|
@@ -164,6 +192,35 @@ describe("RemoteEditableCollection", () => {
|
|
|
164
192
|
expect(refetch).toHaveBeenCalledTimes(1);
|
|
165
193
|
});
|
|
166
194
|
|
|
195
|
+
it("forwards stored sheet context plus the moved item as entry", async () => {
|
|
196
|
+
handleAction.mockResolvedValue("success");
|
|
197
|
+
|
|
198
|
+
const itemA: MenuItem = {
|
|
199
|
+
id: "2",
|
|
200
|
+
title: "B",
|
|
201
|
+
entryActions: [
|
|
202
|
+
{ button: { alias: "reorder_item" }, actions: [removeAction] },
|
|
203
|
+
],
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const { col } = makeCollection(
|
|
207
|
+
[itemA],
|
|
208
|
+
jest.fn().mockResolvedValue(undefined),
|
|
209
|
+
["remove", "reorder"],
|
|
210
|
+
openingContext
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
await col.move(["2"]);
|
|
214
|
+
|
|
215
|
+
expect(handleAction).toHaveBeenCalledWith(
|
|
216
|
+
expect.objectContaining({ type: "sendCloudEvent" }),
|
|
217
|
+
{
|
|
218
|
+
...openingContext,
|
|
219
|
+
entry: itemA,
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
|
|
167
224
|
it("rolls back on failure", async () => {
|
|
168
225
|
handleAction.mockRejectedValue(new Error("nope"));
|
|
169
226
|
|
|
@@ -322,5 +379,37 @@ describe("RemoteEditableCollection", () => {
|
|
|
322
379
|
expect(handleAction).toHaveBeenCalledWith(addAction);
|
|
323
380
|
expect(refetch).toHaveBeenCalledTimes(1);
|
|
324
381
|
});
|
|
382
|
+
|
|
383
|
+
it("forwards stored sheet context into events.add actions", async () => {
|
|
384
|
+
handleAction.mockResolvedValue("success");
|
|
385
|
+
|
|
386
|
+
const addAction = {
|
|
387
|
+
type: "showTextInput",
|
|
388
|
+
options: {
|
|
389
|
+
headerTitle: "Create Playlist",
|
|
390
|
+
buttonLabel: "Create",
|
|
391
|
+
actions: [{ type: "sendCloudEvent" }],
|
|
392
|
+
},
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
const content = {
|
|
396
|
+
items: [],
|
|
397
|
+
context: openingContext,
|
|
398
|
+
dynamicCollection: {
|
|
399
|
+
operations: ["add"],
|
|
400
|
+
postUrl: "https://x/cloud-events",
|
|
401
|
+
events: {
|
|
402
|
+
add: [addAction],
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
} as any;
|
|
406
|
+
|
|
407
|
+
const refetch = jest.fn().mockResolvedValue(undefined);
|
|
408
|
+
const col = new RemoteEditableCollection(content, refetch);
|
|
409
|
+
|
|
410
|
+
await col.add();
|
|
411
|
+
|
|
412
|
+
expect(handleAction).toHaveBeenCalledWith(addAction, openingContext);
|
|
413
|
+
});
|
|
325
414
|
});
|
|
326
415
|
});
|
package/modalState/types.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "16.0.0-rc.
|
|
3
|
+
"version": "16.0.0-rc.85",
|
|
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": "16.0.0-rc.
|
|
30
|
+
"@applicaster/applicaster-types": "16.0.0-rc.85",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|