slice-machine-ui 1.23.2-beta.4 → 1.23.2-beta.6

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.
Files changed (49) hide show
  1. package/components/DeleteSliceModal/index.tsx +34 -24
  2. package/components/Forms/RenameSliceModal/RenameSliceModal.tsx +33 -21
  3. package/out/404.html +1 -1
  4. package/out/_next/static/chunks/25-01f422cea8066349.js +1 -0
  5. package/out/_next/static/chunks/727-358d7fae68a880b3.js +1 -0
  6. package/out/_next/static/chunks/799-d95a93e965557aeb.js +1 -0
  7. package/out/_next/static/chunks/904-1ff7519adece2b55.js +1 -0
  8. package/out/_next/static/chunks/pages/{_app-4a63c0e108026c4d.js → _app-fc26eeb48d6b42ce.js} +37 -37
  9. package/out/_next/static/chunks/pages/custom-types/{[customTypeId]-3f862ad6111a1fc0.js → [customTypeId]-97ab3b90b85d645d.js} +1 -1
  10. package/out/_next/static/chunks/pages/{custom-types-94b8f8dbf7727412.js → custom-types-3c8e721ec6802127.js} +1 -1
  11. package/out/_next/static/chunks/pages/{index-ca194b18d0e3930d.js → index-cf93d16e9c63b6db.js} +1 -1
  12. package/out/_next/static/chunks/pages/page-types/{[pageTypeId]-d1ffca11c42f2603.js → [pageTypeId]-84a22c5e480d3fa9.js} +1 -1
  13. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/{simulator-897ca93c114a1435.js → simulator-52c3e1f9d14160b8.js} +1 -1
  14. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-608d206d10a719e3.js +1 -0
  15. package/out/_next/static/chunks/pages/slices-b0b58192a87df822.js +1 -0
  16. package/out/_next/static/{GqPZYfMQrQUPwvgI_rvdq → y29BInt77vPZ4FQmk4-Xa}/_buildManifest.js +1 -1
  17. package/out/changelog.html +1 -1
  18. package/out/changes.html +1 -1
  19. package/out/custom-types/[customTypeId].html +1 -1
  20. package/out/custom-types.html +1 -1
  21. package/out/index.html +1 -1
  22. package/out/labs.html +1 -1
  23. package/out/page-types/[pageTypeId].html +1 -1
  24. package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
  25. package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
  26. package/out/slices.html +1 -1
  27. package/package.json +3 -3
  28. package/pages/slices.tsx +20 -8
  29. package/src/apiClient.ts +1 -22
  30. package/src/domain/slice.ts +38 -0
  31. package/src/features/slices/actions/createSlice.ts +5 -29
  32. package/src/features/slices/actions/deleteSlice.ts +33 -0
  33. package/src/features/slices/actions/renameSlice.ts +37 -0
  34. package/src/modules/availableCustomTypes/index.ts +3 -3
  35. package/src/modules/loading/types.ts +0 -2
  36. package/src/modules/modal/types.ts +0 -2
  37. package/src/modules/slices/index.ts +27 -193
  38. package/src/modules/slices/selector.ts +0 -14
  39. package/src/modules/useSliceMachineActions.ts +25 -38
  40. package/src/redux/saga.ts +0 -2
  41. package/test/src/modules/availableCustomTypes/index.test.ts +0 -89
  42. package/test/src/modules/slices.test.ts +1 -267
  43. package/out/_next/static/chunks/25-37d6fa7f064be04b.js +0 -1
  44. package/out/_next/static/chunks/727-c5028806448c4387.js +0 -1
  45. package/out/_next/static/chunks/731-341869976a48a09a.js +0 -1
  46. package/out/_next/static/chunks/904-833eed675f19ab60.js +0 -1
  47. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-2d3d84de925b289e.js +0 -1
  48. package/out/_next/static/chunks/pages/slices-e9c70c082ca3e3f9.js +0 -1
  49. /package/out/_next/static/{GqPZYfMQrQUPwvgI_rvdq → y29BInt77vPZ4FQmk4-Xa}/_ssgManifest.js +0 -0
package/pages/slices.tsx CHANGED
@@ -24,7 +24,6 @@ import ScreenshotChangesModal from "@components/ScreenshotChangesModal";
24
24
  import { RenameSliceModal } from "@components/Forms/RenameSliceModal";
