slice-machine-ui 1.23.2-beta.1 → 1.23.2-beta.10
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/.depcheckrc +3 -0
- package/components/DeleteSliceModal/index.tsx +34 -24
- package/components/DeleteVariationModal/index.tsx +1 -0
- package/components/Forms/CreateCustomTypeModal/CreateCustomTypeModal.tsx +61 -38
- package/components/Forms/RenameCustomTypeModal/RenameCustomTypeModal.tsx +2 -2
- package/components/Forms/RenameSliceModal/RenameSliceModal.tsx +33 -21
- package/components/Forms/RenameVariationModal/RenameVariationModal.tsx +0 -1
- package/components/ModalFormCard/index.tsx +0 -1
- package/components/Navigation/ChangesListItem.tsx +14 -32
- package/components/Navigation/index.tsx +29 -12
- package/components/ReviewModal/ReviewForm.tsx +0 -1
- package/lib/builders/common/EditModal/Form.jsx +0 -1
- package/lib/builders/common/Zone/Card/components/NewField.tsx +0 -1
- package/lib/models/common/widgets/StructuredText/index.ts +1 -1
- package/out/404.html +1 -1
- package/out/_next/static/Dz7wwTNVdXvoAjySXz7mE/_buildManifest.js +1 -0
- package/out/_next/static/chunks/18539003-5f78714a35fde4a1.js +97 -0
- package/out/_next/static/chunks/25-01f422cea8066349.js +1 -0
- package/out/_next/static/chunks/318-99b5914b60bf1d17.js +1 -0
- package/out/_next/static/chunks/727-f8fefdd3e50cab2a.js +1 -0
- package/out/_next/static/chunks/777-8c5507e3b119b5dc.js +8 -0
- package/out/_next/static/chunks/799-b616401fe0dafdeb.js +1 -0
- package/out/_next/static/chunks/904-4653b7a849f4db94.js +1 -0
- package/out/_next/static/chunks/pages/_app-5ec41fc53c1f6405.js +434 -0
- package/out/_next/static/chunks/pages/{changelog-afd18276fe018b24.js → changelog-02cd80dad6f40878.js} +1 -1
- package/out/_next/static/chunks/pages/changes-8e9da8fbb809aad3.js +1 -0
- package/out/_next/static/chunks/pages/custom-types/{[customTypeId]-3f862ad6111a1fc0.js → [customTypeId]-97ab3b90b85d645d.js} +1 -1
- package/out/_next/static/chunks/pages/{custom-types-94b8f8dbf7727412.js → custom-types-3c8e721ec6802127.js} +1 -1
- package/out/_next/static/chunks/pages/index-cf93d16e9c63b6db.js +1 -0
- package/out/_next/static/chunks/pages/{labs-ee206005948f8e87.js → labs-39b50541a4c370bf.js} +1 -1
- package/out/_next/static/chunks/pages/page-types/{[pageTypeId]-d1ffca11c42f2603.js → [pageTypeId]-84a22c5e480d3fa9.js} +1 -1
- package/out/_next/static/chunks/pages/settings-879686e3a8759dc3.js +1 -0
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/{simulator-897ca93c114a1435.js → simulator-c498e9c80cae8cce.js} +1 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-9b893c62b2f2fe4a.js +1 -0
- package/out/_next/static/chunks/pages/slices-4522d604117d8c66.js +1 -0
- package/out/_next/static/css/3c26dbbbd8f4be12.css +1 -0
- package/out/_next/static/css/{37153180c3b0dd66.css → 838fd8bb5a7c32b0.css} +1 -1
- package/out/_next/static/css/ca32882a5d2d8d88.css +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/settings.html +1 -0
- 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 +9 -6
- package/pages/settings.tsx +1 -0
- package/pages/slices.tsx +20 -8
- package/postcss.config.js +10 -0
- package/src/apiClient.ts +1 -22
- package/src/components/FieldSet/FieldSet.stories.tsx +20 -11
- package/src/components/RelativeTime/RelativeTime.stories.tsx +25 -0
- package/src/components/RelativeTime/RelativeTime.tsx +40 -0
- package/src/components/RelativeTime/index.ts +1 -0
- package/src/domain/__tests__/customType.test.ts +205 -19
- package/src/domain/customType.ts +132 -7
- package/src/domain/slice.ts +38 -0
- 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/features/environments/actions/setEnvironment.ts +2 -2
- package/src/features/settings/SettingsPage.tsx +47 -0
- package/src/features/settings/git/ConnectGitRepository.tsx +126 -0
- package/src/features/settings/git/ConnectGitRepositoryBlankSlate.tsx +33 -0
- package/src/features/settings/git/GitOwnerSelect.tsx +71 -0
- package/src/features/settings/git/GitProvider.ts +40 -0
- package/src/features/settings/git/GitProviderConnectButtons.tsx +63 -0
- package/src/features/settings/git/GitRepositoriesList.tsx +76 -0
- package/src/features/settings/git/GitRepositoriesSearch.tsx +69 -0
- package/src/features/settings/git/GitRepositoryConnectDialog.tsx +85 -0
- package/src/features/settings/git/GitRepositoryDisconnectDialog.tsx +60 -0
- package/src/features/settings/git/useGitIntegrationExperiment.ts +8 -0
- package/src/features/settings/git/useGitOwners.ts +12 -0
- package/src/features/settings/git/useGitRepos.ts +24 -0
- package/src/features/settings/git/useLinkedGitRepos.ts +41 -0
- package/src/features/settings/git/useWriteAPIToken.ts +23 -0
- package/src/features/slices/actions/createSlice.ts +5 -29
- package/src/features/slices/actions/deleteSlice.ts +33 -0
- package/src/features/slices/actions/renameSlice.ts +37 -0
- package/src/features/slices/convertLegacySlice/ConvertLegacySliceAsNewSliceDialog.tsx +0 -1
- package/src/features/slices/convertLegacySlice/ConvertLegacySliceAsNewVariationDialog.tsx +0 -1
- package/src/features/slices/convertLegacySlice/ConvertLegacySliceMergeWithIdenticalDialog.tsx +0 -1
- package/src/hooks/useUser.ts +14 -0
- package/src/icons/SettingsIcon.tsx +19 -0
- package/src/modules/availableCustomTypes/index.ts +29 -135
- package/src/modules/loading/types.ts +0 -5
- package/src/modules/modal/types.ts +0 -3
- package/src/modules/slices/index.ts +27 -193
- package/src/modules/slices/selector.ts +0 -14
- package/src/modules/useSliceMachineActions.ts +70 -89
- package/src/modules/userContext/index.ts +3 -3
- package/src/redux/saga.ts +0 -4
- package/test/src/modules/__fixtures__/serverState.ts +1 -2
- package/test/src/modules/availableCustomTypes/index.test.ts +2 -243
- package/test/src/modules/slices.test.ts +1 -267
- package/out/_next/static/chunks/18539003-5cc559566b738915.js +0 -97
- package/out/_next/static/chunks/25-37d6fa7f064be04b.js +0 -1
- package/out/_next/static/chunks/318-ce7e74f18f2d5b22.js +0 -1
- package/out/_next/static/chunks/376-7e784d6069e01654.js +0 -8
- 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/904-9a4c1264727ae89a.js +0 -1
- package/out/_next/static/chunks/pages/_app-cd9d4c76a4abc11a.js +0 -432
- package/out/_next/static/chunks/pages/changes-2a976f9efeb719aa.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/out/_next/static/chunks/pages/slices-e9c70c082ca3e3f9.js +0 -1
- package/out/_next/static/css/200244e3e0463c39.css +0 -1
- package/out/_next/static/m6psnC5u1xT7Y6osWHKjp/_buildManifest.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/{m6psnC5u1xT7Y6osWHKjp → Dz7wwTNVdXvoAjySXz7mE}/_ssgManifest.js +0 -0
|
@@ -1,28 +1,15 @@
|
|
|
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,
|
|
22
9
|
normalizeFrontendCustomTypes,
|
|
23
10
|
} from "@lib/models/common/normalizers/customType";
|
|
24
11
|
import { omit } from "lodash";
|
|
25
|
-
import {
|
|
12
|
+
import { sliceDeleteSuccess } from "../slices";
|
|
26
13
|
import { filterSliceFromCustomType } from "@lib/utils/shared/customTypes";
|
|
27
14
|
import {
|
|
28
15
|
LocalOrRemoteCustomType,
|
|
@@ -30,63 +17,37 @@ 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
|
|
89
|
-
| ActionType<typeof
|
|
46
|
+
| ActionType<typeof customTypeCreateSuccess>
|
|
47
|
+
| ActionType<typeof customTypeRenameSuccess>
|
|
48
|
+
| ActionType<typeof customTypeSaveSuccess>
|
|
49
|
+
| ActionType<typeof customTypeDeleteSuccess>
|
|
50
|
+
| ActionType<typeof sliceDeleteSuccess>;
|
|
90
51
|
|
|
91
52
|
// Selectors
|
|
92
53
|
export const selectAllCustomTypes = (
|
|
@@ -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)) {
|
|
@@ -191,7 +152,7 @@ export const availableCustomTypesReducer: Reducer<
|
|
|
191
152
|
return state;
|
|
192
153
|
}
|
|
193
154
|
|
|
194
|
-
case getType(
|
|
155
|
+
case getType(sliceDeleteSuccess): {
|
|
195
156
|
const sliceId = action.payload.sliceId;
|
|
196
157
|
|
|
197
158
|
const customTypesUpdated: AvailableCustomTypesStoreType = Object.entries(
|
|
@@ -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,12 +5,7 @@ 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
|
-
RENAME_SLICE = "RENAME_SLICE",
|
|
11
8
|
GENERATE_SLICE_CUSTOM_SCREENSHOT = "GENERATE_SLICE_CUSTOM_SCREENSHOT",
|
|
12
|
-
SAVE_SLICE = "SAVE_SLICE",
|
|
13
|
-
DELETE_SLICE = "DELETE_SLICE",
|
|
14
9
|
SIMULATOR_SAVE_MOCK = "SIMULATOR_SAVE_MOCK",
|
|
15
10
|
CHANGELOG = "CHANGELOG",
|
|
16
11
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
export enum ModalKeysEnum {
|
|
2
2
|
LOGIN = "LOGIN",
|
|
3
|
-
CREATE_CUSTOM_TYPE = "CREATE_CUSTOM_TYPE",
|
|
4
|
-
RENAME_SLICE = "RENAME_SLICE",
|
|
5
3
|
SCREENSHOT_PREVIEW = "SCREENSHOT_PREVIEW",
|
|
6
4
|
SCREENSHOTS = "SCREENSHOTS",
|
|
7
|
-
DELETE_SLICE = "DELETE_SLICE",
|
|
8
5
|
SIMULATOR_SETUP = "SIMULATOR_SETUP",
|
|
9
6
|
}
|
|
10
7
|
|
|
@@ -1,111 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ActionType,
|
|
3
|
-
createAction,
|
|
4
|
-
createAsyncAction,
|
|
5
|
-
getType,
|
|
6
|
-
} from "typesafe-actions";
|
|
7
|
-
import {
|
|
8
|
-
call,
|
|
9
|
-
fork,
|
|
10
|
-
put,
|
|
11
|
-
SagaReturnType,
|
|
12
|
-
select,
|
|
13
|
-
takeLatest,
|
|
14
|
-
} from "redux-saga/effects";
|
|
1
|
+
import { ActionType, createAction, getType } from "typesafe-actions";
|
|
15
2
|
import { Reducer } from "redux";
|
|
16
3
|
|
|
17
4
|
import { LocalOrRemoteSlice } from "@lib/models/common/ModelData";
|
|
18
5
|
import { normalizeFrontendSlices } from "@lib/models/common/normalizers/slices";
|
|
19
6
|
import { SliceSM } from "@lib/models/common/Slice";
|
|
20
7
|
import { LibraryUI } from "@models/common/LibraryUI";
|
|
21
|
-
import {
|
|
22
|
-
import { LoadingKeysEnum } from "@src/modules/loading/types";
|
|
23
|
-
import { deleteSlice, renameSlice, SaveSliceMockRequest } from "@src/apiClient";
|
|
24
|
-
import { modalCloseCreator } from "@src/modules/modal";
|
|
8
|
+
import { SaveSliceMockRequest } from "@src/apiClient";
|
|
25
9
|
import { refreshStateCreator } from "@src/modules/environment";
|
|
26
10
|
import { SliceMachineStoreType } from "@src/redux/type";
|
|
27
|
-
import { openToasterCreator, ToasterType } from "@src/modules/toaster";
|
|
28
11
|
import { SlicesStoreType } from "./types";
|
|
29
12
|
import { ComponentUI, ScreenshotUI } from "@lib/models/common/ComponentUI";
|
|
30
|
-
import { selectSliceById } from "./selector";
|
|
31
|
-
import { ScreenshotGenerationMethod } from "@lib/models/common/Screenshots";
|
|
32
13
|
|
|
33
14
|
// Action Creators
|
|
34
|
-
export const
|
|
15
|
+
export const sliceCreateSuccess = createAction("SLICES/CREATE_SUCCESS")<{
|
|
35
16
|
libraries: Readonly<LibraryUI[]>;
|
|
36
17
|
}>();
|
|
37
18
|
|
|
38
|
-
export const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
)<
|
|
43
|
-
{
|
|
44
|
-
libName: string;
|
|
45
|
-
sliceId: string;
|
|
46
|
-
newSliceName: string;
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
libName: string;
|
|
50
|
-
renamedSlice: SliceSM;
|
|
51
|
-
}
|
|
52
|
-
>();
|
|
19
|
+
export const sliceRenameSuccess = createAction("SLICES/RENAME_SUCCESS")<{
|
|
20
|
+
libName: string;
|
|
21
|
+
renamedSlice: SliceSM;
|
|
22
|
+
}>();
|
|
53
23
|
|
|
54
|
-
export const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
)<
|
|
59
|
-
{
|
|
60
|
-
sliceId: string;
|
|
61
|
-
sliceName: string;
|
|
62
|
-
libName: string;
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
sliceId: string;
|
|
66
|
-
sliceName: string;
|
|
67
|
-
libName: string;
|
|
68
|
-
}
|
|
69
|
-
>();
|
|
24
|
+
export const sliceDeleteSuccess = createAction("SLICES/DELETE_SUCCESS")<{
|
|
25
|
+
sliceId: string;
|
|
26
|
+
libName: string;
|
|
27
|
+
}>();
|
|
70
28
|
|
|
71
|
-
export const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
"SLICE/UPDATE.FAILURE",
|
|
75
|
-
)<
|
|
76
|
-
{
|
|
77
|
-
component: ComponentUI;
|
|
78
|
-
setSliceBuilderState: () => void;
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
component: ComponentUI;
|
|
82
|
-
}
|
|
83
|
-
>();
|
|
29
|
+
export const sliceUpdateSuccess = createAction("SLICE/UPDATE_SUCCESS")<{
|
|
30
|
+
component: ComponentUI;
|
|
31
|
+
}>();
|
|
84
32
|
|
|
85
|
-
export const
|
|
86
|
-
"SLICE/
|
|
87
|
-
|
|
88
|
-
"SLICE/GENERATE_CUSTOM_SCREENSHOT.FAILURE",
|
|
89
|
-
)<
|
|
90
|
-
{
|
|
91
|
-
variationId: string;
|
|
92
|
-
component: ComponentUI;
|
|
93
|
-
file: Blob;
|
|
94
|
-
method: ScreenshotGenerationMethod;
|
|
95
|
-
},
|
|
96
|
-
{ variationId: string; screenshot: ScreenshotUI; component: ComponentUI }
|
|
97
|
-
>();
|
|
33
|
+
export const sliceGenerateCustomScreenshotSuccess = createAction(
|
|
34
|
+
"SLICE/GENERATE_CUSTOM_SCREENSHOT_SUCCESS",
|
|
35
|
+
)<{ variationId: string; screenshot: ScreenshotUI; component: ComponentUI }>();
|
|
98
36
|
|
|
99
37
|
export const updateSliceMock =
|
|
100
38
|
createAction("SLICE/UPDATE_MOCK")<SaveSliceMockRequest>();
|
|
101
39
|
|
|
102
40
|
type SlicesActions =
|
|
103
41
|
| ActionType<typeof refreshStateCreator>
|
|
104
|
-
| ActionType<typeof
|
|
105
|
-
| ActionType<typeof
|
|
106
|
-
| ActionType<typeof
|
|
107
|
-
| ActionType<typeof
|
|
108
|
-
| ActionType<typeof
|
|
42
|
+
| ActionType<typeof sliceCreateSuccess>
|
|
43
|
+
| ActionType<typeof sliceRenameSuccess>
|
|
44
|
+
| ActionType<typeof sliceDeleteSuccess>
|
|
45
|
+
| ActionType<typeof sliceUpdateSuccess>
|
|
46
|
+
| ActionType<typeof sliceGenerateCustomScreenshotSuccess>
|
|
109
47
|
| ActionType<typeof updateSliceMock>;
|
|
110
48
|
|
|
111
49
|
// Selectors
|
|
@@ -143,12 +81,12 @@ export const slicesReducer: Reducer<SlicesStoreType | null, SlicesActions> = (
|
|
|
143
81
|
libraries: action.payload.libraries,
|
|
144
82
|
remoteSlices: action.payload.remoteSlices,
|
|
145
83
|
};
|
|
146
|
-
case getType(
|
|
84
|
+
case getType(sliceCreateSuccess):
|
|
147
85
|
return {
|
|
148
86
|
...state,
|
|
149
87
|
libraries: action.payload.libraries,
|
|
150
88
|
};
|
|
151
|
-
case getType(
|
|
89
|
+
case getType(sliceRenameSuccess): {
|
|
152
90
|
const { libName, renamedSlice } = action.payload;
|
|
153
91
|
const newLibs = state.libraries.map((library) => {
|
|
154
92
|
if (library.name !== libName) return library;
|
|
@@ -169,7 +107,7 @@ export const slicesReducer: Reducer<SlicesStoreType | null, SlicesActions> = (
|
|
|
169
107
|
libraries: newLibs,
|
|
170
108
|
};
|
|
171
109
|
}
|
|
172
|
-
case getType(
|
|
110
|
+
case getType(sliceUpdateSuccess): {
|
|
173
111
|
const newComponentUI = action.payload.component;
|
|
174
112
|
|
|
175
113
|
const newLibraries = state.libraries.map((library) => {
|
|
@@ -186,7 +124,7 @@ export const slicesReducer: Reducer<SlicesStoreType | null, SlicesActions> = (
|
|
|
186
124
|
|
|
187
125
|
return { ...state, libraries: newLibraries };
|
|
188
126
|
}
|
|
189
|
-
case getType(
|
|
127
|
+
case getType(sliceGenerateCustomScreenshotSuccess): {
|
|
190
128
|
const { component, screenshot, variationId } = action.payload;
|
|
191
129
|
|
|
192
130
|
const newLibraries = state.libraries.map((library) => {
|
|
@@ -209,7 +147,7 @@ export const slicesReducer: Reducer<SlicesStoreType | null, SlicesActions> = (
|
|
|
209
147
|
|
|
210
148
|
return { ...state, libraries: newLibraries };
|
|
211
149
|
}
|
|
212
|
-
case getType(
|
|
150
|
+
case getType(sliceDeleteSuccess): {
|
|
213
151
|
const { libName, sliceId } = action.payload;
|
|
214
152
|
const newLibs = state.libraries.map((library) => {
|
|
215
153
|
if (library.name !== libName) return library;
|
|
@@ -254,107 +192,3 @@ export const slicesReducer: Reducer<SlicesStoreType | null, SlicesActions> = (
|
|
|
254
192
|
return state;
|
|
255
193
|
}
|
|
256
194
|
};
|
|
257
|
-
|
|
258
|
-
// Sagas
|
|
259
|
-
|
|
260
|
-
export function* renameSliceSaga({
|
|
261
|
-
payload,
|
|
262
|
-
}: ReturnType<typeof renameSliceCreator.request>) {
|
|
263
|
-
const { libName, sliceId, newSliceName } = payload;
|
|
264
|
-
try {
|
|
265
|
-
const slice = (yield select((store: SliceMachineStoreType) =>
|
|
266
|
-
selectSliceById(store, libName, sliceId),
|
|
267
|
-
)) as ReturnType<typeof selectSliceById>;
|
|
268
|
-
if (!slice) {
|
|
269
|
-
throw new Error(
|
|
270
|
-
`Slice "${payload.sliceId} in the "${payload.libName}" library not found.`,
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const renamedSlice = renameSliceModel({
|
|
275
|
-
slice: slice.model,
|
|
276
|
-
newName: newSliceName,
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
yield call(renameSlice, renamedSlice, libName);
|
|
280
|
-
yield put(renameSliceCreator.success({ libName, renamedSlice }));
|
|
281
|
-
|
|
282
|
-
yield put(modalCloseCreator());
|
|
283
|
-
yield put(
|
|
284
|
-
openToasterCreator({
|
|
285
|
-
content: "Slice name updated",
|
|
286
|
-
type: ToasterType.SUCCESS,
|
|
287
|
-
}),
|
|
288
|
-
);
|
|
289
|
-
} catch (e) {
|
|
290
|
-
yield put(
|
|
291
|
-
openToasterCreator({
|
|
292
|
-
content: "Internal Error: Slice name not saved",
|
|
293
|
-
type: ToasterType.ERROR,
|
|
294
|
-
}),
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
function* watchRenameSlice() {
|
|
300
|
-
yield takeLatest(
|
|
301
|
-
getType(renameSliceCreator.request),
|
|
302
|
-
withLoader(renameSliceSaga, LoadingKeysEnum.RENAME_SLICE),
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
export function* deleteSliceSaga({
|
|
307
|
-
payload,
|
|
308
|
-
}: ReturnType<typeof deleteSliceCreator.request>) {
|
|
309
|
-
const { libName, sliceId, sliceName } = payload;
|
|
310
|
-
try {
|
|
311
|
-
const result = (yield call(
|
|
312
|
-
deleteSlice,
|
|
313
|
-
sliceId,
|
|
314
|
-
libName,
|
|
315
|
-
)) as SagaReturnType<typeof deleteSlice>;
|
|
316
|
-
if (result.errors.length > 0) {
|
|
317
|
-
throw result.errors;
|
|
318
|
-
}
|
|
319
|
-
yield put(deleteSliceCreator.success(payload));
|
|
320
|
-
yield put(
|
|
321
|
-
openToasterCreator({
|
|
322
|
-
content: `Successfully deleted Slice “${sliceName}”`,
|
|
323
|
-
type: ToasterType.SUCCESS,
|
|
324
|
-
}),
|
|
325
|
-
);
|
|
326
|
-
} catch (e) {
|
|
327
|
-
yield put(
|
|
328
|
-
openToasterCreator({
|
|
329
|
-
content: "An unexpected error happened while deleting your slice.",
|
|
330
|
-
type: ToasterType.ERROR,
|
|
331
|
-
}),
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
yield put(modalCloseCreator());
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
function* watchDeleteSlice() {
|
|
338
|
-
yield takeLatest(
|
|
339
|
-
getType(deleteSliceCreator.request),
|
|
340
|
-
withLoader(deleteSliceSaga, LoadingKeysEnum.DELETE_SLICE),
|
|
341
|
-
);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
// Saga Exports
|
|
345
|
-
export function* watchSliceSagas() {
|
|
346
|
-
yield fork(watchRenameSlice);
|
|
347
|
-
yield fork(watchDeleteSlice);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
type RenameSliceModelArgs = {
|
|
351
|
-
slice: SliceSM;
|
|
352
|
-
newName: string;
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
export function renameSliceModel(args: RenameSliceModelArgs): SliceSM {
|
|
356
|
-
return {
|
|
357
|
-
...args.slice,
|
|
358
|
-
name: args.newName,
|
|
359
|
-
};
|
|
360
|
-
}
|
|
@@ -2,20 +2,6 @@ import { SliceMachineStoreType } from "@src/redux/type";
|
|
|
2
2
|
|
|
3
3
|
import { getLibraries } from "./index";
|
|
4
4
|
|
|
5
|
-
export const selectSliceById = (
|
|
6
|
-
store: SliceMachineStoreType,
|
|
7
|
-
libraryName: string,
|
|
8
|
-
sliceId: string,
|
|
9
|
-
) => {
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
11
|
-
const libraries = getLibraries(store) || [];
|
|
12
|
-
|
|
13
|
-
const library = libraries.find((library) => library.name === libraryName);
|
|
14
|
-
const slice = library?.components.find((c) => c.model.id === sliceId);
|
|
15
|
-
|
|
16
|
-
return slice;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
5
|
export const selectCurrentSlice = (
|
|
20
6
|
store: SliceMachineStoreType,
|
|
21
7
|
lib: string,
|