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.
- package/components/DeleteVariationModal/index.tsx +12 -11
- package/components/Forms/CreateSliceModal/CreateSliceModal.tsx +2 -5
- package/components/Forms/RenameCustomTypeModal/RenameCustomTypeModal.tsx +9 -5
- package/components/Forms/RenameVariationModal/RenameVariationModal.tsx +12 -11
- package/components/ItemHeader/index.tsx +1 -0
- package/components/ListItem/index.tsx +5 -2
- package/components/ScreenshotChangesModal/VariationDropZone.tsx +31 -9
- package/components/ScreenshotChangesModal/index.tsx +3 -0
- package/components/ScreenshotChangesModal/useCustomScreenshot.tsx +5 -5
- package/components/Simulator/index.tsx +9 -3
- package/lib/builders/CustomTypeBuilder/SliceZone/SlicesTemplatesModal.tsx +2 -2
- package/lib/builders/CustomTypeBuilder/SliceZone/UpdateSliceZoneModal.tsx +2 -2
- package/lib/builders/CustomTypeBuilder/SliceZone/index.tsx +12 -20
- package/lib/builders/CustomTypeBuilder/TabModal/update.tsx +3 -1
- package/lib/builders/CustomTypeBuilder/TabZone/index.tsx +119 -52
- package/lib/builders/CustomTypeBuilder/index.tsx +39 -42
- package/lib/builders/SliceBuilder/FieldZones/index.tsx +81 -56
- package/lib/builders/SliceBuilder/Sidebar/AddVariationModal.tsx +24 -16
- package/lib/builders/SliceBuilder/Sidebar/index.tsx +44 -46
- package/lib/builders/SliceBuilder/SimulatorButton/index.tsx +4 -28
- package/lib/builders/SliceBuilder/index.tsx +10 -96
- package/lib/builders/common/Zone/Card/components/Hints/CodeBlock.tsx +5 -1
- package/lib/builders/common/Zone/Card/components/NewField.tsx +16 -15
- package/lib/builders/common/Zone/Card/index.jsx +2 -0
- package/lib/builders/common/Zone/index.jsx +3 -1
- package/lib/models/common/ComponentUI.ts +0 -14
- package/lib/models/common/CustomType/sliceZone.ts +0 -29
- package/lib/models/common/CustomType/tab.ts +10 -142
- package/lib/models/common/widgets/Group/ListItem/index.jsx +61 -23
- package/out/404.html +1 -1
- package/out/_next/static/2SXh8a0HZLb2Awmhh2xob/_buildManifest.js +1 -0
- package/out/_next/static/chunks/065a3ddb-9a38ca0d60f0bf2f.js +1 -0
- package/out/_next/static/chunks/183-4feb6bb3eddbc768.js +1 -0
- package/out/_next/static/chunks/1cc2734a-2c5b6c0367fcde86.js +1 -0
- package/out/_next/static/chunks/25-8fedd33ad9b6de5b.js +1 -0
- package/out/_next/static/chunks/318-541db69860d31138.js +1 -0
- package/out/_next/static/chunks/{505-3f1cf09a086dcba8.js → 376-0ed5822f8afcaa7c.js} +3 -3
- package/out/_next/static/chunks/4c744e84-e3161d754618373f.js +1 -0
- package/out/_next/static/chunks/50-cfc2514205b86001.js +1 -0
- package/out/_next/static/chunks/543-f8766685f7f451e2.js +1 -0
- package/out/_next/static/chunks/59b4e022-7a3b5554b806349f.js +1 -0
- package/out/_next/static/chunks/696-b12edad30a3617e5.js +31 -0
- package/out/_next/static/chunks/727-15cf3f2fea9a37e5.js +1 -0
- package/out/_next/static/chunks/731-501990ebe6a71b32.js +1 -0
- package/out/_next/static/chunks/787-727e3aef5d2a10a8.js +1 -0
- package/out/_next/static/chunks/904-ccd8ca3368ce29fc.js +1 -0
- package/out/_next/static/chunks/{918-38d08f1e885b222d.js → 918-5bb55fb464e34768.js} +1 -1
- package/out/_next/static/chunks/f36c6662-03bb5e9d9aa0b0aa.js +1 -0
- package/out/_next/static/chunks/pages/_app-49f29218569a926a.js +428 -0
- package/out/_next/static/chunks/pages/changelog-68d115a14f1423d7.js +1 -0
- package/out/_next/static/chunks/pages/changes-6f62ae7b6243a1c7.js +1 -0
- package/out/_next/static/chunks/pages/custom-types/{[customTypeId]-3a37eb3373bb8823.js → [customTypeId]-3f862ad6111a1fc0.js} +1 -1
- package/out/_next/static/chunks/pages/{custom-types-2f5664d9492b13fb.js → custom-types-94b8f8dbf7727412.js} +1 -1
- package/out/_next/static/chunks/pages/{index-d8e3a2c0d712904f.js → index-64cfb8b0948ba8ef.js} +1 -1
- package/out/_next/static/chunks/pages/page-types/{[pageTypeId]-733f3890c0466a05.js → [pageTypeId]-d1ffca11c42f2603.js} +1 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-897ca93c114a1435.js +1 -0
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-e89e2e6f772a3454.js +1 -0
- package/out/_next/static/chunks/pages/slices-9628f8aa54968d6a.js +1 -0
- package/out/changelog.html +1 -1
- package/out/changes.html +1 -1
- package/out/custom-types/[customTypeId].html +1 -1
- package/out/custom-types.html +1 -1
- package/out/index.html +1 -1
- package/out/labs.html +1 -1
- package/out/page-types/[pageTypeId].html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
- package/out/slices.html +1 -1
- package/package.json +3 -3
- package/pages/slices/[lib]/[sliceName]/[variation]/index.tsx +25 -11
- package/pages/slices/[lib]/[sliceName]/[variation]/simulator.tsx +12 -9
- package/src/apiClient.ts +7 -6
- package/src/components/CodeBlock/CodeBlock.tsx +1 -0
- package/src/components/Window/Window.tsx +7 -1
- package/src/domain/__tests__/customType.test.ts +785 -0
- package/src/domain/customType.ts +519 -6
- package/src/domain/slice.ts +166 -1
- package/src/features/autoSave/AutoSaveStatusIndicator.tsx +43 -0
- package/src/features/autoSave/useAutoSave.tsx +177 -0
- package/src/features/customTypes/EditDropdown.tsx +3 -0
- package/src/features/customTypes/actions/convertCustomToPageType.ts +2 -4
- package/src/features/customTypes/customTypesBuilder/CustomTypeProvider.tsx +90 -0
- package/src/features/customTypes/customTypesBuilder/CustomTypesBuilderPage.tsx +46 -79
- package/src/features/customTypes/customTypesMessages.ts +4 -0
- package/src/features/slices/actions/addSlicesToSliceZone.ts +2 -7
- package/src/features/slices/actions/uploadSliceScreenshot.ts +45 -0
- package/src/features/slices/convertLegacySlice/ConvertLegacySliceAsNewVariationDialog.tsx +5 -5
- package/src/features/slices/convertLegacySlice/ConvertLegacySliceButton.tsx +4 -10
- package/src/features/slices/sliceBuilder/SliceBuilderProvider.tsx +110 -0
- package/src/features/slices/sliceBuilder/actions/deleteVariation.ts +8 -24
- package/src/features/slices/sliceBuilder/actions/renameVariation.ts +8 -24
- package/src/features/slices/sliceCards/SharedSliceCard.tsx +1 -0
- package/src/hooks/useCurrentSlice.tsx +4 -16
- package/src/hooks/useScreenshotChangesModal.ts +1 -0
- package/src/hooks/useServerState.ts +1 -58
- package/src/modules/availableCustomTypes/index.ts +8 -3
- package/src/modules/simulator/index.ts +0 -2
- package/src/modules/slices/index.ts +32 -25
- package/src/modules/slices/selector.ts +30 -0
- package/src/modules/useSliceMachineActions.ts +20 -270
- package/src/redux/reducer.ts +0 -4
- package/src/redux/saga.ts +0 -6
- package/src/redux/type.ts +0 -4
- package/test/src/modules/availableCustomTypes/index.test.ts +8 -10
- package/test/src/modules/simulator.test.ts +0 -2
- package/lib/models/common/CustomType/group.ts +0 -80
- package/lib/models/common/Variation.ts +0 -100
- package/out/_next/static/ZrWICkLApT4ZATA_akn-2/_buildManifest.js +0 -1
- package/out/_next/static/chunks/482-34cee2a2071c235f.js +0 -1
- package/out/_next/static/chunks/550-c80fd46fb64d1eef.js +0 -1
- package/out/_next/static/chunks/80-7b8a97d0122ff74a.js +0 -1
- package/out/_next/static/chunks/840-163f8a1040e6820d.js +0 -1
- package/out/_next/static/chunks/904-519dbf0f7e8c6243.js +0 -1
- package/out/_next/static/chunks/958-8aca174b80cb0c35.js +0 -1
- package/out/_next/static/chunks/pages/_app-132564608e9a9502.js +0 -458
- package/out/_next/static/chunks/pages/changelog-4d0f2f1222e403fe.js +0 -1
- package/out/_next/static/chunks/pages/changes-52c9d917808d1461.js +0 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-7b17cb59d0db03b5.js +0 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-ef11594ce026b650.js +0 -1
- package/out/_next/static/chunks/pages/slices-884a936a9a062a65.js +0 -1
- package/src/domain/__tests__/CustomTypeModel.test.ts +0 -247
- package/src/layouts/WithSlice.tsx +0 -26
- package/src/modules/screenshots/actions.ts +0 -21
- package/src/modules/screenshots/sagas.ts +0 -70
- package/src/modules/selectedCustomType/actions.ts +0 -147
- package/src/modules/selectedCustomType/index.ts +0 -11
- package/src/modules/selectedCustomType/reducer.ts +0 -287
- package/src/modules/selectedCustomType/sagas.ts +0 -72
- package/src/modules/selectedCustomType/selectors.ts +0 -33
- package/src/modules/selectedCustomType/stateHelpers.ts +0 -42
- package/src/modules/selectedCustomType/types.ts +0 -9
- package/src/modules/selectedSlice/actions.ts +0 -106
- package/src/modules/selectedSlice/reducer.ts +0 -175
- package/src/modules/selectedSlice/sagas.ts +0 -72
- package/src/modules/selectedSlice/selectors.ts +0 -55
- package/src/modules/selectedSlice/types.ts +0 -3
- package/src/modules/toaster/utils.tsx +0 -23
- package/test/lib/models/common/CustomType/sliceZone.test.ts +0 -49
- package/test/pages/custom-types.test.tsx +0 -625
- package/test/src/modules/selectedCustomType/__fixtures__/model.json +0 -119
- package/test/src/modules/selectedCustomType/reducer.test.ts +0 -322
- package/test/src/modules/selectedCustomType/sagas.test.ts +0 -89
- package/test/src/modules/selectedCustomType/selectors.test.ts +0 -54
- package/test/src/modules/selectedSlice/__fixtures__/mocks.json +0 -171
- package/test/src/modules/selectedSlice/__fixtures__/model.json +0 -35
- package/test/src/modules/selectedSlice/__testutils__/getRefreshStateCreatorPayloadData.ts +0 -72
- package/test/src/modules/selectedSlice/__testutils__/getSelectedSliceDummyData.ts +0 -30
- package/test/src/modules/selectedSlice/reducer.test.ts +0 -170
- package/test/src/modules/selectedSlice/sagas.test.ts +0 -82
- package/test/src/modules/toaster/utils.test.ts +0 -50
- /package/out/_next/static/{ZrWICkLApT4ZATA_akn-2 → 2SXh8a0HZLb2Awmhh2xob}/_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,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;
|