slice-machine-ui 1.23.2-alpha.bmo-add-github-settings-page.4 → 1.23.2-alpha.bmo-add-github-settings-page.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 (75) hide show
  1. package/components/DeleteSliceModal/index.tsx +34 -24
  2. package/components/Forms/CreateCustomTypeModal/CreateCustomTypeModal.tsx +61 -38
  3. package/components/Forms/RenameCustomTypeModal/RenameCustomTypeModal.tsx +2 -2
  4. package/components/Forms/RenameSliceModal/RenameSliceModal.tsx +33 -21
  5. package/components/Navigation/ChangesListItem.tsx +14 -32
  6. package/lib/models/common/widgets/StructuredText/index.ts +1 -1
  7. package/out/404.html +1 -1
  8. package/out/_next/static/chunks/25-01f422cea8066349.js +1 -0
  9. package/out/_next/static/chunks/{318-bd030cc1725e23b5.js → 318-99b5914b60bf1d17.js} +1 -1
  10. package/out/_next/static/chunks/727-f8fefdd3e50cab2a.js +1 -0
  11. package/out/_next/static/chunks/799-b467582de0a7254f.js +1 -0
  12. package/out/_next/static/chunks/904-4653b7a849f4db94.js +1 -0
  13. package/out/_next/static/chunks/pages/{_app-027b9e90438a0d83.js → _app-95e9373e879af96c.js} +26 -26
  14. package/out/_next/static/chunks/pages/{changes-8de69920dfb5a48f.js → changes-ac7d64fc8ec82b39.js} +1 -1
  15. package/out/_next/static/chunks/pages/custom-types/{[customTypeId]-3f862ad6111a1fc0.js → [customTypeId]-97ab3b90b85d645d.js} +1 -1
  16. package/out/_next/static/chunks/pages/{custom-types-94b8f8dbf7727412.js → custom-types-3c8e721ec6802127.js} +1 -1
  17. package/out/_next/static/chunks/pages/index-cf93d16e9c63b6db.js +1 -0
  18. package/out/_next/static/chunks/pages/page-types/{[pageTypeId]-d1ffca11c42f2603.js → [pageTypeId]-84a22c5e480d3fa9.js} +1 -1
  19. package/out/_next/static/chunks/pages/settings-0961cf5b601e4baf.js +1 -0
  20. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/{simulator-b12346e58ac9abea.js → simulator-c498e9c80cae8cce.js} +1 -1
  21. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-8038454f751ad0b9.js +1 -0
  22. package/out/_next/static/chunks/pages/slices-4522d604117d8c66.js +1 -0
  23. package/out/_next/static/{eFhKCr9d2Q8SjtAKgFjlm → giA50Mi0bmd47Gv-gysZU}/_buildManifest.js +1 -1
  24. package/out/changelog.html +1 -1
  25. package/out/changes.html +1 -1
  26. package/out/custom-types/[customTypeId].html +1 -1
  27. package/out/custom-types.html +1 -1
  28. package/out/index.html +1 -1
  29. package/out/labs.html +1 -1
  30. package/out/page-types/[pageTypeId].html +1 -1
  31. package/out/settings.html +1 -1
  32. package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
  33. package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
  34. package/out/slices.html +1 -1
  35. package/package.json +3 -3
  36. package/pages/slices.tsx +20 -8
  37. package/src/apiClient.ts +1 -22
  38. package/src/domain/__tests__/customType.test.ts +179 -0
  39. package/src/domain/customType.ts +110 -2
  40. package/src/domain/slice.ts +38 -0
  41. package/src/features/customTypes/PageTypeOnboarding.tsx +21 -26
  42. package/src/features/customTypes/actions/convertCustomToPageType.ts +14 -10
  43. package/src/features/customTypes/actions/createCustomType.ts +69 -0
  44. package/src/features/customTypes/actions/deleteCustomType.ts +13 -3
  45. package/src/features/customTypes/actions/renameCustomType.ts +10 -4
  46. package/src/features/customTypes/customTypesBuilder/CustomTypesBuilderPage.tsx +3 -1
  47. package/src/features/customTypes/customTypesTable/CustomTypesTable.tsx +8 -8
  48. package/src/features/customTypes/customTypesTable/CustomTypesTablePage.tsx +18 -17
  49. package/src/features/settings/git/GitProvider.ts +1 -1
  50. package/src/features/settings/git/GitRepositoryConnectDialog.tsx +1 -2
  51. package/src/features/slices/actions/createSlice.ts +5 -29
  52. package/src/features/slices/actions/deleteSlice.ts +33 -0
  53. package/src/features/slices/actions/renameSlice.ts +37 -0
  54. package/src/modules/availableCustomTypes/index.ts +29 -135
  55. package/src/modules/loading/types.ts +0 -5
  56. package/src/modules/modal/types.ts +0 -3
  57. package/src/modules/slices/index.ts +27 -193
  58. package/src/modules/slices/selector.ts +0 -14
  59. package/src/modules/useSliceMachineActions.ts +70 -89
  60. package/src/modules/userContext/index.ts +3 -3
  61. package/src/redux/saga.ts +0 -4
  62. package/test/src/modules/availableCustomTypes/index.test.ts +2 -243
  63. package/test/src/modules/slices.test.ts +1 -267
  64. package/out/_next/static/chunks/25-37d6fa7f064be04b.js +0 -1
  65. package/out/_next/static/chunks/727-2235967a881f9035.js +0 -1
  66. package/out/_next/static/chunks/731-a9b66ccdc3fae2c2.js +0 -1
  67. package/out/_next/static/chunks/904-6d6937d53ea2761e.js +0 -1
  68. package/out/_next/static/chunks/pages/index-64cfb8b0948ba8ef.js +0 -1
  69. package/out/_next/static/chunks/pages/settings-41fc2a11b6be2683.js +0 -1
  70. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-62b55bae7f1b3793.js +0 -1
  71. package/out/_next/static/chunks/pages/slices-81e382c3374273df.js +0 -1
  72. package/src/features/customTypes/__tests__/createCustomType.test.ts +0 -159
  73. package/src/features/customTypes/customTypesTable/createCustomType.ts +0 -107
  74. package/test/components/CreateCustomTypeModal.test.tsx +0 -73
  75. /package/out/_next/static/{eFhKCr9d2Q8SjtAKgFjlm → giA50Mi0bmd47Gv-gysZU}/_ssgManifest.js +0 -0
