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

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 (154) 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/chunks/065a3ddb-9a38ca0d60f0bf2f.js +1 -0
  32. package/out/_next/static/chunks/183-4feb6bb3eddbc768.js +1 -0
  33. package/out/_next/static/chunks/18539003-7b2711e6c51d6fac.js +97 -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-20876abeebe0fda7.js +430 -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/_next/static/css/{1bbf650dfd37ce69.css → 1aa04669758c24f4.css} +1 -1
  60. package/out/_next/static/j_voPTrYzsuLCERqtl3Hn/_buildManifest.js +1 -0
  61. package/out/changelog.html +1 -1
  62. package/out/changes.html +1 -1
  63. package/out/custom-types/[customTypeId].html +1 -1
  64. package/out/custom-types.html +1 -1
  65. package/out/index.html +1 -1
  66. package/out/labs.html +1 -1
  67. package/out/page-types/[pageTypeId].html +1 -1
  68. package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
  69. package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
  70. package/out/slices.html +1 -1
  71. package/package.json +6 -6
  72. package/pages/slices/[lib]/[sliceName]/[variation]/index.tsx +25 -11
  73. package/pages/slices/[lib]/[sliceName]/[variation]/simulator.tsx +12 -9
  74. package/src/apiClient.ts +7 -6
  75. package/src/components/CodeBlock/CodeBlock.tsx +1 -0
  76. package/src/components/Window/Window.tsx +7 -1
  77. package/src/domain/__tests__/customType.test.ts +785 -0
  78. package/src/domain/customType.ts +519 -6
  79. package/src/domain/slice.ts +166 -1
  80. package/src/features/autoSave/AutoSaveStatusIndicator.tsx +43 -0
  81. package/src/features/autoSave/useAutoSave.tsx +177 -0
  82. package/src/features/customTypes/EditDropdown.tsx +3 -0
  83. package/src/features/customTypes/actions/convertCustomToPageType.ts +2 -4
  84. package/src/features/customTypes/customTypesBuilder/CustomTypeProvider.tsx +90 -0
  85. package/src/features/customTypes/customTypesBuilder/CustomTypesBuilderPage.tsx +46 -79
  86. package/src/features/customTypes/customTypesMessages.ts +4 -0
  87. package/src/features/slices/actions/addSlicesToSliceZone.ts +2 -7
  88. package/src/features/slices/actions/uploadSliceScreenshot.ts +45 -0
  89. package/src/features/slices/convertLegacySlice/ConvertLegacySliceAsNewVariationDialog.tsx +5 -5
  90. package/src/features/slices/convertLegacySlice/ConvertLegacySliceButton.tsx +4 -10
  91. package/src/features/slices/sliceBuilder/SliceBuilderProvider.tsx +110 -0
  92. package/src/features/slices/sliceBuilder/actions/deleteVariation.ts +8 -24
  93. package/src/features/slices/sliceBuilder/actions/renameVariation.ts +8 -24
  94. package/src/features/slices/sliceCards/SharedSliceCard.tsx +1 -0
  95. package/src/hooks/useCurrentSlice.tsx +4 -16
  96. package/src/hooks/useScreenshotChangesModal.ts +1 -0
  97. package/src/hooks/useServerState.ts +1 -58
  98. package/src/modules/availableCustomTypes/index.ts +8 -3
  99. package/src/modules/simulator/index.ts +0 -2
  100. package/src/modules/slices/index.ts +32 -25
  101. package/src/modules/slices/selector.ts +30 -0
  102. package/src/modules/useSliceMachineActions.ts +20 -270
  103. package/src/redux/reducer.ts +0 -4
  104. package/src/redux/saga.ts +0 -6
  105. package/src/redux/type.ts +0 -4
  106. package/test/src/modules/availableCustomTypes/index.test.ts +8 -10
  107. package/test/src/modules/simulator.test.ts +0 -2
  108. package/lib/models/common/CustomType/group.ts +0 -80
  109. package/lib/models/common/Variation.ts +0 -100
  110. package/out/_next/static/ZrWICkLApT4ZATA_akn-2/_buildManifest.js +0 -1
  111. package/out/_next/static/chunks/18539003-4460ccbfe3109578.js +0 -97
  112. package/out/_next/static/chunks/482-34cee2a2071c235f.js +0 -1
  113. package/out/_next/static/chunks/550-c80fd46fb64d1eef.js +0 -1
  114. package/out/_next/static/chunks/80-7b8a97d0122ff74a.js +0 -1
  115. package/out/_next/static/chunks/840-163f8a1040e6820d.js +0 -1
  116. package/out/_next/static/chunks/904-519dbf0f7e8c6243.js +0 -1
  117. package/out/_next/static/chunks/958-8aca174b80cb0c35.js +0 -1
  118. package/out/_next/static/chunks/pages/_app-132564608e9a9502.js +0 -458
  119. package/out/_next/static/chunks/pages/changelog-4d0f2f1222e403fe.js +0 -1
  120. package/out/_next/static/chunks/pages/changes-52c9d917808d1461.js +0 -1
  121. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-7b17cb59d0db03b5.js +0 -1
  122. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-ef11594ce026b650.js +0 -1
  123. package/out/_next/static/chunks/pages/slices-884a936a9a062a65.js +0 -1
  124. package/src/domain/__tests__/CustomTypeModel.test.ts +0 -247
  125. package/src/layouts/WithSlice.tsx +0 -26
  126. package/src/modules/screenshots/actions.ts +0 -21
  127. package/src/modules/screenshots/sagas.ts +0 -70
  128. package/src/modules/selectedCustomType/actions.ts +0 -147
  129. package/src/modules/selectedCustomType/index.ts +0 -11
  130. package/src/modules/selectedCustomType/reducer.ts +0 -287
  131. package/src/modules/selectedCustomType/sagas.ts +0 -72
  132. package/src/modules/selectedCustomType/selectors.ts +0 -33
  133. package/src/modules/selectedCustomType/stateHelpers.ts +0 -42
  134. package/src/modules/selectedCustomType/types.ts +0 -9
  135. package/src/modules/selectedSlice/actions.ts +0 -106
  136. package/src/modules/selectedSlice/reducer.ts +0 -175
  137. package/src/modules/selectedSlice/sagas.ts +0 -72
  138. package/src/modules/selectedSlice/selectors.ts +0 -55
  139. package/src/modules/selectedSlice/types.ts +0 -3
  140. package/src/modules/toaster/utils.tsx +0 -23
  141. package/test/lib/models/common/CustomType/sliceZone.test.ts +0 -49
  142. package/test/pages/custom-types.test.tsx +0 -625
  143. package/test/src/modules/selectedCustomType/__fixtures__/model.json +0 -119
  144. package/test/src/modules/selectedCustomType/reducer.test.ts +0 -322
  145. package/test/src/modules/selectedCustomType/sagas.test.ts +0 -89
  146. package/test/src/modules/selectedCustomType/selectors.test.ts +0 -54
  147. package/test/src/modules/selectedSlice/__fixtures__/mocks.json +0 -171
  148. package/test/src/modules/selectedSlice/__fixtures__/model.json +0 -35
  149. package/test/src/modules/selectedSlice/__testutils__/getRefreshStateCreatorPayloadData.ts +0 -72
  150. package/test/src/modules/selectedSlice/__testutils__/getSelectedSliceDummyData.ts +0 -30
  151. package/test/src/modules/selectedSlice/reducer.test.ts +0 -170
  152. package/test/src/modules/selectedSlice/sagas.test.ts +0 -82
  153. package/test/src/modules/toaster/utils.test.ts +0 -50
  154. /package/out/_next/static/{ZrWICkLApT4ZATA_akn-2 → j_voPTrYzsuLCERqtl3Hn}/_ssgManifest.js +0 -0
