slice-machine-ui 1.23.2-beta.3 → 1.23.2-beta.4
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/components/Forms/CreateCustomTypeModal/CreateCustomTypeModal.tsx +61 -38
- package/components/Forms/RenameCustomTypeModal/RenameCustomTypeModal.tsx +2 -2
- package/components/Navigation/ChangesListItem.tsx +14 -32
- package/out/404.html +1 -1
- package/out/_next/static/{RRBm5bm2F__Ws0vsvXhN6 → GqPZYfMQrQUPwvgI_rvdq}/_buildManifest.js +1 -1
- package/out/_next/static/chunks/{183-aab7066c73ebde44.js → 183-4feb6bb3eddbc768.js} +1 -1
- package/out/_next/static/chunks/{318-2112803ca34b2f49.js → 318-34a2dea7cfd4661d.js} +1 -1
- package/out/_next/static/chunks/727-c5028806448c4387.js +1 -0
- package/out/_next/static/chunks/731-341869976a48a09a.js +1 -0
- package/out/_next/static/chunks/{904-9a4c1264727ae89a.js → 904-833eed675f19ab60.js} +1 -1
- package/out/_next/static/chunks/pages/{_app-9f3513533bb2dfb8.js → _app-4a63c0e108026c4d.js} +2 -2
- package/out/_next/static/chunks/pages/{changes-2a976f9efeb719aa.js → changes-92c84f6cac0285fd.js} +1 -1
- package/out/_next/static/chunks/pages/index-ca194b18d0e3930d.js +1 -0
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-2d3d84de925b289e.js +1 -0
- package/out/changelog.html +1 -1
- package/out/changes.html +1 -1
- package/out/custom-types/[customTypeId].html +1 -1
- package/out/custom-types.html +1 -1
- package/out/index.html +1 -1
- package/out/labs.html +1 -1
- package/out/page-types/[pageTypeId].html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
- package/out/slices.html +1 -1
- package/package.json +3 -3
- package/src/domain/__tests__/customType.test.ts +179 -0
- package/src/domain/customType.ts +110 -2
- package/src/features/customTypes/PageTypeOnboarding.tsx +21 -26
- package/src/features/customTypes/actions/convertCustomToPageType.ts +14 -10
- package/src/features/customTypes/actions/createCustomType.ts +69 -0
- package/src/features/customTypes/actions/deleteCustomType.ts +13 -3
- package/src/features/customTypes/actions/renameCustomType.ts +10 -4
- package/src/features/customTypes/customTypesBuilder/CustomTypesBuilderPage.tsx +3 -1
- package/src/features/customTypes/customTypesTable/CustomTypesTable.tsx +8 -8
- package/src/features/customTypes/customTypesTable/CustomTypesTablePage.tsx +18 -17
- package/src/modules/availableCustomTypes/index.ts +26 -132
- package/src/modules/loading/types.ts +0 -3
- package/src/modules/modal/types.ts +0 -1
- package/src/modules/useSliceMachineActions.ts +72 -78
- package/src/modules/userContext/index.ts +3 -3
- package/src/redux/saga.ts +0 -2
- package/test/src/modules/availableCustomTypes/index.test.ts +4 -156
- package/out/_next/static/chunks/727-3a3bc32518778317.js +0 -1
- package/out/_next/static/chunks/731-501990ebe6a71b32.js +0 -1
- package/out/_next/static/chunks/pages/index-64cfb8b0948ba8ef.js +0 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-b2a9d773ce5d7739.js +0 -1
- package/src/features/customTypes/__tests__/createCustomType.test.ts +0 -159
- package/src/features/customTypes/customTypesTable/createCustomType.ts +0 -107
- package/test/components/CreateCustomTypeModal.test.tsx +0 -73
- /package/out/_next/static/{RRBm5bm2F__Ws0vsvXhN6 → GqPZYfMQrQUPwvgI_rvdq}/_ssgManifest.js +0 -0
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
import { Reducer } from "redux";
|
|
2
2
|
import { AvailableCustomTypesStoreType } from "./types";
|
|
3
|
-
import {
|
|
4
|
-
ActionType,
|
|
5
|
-
createAction,
|
|
6
|
-
createAsyncAction,
|
|
7
|
-
getType,
|
|
8
|
-
} from "typesafe-actions";
|
|
3
|
+
import { ActionType, createAction, getType } from "typesafe-actions";
|
|
9
4
|
import { SliceMachineStoreType } from "@src/redux/type";
|
|
10
5
|
import { refreshStateCreator } from "@src/modules/environment";
|
|
11
|
-
import { call, fork, put, takeLatest } from "redux-saga/effects";
|
|
12
|
-
import { withLoader } from "@src/modules/loading";
|
|
13
|
-
import { LoadingKeysEnum } from "@src/modules/loading/types";
|
|
14
|
-
import { updateCustomType } from "@src/apiClient";
|
|
15
|
-
import { modalCloseCreator } from "@src/modules/modal";
|
|
16
|
-
import { push } from "connected-next-router";
|
|
17
|
-
import { createCustomType } from "@src/features/customTypes/customTypesTable/createCustomType";
|
|
18
|
-
import { openToasterCreator, ToasterType } from "@src/modules/toaster";
|
|
19
6
|
import { CustomTypeSM } from "@lib/models/common/CustomType";
|
|
20
7
|
import {
|
|
21
8
|
normalizeFrontendCustomType,
|
|
@@ -30,62 +17,36 @@ import {
|
|
|
30
17
|
hasLocal,
|
|
31
18
|
hasLocalAndRemote,
|
|
32
19
|
} from "@lib/models/common/ModelData";
|
|
33
|
-
import { CustomTypeFormat } from "@slicemachine/manager";
|
|
34
|
-
import { CUSTOM_TYPES_CONFIG } from "@src/features/customTypes/customTypesConfig";
|
|
35
|
-
import { CUSTOM_TYPES_MESSAGES } from "@src/features/customTypes/customTypesMessages";
|
|
36
|
-
import { CustomTypes } from "@lib/models/common/CustomType";
|
|
37
|
-
import { ToastMessageWithPath } from "@components/ToasterContainer";
|
|
38
|
-
|
|
39
|
-
export const saveCustomTypeCreator = createAsyncAction(
|
|
40
|
-
"CUSTOM_TYPE/SAVE.REQUEST",
|
|
41
|
-
"CUSTOM_TYPE/SAVE.RESPONSE",
|
|
42
|
-
"CUSTOM_TYPE/SAVE.FAILURE",
|
|
43
|
-
)<undefined, { customType: CustomTypeSM }>();
|
|
44
20
|
|
|
45
21
|
// Action Creators
|
|
46
|
-
export const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"CUSTOM_TYPES/CREATE.FAILURE",
|
|
50
|
-
)<
|
|
51
|
-
{
|
|
52
|
-
id: string;
|
|
53
|
-
label: string;
|
|
54
|
-
repeatable: boolean;
|
|
55
|
-
format: CustomTypeFormat;
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
newCustomType: CustomTypeSM;
|
|
59
|
-
}
|
|
60
|
-
>();
|
|
22
|
+
export const customTypeSaveSuccess = createAction("CUSTOM_TYPE/SAVE_SUCCESS")<{
|
|
23
|
+
newCustomType: CustomTypeSM;
|
|
24
|
+
}>();
|
|
61
25
|
|
|
62
|
-
export const
|
|
63
|
-
"CUSTOM_TYPES/
|
|
26
|
+
export const customTypeCreateSuccess = createAction(
|
|
27
|
+
"CUSTOM_TYPES/CREATE_SUCCESS",
|
|
28
|
+
)<{
|
|
29
|
+
newCustomType: CustomTypeSM;
|
|
30
|
+
}>();
|
|
31
|
+
|
|
32
|
+
export const customTypeRenameSuccess = createAction(
|
|
33
|
+
"CUSTOM_TYPES/RENAME_SUCCESS",
|
|
64
34
|
)<{
|
|
65
35
|
renamedCustomType: CustomTypeSM;
|
|
66
36
|
}>();
|
|
67
37
|
|
|
68
|
-
export const
|
|
69
|
-
"CUSTOM_TYPES/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
)
|
|
73
|
-
{
|
|
74
|
-
customTypeId: string;
|
|
75
|
-
customTypeName: string;
|
|
76
|
-
format: CustomTypeFormat;
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
customTypeId: string;
|
|
80
|
-
}
|
|
81
|
-
>();
|
|
38
|
+
export const customTypeDeleteSuccess = createAction(
|
|
39
|
+
"CUSTOM_TYPES/DELETE_SUCCESS",
|
|
40
|
+
)<{
|
|
41
|
+
customTypeId: string;
|
|
42
|
+
}>();
|
|
82
43
|
|
|
83
44
|
type CustomTypesActions =
|
|
84
45
|
| ActionType<typeof refreshStateCreator>
|
|
85
|
-
| ActionType<typeof
|
|
86
|
-
| ActionType<typeof
|
|
87
|
-
| ActionType<typeof
|
|
88
|
-
| ActionType<typeof
|
|
46
|
+
| ActionType<typeof customTypeCreateSuccess>
|
|
47
|
+
| ActionType<typeof customTypeRenameSuccess>
|
|
48
|
+
| ActionType<typeof customTypeSaveSuccess>
|
|
49
|
+
| ActionType<typeof customTypeDeleteSuccess>
|
|
89
50
|
| ActionType<typeof deleteSliceCreator.success>;
|
|
90
51
|
|
|
91
52
|
// Selectors
|
|
@@ -134,7 +95,7 @@ export const availableCustomTypesReducer: Reducer<
|
|
|
134
95
|
...normalizedNewCustomType,
|
|
135
96
|
};
|
|
136
97
|
}
|
|
137
|
-
case getType(
|
|
98
|
+
case getType(customTypeCreateSuccess): {
|
|
138
99
|
const normalizedNewCustomType = normalizeFrontendCustomType(
|
|
139
100
|
action.payload.newCustomType,
|
|
140
101
|
);
|
|
@@ -145,8 +106,8 @@ export const availableCustomTypesReducer: Reducer<
|
|
|
145
106
|
};
|
|
146
107
|
}
|
|
147
108
|
|
|
148
|
-
case getType(
|
|
149
|
-
const localCustomType = action.payload.
|
|
109
|
+
case getType(customTypeSaveSuccess): {
|
|
110
|
+
const localCustomType = action.payload.newCustomType;
|
|
150
111
|
|
|
151
112
|
return {
|
|
152
113
|
...state,
|
|
@@ -157,7 +118,7 @@ export const availableCustomTypesReducer: Reducer<
|
|
|
157
118
|
};
|
|
158
119
|
}
|
|
159
120
|
|
|
160
|
-
case getType(
|
|
121
|
+
case getType(customTypeRenameSuccess): {
|
|
161
122
|
const id = action.payload.renamedCustomType.id;
|
|
162
123
|
const customType = state[id];
|
|
163
124
|
|
|
@@ -172,7 +133,7 @@ export const availableCustomTypesReducer: Reducer<
|
|
|
172
133
|
};
|
|
173
134
|
}
|
|
174
135
|
|
|
175
|
-
case getType(
|
|
136
|
+
case getType(customTypeDeleteSuccess): {
|
|
176
137
|
const customType = state[action.payload.customTypeId];
|
|
177
138
|
|
|
178
139
|
if (hasLocalAndRemote(customType)) {
|
|
@@ -229,70 +190,3 @@ export const availableCustomTypesReducer: Reducer<
|
|
|
229
190
|
return state;
|
|
230
191
|
}
|
|
231
192
|
};
|
|
232
|
-
|
|
233
|
-
export function* createCustomTypeSaga({
|
|
234
|
-
payload,
|
|
235
|
-
}: ReturnType<typeof createCustomTypeCreator.request>) {
|
|
236
|
-
const customTypesConfig = CUSTOM_TYPES_CONFIG[payload.format];
|
|
237
|
-
const customTypesMessages = CUSTOM_TYPES_MESSAGES[payload.format];
|
|
238
|
-
|
|
239
|
-
try {
|
|
240
|
-
const newCustomType = CustomTypes.toSM(
|
|
241
|
-
createCustomType(
|
|
242
|
-
payload.id,
|
|
243
|
-
payload.label,
|
|
244
|
-
payload.repeatable,
|
|
245
|
-
payload.format,
|
|
246
|
-
),
|
|
247
|
-
);
|
|
248
|
-
yield call(updateCustomType, CustomTypes.fromSM(newCustomType));
|
|
249
|
-
yield put(createCustomTypeCreator.success({ newCustomType }));
|
|
250
|
-
yield put(modalCloseCreator());
|
|
251
|
-
yield put(
|
|
252
|
-
push({
|
|
253
|
-
pathname: customTypesConfig.getBuilderPagePathname(payload.id),
|
|
254
|
-
query:
|
|
255
|
-
newCustomType.format === "page"
|
|
256
|
-
? {
|
|
257
|
-
newPageType: true,
|
|
258
|
-
}
|
|
259
|
-
: undefined,
|
|
260
|
-
}),
|
|
261
|
-
);
|
|
262
|
-
yield put(
|
|
263
|
-
openToasterCreator({
|
|
264
|
-
content: ToastMessageWithPath({
|
|
265
|
-
message: `${customTypesMessages.name({
|
|
266
|
-
start: true,
|
|
267
|
-
plural: false,
|
|
268
|
-
})} saved successfully at `,
|
|
269
|
-
path: `./customtypes/${newCustomType.id}/index.json`,
|
|
270
|
-
}),
|
|
271
|
-
type: ToasterType.SUCCESS,
|
|
272
|
-
}),
|
|
273
|
-
);
|
|
274
|
-
} catch (e) {
|
|
275
|
-
yield put(
|
|
276
|
-
openToasterCreator({
|
|
277
|
-
content: `Internal Error: ${customTypesMessages.name({
|
|
278
|
-
start: true,
|
|
279
|
-
plural: false,
|
|
280
|
-
})} not saved`,
|
|
281
|
-
type: ToasterType.ERROR,
|
|
282
|
-
}),
|
|
283
|
-
);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// Saga watchers
|
|
288
|
-
function* handleCustomTypeRequests() {
|
|
289
|
-
yield takeLatest(
|
|
290
|
-
getType(createCustomTypeCreator.request),
|
|
291
|
-
withLoader(createCustomTypeSaga, LoadingKeysEnum.CREATE_CUSTOM_TYPE),
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// Saga Exports
|
|
296
|
-
export function* watchAvailableCustomTypesSagas() {
|
|
297
|
-
yield fork(handleCustomTypeRequests);
|
|
298
|
-
}
|
|
@@ -5,11 +5,8 @@ export enum LoadingKeysEnum {
|
|
|
5
5
|
REVIEW = "REVIEW",
|
|
6
6
|
CHECK_SIMULATOR = "CHECK_SIMULATOR",
|
|
7
7
|
CHECK_SIMULATOR_IFRAME = "CHECK_SIMULATOR_IFRAME",
|
|
8
|
-
CREATE_CUSTOM_TYPE = "CREATE_CUSTOM_TYPE",
|
|
9
|
-
SAVE_CUSTOM_TYPE = "SAVE_CUSTOM_TYPE",
|
|
10
8
|
RENAME_SLICE = "RENAME_SLICE",
|
|
11
9
|
GENERATE_SLICE_CUSTOM_SCREENSHOT = "GENERATE_SLICE_CUSTOM_SCREENSHOT",
|
|
12
|
-
SAVE_SLICE = "SAVE_SLICE",
|
|
13
10
|
DELETE_SLICE = "DELETE_SLICE",
|
|
14
11
|
SIMULATOR_SAVE_MOCK = "SIMULATOR_SAVE_MOCK",
|
|
15
12
|
CHANGELOG = "CHANGELOG",
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
hasSeenTutorialsToolTipCreator,
|
|
11
11
|
hasSeenSimulatorToolTipCreator,
|
|
12
12
|
hasSeenChangesToolTipCreator,
|
|
13
|
-
|
|
13
|
+
changesPushSuccess,
|
|
14
14
|
} from "./userContext";
|
|
15
15
|
import { getChangelogCreator, refreshStateCreator } from "./environment";
|
|
16
16
|
import {
|
|
@@ -19,10 +19,10 @@ import {
|
|
|
19
19
|
} from "./simulator";
|
|
20
20
|
import ServerState from "@models/server/ServerState";
|
|
21
21
|
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
customTypeCreateSuccess,
|
|
23
|
+
customTypeDeleteSuccess,
|
|
24
|
+
customTypeRenameSuccess,
|
|
25
|
+
customTypeSaveSuccess,
|
|
26
26
|
} from "./availableCustomTypes";
|
|
27
27
|
import {
|
|
28
28
|
createSlice,
|
|
@@ -38,7 +38,6 @@ import { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
|
38
38
|
import { ComponentUI, ScreenshotUI } from "../../lib/models/common/ComponentUI";
|
|
39
39
|
import { saveSliceMockCreator } from "./simulator";
|
|
40
40
|
import { SaveSliceMockRequest } from "@src/apiClient";
|
|
41
|
-
import { CustomTypeFormat } from "@slicemachine/manager";
|
|
42
41
|
import { LibraryUI } from "@lib/models/common/LibraryUI";
|
|
43
42
|
|
|
44
43
|
const useSliceMachineActions = () => {
|
|
@@ -64,8 +63,6 @@ const useSliceMachineActions = () => {
|
|
|
64
63
|
dispatch(modalOpenCreator({ modalKey: ModalKeysEnum.SCREENSHOTS }));
|
|
65
64
|
const openRenameSliceModal = () =>
|
|
66
65
|
dispatch(modalOpenCreator({ modalKey: ModalKeysEnum.RENAME_SLICE }));
|
|
67
|
-
const openCreateCustomTypeModal = () =>
|
|
68
|
-
dispatch(modalOpenCreator({ modalKey: ModalKeysEnum.CREATE_CUSTOM_TYPE }));
|
|
69
66
|
const openScreenshotPreviewModal = () =>
|
|
70
67
|
dispatch(modalOpenCreator({ modalKey: ModalKeysEnum.SCREENSHOT_PREVIEW }));
|
|
71
68
|
const openDeleteSliceModal = () =>
|
|
@@ -104,71 +101,6 @@ const useSliceMachineActions = () => {
|
|
|
104
101
|
dispatch(hasSeenTutorialsToolTipCreator());
|
|
105
102
|
const setSeenChangesToolTip = () => dispatch(hasSeenChangesToolTipCreator());
|
|
106
103
|
|
|
107
|
-
// Custom types module
|
|
108
|
-
const createCustomType = (
|
|
109
|
-
id: string,
|
|
110
|
-
label: string,
|
|
111
|
-
repeatable: boolean,
|
|
112
|
-
format: CustomTypeFormat,
|
|
113
|
-
) =>
|
|
114
|
-
dispatch(
|
|
115
|
-
createCustomTypeCreator.request({ id, label, repeatable, format }),
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Success actions = sync store state from external actions. If its name
|
|
120
|
-
* contains "Creator", it means it is still used in a saga and that `.request`
|
|
121
|
-
* and `.failure` need to be preserved
|
|
122
|
-
*/
|
|
123
|
-
const saveCustomTypeSuccess = (customType: CustomType) =>
|
|
124
|
-
dispatch(
|
|
125
|
-
saveCustomTypeCreator.success({
|
|
126
|
-
customType: CustomTypes.toSM(customType),
|
|
127
|
-
}),
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
const deleteCustomTypeSuccess = (id: string) =>
|
|
131
|
-
dispatch(
|
|
132
|
-
deleteCustomTypeCreator.success({
|
|
133
|
-
customTypeId: id,
|
|
134
|
-
}),
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
const renameAvailableCustomTypeSuccess = (customType: CustomType) =>
|
|
138
|
-
dispatch(
|
|
139
|
-
renameAvailableCustomType({
|
|
140
|
-
renamedCustomType: CustomTypes.toSM(customType),
|
|
141
|
-
}),
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
/** End of sucess actions */
|
|
145
|
-
|
|
146
|
-
// Slice module
|
|
147
|
-
const saveSliceSuccess = (component: ComponentUI) => {
|
|
148
|
-
dispatch(
|
|
149
|
-
updateSliceCreator.success({
|
|
150
|
-
component,
|
|
151
|
-
}),
|
|
152
|
-
);
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
const saveSliceCustomScreenshotSuccess = (
|
|
156
|
-
variationId: string,
|
|
157
|
-
screenshot: ScreenshotUI,
|
|
158
|
-
component: ComponentUI,
|
|
159
|
-
) => {
|
|
160
|
-
dispatch(
|
|
161
|
-
generateSliceCustomScreenshotCreator.success({
|
|
162
|
-
variationId,
|
|
163
|
-
screenshot,
|
|
164
|
-
component,
|
|
165
|
-
}),
|
|
166
|
-
);
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
const createSliceSuccess = (libraries: readonly LibraryUI[]) =>
|
|
170
|
-
dispatch(createSlice({ libraries }));
|
|
171
|
-
|
|
172
104
|
const renameSlice = (
|
|
173
105
|
libName: string,
|
|
174
106
|
sliceId: string,
|
|
@@ -191,8 +123,6 @@ const useSliceMachineActions = () => {
|
|
|
191
123
|
}),
|
|
192
124
|
);
|
|
193
125
|
|
|
194
|
-
const pushChangesSuccess = () => dispatch(changesPushSuccessCreator());
|
|
195
|
-
|
|
196
126
|
// Toaster store
|
|
197
127
|
const openToaster = (
|
|
198
128
|
content: string | React.ReactNode,
|
|
@@ -221,6 +151,71 @@ const useSliceMachineActions = () => {
|
|
|
221
151
|
dispatch(getChangelogCreator.request());
|
|
222
152
|
};
|
|
223
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Success actions = sync store state from external actions. If its name
|
|
156
|
+
* contains "Creator", it means it is still used in a saga and that `.request`
|
|
157
|
+
* and `.failure` need to be preserved
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Custom Type module
|
|
162
|
+
*/
|
|
163
|
+
const createCustomTypeSuccess = (newCustomType: CustomType) =>
|
|
164
|
+
dispatch(
|
|
165
|
+
customTypeCreateSuccess({
|
|
166
|
+
newCustomType: CustomTypes.toSM(newCustomType),
|
|
167
|
+
}),
|
|
168
|
+
);
|
|
169
|
+
const saveCustomTypeSuccess = (customType: CustomType) =>
|
|
170
|
+
dispatch(
|
|
171
|
+
customTypeSaveSuccess({
|
|
172
|
+
newCustomType: CustomTypes.toSM(customType),
|
|
173
|
+
}),
|
|
174
|
+
);
|
|
175
|
+
const deleteCustomTypeSuccess = (id: string) =>
|
|
176
|
+
dispatch(
|
|
177
|
+
customTypeDeleteSuccess({
|
|
178
|
+
customTypeId: id,
|
|
179
|
+
}),
|
|
180
|
+
);
|
|
181
|
+
const renameCustomTypeSuccess = (customType: CustomType) =>
|
|
182
|
+
dispatch(
|
|
183
|
+
customTypeRenameSuccess({
|
|
184
|
+
renamedCustomType: CustomTypes.toSM(customType),
|
|
185
|
+
}),
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Slice module
|
|
190
|
+
*/
|
|
191
|
+
const saveSliceSuccess = (component: ComponentUI) => {
|
|
192
|
+
dispatch(
|
|
193
|
+
updateSliceCreator.success({
|
|
194
|
+
component,
|
|
195
|
+
}),
|
|
196
|
+
);
|
|
197
|
+
};
|
|
198
|
+
const saveSliceCustomScreenshotSuccess = (
|
|
199
|
+
variationId: string,
|
|
200
|
+
screenshot: ScreenshotUI,
|
|
201
|
+
component: ComponentUI,
|
|
202
|
+
) => {
|
|
203
|
+
dispatch(
|
|
204
|
+
generateSliceCustomScreenshotCreator.success({
|
|
205
|
+
variationId,
|
|
206
|
+
screenshot,
|
|
207
|
+
component,
|
|
208
|
+
}),
|
|
209
|
+
);
|
|
210
|
+
};
|
|
211
|
+
const createSliceSuccess = (libraries: readonly LibraryUI[]) =>
|
|
212
|
+
dispatch(createSlice({ libraries }));
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Changes module
|
|
216
|
+
*/
|
|
217
|
+
const pushChangesSuccess = () => dispatch(changesPushSuccess());
|
|
218
|
+
|
|
224
219
|
return {
|
|
225
220
|
checkSimulatorSetup,
|
|
226
221
|
connectToSimulatorFailure,
|
|
@@ -233,9 +228,8 @@ const useSliceMachineActions = () => {
|
|
|
233
228
|
stopLoadingLogin,
|
|
234
229
|
stopLoadingReview,
|
|
235
230
|
startLoadingReview,
|
|
236
|
-
createCustomType,
|
|
237
231
|
deleteCustomTypeSuccess,
|
|
238
|
-
|
|
232
|
+
renameCustomTypeSuccess,
|
|
239
233
|
saveCustomTypeSuccess,
|
|
240
234
|
saveSliceSuccess,
|
|
241
235
|
saveSliceCustomScreenshotSuccess,
|
|
@@ -248,7 +242,6 @@ const useSliceMachineActions = () => {
|
|
|
248
242
|
setSeenTutorialsToolTip,
|
|
249
243
|
setSeenSimulatorToolTip,
|
|
250
244
|
setSeenChangesToolTip,
|
|
251
|
-
openCreateCustomTypeModal,
|
|
252
245
|
openScreenshotPreviewModal,
|
|
253
246
|
openDeleteSliceModal,
|
|
254
247
|
openSimulatorSetupModal,
|
|
@@ -258,6 +251,7 @@ const useSliceMachineActions = () => {
|
|
|
258
251
|
saveSliceMock,
|
|
259
252
|
getChangelog,
|
|
260
253
|
pushChangesSuccess,
|
|
254
|
+
createCustomTypeSuccess,
|
|
261
255
|
};
|
|
262
256
|
};
|
|
263
257
|
|
|
@@ -53,7 +53,7 @@ export const hasSeenChangesToolTipCreator = createAction(
|
|
|
53
53
|
"USER_CONTEXT/VIEW_CHANGES_TOOL_TIP",
|
|
54
54
|
)();
|
|
55
55
|
|
|
56
|
-
export const
|
|
56
|
+
export const changesPushSuccess = createAction(
|
|
57
57
|
"USER_CONTEXT/CHANGES_PUSH_SUCCESS",
|
|
58
58
|
)();
|
|
59
59
|
|
|
@@ -65,7 +65,7 @@ type userContextActions = ActionType<
|
|
|
65
65
|
| typeof hasSeenSimulatorToolTipCreator
|
|
66
66
|
| typeof hasSeenChangesToolTipCreator
|
|
67
67
|
| typeof refreshStateCreator
|
|
68
|
-
| typeof
|
|
68
|
+
| typeof changesPushSuccess
|
|
69
69
|
>;
|
|
70
70
|
|
|
71
71
|
// Selectors
|
|
@@ -140,7 +140,7 @@ export const userContextReducer: Reducer<
|
|
|
140
140
|
authStatus: getAuthStatus(action.payload.clientError),
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
|
-
case getType(
|
|
143
|
+
case getType(changesPushSuccess): {
|
|
144
144
|
return {
|
|
145
145
|
...state,
|
|
146
146
|
lastSyncChange: Date.now(),
|
package/src/redux/saga.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { fork } from "redux-saga/effects";
|
|
2
2
|
|
|
3
3
|
import { watchSimulatorSagas } from "@src/modules/simulator";
|
|
4
|
-
import { watchAvailableCustomTypesSagas } from "@src/modules/availableCustomTypes";
|
|
5
4
|
import { watchSliceSagas } from "@src/modules/slices";
|
|
6
5
|
import { watchToasterSagas } from "@src/modules/toaster";
|
|
7
6
|
import { watchChangelogSagas } from "@src/modules/environment";
|
|
@@ -9,7 +8,6 @@ import { watchChangelogSagas } from "@src/modules/environment";
|
|
|
9
8
|
// Single entry point to start all Sagas at once
|
|
10
9
|
export default function* rootSaga() {
|
|
11
10
|
yield fork(watchSimulatorSagas);
|
|
12
|
-
yield fork(watchAvailableCustomTypesSagas);
|
|
13
11
|
yield fork(watchSliceSagas);
|
|
14
12
|
yield fork(watchToasterSagas);
|
|
15
13
|
yield fork(watchChangelogSagas);
|
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
createCustomTypeCreator,
|
|
5
|
-
availableCustomTypesReducer,
|
|
6
|
-
deleteCustomTypeCreator,
|
|
7
|
-
} from "@src/modules/availableCustomTypes";
|
|
8
|
-
import { testSaga } from "redux-saga-test-plan";
|
|
2
|
+
|
|
3
|
+
import { availableCustomTypesReducer } from "@src/modules/availableCustomTypes";
|
|
9
4
|
import { AvailableCustomTypesStoreType } from "@src/modules/availableCustomTypes/types";
|
|
10
5
|
import { refreshStateCreator } from "@src/modules/environment";
|
|
6
|
+
import { CustomTypeSM } from "@lib/models/common/CustomType";
|
|
7
|
+
import { deleteSliceCreator } from "@src/modules/slices";
|
|
11
8
|
|
|
12
9
|
import { dummyServerState } from "../__fixtures__/serverState";
|
|
13
|
-
import { updateCustomType } from "@src/apiClient";
|
|
14
|
-
import { createCustomType } from "@src/features/customTypes/customTypesTable/createCustomType";
|
|
15
|
-
import { push } from "connected-next-router";
|
|
16
|
-
import { modalCloseCreator } from "@src/modules/modal";
|
|
17
|
-
import { openToasterCreator, ToasterType } from "@src/modules/toaster";
|
|
18
|
-
import { CustomTypeSM, CustomTypes } from "@lib/models/common/CustomType";
|
|
19
|
-
import { deleteSliceCreator } from "@src/modules/slices";
|
|
20
10
|
|
|
21
11
|
const dummyCustomTypesState: AvailableCustomTypesStoreType = {};
|
|
22
12
|
|
|
@@ -57,70 +47,6 @@ describe("[Available Custom types module]", () => {
|
|
|
57
47
|
},
|
|
58
48
|
});
|
|
59
49
|
});
|
|
60
|
-
it("should update the custom types state given CUSTOM_TYPES/CREATE.SUCCESS action", () => {
|
|
61
|
-
const createdCustomType: CustomTypeSM = {
|
|
62
|
-
id: "id",
|
|
63
|
-
label: "lama",
|
|
64
|
-
repeatable: false,
|
|
65
|
-
status: true,
|
|
66
|
-
format: "custom",
|
|
67
|
-
tabs: [
|
|
68
|
-
{
|
|
69
|
-
key: "Main",
|
|
70
|
-
value: [],
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const action = createCustomTypeCreator.success({
|
|
76
|
-
newCustomType: createdCustomType,
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
expect(
|
|
80
|
-
availableCustomTypesReducer(dummyCustomTypesState, action),
|
|
81
|
-
).toEqual({
|
|
82
|
-
...dummyCustomTypesState,
|
|
83
|
-
[createdCustomType.id]: {
|
|
84
|
-
local: createdCustomType,
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("should update the custom types state given CUSTOM_TYPES/DELETE.SUCCESS action", () => {
|
|
90
|
-
const customTypeIdToDelete = "id";
|
|
91
|
-
const mockCustomTypeToDelete: CustomTypeSM = {
|
|
92
|
-
id: "id",
|
|
93
|
-
label: "lama",
|
|
94
|
-
repeatable: false,
|
|
95
|
-
status: true,
|
|
96
|
-
format: "custom",
|
|
97
|
-
tabs: [
|
|
98
|
-
{
|
|
99
|
-
key: "Main",
|
|
100
|
-
value: [],
|
|
101
|
-
},
|
|
102
|
-
],
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const originalState = { ...dummyCustomTypesState };
|
|
106
|
-
|
|
107
|
-
originalState[customTypeIdToDelete] = {
|
|
108
|
-
local: mockCustomTypeToDelete,
|
|
109
|
-
};
|
|
110
|
-
mockCustomTypeToDelete.id = "another_ct";
|
|
111
|
-
originalState["another_ct"] = { local: mockCustomTypeToDelete };
|
|
112
|
-
|
|
113
|
-
const action = deleteCustomTypeCreator.success({
|
|
114
|
-
customTypeId: customTypeIdToDelete,
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
const result = availableCustomTypesReducer(originalState, action);
|
|
118
|
-
|
|
119
|
-
const expectState = { ...originalState };
|
|
120
|
-
delete expectState[customTypeIdToDelete];
|
|
121
|
-
|
|
122
|
-
expect(result).toEqual(expectState);
|
|
123
|
-
});
|
|
124
50
|
|
|
125
51
|
it("should update the custom types state given SLICES/DELETE.SUCCESS action", () => {
|
|
126
52
|
const sliceToDeleteId = "slice_id";
|
|
@@ -209,82 +135,4 @@ describe("[Available Custom types module]", () => {
|
|
|
209
135
|
});
|
|
210
136
|
});
|
|
211
137
|
});
|
|
212
|
-
|
|
213
|
-
describe("[createCustomTypeSaga]", () => {
|
|
214
|
-
it("should call the api and dispatch the good actions on success", () => {
|
|
215
|
-
const actionPayload = {
|
|
216
|
-
format: "custom" as const, // CustomTypeFormat,
|
|
217
|
-
id: "id",
|
|
218
|
-
label: "label",
|
|
219
|
-
repeatable: true,
|
|
220
|
-
};
|
|
221
|
-
const customTypeCreated = CustomTypes.toSM(
|
|
222
|
-
createCustomType(
|
|
223
|
-
actionPayload.id,
|
|
224
|
-
actionPayload.label,
|
|
225
|
-
actionPayload.repeatable,
|
|
226
|
-
actionPayload.format,
|
|
227
|
-
),
|
|
228
|
-
);
|
|
229
|
-
const saga = testSaga(
|
|
230
|
-
createCustomTypeSaga,
|
|
231
|
-
createCustomTypeCreator.request(actionPayload),
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
saga.next().call(updateCustomType, CustomTypes.fromSM(customTypeCreated));
|
|
235
|
-
saga
|
|
236
|
-
.next()
|
|
237
|
-
.put(
|
|
238
|
-
createCustomTypeCreator.success({ newCustomType: customTypeCreated }),
|
|
239
|
-
);
|
|
240
|
-
saga.next().put(modalCloseCreator());
|
|
241
|
-
saga.next().put(
|
|
242
|
-
push({
|
|
243
|
-
pathname: "/custom-types/id",
|
|
244
|
-
query: undefined,
|
|
245
|
-
}),
|
|
246
|
-
);
|
|
247
|
-
saga
|
|
248
|
-
.next()
|
|
249
|
-
.inspect(
|
|
250
|
-
(action: {
|
|
251
|
-
payload: { action: { type: string; payload: { type: string } } };
|
|
252
|
-
}) => {
|
|
253
|
-
expect(action.payload.action.type).toBe("TOASTER/OPEN");
|
|
254
|
-
expect(action.payload.action.payload.type).toBe(
|
|
255
|
-
ToasterType.SUCCESS,
|
|
256
|
-
);
|
|
257
|
-
},
|
|
258
|
-
);
|
|
259
|
-
saga.next().isDone();
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it("should call the api and dispatch the good actions on failure", () => {
|
|
263
|
-
const actionPayload = {
|
|
264
|
-
id: "id",
|
|
265
|
-
label: "label",
|
|
266
|
-
repeatable: true,
|
|
267
|
-
format: "custom" as const,
|
|
268
|
-
};
|
|
269
|
-
const customTypeCreated = createCustomType(
|
|
270
|
-
actionPayload.id,
|
|
271
|
-
actionPayload.label,
|
|
272
|
-
actionPayload.repeatable,
|
|
273
|
-
actionPayload.format,
|
|
274
|
-
);
|
|
275
|
-
const saga = testSaga(
|
|
276
|
-
createCustomTypeSaga,
|
|
277
|
-
createCustomTypeCreator.request(actionPayload),
|
|
278
|
-
);
|
|
279
|
-
|
|
280
|
-
saga.next().call(updateCustomType, customTypeCreated);
|
|
281
|
-
saga.throw(new Error()).put(
|
|
282
|
-
openToasterCreator({
|
|
283
|
-
content: "Internal Error: Custom type not saved",
|
|
284
|
-
type: ToasterType.ERROR,
|
|
285
|
-
}),
|
|
286
|
-
);
|
|
287
|
-
saga.next().isDone();
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
138
|
});
|