slice-machine-ui 1.22.3-beta.1 → 1.22.3-beta.2

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 (151) hide show
  1. package/components/DeleteVariationModal/index.tsx +12 -11
  2. package/components/Forms/CreateSliceModal/CreateSliceModal.tsx +2 -5
  3. package/components/Forms/RenameCustomTypeModal/RenameCustomTypeModal.tsx +9 -5
  4. package/components/Forms/RenameVariationModal/RenameVariationModal.tsx +12 -11
  5. package/components/ItemHeader/index.tsx +1 -0
  6. package/components/ListItem/index.tsx +5 -2
  7. package/components/ScreenshotChangesModal/VariationDropZone.tsx +31 -9
  8. package/components/ScreenshotChangesModal/index.tsx +3 -0
  9. package/components/ScreenshotChangesModal/useCustomScreenshot.tsx +5 -5
  10. package/components/Simulator/index.tsx +9 -3
  11. package/lib/builders/CustomTypeBuilder/SliceZone/SlicesTemplatesModal.tsx +2 -2
  12. package/lib/builders/CustomTypeBuilder/SliceZone/UpdateSliceZoneModal.tsx +2 -2
  13. package/lib/builders/CustomTypeBuilder/SliceZone/index.tsx +12 -20
  14. package/lib/builders/CustomTypeBuilder/TabModal/update.tsx +3 -1
  15. package/lib/builders/CustomTypeBuilder/TabZone/index.tsx +119 -52
  16. package/lib/builders/CustomTypeBuilder/index.tsx +39 -42
  17. package/lib/builders/SliceBuilder/FieldZones/index.tsx +81 -56
  18. package/lib/builders/SliceBuilder/Sidebar/AddVariationModal.tsx +24 -16
  19. package/lib/builders/SliceBuilder/Sidebar/index.tsx +44 -46
  20. package/lib/builders/SliceBuilder/SimulatorButton/index.tsx +4 -28
  21. package/lib/builders/SliceBuilder/index.tsx +10 -96
  22. package/lib/builders/common/Zone/Card/components/Hints/CodeBlock.tsx +5 -1
  23. package/lib/builders/common/Zone/Card/components/NewField.tsx +16 -15
  24. package/lib/builders/common/Zone/Card/index.jsx +2 -0
  25. package/lib/builders/common/Zone/index.jsx +3 -1
  26. package/lib/models/common/ComponentUI.ts +0 -14
  27. package/lib/models/common/CustomType/sliceZone.ts +0 -29
  28. package/lib/models/common/CustomType/tab.ts +10 -142
  29. package/lib/models/common/widgets/Group/ListItem/index.jsx +61 -23
  30. package/out/404.html +1 -1
  31. package/out/_next/static/2SXh8a0HZLb2Awmhh2xob/_buildManifest.js +1 -0
  32. package/out/_next/static/chunks/065a3ddb-9a38ca0d60f0bf2f.js +1 -0
  33. package/out/_next/static/chunks/183-4feb6bb3eddbc768.js +1 -0
  34. package/out/_next/static/chunks/1cc2734a-2c5b6c0367fcde86.js +1 -0
  35. package/out/_next/static/chunks/25-8fedd33ad9b6de5b.js +1 -0
  36. package/out/_next/static/chunks/318-541db69860d31138.js +1 -0
  37. package/out/_next/static/chunks/{505-3f1cf09a086dcba8.js → 376-0ed5822f8afcaa7c.js} +3 -3
  38. package/out/_next/static/chunks/4c744e84-e3161d754618373f.js +1 -0
  39. package/out/_next/static/chunks/50-cfc2514205b86001.js +1 -0
  40. package/out/_next/static/chunks/543-f8766685f7f451e2.js +1 -0
  41. package/out/_next/static/chunks/59b4e022-7a3b5554b806349f.js +1 -0
  42. package/out/_next/static/chunks/696-b12edad30a3617e5.js +31 -0
  43. package/out/_next/static/chunks/727-15cf3f2fea9a37e5.js +1 -0
  44. package/out/_next/static/chunks/731-501990ebe6a71b32.js +1 -0
  45. package/out/_next/static/chunks/787-727e3aef5d2a10a8.js +1 -0
  46. package/out/_next/static/chunks/904-ccd8ca3368ce29fc.js +1 -0
  47. package/out/_next/static/chunks/{918-38d08f1e885b222d.js → 918-5bb55fb464e34768.js} +1 -1
  48. package/out/_next/static/chunks/f36c6662-03bb5e9d9aa0b0aa.js +1 -0
  49. package/out/_next/static/chunks/pages/_app-49f29218569a926a.js +428 -0
  50. package/out/_next/static/chunks/pages/changelog-68d115a14f1423d7.js +1 -0
  51. package/out/_next/static/chunks/pages/changes-6f62ae7b6243a1c7.js +1 -0
  52. package/out/_next/static/chunks/pages/custom-types/{[customTypeId]-3a37eb3373bb8823.js → [customTypeId]-3f862ad6111a1fc0.js} +1 -1
  53. package/out/_next/static/chunks/pages/{custom-types-2f5664d9492b13fb.js → custom-types-94b8f8dbf7727412.js} +1 -1
  54. package/out/_next/static/chunks/pages/{index-d8e3a2c0d712904f.js → index-64cfb8b0948ba8ef.js} +1 -1
  55. package/out/_next/static/chunks/pages/page-types/{[pageTypeId]-733f3890c0466a05.js → [pageTypeId]-d1ffca11c42f2603.js} +1 -1
  56. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-897ca93c114a1435.js +1 -0
  57. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-e89e2e6f772a3454.js +1 -0
  58. package/out/_next/static/chunks/pages/slices-9628f8aa54968d6a.js +1 -0
  59. package/out/changelog.html +1 -1
  60. package/out/changes.html +1 -1
  61. package/out/custom-types/[customTypeId].html +1 -1
  62. package/out/custom-types.html +1 -1
  63. package/out/index.html +1 -1
  64. package/out/labs.html +1 -1
  65. package/out/page-types/[pageTypeId].html +1 -1
  66. package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
  67. package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
  68. package/out/slices.html +1 -1
  69. package/package.json +3 -3
  70. package/pages/slices/[lib]/[sliceName]/[variation]/index.tsx +25 -11
  71. package/pages/slices/[lib]/[sliceName]/[variation]/simulator.tsx +12 -9
  72. package/src/apiClient.ts +7 -6
  73. package/src/components/CodeBlock/CodeBlock.tsx +1 -0
  74. package/src/components/Window/Window.tsx +7 -1
  75. package/src/domain/__tests__/customType.test.ts +785 -0
  76. package/src/domain/customType.ts +519 -6
  77. package/src/domain/slice.ts +166 -1
  78. package/src/features/autoSave/AutoSaveStatusIndicator.tsx +43 -0
  79. package/src/features/autoSave/useAutoSave.tsx +177 -0
  80. package/src/features/customTypes/EditDropdown.tsx +3 -0
  81. package/src/features/customTypes/actions/convertCustomToPageType.ts +2 -4
  82. package/src/features/customTypes/customTypesBuilder/CustomTypeProvider.tsx +90 -0
  83. package/src/features/customTypes/customTypesBuilder/CustomTypesBuilderPage.tsx +46 -79
  84. package/src/features/customTypes/customTypesMessages.ts +4 -0
  85. package/src/features/slices/actions/addSlicesToSliceZone.ts +2 -7
  86. package/src/features/slices/actions/uploadSliceScreenshot.ts +45 -0
  87. package/src/features/slices/convertLegacySlice/ConvertLegacySliceAsNewVariationDialog.tsx +5 -5
  88. package/src/features/slices/convertLegacySlice/ConvertLegacySliceButton.tsx +4 -10
  89. package/src/features/slices/sliceBuilder/SliceBuilderProvider.tsx +110 -0
  90. package/src/features/slices/sliceBuilder/actions/deleteVariation.ts +8 -24
  91. package/src/features/slices/sliceBuilder/actions/renameVariation.ts +8 -24
  92. package/src/features/slices/sliceCards/SharedSliceCard.tsx +1 -0
  93. package/src/hooks/useCurrentSlice.tsx +4 -16
  94. package/src/hooks/useScreenshotChangesModal.ts +1 -0
  95. package/src/hooks/useServerState.ts +1 -58
  96. package/src/modules/availableCustomTypes/index.ts +8 -3
  97. package/src/modules/simulator/index.ts +0 -2
  98. package/src/modules/slices/index.ts +32 -25
  99. package/src/modules/slices/selector.ts +30 -0
  100. package/src/modules/useSliceMachineActions.ts +20 -270
  101. package/src/redux/reducer.ts +0 -4
  102. package/src/redux/saga.ts +0 -6
  103. package/src/redux/type.ts +0 -4
  104. package/test/src/modules/availableCustomTypes/index.test.ts +8 -10
  105. package/test/src/modules/simulator.test.ts +0 -2
  106. package/lib/models/common/CustomType/group.ts +0 -80
  107. package/lib/models/common/Variation.ts +0 -100
  108. package/out/_next/static/ZrWICkLApT4ZATA_akn-2/_buildManifest.js +0 -1
  109. package/out/_next/static/chunks/482-34cee2a2071c235f.js +0 -1
  110. package/out/_next/static/chunks/550-c80fd46fb64d1eef.js +0 -1
  111. package/out/_next/static/chunks/80-7b8a97d0122ff74a.js +0 -1
  112. package/out/_next/static/chunks/840-163f8a1040e6820d.js +0 -1
  113. package/out/_next/static/chunks/904-519dbf0f7e8c6243.js +0 -1
  114. package/out/_next/static/chunks/958-8aca174b80cb0c35.js +0 -1
  115. package/out/_next/static/chunks/pages/_app-132564608e9a9502.js +0 -458
  116. package/out/_next/static/chunks/pages/changelog-4d0f2f1222e403fe.js +0 -1
  117. package/out/_next/static/chunks/pages/changes-52c9d917808d1461.js +0 -1
  118. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-7b17cb59d0db03b5.js +0 -1
  119. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-ef11594ce026b650.js +0 -1
  120. package/out/_next/static/chunks/pages/slices-884a936a9a062a65.js +0 -1
  121. package/src/domain/__tests__/CustomTypeModel.test.ts +0 -247
  122. package/src/layouts/WithSlice.tsx +0 -26
  123. package/src/modules/screenshots/actions.ts +0 -21
  124. package/src/modules/screenshots/sagas.ts +0 -70
  125. package/src/modules/selectedCustomType/actions.ts +0 -147
  126. package/src/modules/selectedCustomType/index.ts +0 -11
  127. package/src/modules/selectedCustomType/reducer.ts +0 -287
  128. package/src/modules/selectedCustomType/sagas.ts +0 -72
  129. package/src/modules/selectedCustomType/selectors.ts +0 -33
  130. package/src/modules/selectedCustomType/stateHelpers.ts +0 -42
  131. package/src/modules/selectedCustomType/types.ts +0 -9
  132. package/src/modules/selectedSlice/actions.ts +0 -106
  133. package/src/modules/selectedSlice/reducer.ts +0 -175
  134. package/src/modules/selectedSlice/sagas.ts +0 -72
  135. package/src/modules/selectedSlice/selectors.ts +0 -55
  136. package/src/modules/selectedSlice/types.ts +0 -3
  137. package/src/modules/toaster/utils.tsx +0 -23
  138. package/test/lib/models/common/CustomType/sliceZone.test.ts +0 -49
  139. package/test/pages/custom-types.test.tsx +0 -625
  140. package/test/src/modules/selectedCustomType/__fixtures__/model.json +0 -119
  141. package/test/src/modules/selectedCustomType/reducer.test.ts +0 -322
  142. package/test/src/modules/selectedCustomType/sagas.test.ts +0 -89
  143. package/test/src/modules/selectedCustomType/selectors.test.ts +0 -54
  144. package/test/src/modules/selectedSlice/__fixtures__/mocks.json +0 -171
  145. package/test/src/modules/selectedSlice/__fixtures__/model.json +0 -35
  146. package/test/src/modules/selectedSlice/__testutils__/getRefreshStateCreatorPayloadData.ts +0 -72
  147. package/test/src/modules/selectedSlice/__testutils__/getSelectedSliceDummyData.ts +0 -30
  148. package/test/src/modules/selectedSlice/reducer.test.ts +0 -170
  149. package/test/src/modules/selectedSlice/sagas.test.ts +0 -82
  150. package/test/src/modules/toaster/utils.test.ts +0 -50
  151. /package/out/_next/static/{ZrWICkLApT4ZATA_akn-2 → 2SXh8a0HZLb2Awmhh2xob}/_ssgManifest.js +0 -0