@@ -1,147 +0,0 @@
1
- import { ActionType, createAction, createAsyncAction } from "typesafe-actions";
2
- import { NestableWidget } from "@prismicio/types-internal/lib/customtypes";
3
- import { CustomTypeSM, TabField } from "@lib/models/common/CustomType";
4
-
5
- export type SelectedCustomTypeActions =
6
- | ActionType<typeof initCustomTypeStoreCreator>
7
- | ActionType<typeof cleanupCustomTypeStoreCreator>
8
- | ActionType<typeof saveCustomTypeCreator>
9
- | ActionType<typeof createTabCreator>
10
- | ActionType<typeof updateTabCreator>
11
- | ActionType<typeof deleteTabCreator>
12
- | ActionType<typeof addFieldCreator>
13
- | ActionType<typeof deleteFieldCreator>
14
- | ActionType<typeof replaceFieldCreator>
15
- | ActionType<typeof reorderFieldCreator>
16
- | ActionType<typeof createSliceZoneCreator>
17
- | ActionType<typeof deleteSliceZoneCreator>
18
- | ActionType<typeof addFieldIntoGroupCreator>
19
- | ActionType<typeof replaceFieldIntoGroupCreator>
20
- | ActionType<typeof reorderFieldIntoGroupCreator>
21
- | ActionType<typeof deleteFieldIntoGroupCreator>
22
- | ActionType<typeof deleteSharedSliceCreator>
23
- | ActionType<typeof renameSelectedCustomTypeLabel>;
24
-
25
- export const initCustomTypeStoreCreator = createAction("CUSTOM_TYPE/INIT")<{
26
- model: CustomTypeSM;
27
- remoteModel: CustomTypeSM | undefined;
28
- }>();
29
-
30
- export const cleanupCustomTypeStoreCreator = createAction(
31
- "CUSTOM_TYPE/CLEANUP",
32
- )();
33
-
34
- // Async actions
35
- export const saveCustomTypeCreator = createAsyncAction(
36
- "CUSTOM_TYPE/SAVE.REQUEST",
37
- "CUSTOM_TYPE/SAVE.RESPONSE",
38
- "CUSTOM_TYPE/SAVE.FAILURE",
39
- )<undefined, { customType: CustomTypeSM }>();
40
-
41
- // Tab actions
42
- export const createTabCreator = createAction("CUSTOM_TYPE/CREATE_TAB")<{
43
- tabId: string;
44
- }>();
45
-
46
- export const updateTabCreator = createAction("CUSTOM_TYPE/UPDATE_TAB")<{
47
- tabId: string;
48
- newTabId: string;
49
- }>();
50
-
51
- export const deleteTabCreator = createAction("CUSTOM_TYPE/DELETE_TAB")<{
52
- tabId: string;
53
- }>();
54
-
55
- // Field actions
56
- export const addFieldCreator = createAction("CUSTOM_TYPE/ADD_FIELD")<{
57
- tabId: string;
58
- fieldId: string;
59
- field: TabField;
60
- }>();
61
-
62
- export const deleteFieldCreator = createAction("CUSTOM_TYPE/DELETE_FIELD")<{
63
- tabId: string;
64
- fieldId: string;
65
- }>();
66
-
67
- export const replaceFieldCreator = createAction("CUSTOM_TYPE/REPLACE_FIELD")<{
68
- tabId: string;
69
- previousFieldId: string;
70
- newFieldId: string;
71
- value: TabField;
72
- }>();
73
-
74
- export const reorderFieldCreator = createAction("CUSTOM_TYPE/REORDER_FIELD")<{
75
- tabId: string;
76
- start: number;
77
- end: number;
78
- }>();
79
-
80
- // Slice zone actions
81
- export const createSliceZoneCreator = createAction(
82
- "CUSTOM_TYPE/CREATE_SLICE_ZONE",
83
- )<{
84
- tabId: string;
85
- }>();
86
-
87
- export const deleteSliceZoneCreator = createAction(
88
- "CUSTOM_TYPE/DELETE_SLICE_ZONE",
89
- )<{
90
- tabId: string;
91
- }>();
92
-
93
- export type ReplaceSharedSliceCreatorPayload = {
94
- tabId: string;
95
- sliceKeys: string[];
96
- preserve: string[];
97
- };
98
-
99
- export const deleteSharedSliceCreator = createAction(
100
- "CUSTOM_TYPE/DELETE_SHARED_SLICE",
101
- )<{
102
- tabId: string;
103
- sliceId: string;
104
- }>();
105
-
106
- export const renameSelectedCustomTypeLabel = createAction(
107
- "CUSTOM_TYPE/RENAME_CUSTOM_TYPE",
108
- )<{
109
- newLabel: string;
110
- }>();
111
-
112
- // Group actions (can be grouped into the field actions probably)
113
- export const addFieldIntoGroupCreator = createAction(
114
- "CUSTOM_TYPE/GROUP/ADD_FIELD",
115
- )<{
116
- tabId: string;
117
- groupId: string;
118
- fieldId: string;
119
- field: NestableWidget;
120
- }>();
121
-
122
- export const replaceFieldIntoGroupCreator = createAction(
123
- "CUSTOM_TYPE/GROUP/REPLACE_FIELD",
124
- )<{
125
- tabId: string;
126
- groupId: string;
127
- previousFieldId: string;
128
- newFieldId: string;
129
- value: NestableWidget;
130
- }>();
131
-
132
- export const reorderFieldIntoGroupCreator = createAction(
133
- "CUSTOM_TYPE/GROUP/REORDER_FIELD",
134
- )<{
135
- tabId: string;
136
- groupId: string;
137
- start: number;
138
- end: number;
139
- }>();
140
-
141
- export const deleteFieldIntoGroupCreator = createAction(
142
- "CUSTOM_TYPE/GROUP/DELETE_FIELD",
143
- )<{
144
- tabId: string;
145
- groupId: string;
146
- fieldId: string;
147
- }>();
@@ -1,11 +0,0 @@
1
- // Actions
2
- export * from "./actions";
3
-
4
- // Selectors
5
- export * from "./selectors";
6
-
7
- // Reducer
8
- export { selectedCustomTypeReducer } from "./reducer";
9
-
10
- // Saga Exports
11
- export { watchSelectedCustomTypeSagas } from "./sagas";
@@ -1,287 +0,0 @@
1
- import { Reducer } from "redux";
2
- import { SelectedCustomTypeStoreType } from "./types";
3
- import { getType } from "typesafe-actions";
4
- import {
5
- createTabCreator,
6
- updateTabCreator,
7
- SelectedCustomTypeActions,
8
- initCustomTypeStoreCreator,
9
- cleanupCustomTypeStoreCreator,
10
- addFieldCreator,
11
- deleteTabCreator,
12
- renameSelectedCustomTypeLabel,
13
- createSliceZoneCreator,
14
- deleteSliceZoneCreator,
15
- deleteFieldCreator,
16
- deleteSharedSliceCreator,
17
- reorderFieldCreator,
18
- replaceFieldCreator,
19
- addFieldIntoGroupCreator,
20
- deleteFieldIntoGroupCreator,
21
- reorderFieldIntoGroupCreator,
22
- replaceFieldIntoGroupCreator,
23
- saveCustomTypeCreator,
24
- } from "./actions";
25
- import { Tab } from "@models/common/CustomType/tab";
26
- import { SliceZone } from "@models/common/CustomType/sliceZone";
27
- import { AnyWidget } from "@models/common/widgets/Widget";
28
- import * as Widgets from "@models/common/widgets/withGroup";
29
- import StateHelpers from "./stateHelpers";
30
- import { CustomType } from "@models/common/CustomType";
31
- import { SlicesSM } from "@lib/models/common/Slices";
32
- import { GroupSM } from "@lib/models/common/Group";
33
- import { Group } from "@lib/models/common/CustomType/group";
34
-
35
- // Reducer
36
- export const selectedCustomTypeReducer: Reducer<
37
- SelectedCustomTypeStoreType,
38
- SelectedCustomTypeActions
39
- > = (state = null, action) => {
40
- switch (action.type) {
41
- case getType(cleanupCustomTypeStoreCreator):
42
- return null;
43
- case getType(initCustomTypeStoreCreator):
44
- return {
45
- ...state,
46
- model: action.payload.model,
47
- initialModel: action.payload.model,
48
- remoteModel: action.payload.remoteModel,
49
- };
50
- case getType(saveCustomTypeCreator.success): {
51
- if (!state) return state;
52
-
53
- return {
54
- ...state,
55
- initialModel: state.model,
56
- };
57
- }
58
- case getType(createTabCreator):
59
- if (!state) return state;
60
- const { tabId } = action.payload;
61
- if (state.model.tabs.find((e) => e.key === tabId)) {
62
- return state;
63
- }
64
- return {
65
- ...state,
66
- model: {
67
- ...state.model,
68
- tabs: [...state.model.tabs, Tab.init(tabId)],
69
- },
70
- };
71
- case getType(updateTabCreator): {
72
- if (!state) return state;
73
- const { tabId, newTabId } = action.payload;
74
- if (newTabId === tabId) {
75
- return state;
76
- }
77
- return {
78
- ...state,
79
- model: {
80
- ...state.model,
81
- tabs: state.model.tabs.map((t) => {
82
- if (t.key === tabId) {
83
- return {
84
- ...t,
85
- key: newTabId,
86
- };
87
- }
88
- return t;
89
- }),
90
- },
91
- };
92
- }
93
- case getType(renameSelectedCustomTypeLabel): {
94
- if (!state) return state;
95
- return {
96
- ...state,
97
- model: {
98
- ...state.model,
99
- label: action.payload.newLabel,
100
- },
101
- };
102
- }
103
- case getType(deleteTabCreator): {
104
- if (!state) return state;
105
- const { tabId } = action.payload;
106
- return StateHelpers.deleteTab(state, tabId);
107
- }
108
- case getType(addFieldCreator): {
109
- const { tabId, field, fieldId } = action.payload;
110
- try {
111
- if (
112
- field.type === "Range" ||
113
- field.type === "IntegrationFields" ||
114
- field.type === "Separator"
115
- ) {
116
- throw new Error("Unsupported Field Type.");
117
- }
118
- const CurrentWidget: AnyWidget = Widgets[field.type];
119
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
120
- CurrentWidget.schema.validateSync(field, { stripUnknown: false });
121
- return StateHelpers.updateTab(
122
- state,
123
- tabId,
124
- )((tab) => Tab.addWidget(tab, fieldId, field));
125
- } catch (err) {
126
- console.error(
127
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
128
- `[store/addWidget] Model is invalid for widget "${field.type}".\nFull error: ${err}`,
129
- );
130
- return state;
131
- }
132
- }
133
- case getType(deleteFieldCreator): {
134
- const { tabId, fieldId } = action.payload;
135
- return StateHelpers.updateTab(
136
- state,
137
- tabId,
138
- )((tab) => Tab.removeWidget(tab, fieldId));
139
- }
140
- case getType(replaceFieldCreator): {
141
- const { tabId, previousFieldId, newFieldId, value } = action.payload;
142
- try {
143
- if (
144
- value.type === "Range" ||
145
- value.type === "IntegrationFields" ||
146
- value.type === "Separator"
147
- ) {
148
- throw new Error("Unsupported Field Type.");
149
- }
150
- const CurrentWidget: AnyWidget = Widgets[value.type];
151
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
152
- CurrentWidget.schema.validateSync(value, { stripUnknown: false });
153
- return StateHelpers.updateTab(
154
- state,
155
- tabId,
156
- )((tab) => Tab.replaceWidget(tab, previousFieldId, newFieldId, value));
157
- } catch (err) {
158
- return state;
159
- }
160
- }
161
- case getType(reorderFieldCreator): {
162
- const { tabId, start, end } = action.payload;
163
- return StateHelpers.updateTab(
164
- state,
165
- tabId,
166
- )((tab) => Tab.reorderWidget(tab, start, end));
167
- }
168
- case getType(createSliceZoneCreator): {
169
- if (!state) return state;
170
- const { tabId } = action.payload;
171
- const tabIndex = state.model.tabs.findIndex((t) => t.key === tabId);
172
-
173
- if (tabIndex === -1) {
174
- console.error(`No tabId ${tabId} found in tabs`);
175
- return state;
176
- }
177
-
178
- const existingSliceZones = CustomType.getSliceZones(state.model).filter(
179
- (e) => e,
180
- );
181
- return StateHelpers.updateTab(
182
- state,
183
- tabId,
184
- )((tab) => {
185
- const i = findAvailableKey(tabIndex, existingSliceZones);
186
- return Tab.createSliceZone(tab, `slices${i !== 0 ? i.toString() : ""}`);
187
- });
188
- }
189
- case getType(deleteSliceZoneCreator): {
190
- if (!state) return state;
191
- const { tabId } = action.payload;
192
- const tabIndex = state.model.tabs.findIndex((t) => t.key === tabId);
193
-
194
- if (tabIndex === -1) {
195
- console.error(`No tabId ${tabId} found in tabs`);
196
- return state;
197
- }
198
-
199
- return StateHelpers.updateTab(
200
- state,
201
- tabId,
202
- )((tab) => {
203
- return Tab.deleteSliceZone(tab);
204
- });
205
- }
206
- case getType(deleteSharedSliceCreator): {
207
- const { tabId, sliceId } = action.payload;
208
- return StateHelpers.updateTab(
209
- state,
210
- tabId,
211
- )((tab) =>
212
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
213
- Tab.updateSliceZone(tab)((sliceZone: SlicesSM) =>
214
- SliceZone.removeSharedSlice(sliceZone, sliceId),
215
- ),
216
- );
217
- }
218
- case getType(addFieldIntoGroupCreator): {
219
- const { tabId, groupId, fieldId, field } = action.payload;
220
- return StateHelpers.updateTab(
221
- state,
222
- tabId,
223
- )((tab) =>
224
- Tab.updateGroup(
225
- tab,
226
- groupId,
227
- )((group: GroupSM) =>
228
- Group.addWidget(group, { key: fieldId, value: field }),
229
- ),
230
- );
231
- }
232
- case getType(replaceFieldIntoGroupCreator): {
233
- const { tabId, groupId, previousFieldId, newFieldId, value } =
234
- action.payload;
235
- return StateHelpers.updateTab(
236
- state,
237
- tabId,
238
- )((tab) =>
239
- Tab.updateGroup(
240
- tab,
241
- groupId,
242
- )((group: GroupSM) =>
243
- Group.replaceWidget(group, previousFieldId, newFieldId, value),
244
- ),
245
- );
246
- }
247
- case getType(deleteFieldIntoGroupCreator): {
248
- const { tabId, groupId, fieldId } = action.payload;
249
- return StateHelpers.updateTab(
250
- state,
251
- tabId,
252
- )((tab) =>
253
- Tab.updateGroup(
254
- tab,
255
- groupId,
256
- )((group: GroupSM) => Group.deleteWidget(group, fieldId)),
257
- );
258
- }
259
- case getType(reorderFieldIntoGroupCreator): {
260
- const { tabId, groupId, start, end } = action.payload;
261
- return StateHelpers.updateTab(
262
- state,
263
- tabId,
264
- )((tab) =>
265
- Tab.updateGroup(
266
- tab,
267
- groupId,
268
- )((group: GroupSM) => Group.reorderWidget(group, start, end)),
269
- );
270
- }
271
- default:
272
- return state;
273
- }
274
- };
275
-
276
- const findAvailableKey = (
277
- startI: number,
278
- existingSliceZones: (SlicesSM | null)[],
279
- ) => {
280
- for (let i = startI; i < Infinity; i++) {
281
- const key = `slices${i.toString()}`;
282
- if (!existingSliceZones.find((e) => e?.key === key)) {
283
- return i;
284
- }
285
- }
286
- return -1;
287
- };
@@ -1,72 +0,0 @@
1
- import { call, fork, put, select, takeLatest } from "redux-saga/effects";
2
- import { openToasterCreator, ToasterType } from "../toaster";
3
- import { getType } from "typesafe-actions";
4
- import { withLoader } from "../loading";
5
- import { LoadingKeysEnum } from "../loading/types";
6
- import { saveCustomTypeCreator } from "./actions";
7
- import { selectCurrentCustomType } from "./index";
8
- import { saveCustomType, telemetry } from "@src/apiClient";
9
- import { ToastMessageWithPath } from "@components/ToasterContainer";
10
- import { CUSTOM_TYPES_MESSAGES } from "@src/features/customTypes/customTypesMessages";
11
-
12
- export function* saveCustomTypeSaga() {
13
- try {
14
- const currentCustomType = (yield select(
15
- selectCurrentCustomType,
16
- )) as ReturnType<typeof selectCurrentCustomType>;
17
-
18
- if (!currentCustomType) {
19
- return;
20
- }
21
-
22
- const { errors } = (yield call(
23
- saveCustomType,
24
- currentCustomType,
25
- )) as Awaited<ReturnType<typeof saveCustomType>>;
26
- if (errors.length) {
27
- throw errors;
28
- }
29
- void telemetry.track({
30
- event: "custom-type:saved",
31
- id: currentCustomType.id,
32
- name: currentCustomType.label ?? currentCustomType.id,
33
- format: currentCustomType.format,
34
- type: currentCustomType.repeatable ? "repeatable" : "single",
35
- });
36
- yield put(saveCustomTypeCreator.success({ customType: currentCustomType }));
37
- const formatName = CUSTOM_TYPES_MESSAGES[currentCustomType.format].name({
38
- start: true,
39
- plural: false,
40
- });
41
- yield put(
42
- openToasterCreator({
43
- content: ToastMessageWithPath({
44
- message: `${formatName} saved successfully at `,
45
- path: `./customtypes/${currentCustomType.id}/index.json`,
46
- }),
47
- type: ToasterType.SUCCESS,
48
- }),
49
- );
50
- } catch (e) {
51
- // Unknown errors
52
- yield put(
53
- openToasterCreator({
54
- content: "Internal Error: Custom type not saved",
55
- type: ToasterType.ERROR,
56
- }),
57
- );
58
- }
59
- }
60
-
61
- // Saga watchers
62
- function* watchSaveCustomType() {
63
- yield takeLatest(
64
- getType(saveCustomTypeCreator.request),
65
- withLoader(saveCustomTypeSaga, LoadingKeysEnum.SAVE_CUSTOM_TYPE),
66
- );
67
- }
68
-
69
- // Saga Exports
70
- export function* watchSelectedCustomTypeSagas() {
71
- yield fork(watchSaveCustomType);
72
- }
@@ -1,33 +0,0 @@
1
- import { SliceMachineStoreType } from "@src/redux/type";
2
- import equal from "fast-deep-equal";
3
- import { PoolOfFields } from "@src/modules/selectedCustomType/types";
4
- import { CustomTypeSM, TabSM } from "@lib/models/common/CustomType";
5
-
6
- // Selectors
7
- export const selectCurrentCustomType = (
8
- store: SliceMachineStoreType,
9
- ): CustomTypeSM | null => {
10
- if (!store.selectedCustomType) return null;
11
- return store.selectedCustomType.model;
12
- };
13
-
14
- export const selectCurrentPoolOfFields = (
15
- store: SliceMachineStoreType,
16
- ): PoolOfFields => {
17
- if (!store.selectedCustomType) return [];
18
- return store.selectedCustomType.model.tabs.reduce<PoolOfFields>(
19
- (acc: PoolOfFields, curr: TabSM) => {
20
- return [...acc, ...curr.value];
21
- },
22
- [],
23
- );
24
- };
25
-
26
- export const isSelectedCustomTypeTouched = (store: SliceMachineStoreType) => {
27
- if (!store.selectedCustomType) return false;
28
-
29
- return !equal(
30
- store.selectedCustomType.initialModel,
31
- store.selectedCustomType.model,
32
- );
33
- };
@@ -1,42 +0,0 @@
1
- import { TabSM } from "@lib/models/common/CustomType";
2
- import { SelectedCustomTypeStoreType } from "@src/modules/selectedCustomType/types";
3
-
4
- const updateTab =
5
- (state: SelectedCustomTypeStoreType, tabId: string) =>
6
- (mutate: (v: TabSM) => TabSM): SelectedCustomTypeStoreType => {
7
- if (!state) return state;
8
-
9
- const tabs = state.model.tabs.map((tab) => {
10
- if (tab.key === tabId) return mutate(tab);
11
- else return tab;
12
- });
13
-
14
- return {
15
- ...state,
16
- model: {
17
- ...state.model,
18
- tabs,
19
- },
20
- };
21
- };
22
-
23
- const deleteTab = (
24
- state: SelectedCustomTypeStoreType,
25
- tabId: string,
26
- ): SelectedCustomTypeStoreType => {
27
- if (!state) return state;
28
- const tabs = state.model.tabs.filter((v) => v.key !== tabId);
29
-
30
- return {
31
- ...state,
32
- model: {
33
- ...state.model,
34
- tabs,
35
- },
36
- };
37
- };
38
-
39
- export default {
40
- deleteTab,
41
- updateTab,
42
- };
@@ -1,9 +0,0 @@
1
- import { CustomTypeSM, TabField } from "@lib/models/common/CustomType";
2
-
3
- export type PoolOfFields = ReadonlyArray<{ key: string; value: TabField }>;
4
-
5
- export type SelectedCustomTypeStoreType = {
6
- model: CustomTypeSM;
7
- initialModel: CustomTypeSM;
8
- remoteModel: CustomTypeSM | undefined;
9
- } | null;