25
25
  import { DeleteSliceModal } from "@components/DeleteSliceModal";
26
26
  import { SliceMachineStoreType } from "@src/redux/type";
27
- import useSliceMachineActions from "@src/modules/useSliceMachineActions";
28
27
  import { getLibraries, getRemoteSlices } from "@src/modules/slices";
29
28
  import { useScreenshotChangesModal } from "@src/hooks/useScreenshotChangesModal";
30
29
  import { SharedSliceCard } from "@src/features/slices/sliceCards/SharedSliceCard";
@@ -33,9 +32,6 @@ import { SliceToastMessage } from "@components/ToasterContainer";
33
32
 
34
33
  const SlicesIndex: React.FunctionComponent = () => {
35
34
  const router = useRouter();
36
- const { openRenameSliceModal, openDeleteSliceModal } =
37
- useSliceMachineActions();
38
-
39
35
  const { modalPayload, onOpenModal } = useScreenshotChangesModal();
40
36
 
41
37
  const { sliceFilterFn, defaultVariationSelector } = modalPayload;
@@ -47,6 +43,8 @@ const SlicesIndex: React.FunctionComponent = () => {
47
43
  }),
48
44
  );
49
45
  const [isCreateSliceModalOpen, setIsCreateSliceModalOpen] = useState(false);
46
+ const [isDeleteSliceModalOpen, setIsDeleteSliceModalOpen] = useState(false);
47
+ const [isRenameSliceModalOpen, setIsRenameSliceModalOpen] = useState(false);
50
48
 