@@ -1,35 +1,15 @@
1
- import { useEffect, useState } from "react";
2
- import { useSelector } from "react-redux";
1
+ import { useState } from "react";
3
2
  import { Box, Button, Text } from "@prismicio/editor-ui";
4
3
  import { cache } from "@prismicio/editor-support/Suspense";
5
4
 
6
5
  import { CreateCustomTypeModal } from "@components/Forms/CreateCustomTypeModal";
7
- import { SliceMachineStoreType } from "@src/redux/type";
8
- import useSliceMachineActions from "@src/modules/useSliceMachineActions";
9
- import { LoadingKeysEnum } from "@src/modules/loading/types";
10
- import { isLoading } from "@src/modules/loading";
11
6
  import { BlankPageIcon } from "@src/icons/BlankPageIcon";
12
7
  import { getIsEmptyProject } from "@src/hooks/useIsEmptyProject";
13
8
 
14
9
  export function PageTypeOnboarding() {
15
- const { openCreateCustomTypeModal } = useSliceMachineActions();
16
- const { isCreatingCustomType } = useSelector(
17
- (store: SliceMachineStoreType) => ({
18
- isCreatingCustomType: isLoading(
19
- store,
20
- LoadingKeysEnum.CREATE_CUSTOM_TYPE,
21
- ),
22
- }),
23
- );
24
- // State to ensure button loader is still visible while redirecting
25
- const [isButtonLoading, setIsButtonLoading] = useState(false);
26
-
27
- useEffect(() => {
28
- if (isCreatingCustomType) {
29
- setIsButtonLoading(true);
30
- cache.clear(getIsEmptyProject, []);
31
- }
32
- }, [isCreatingCustomType]);
10
+ const [isCreatingCustomType, setIsCreatingCustomType] = useState(false);
11
+ const [isCreateCustomTypeModalOpen, setIsCreateCustomTypeModalOpen] =
12
+ useState(false);
33
13
 
34
14
  return (
35
15
  <Box
@@ -53,10 +33,25 @@ export function PageTypeOnboarding() {
53
33
  Welcome to Slice Machine. Your journey starts with your first page
54
34
  type — the model that you will use to create pages for your website.
55
35
  </Text>
56
- <Button onClick={openCreateCustomTypeModal} loading={isButtonLoading}>
36
+ <Button
37
+ loading={isCreatingCustomType}
38
+ onClick={() => {
39
+ setIsCreateCustomTypeModalOpen(true);
40
+ }}
41
+ >
57
42
  Create a page type
58
43
  </Button>
59
- <CreateCustomTypeModal format="page" origin="onboarding" />
44
+ <CreateCustomTypeModal
45
+ format="page"
46
+ isCreating={isCreatingCustomType}
47
+ isOpen={isCreateCustomTypeModalOpen}
48
+ origin="onboarding"
49
+ onCreateChange={(isCreating) => {
50
+ setIsCreatingCustomType(isCreating);
51
+ cache.clear(getIsEmptyProject, []);
52
+ }}
53
+ onOpenChange={setIsCreateCustomTypeModalOpen}
54
+ />
60
55
  </Box>
61
56
  </Box>
62
57
  );
@@ -9,17 +9,20 @@ import { CUSTOM_TYPES_MESSAGES } from "../customTypesMessages";
9
9
 
10
10
  export async function convertCustomToPageType(
11
11
  customType: CustomType,
12
- saveCustomType: (customType: CustomType) => void,
12
+ onSuccess: (newCustomType: CustomType) => void,
13
13
  ) {
14
14
  const customTypesMessages =
15
15
  CUSTOM_TYPES_MESSAGES[customType.format as CustomTypeFormat];
16
16
 
17
17
  try {
18
18
  const newCustomType = convertToPageType(customType);
19
- await updateCustomType(newCustomType);
19
+ const { errors } = await updateCustomType(newCustomType);
20
20
 
21
- // Update the custom type in the redux store
22
- saveCustomType(newCustomType);
21
+ if (errors.length > 0) {
22
+ throw errors;
23
+ }
24
+
25
+ onSuccess(newCustomType);
23
26
 
24
27
  toast.success(
25
28
  `${customTypesMessages.name({
@@ -28,11 +31,12 @@ export async function convertCustomToPageType(
28
31
  })} converted to page type`,
29
32
  );
30
33
  } catch (e) {
31
- toast.error(
32
- `Internal Error: ${customTypesMessages.name({
33
- start: true,
34
- plural: false,
35
- })} not converted to page type`,
36
- );
34
+ const errorMessage = `Internal Error: ${customTypesMessages.name({
35
+ start: true,
36
+ plural: false,
37
+ })} not converted to page type`;
38
+
39
+ console.error(errorMessage, e);
40
+ toast.error(errorMessage);
37
41
  }
38
42
  }
@@ -0,0 +1,69 @@
1
+ import { toast } from "react-toastify";
2
+ import { CustomType } from "@prismicio/types-internal/lib/customtypes";
3
+
4
+ import { ToastMessageWithPath } from "@components/ToasterContainer";
5
+ import { CustomTypeFormat } from "@slicemachine/manager";
6
+ import { telemetry, updateCustomType } from "@src/apiClient";
7
+ import { create } from "@src/domain/customType";
8
+
9
+ import { CUSTOM_TYPES_MESSAGES } from "../customTypesMessages";
10
+
11
+ type DeleteCustomTypeArgs = {
12
+ format: CustomTypeFormat;
13
+ id: string;
14
+ label: string;
15
+ origin: CustomTypeOrigin;
16
+ repeatable: boolean;
17
+ onSuccess: (newCustomType: CustomType) => Promise<void>;
18
+ };
19
+
20
+ export type CustomTypeOrigin = "onboarding" | "table";
21
+
22
+ export async function createCustomType(args: DeleteCustomTypeArgs) {
23
+ const { id, label, repeatable, format, onSuccess } = args;
24
+ const customTypesMessages = CUSTOM_TYPES_MESSAGES[format];
25
+
26
+ const newCustomType: CustomType = create({
27
+ id,
28
+ label,
29
+ repeatable,
30
+ format,
31
+ });
32
+
33
+ try {
34
+ const { errors } = await updateCustomType(newCustomType);
35
+
36
+ if (errors.length > 0) {
37
+ throw errors;
38
+ }
39
+
40
+ void telemetry.track({
41
+ event: "custom-type:created",
42
+ id: newCustomType.id,
43
+ name: label,
44
+ format: format,
45
+ type: repeatable ? "repeatable" : "single",
46
+ origin: "table",
47
+ });
48
+
49
+ await onSuccess(newCustomType);
50
+
51
+ toast.success(
52
+ ToastMessageWithPath({
53
+ message: `${customTypesMessages.name({
54
+ start: true,
55
+ plural: false,
56
+ })} saved successfully at `,
57
+ path: `./customtypes/${newCustomType.id}/index.json`,
58
+ }),
59
+ );
60
+ } catch (e) {
61
+ const errorMessage = `Internal Error: ${customTypesMessages.name({
62
+ start: true,
63
+ plural: false,
64
+ })} not saved`;
65
+
66
+ console.error(errorMessage, e);
67
+ toast.error(errorMessage);
68
+ }
69
+ }
@@ -1,8 +1,10 @@
1
+ import { toast } from "react-toastify";
1
2
  import { CustomType } from "@prismicio/types-internal/lib/customtypes";
3
+
2
4
  import { managerClient } from "@src/managerClient";
5
+ import { CustomTypeFormat } from "@slicemachine/manager";
6
+
3
7
  import { CUSTOM_TYPES_MESSAGES } from "../customTypesMessages";
4
- import { CustomTypeFormat } from "@slicemachine/manager/*";
5
- import { toast } from "react-toastify";
6
8
 
7
9
  type DeleteCustomTypeArgs = {
8
10
  customType: CustomType;
@@ -17,7 +19,13 @@ export async function deleteCustomType({
17
19
  CUSTOM_TYPES_MESSAGES[customType.format as CustomTypeFormat];
18
20
 
19
21
  try {
20
- await managerClient.customTypes.deleteCustomType({ id: customType.id });
22
+ const { errors } = await managerClient.customTypes.deleteCustomType({
23
+ id: customType.id,
24
+ });
25
+
26
+ if (errors.length > 0) {
27
+ throw errors;
28
+ }
21
29
 
22
30
  onSuccess();
23
31
 
@@ -32,6 +40,8 @@ export async function deleteCustomType({
32
40
  start: true,
33
41
  plural: false,
34
42
  })} could not be deleted`;
43
+
35
44
  console.error(errorMessage, e);
45
+ toast.error(errorMessage);
36
46
  }
37
47
  }
@@ -1,8 +1,10 @@
1
+ import { toast } from "react-toastify";
1
2
  import { CustomType } from "@prismicio/types-internal/lib/customtypes";
3
+
2
4
  import { managerClient } from "@src/managerClient";
3
- import { CUSTOM_TYPES_MESSAGES } from "../customTypesMessages";
4
5
  import { CustomTypeFormat } from "@slicemachine/manager";
5
- import { toast } from "react-toastify";
6
+
7
+ import { CUSTOM_TYPES_MESSAGES } from "../customTypesMessages";
6
8
 
7
9
  type RenameCustomTypeArgs = {
8
10
  model: CustomType;
@@ -23,10 +25,14 @@ export async function renameCustomType({
23
25
  label: newLabel,
24
26
  };
25
27
 
26
- await managerClient.customTypes.renameCustomType({
28
+ const { errors } = await managerClient.customTypes.renameCustomType({
27
29
  model: renamedCustomType,
28
30
  });
29
31
 
32
+ if (errors.length > 0) {
33
+ throw errors;
34
+ }
35
+
30
36
  onSuccess(renamedCustomType);
31
37
 
32
38
  toast.success(
@@ -40,8 +46,8 @@ export async function renameCustomType({
40
46
  start: true,
41
47
  plural: false,
42
48
  })} could not be renamed`;
43
- console.error(errorMessage, e);
44
49
 
50
+ console.error(errorMessage, e);
45
51
  toast.error(errorMessage);
46
52
  }
47
53
  }
@@ -39,7 +39,9 @@ export const CustomTypesBuilderPage: FC = () => {
39
39
  );
40
40
 
41
41
  useEffect(() => {
42
- // TODO(DT-1801): When creating a custom type, don't redirect to the builder page until the custom type is created
42
+ // This is a fallback in case the user try to directly access a custom type
43
+ // that don't exist
44
+ // TODO(DT-1801): Implement a 404 page
43
45
  if (!selectedCustomType || !hasLocal(selectedCustomType)) {
44
46
  void router.replace("/");
45
47
  }
@@ -11,16 +11,9 @@ import {
11
11
  } from "@src/components/Table";
12
12
  import { ReusableIcon } from "@src/icons/ReusableIcon";
13
13
  import { UniqueIcon } from "@src/icons/UniqueIcon";
14
- import useSliceMachineActions from "@src/modules/useSliceMachineActions";
15
14
  import { type CustomType } from "@prismicio/types-internal/lib/customtypes";
16
15
  import { type CustomTypeFormat } from "@slicemachine/manager";
17
16
  import { CUSTOM_TYPES_MESSAGES } from "@src/features/customTypes/customTypesMessages";
18
- import { CUSTOM_TYPES_CONFIG } from "../customTypesConfig";
19
- import {
20
- useCustomTypes,
21
- useCustomTypesAutoRevalidation,
22
- } from "./useCustomTypes";
23
-
24
17
  import {
25
18
  BlankSlate,
26
19
  BlankSlateImage,
@@ -29,18 +22,25 @@ import {
29
22
  BlankSlateActions,
30
23
  BlankSlateContent,
31
24
  } from "@src/components/BlankSlate";
25
+
26
+ import { CUSTOM_TYPES_CONFIG } from "../customTypesConfig";
32
27
  import { EditDropdown } from "../EditDropdown";
28
+ import {
29
+ useCustomTypes,
30
+ useCustomTypesAutoRevalidation,
31
+ } from "./useCustomTypes";
33
32
 
34
33
  type CustomTypesTableProps = {
35
34
  format: CustomTypeFormat;
36
35
  isCreatingCustomType: boolean;
36
+ openCreateCustomTypeModal: () => void;
37
37
  };
38
38
 
39
39
  export const CustomTypesTable: FC<CustomTypesTableProps> = ({
40
40
  format,
41
41
  isCreatingCustomType,
42
+ openCreateCustomTypeModal,
42
43
  }) => {
43
- const { openCreateCustomTypeModal } = useSliceMachineActions();
44
44
  const router = useRouter();
45
45
  const { customTypes, updateCustomTypes } = useCustomTypes(format);
46
46
  const sortedCustomTypes = customTypes.sort(
@@ -1,4 +1,4 @@
1
- import { type FC, Suspense } from "react";
1
+ import { type FC, Suspense, useState } from "react";
2
2
  import {
3
3
  Button,
4
4
  ErrorBoundary,
@@ -7,7 +7,6 @@ import {
7
7
  DefaultErrorMessage,
8
8
  } from "@prismicio/editor-ui";
9
9
  import Head from "next/head";
10
- import { useSelector } from "react-redux";
11
10
 
12
11
  import {
13
12
  AppLayout,
@@ -16,13 +15,10 @@ import {
16
15
  AppLayoutContent,
17
16
  AppLayoutHeader,
18
17
  } from "@components/AppLayout";
19
- import useSliceMachineActions from "@src/modules/useSliceMachineActions";
20
- import { isLoading } from "@src/modules/loading";
21
- import { type SliceMachineStoreType } from "@src/redux/type";
22
- import { LoadingKeysEnum } from "@src/modules/loading/types";
23
18
  import { CreateCustomTypeModal } from "@components/Forms/CreateCustomTypeModal";
24
19
  import { CUSTOM_TYPES_MESSAGES } from "@src/features/customTypes/customTypesMessages";
25
20
  import type { CustomTypeFormat } from "@slicemachine/manager";
21
+
26
22
  import { CustomTypesTable } from "./CustomTypesTable";
27
23
 
28
24
  type CustomTypesTablePageProps = {
@@ -33,15 +29,9 @@ export const CustomTypesTablePage: FC<CustomTypesTablePageProps> = ({
33
29
  format,
34
30
  }) => {
35
31
  const customTypesMessages = CUSTOM_TYPES_MESSAGES[format];
36
- const { openCreateCustomTypeModal } = useSliceMachineActions();
37
- const { isCreatingCustomType } = useSelector(
38
- (store: SliceMachineStoreType) => ({
39
- isCreatingCustomType: isLoading(
40
- store,
41
- LoadingKeysEnum.CREATE_CUSTOM_TYPE,
42
- ),
43
- }),
44
- );
32
+ const [isCreatingCustomType, setIsCreatingCustomType] = useState(false);
33
+ const [isCreateCustomTypeModalOpen, setIsCreateCustomTypeModalOpen] =
34
+ useState(false);
45
35
 
46
36
  return (
47
37
  <>
@@ -101,7 +91,9 @@ export const CustomTypesTablePage: FC<CustomTypesTablePageProps> = ({
101
91
  <Button
102
92
  data-cy="create-ct"
103
93
  loading={isCreatingCustomType}
104
- onClick={openCreateCustomTypeModal}
94
+ onClick={() => {
95
+ setIsCreateCustomTypeModalOpen(true);
96
+ }}
105
97
  startIcon="add"
106
98
  >
107
99
  Create
@@ -113,8 +105,17 @@ export const CustomTypesTablePage: FC<CustomTypesTablePageProps> = ({
113
105
  <CustomTypesTable
114
106
  format={format}
115
107
  isCreatingCustomType={isCreatingCustomType}
108
+ openCreateCustomTypeModal={() => {
109
+ setIsCreateCustomTypeModalOpen(true);
110
+ }}
111
+ />
112
+ <CreateCustomTypeModal
113
+ format={format}
114
+ isCreating={isCreatingCustomType}
115
+ isOpen={isCreateCustomTypeModalOpen}
116
+ onCreateChange={setIsCreatingCustomType}
117
+ onOpenChange={setIsCreateCustomTypeModalOpen}
116
118
  />
117
- <CreateCustomTypeModal format={format} />
118
119
  </Box>
119
120
  </AppLayoutContent>
120
121
  </AppLayout>
@@ -5,7 +5,7 @@ import { managerClient } from "@src/managerClient";
5
5
 
6
6
  export type GitProvider = keyof typeof gitProviderToConfig;
7
7
 
8
- const GITHUB_APP_SLUG = "prismic-prod-internal-test";
8
+ const GITHUB_APP_SLUG = "prismic-io";
9
9
 
10
10
  export const gitProviderToConfig = {
11
11
  gitHub: {
@@ -63,8 +63,7 @@ export const GitRepositoryConnectDialog: FC<
63
63
  value={formikProps.values.writeAPIToken}
64
64
  />
65
65
  <Text color="grey11">
66
- Required to sync models from ${providerConfig.name} to
67
- Prismic.
66
+ Required to sync models from {providerConfig.name} to Prismic.
68
67
  </Text>
69
68
  </Box>
70
69
  <DialogActions
@@ -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
+ }