@@ -1,106 +0,0 @@
1
- import { ActionType, createAction, createAsyncAction } from "typesafe-actions";
2
- import { NestableWidget } from "@prismicio/types-internal/lib/customtypes";
3
- import type { SliceBuilderState } from "@builders/SliceBuilder";
4
- import { ComponentUI } from "@lib/models/common/ComponentUI";
5
- import { renameSliceCreator } from "../slices";
6
- import { SelectedSliceStoreType } from "./types";
7
- import { refreshStateCreator } from "../environment";
8
- import { generateSliceCustomScreenshotCreator } from "../screenshots/actions";
9
- import { VariationSM, WidgetsArea } from "@lib/models/common/Slice";
10
- import { SharedSliceContent } from "@prismicio/types-internal/lib/content";
11
-
12
- export type SelectedSliceActions =
13
- | ActionType<typeof initSliceStoreCreator>
14
- | ActionType<typeof addSliceWidgetCreator>
15
- | ActionType<typeof replaceSliceWidgetCreator>
16
- | ActionType<typeof reorderSliceWidgetCreator>
17
- | ActionType<typeof removeSliceWidgetCreator>
18
- | ActionType<typeof updateSliceWidgetMockCreator>
19
- | ActionType<typeof deleteSliceWidgetMockCreator>
20
- | ActionType<typeof updateSliceCreator>
21
- | ActionType<typeof updateAndSaveSliceCreator>
22
- | ActionType<typeof copyVariationSliceCreator>
23
- | ActionType<typeof renameSliceCreator>
24
- | ActionType<typeof refreshStateCreator>
25
- | ActionType<typeof generateSliceCustomScreenshotCreator>
26
- | ActionType<typeof updateSelectedSliceMocks>;
27
-
28
- export const updateSelectedSliceMocks = createAction(
29
- "SELECTED_SLICE/UPDATE_MOCKS",
30
- )<{
31
- mocks: SharedSliceContent[];
32
- }>();
33
-
34
- export const initSliceStoreCreator =
35
- createAction("SLICE/INIT")<SelectedSliceStoreType>();
36
-
37
- export const addSliceWidgetCreator = createAction("SLICE/ADD_WIDGET")<{
38
- variationId: string;
39
- widgetsArea: WidgetsArea;
40
- key: string;
41
- value: NestableWidget;
42
- }>();
43
-
44
- export const replaceSliceWidgetCreator = createAction("SLICE/REPLACE_WIDGET")<{
45
- variationId: string;
46
- widgetsArea: WidgetsArea;
47
- previousKey: string;
48
- newKey: string;
49
- value: NestableWidget;
50
- }>();
51
-
52
- export const reorderSliceWidgetCreator = createAction("SLICE/REORDER_WIDGET")<{
53
- variationId: string;
54
- widgetsArea: WidgetsArea;
55
- start: number;
56
- end: number | undefined;
57
- }>();
58
-
59
- export const removeSliceWidgetCreator = createAction("SLICE/REMOVE_WIDGET")<{
60
- variationId: string;
61
- widgetsArea: WidgetsArea;
62
- key: string;
63
- }>();
64
-
65
- export const updateSliceWidgetMockCreator = createAction(
66
- "SLICE/UPDATE_WIDGET_MOCK",
67
- )<{
68
- variationId: string;
69
- widgetArea: WidgetsArea;
70
- previousKey: string;
71
- newKey: string;
72
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
- mockValue: any;
74
- }>();
75
-
76
- export const deleteSliceWidgetMockCreator = createAction(
77
- "SLICE/DELETE_WIDGET_MOCK",
78
- )<{
79
- variationId: string;
80
- widgetArea: WidgetsArea;
81
- newKey: string;
82
- }>();
83
-
84
- export const updateSliceCreator = createAsyncAction(
85
- "SLICE/UPDATE.REQUEST",
86
- "SLICE/UPDATE.RESPONSE",
87
- "SLICE/UPDATE.FAILURE",
88
- )<
89
- {
90
- component: ComponentUI;
91
- setSliceBuilderState: (sliceBuilderState: SliceBuilderState) => void;
92
- },
93
- {
94
- component: ComponentUI;
95
- }
96
- >();
97
-
98
- export const updateAndSaveSliceCreator = createAction("SLICE/UPDATE_AND_SAVE")<{
99
- component: ComponentUI;
100
- }>();
101
-
102
- export const copyVariationSliceCreator = createAction("SLICE/COPY_VARIATION")<{
103
- key: string;
104
- name: string;
105
- copied: VariationSM;
106
- }>();
@@ -1,175 +0,0 @@
1
- import { AnyWidget } from "@lib/models/common/widgets/Widget";
2
- import { Reducer } from "redux";
3
- import { getType } from "typesafe-actions";
4
- import {
5
- addSliceWidgetCreator,
6
- copyVariationSliceCreator,
7
- initSliceStoreCreator,
8
- removeSliceWidgetCreator,
9
- updateAndSaveSliceCreator,
10
- reorderSliceWidgetCreator,
11
- replaceSliceWidgetCreator,
12
- SelectedSliceActions,
13
- updateSelectedSliceMocks,
14
- } from "./actions";
15
- import { SelectedSliceStoreType } from "./types";
16
- import * as Widgets from "../../../lib/models/common/widgets";
17
- import { Variation } from "@lib/models/common/Variation";
18
- import { ComponentUI } from "@lib/models/common/ComponentUI";
19
- import { SliceSM } from "@lib/models/common/Slice";
20
- import { renameSliceCreator } from "../slices";
21
- import { refreshStateCreator } from "../environment";
22
- import { generateSliceCustomScreenshotCreator } from "../screenshots/actions";
23
-
24
- // Reducer
25
- export const selectedSliceReducer: Reducer<
26
- SelectedSliceStoreType,
27
- SelectedSliceActions
28
- > = (prevState = null, action) => {
29
- switch (action.type) {
30
- case getType(initSliceStoreCreator): {
31
- if (!action.payload) return null;
32
- return action.payload;
33
- }
34
- case getType(refreshStateCreator):
35
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
36
- if (prevState === null || !action.payload.libraries) return prevState;
37
-
38
- const updatedSlice = action.payload.libraries
39
- .find((l) => l.name === prevState.from)
40
- ?.components.find((c) => c.model.id === prevState.model.id);
41
-
42
- if (updatedSlice === undefined) {
43
- return prevState;
44
- }
45
- return {
46
- ...prevState,
47
- screenshots: updatedSlice.screenshots,
48
- };
49
- case getType(addSliceWidgetCreator): {
50
- if (!prevState) return prevState;
51
- const { variationId, widgetsArea, key, value } = action.payload;
52
- try {
53
- if (
54
- value.type !== "Range" &&
55
- value.type !== "Separator" &&
56
- value.type !== "IntegrationFields"
57
- ) {
58
- const CurrentWidget: AnyWidget = Widgets[value.type];
59
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
60
- CurrentWidget.schema.validateSync(value, { stripUnknown: false });
61
-
62
- return ComponentUI.updateVariation(
63
- prevState,
64
- variationId,
65
- )((v) => Variation.addWidget(v, widgetsArea, key, value));
66
- }
67
- return prevState;
68
- } catch (err) {
69
- console.error(
70
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
71
- `[store/addWidget] Model is invalid for widget "${value.type}".\nFull error: ${err}`,
72
- );
73
- return prevState;
74
- }
75
- }
76
- case getType(replaceSliceWidgetCreator): {
77
- if (!prevState) return prevState;
78
- const { variationId, widgetsArea, previousKey, newKey, value } =
79
- action.payload;
80
- try {
81
- if (
82
- value.type !== "Range" &&
83
- value.type !== "Separator" &&
84
- value.type !== "IntegrationFields"
85
- ) {
86
- const CurrentWidget: AnyWidget = Widgets[value.type];
87
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
88
- CurrentWidget.schema.validateSync(value, { stripUnknown: false });
89
-
90
- return ComponentUI.updateVariation(
91
- prevState,
92
- variationId,
93
- )((v) =>
94
- Variation.replaceWidget(v, widgetsArea, previousKey, newKey, value),
95
- );
96
- }
97
- return prevState;
98
- } catch (err) {
99
- console.error(
100
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
101
- `[store/replaceWidget] Model is invalid for widget "${value.type}".\nFull error: ${err}`,
102
- );
103
- return prevState;
104
- }
105
- }
106
- case getType(generateSliceCustomScreenshotCreator.success): {
107
- if (!prevState) return prevState;
108
- const { component, screenshot, variationId } = action.payload;
109
- return {
110
- ...component,
111
- screenshots: {
112
- ...component.screenshots,
113
- [variationId]: screenshot,
114
- },
115
- };
116
- }
117
- case getType(reorderSliceWidgetCreator): {
118
- if (!prevState) return prevState;
119
- const { variationId, widgetsArea, start, end } = action.payload;
120
- if (end === undefined) return prevState;
121
-
122
- return ComponentUI.updateVariation(
123
- prevState,
124
- variationId,
125
- )((v) => Variation.reorderWidget(v, widgetsArea, start, end));
126
- }
127
- case getType(removeSliceWidgetCreator): {
128
- if (!prevState) return prevState;
129
- const { variationId, widgetsArea, key } = action.payload;
130
-
131
- return ComponentUI.updateVariation(
132
- prevState,
133
- variationId,
134
- )((v) => Variation.deleteWidget(v, widgetsArea, key));
135
- }
136
- case getType(copyVariationSliceCreator): {
137
- if (!prevState) return prevState;
138
- const { key, name, copied } = action.payload;
139
- const newVariation = Variation.copyValue(copied, key, name);
140
-
141
- const model: SliceSM = {
142
- ...prevState.model,
143
- variations: prevState.model.variations.concat([newVariation]),
144
- };
145
- return {
146
- ...prevState,
147
- model,
148
- };
149
- }
150
- case getType(renameSliceCreator.success): {
151
- if (!prevState) return prevState;
152
- const { renamedSlice } = action.payload;
153
-
154
- return {
155
- ...prevState,
156
- model: renamedSlice,
157
- };
158
- }
159
- case getType(updateAndSaveSliceCreator): {
160
- return prevState
161
- ? { ...prevState, ...action.payload.component }
162
- : prevState;
163
- }
164
- case getType(updateSelectedSliceMocks): {
165
- if (!prevState) return prevState;
166
- const { mocks } = action.payload;
167
- return {
168
- ...prevState,
169
- mocks,
170
- };
171
- }
172
- default:
173
- return prevState;
174
- }
175
- };
@@ -1,72 +0,0 @@
1
- import {
2
- call,
3
- fork,
4
- takeLatest,
5
- put,
6
- SagaReturnType,
7
- } from "redux-saga/effects";
8
-
9
- import { getType } from "typesafe-actions";
10
- import { withLoader } from "../loading";
11
- import { LoadingKeysEnum } from "../loading/types";
12
- import { updateSliceCreator } from "./actions";
13
- import { readSliceMocks, updateSlice } from "@src/apiClient";
14
- import { openToasterCreator, ToasterType } from "@src/modules/toaster";
15
- import { SliceToastMessage } from "@components/ToasterContainer";
16
-
17
- export function* updateSliceSaga({
18
- payload,
19
- }: ReturnType<typeof updateSliceCreator.request>) {
20
- const { component, setSliceBuilderState } = payload;
21
-
22
- try {
23
- setSliceBuilderState({ loading: true, done: false });
24
- const { errors } = (yield call(updateSlice, component)) as SagaReturnType<
25
- typeof updateSlice
26
- >;
27
- if (errors.length > 0) {
28
- return setSliceBuilderState({
29
- loading: false,
30
- done: true,
31
- error: true,
32
- message: errors[0].message,
33
- });
34
- }
35
- setSliceBuilderState({
36
- loading: false,
37
- done: true,
38
- error: false,
39
- message: SliceToastMessage({
40
- path: `${component.from}/${component.model.name}/model.json`,
41
- }),
42
- });
43
-
44
- const { mocks } = (yield call(readSliceMocks, {
45
- libraryID: component.from,
46
- sliceID: component.model.id,
47
- })) as SagaReturnType<typeof readSliceMocks>;
48
-
49
- yield put(
50
- updateSliceCreator.success({ component: { ...component, mocks } }),
51
- );
52
- } catch (e) {
53
- yield put(
54
- openToasterCreator({
55
- content: "Internal Error: Models & mocks not generated",
56
- type: ToasterType.ERROR,
57
- }),
58
- );
59
- }
60
- }
61
-
62
- function* watchSaveSlice() {
63
- yield takeLatest(
64
- getType(updateSliceCreator.request),
65
- withLoader(updateSliceSaga, LoadingKeysEnum.SAVE_SLICE),
66
- );
67
- }
68
-
69
- // Saga Exports
70
- export function* selectedSliceSagas() {
71
- yield fork(watchSaveSlice);
72
- }
@@ -1,55 +0,0 @@
1
- import equal from "fast-deep-equal";
2
- import { SliceMachineStoreType } from "@src/redux/type";
3
- import { getLibraries } from "../slices";
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
- export const selectCurrentSlice = (
20
- store: SliceMachineStoreType,
21
- lib: string,
22
- sliceName: string,
23
- ) => {
24
- const openedModel = store.selectedSlice;
25
- if (openedModel?.model.name === sliceName) {
26
- return openedModel;
27
- }
28
-
29
- const library = getLibraries(store)?.find(
30
- (l) => l.name.replace(/\//g, "--") === lib,
31
- );
32
- const slice = library?.components.find((c) => c.model.name === sliceName);
33
-
34
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
35
- return slice || null;
36
- };
37
-
38
- export const isSelectedSliceTouched = (
39
- store: SliceMachineStoreType,
40
- lib: string,
41
- sliceId: string,
42
- ): boolean => {
43
- const selectedSlice = store.selectedSlice;
44
- const library = getLibraries(store)?.find((l) => l.name === lib);
45
- const librarySlice = library?.components.find((c) => c.model.id === sliceId);
46
-
47
- if (!selectedSlice || !librarySlice) return false;
48
-
49
- const sameVariations = equal(
50
- librarySlice.model.variations,
51
- selectedSlice.model.variations,
52
- );
53
-
54
- return !sameVariations;
55
- };
@@ -1,3 +0,0 @@
1
- import { ComponentUI } from "@lib/models/common/ComponentUI";
2
-
3
- export type SelectedSliceStoreType = ComponentUI | null;
@@ -1,23 +0,0 @@
1
- import type { ReactNode } from "react";
2
-
3
- import { ToasterType } from "../toaster";
4
-
5
- export type ToastPayload =
6
- | { done: true; message: ReactNode; error: boolean }
7
- | { done: false };
8
-
9
- export const handleRemoteResponse =
10
- (addToast: (message: ReactNode, type: ToasterType) => void) =>
11
- (payload: ToastPayload) => {
12
- if (payload.done) {
13
- addToast(
14
- payload.message,
15
- (() => {
16
- if (payload.error) {
17
- return ToasterType.ERROR;
18
- }
19
- return ToasterType.SUCCESS;
20
- })(),
21
- );
22
- }
23
- };
@@ -1,49 +0,0 @@
1
- import { SliceZone } from "@lib/models/common/CustomType/sliceZone";
2
- // @ts-expect-error TS(2307) FIXME: Cannot find module '@slicemachine/core/build/model... Remove this comment to see the full error message
3
- import { SlicesSM } from "@slicemachine/core/build/models/Slices";
4
-
5
- const mockSliceZone: SlicesSM = {
6
- key: "slices",
7
- value: [
8
- { key: "slice_in_zone_0", value: { type: "SharedSlice" } },
9
- { key: "slice_in_zone_1", value: { type: "SharedSlice" } },
10
- { key: "slice_in_zone_2", value: { type: "SharedSlice" } },
11
- ],
12
- };
13
-
14
- describe("Slice Zone", () => {
15
- describe("Remove shared slices", () => {
16
- it("removes the correct slice", () => {
17
- const keyToRemove = "slice_in_zone_1";
18
-
19
- const result = SliceZone.removeSharedSlice(mockSliceZone, keyToRemove);
20
-
21
- expect(result.value.map((slice) => slice.key).includes(keyToRemove)).toBe(
22
- false,
23
- );
24
- expect(result.value.length).toEqual(2);
25
- });
26
-
27
- it("removes nothing if the key does not exist", () => {
28
- const keyToRemove = "invalid_key";
29
-
30
- const result = SliceZone.removeSharedSlice(mockSliceZone, keyToRemove);
31
-
32
- expect(result).toEqual(mockSliceZone);
33
- });
34
- });
35
-
36
- describe("Add shared slices", () => {
37
- it("adds a new slice to the slice zone", () => {
38
- const newKey = "new_slice_in_zone";
39
-
40
- const result = SliceZone.addSharedSlice(mockSliceZone, newKey);
41
-
42
- expect(result.value.map((slice) => slice.key)).toEqual(
43
- // @ts-expect-error TS(7006) FIXME: Parameter 'slice' implicitly has an 'any' type.
44
- mockSliceZone.value.map((slice) => slice.key).concat([newKey]),
45
- );
46
- expect(result.value.length).toEqual(4);
47
- });
48
- });
49
- });