51
49
  const localLibraries: LibraryUI[] = libraries.filter(
52
50
  (library) => library.isLocal,
@@ -65,6 +63,14 @@ const SlicesIndex: React.FunctionComponent = () => {
65
63
 
66
64
  const [sliceForEdit, setSliceForEdit] = useState<ComponentUI>();
67
65
 
66
+ const openDeleteSliceModal = () => {
67
+ setIsDeleteSliceModalOpen(true);
68
+ };
69
+
70
+ const openRenameSliceModal = () => {
71
+ setIsRenameSliceModalOpen(true);
72
+ };
73
+
68
74
  return (
69
75
  <>
70
76
  <Head>
@@ -237,15 +243,21 @@ const SlicesIndex: React.FunctionComponent = () => {
237
243
  />
238
244
  )}
239
245
  <RenameSliceModal
240
- sliceId={sliceForEdit?.model.id ?? ""}
241
- sliceName={sliceForEdit?.model.name ?? ""}
242
- libName={sliceForEdit?.from ?? ""}
246
+ isOpen={isRenameSliceModalOpen}
247
+ slice={sliceForEdit}
248
+ onClose={() => {
249
+ setIsRenameSliceModalOpen(false);
250
+ }}
243
251
  data-cy="rename-slice-modal"
244
252
  />
245
253
  <DeleteSliceModal
254
+ isOpen={isDeleteSliceModalOpen}
255
+ libName={sliceForEdit?.from ?? ""}
246
256
  sliceId={sliceForEdit?.model.id ?? ""}
247
257
  sliceName={sliceForEdit?.model.name ?? ""}
248
- libName={sliceForEdit?.from ?? ""}
258
+ onClose={() => {
259
+ setIsDeleteSliceModalOpen(false);
260
+ }}
249
261
  />
250
262
  </AppLayoutContent>
251
263
  </AppLayout>
package/src/apiClient.ts CHANGED
@@ -3,12 +3,7 @@ import { SharedSliceContent } from "@prismicio/types-internal/lib/content";
3
3
 
4
4
  import { SimulatorCheckResponse } from "@models/common/Simulator";
5
5
  import { SliceMachineManagerClient } from "@slicemachine/manager/client";
6
- import {
7
- type SliceSM,
8
- Slices,
9
- type VariationSM,
10
- Variations,
11
- } from "@lib/models/common/Slice";
6
+ import { Slices, type VariationSM, Variations } from "@lib/models/common/Slice";
12
7
  import { CustomTypes } from "@lib/models/common/CustomType";
13
8
  import { CheckAuthStatusResponse } from "@models/common/Auth";
14
9
  import ServerState from "@models/server/ServerState";
@@ -89,22 +84,6 @@ export const readSlice = async (libraryID: string, sliceID: string) => {
89
84
  return { slice: model ? Slices.toSM(model) : undefined, errors };
90
85
  };
91
86
 
92
- export const renameSlice = async (
93
- slice: SliceSM,
94
- libName: string,
95
- ): ReturnType<SliceMachineManagerClient["slices"]["renameSlice"]> => {
96
- return await managerClient.slices.renameSlice({
97
- libraryID: libName,
98
- model: Slices.fromSM(slice),
99
- });
100
- };
101
-
102
- export const deleteSlice = async (sliceId: string, libName: string) =>
103
- await managerClient.slices.deleteSlice({
104
- libraryID: libName,
105
- sliceID: sliceId,
106
- });
107
-
108
87
  export const renameSliceVariation = async (
109
88
  slice: ComponentUI,
110
89
  variation: VariationSM,
@@ -1,11 +1,13 @@
1
1
  import type {
2
2
  CompositeSlice,
3
3
  LegacySlice,
4
+ SharedSlice,
4
5
  } from "@prismicio/types-internal/lib/customtypes/widgets/slices";
5
6
  import { NestableWidget } from "@prismicio/types-internal/lib/customtypes";
6
7
 
7
8
  import type { ComponentUI } from "@lib/models/common/ComponentUI";
8
9
  import type { VariationSM, WidgetsArea } from "@lib/models/common/Slice";
10
+ import { pascalize, snakelize } from "@lib/utils/str";
9
11
 
10
12
  type CopySliceVariationArgs = {
11
13
  copiedVariation: VariationSM;
@@ -46,6 +48,8 @@ type ReorderFieldArgs = {
46
48
  destinationIndex: number;
47
49
  };
48
50
 
51
+ const DEFAULT_VARIATION_ID = "default";
52
+
49
53
  export function countMissingScreenshots(slice: ComponentUI): number {
50
54
  return slice.model.variations.length - Object.keys(slice.screenshots).length;
51
55
  }
@@ -243,3 +247,37 @@ export function reorderField(args: ReorderFieldArgs): ComponentUI {
243
247
  },
244
248
  };
245
249
  }
250
+
251
+ export function buildEmptySliceModel(sliceName: string): SharedSlice {
252
+ return {
253
+ id: snakelize(sliceName),
254
+ type: "SharedSlice",
255
+ name: sliceName,
256
+ description: sliceName,
257
+ variations: [
258
+ {
259
+ id: DEFAULT_VARIATION_ID,
260
+ name: pascalize(DEFAULT_VARIATION_ID),
261
+ // Property not used yet. Fallback to "...".
262
+ docURL: "...",
263
+ // "initial" is fine here as default value.
264
+ version: "initial",
265
+ description: pascalize(DEFAULT_VARIATION_ID),
266
+ // Empty string is fine, we don't want to save imageUrl.
267
+ // We don't want to compare local and remote image with imageUrl.
268
+ // It will be striped anyway when doing the comparison.
269
+ imageUrl: "",
270
+ },
271
+ ],
272
+ };
273
+ }
274
+
275
+ export function rename(slice: ComponentUI, newSliceName: string): ComponentUI {
276
+ return {
277
+ ...slice,
278
+ model: {
279
+ ...slice.model,
280
+ name: newSliceName,
281
+ },
282
+ };
283
+ }
@@ -1,9 +1,10 @@
1
1
  import { toast } from "react-toastify";
2
2
  import { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
3
3
 
4
- import { pascalize, snakelize } from "@lib/utils/str";
4
+ import { pascalize } from "@lib/utils/str";
5
5
  import { managerClient } from "@src/managerClient";
6
6
  import { telemetry } from "@src/apiClient";
7
+ import { buildEmptySliceModel } from "@src/domain/slice";
7
8
 
8
9
  type CreateSliceArgs = {
9
10
  sliceName: string;
@@ -12,8 +13,9 @@ type CreateSliceArgs = {
12
13
  };
13
14
 
14
15
  export async function createSlice(args: CreateSliceArgs) {
16
+ const { sliceName, libraryName, onSuccess } = args;
17
+
15
18
  try {
16
- const { sliceName, libraryName, onSuccess } = args;
17
19
  const newSlice = buildEmptySliceModel(sliceName);
18
20
  const { errors } = await managerClient.slices.createSlice({
19
21
  libraryID: libraryName,
@@ -33,34 +35,8 @@ export async function createSlice(args: CreateSliceArgs) {
33
35
 
34
36
  await onSuccess(newSlice);
35
37
  } catch (e) {
36
- const errorMessage = "Internal Error: Slice not created";
38
+ const errorMessage = `An unexpected error happened while creating slice ${sliceName}.`;
37
39
  console.error(errorMessage, e);
38
40
  toast.error(errorMessage);
39
41
  }
40
42
  }
41
-
42
- const DEFAULT_VARIATION_ID = "default";
43
-
44
- function buildEmptySliceModel(sliceName: string): SharedSlice {
45
- return {
46
- id: snakelize(sliceName),
47
- type: "SharedSlice",
48
- name: sliceName,
49
- description: sliceName,
50
- variations: [
51
- {
52
- id: DEFAULT_VARIATION_ID,
53
- name: pascalize(DEFAULT_VARIATION_ID),
54
- // Property not used yet. Fallback to "...".
55
- docURL: "...",
56
- // "initial" is fine here as default value.
57
- version: "initial",
58
- description: pascalize(DEFAULT_VARIATION_ID),
59
- // Empty string is fine, we don't want to save imageUrl.
60
- // We don't want to compare local and remote image with imageUrl.
61
- // It will be striped anyway when doing the comparison.
62
- imageUrl: "",
63
- },
64
- ],
65
- };
66
- }
@@ -0,0 +1,33 @@
1
+ import { toast } from "react-toastify";
2
+
3
+ import { managerClient } from "@src/managerClient";
4
+
5
+ type DeleteSliceArgs = {
6
+ libraryID: string;
7
+ sliceID: string;
8
+ sliceName: string;
9
+ onSuccess: () => void;
10
+ };
11
+
12
+ export async function deleteSlice(args: DeleteSliceArgs) {
13
+ const { sliceName, sliceID, libraryID, onSuccess } = args;
14
+
15
+ try {
16
+ const { errors } = await managerClient.slices.deleteSlice({
17
+ libraryID,
18
+ sliceID,
19
+ });
20
+
21
+ if (errors.length > 0) {
22
+ throw errors;
23
+ }
24
+
25
+ onSuccess();
26
+
27
+ toast.success(`Successfully deleted slice “${sliceName}”`);
28
+ } catch (e) {
29
+ const errorMessage = `An unexpected error happened while deleting slice “${sliceName}”.`;
30
+ console.error(errorMessage, e);
31
+ toast.error(errorMessage);
32
+ }
33
+ }
@@ -0,0 +1,37 @@
1
+ import { toast } from "react-toastify";
2
+
3
+ import { managerClient } from "@src/managerClient";
4
+ import { ComponentUI } from "@lib/models/common/ComponentUI";
5
+ import { rename } from "@src/domain/slice";
6
+ import { Slices } from "@lib/models/common/Slice";
7
+
8
+ type DeleteSliceArgs = {
9
+ newSliceName: string;
10
+ slice: ComponentUI;
11
+ onSuccess: (renamedSlice: ComponentUI) => void;
12
+ };
13
+
14
+ export async function renameSlice(args: DeleteSliceArgs) {
15
+ const { slice, newSliceName, onSuccess } = args;
16
+
17
+ try {
18
+ const renamedSlice = rename(slice, newSliceName);
19
+
20
+ const { errors } = await managerClient.slices.renameSlice({
21
+ libraryID: slice.from,
22
+ model: Slices.fromSM(renamedSlice.model),
23
+ });
24
+
25
+ if (errors.length > 0) {
26
+ throw errors;
27
+ }
28
+
29
+ onSuccess(renamedSlice);
30
+
31
+ toast.success("Slice name updated");
32
+ } catch (e) {
33
+ const errorMessage = `An unexpected error happened while renaming “${slice.model.name}”.`;
34
+ console.error(errorMessage, e);
35
+ toast.error(errorMessage);
36
+ }
37
+ }
@@ -9,7 +9,7 @@ import {
9
9
  normalizeFrontendCustomTypes,
10
10
  } from "@lib/models/common/normalizers/customType";
11
11
  import { omit } from "lodash";
12
- import { deleteSliceCreator } from "../slices";
12
+ import { sliceDeleteSuccess } from "../slices";
13
13
  import { filterSliceFromCustomType } from "@lib/utils/shared/customTypes";
14
14
  import {
15
15
  LocalOrRemoteCustomType,
@@ -47,7 +47,7 @@ type CustomTypesActions =
47
47
  | ActionType<typeof customTypeRenameSuccess>
48
48
  | ActionType<typeof customTypeSaveSuccess>
49
49
  | ActionType<typeof customTypeDeleteSuccess>
50
- | ActionType<typeof deleteSliceCreator.success>;
50
+ | ActionType<typeof sliceDeleteSuccess>;
51
51
 
52
52
  // Selectors
53
53
  export const selectAllCustomTypes = (
@@ -152,7 +152,7 @@ export const availableCustomTypesReducer: Reducer<
152
152
  return state;
153
153
  }
154
154
 
155
- case getType(deleteSliceCreator.success): {
155
+ case getType(sliceDeleteSuccess): {
156
156
  const sliceId = action.payload.sliceId;
157
157
 
158
158
  const customTypesUpdated: AvailableCustomTypesStoreType = Object.entries(
@@ -5,9 +5,7 @@ export enum LoadingKeysEnum {
5
5
  REVIEW = "REVIEW",
6
6
  CHECK_SIMULATOR = "CHECK_SIMULATOR",
7
7
  CHECK_SIMULATOR_IFRAME = "CHECK_SIMULATOR_IFRAME",
8
- RENAME_SLICE = "RENAME_SLICE",
9
8
  GENERATE_SLICE_CUSTOM_SCREENSHOT = "GENERATE_SLICE_CUSTOM_SCREENSHOT",
10
- DELETE_SLICE = "DELETE_SLICE",
11
9
  SIMULATOR_SAVE_MOCK = "SIMULATOR_SAVE_MOCK",
12
10
  CHANGELOG = "CHANGELOG",
13
11
  }
@@ -1,9 +1,7 @@
1
1
  export enum ModalKeysEnum {
2
2
  LOGIN = "LOGIN",
3
- RENAME_SLICE = "RENAME_SLICE",
4
3
  SCREENSHOT_PREVIEW = "SCREENSHOT_PREVIEW",
5
4
  SCREENSHOTS = "SCREENSHOTS",
6
- DELETE_SLICE = "DELETE_SLICE",
7
5
  SIMULATOR_SETUP = "SIMULATOR_SETUP",
8
6
  }
9
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 { withLoader } from "@src/modules/loading";
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 createSlice = createAction("SLICES/CREATE_SLICE")<{
15
+ export const sliceCreateSuccess = createAction("SLICES/CREATE_SUCCESS")<{
35
16
  libraries: Readonly<LibraryUI[]>;
36
17
  }>();
37
18
 
38
- export const renameSliceCreator = createAsyncAction(
39
- "SLICES/RENAME.REQUEST",
40
- "SLICES/RENAME.RESPONSE",
41
- "SLICES/RENAME.FAILURE",
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 deleteSliceCreator = createAsyncAction(
55
- "SLICES/DELETE.REQUEST",
56
- "SLICES/DELETE.RESPONSE",
57
- "SLICES/DELETE.FAILURE",
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 updateSliceCreator = createAsyncAction(
72
- "SLICE/UPDATE.REQUEST",
73
- "SLICE/UPDATE.RESPONSE",
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 generateSliceCustomScreenshotCreator = createAsyncAction(
86
- "SLICE/GENERATE_CUSTOM_SCREENSHOT.REQUEST",
87
- "SLICE/GENERATE_CUSTOM_SCREENSHOT.RESPONSE",
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 createSlice>
105
- | ActionType<typeof renameSliceCreator>
106
- | ActionType<typeof deleteSliceCreator>
107
- | ActionType<typeof updateSliceCreator>
108
- | ActionType<typeof generateSliceCustomScreenshotCreator>
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(createSlice):
84
+ case getType(sliceCreateSuccess):
147
85
  return {
148
86
  ...state,
149
87
  libraries: action.payload.libraries,
150
88
  };
151
- case getType(renameSliceCreator.success): {
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(updateSliceCreator.success): {
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(generateSliceCustomScreenshotCreator.success): {
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(deleteSliceCreator.success): {
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,