slice-machine-ui 1.23.2-beta.1 → 1.23.2-beta.11

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 (164) hide show
  1. package/.depcheckrc +3 -0
  2. package/components/ChangesEmptyState/OfflinePage.tsx +1 -1
  3. package/components/ChangesItems/ChangesItems.tsx +6 -2
  4. package/components/CustomTypeTable/changesPage.tsx +12 -7
  5. package/components/DeleteSliceModal/index.tsx +37 -24
  6. package/components/DeleteVariationModal/index.tsx +1 -0
  7. package/components/Forms/CreateCustomTypeModal/CreateCustomTypeModal.tsx +65 -38
  8. package/components/Forms/CreateSliceModal/CreateSliceModal.tsx +3 -1
  9. package/components/Forms/RenameCustomTypeModal/RenameCustomTypeModal.tsx +7 -2
  10. package/components/Forms/RenameSliceModal/RenameSliceModal.tsx +36 -21
  11. package/components/Forms/RenameVariationModal/RenameVariationModal.tsx +0 -1
  12. package/components/LoginModal/index.tsx +40 -2
  13. package/components/ModalFormCard/index.tsx +0 -1
  14. package/components/Navigation/ChangesItem.tsx +117 -0
  15. package/components/Navigation/Environment.tsx +51 -4
  16. package/components/Navigation/index.css.ts +1 -2
  17. package/components/Navigation/index.test.tsx +5 -85
  18. package/components/Navigation/index.tsx +32 -20
  19. package/components/ReviewModal/ReviewForm.tsx +0 -1
  20. package/lib/builders/SliceBuilder/index.tsx +3 -3
  21. package/lib/builders/common/EditModal/Form.jsx +0 -1
  22. package/lib/builders/common/Zone/Card/components/NewField.tsx +0 -1
  23. package/lib/models/common/ModelStatus/index.ts +25 -0
  24. package/lib/models/common/widgets/StructuredText/index.ts +1 -1
  25. package/out/404.html +1 -1
  26. package/out/_next/static/chunks/18539003-5f78714a35fde4a1.js +97 -0
  27. package/out/_next/static/chunks/25-3aa4d4b24167d340.js +1 -0
  28. package/out/_next/static/chunks/318-19dbcae10cdb6408.js +1 -0
  29. package/out/_next/static/chunks/727-de03055e40815a3a.js +1 -0
  30. package/out/_next/static/chunks/777-8c5507e3b119b5dc.js +8 -0
  31. package/out/_next/static/chunks/799-0af1215eb2b3c17e.js +1 -0
  32. package/out/_next/static/chunks/904-40686b0426716111.js +1 -0
  33. package/out/_next/static/chunks/pages/_app-bca191df4ac7078e.js +434 -0
  34. package/out/_next/static/chunks/pages/{changelog-afd18276fe018b24.js → changelog-cb1df3a70b20f1b8.js} +1 -1
  35. package/out/_next/static/chunks/pages/changes-ccfd715c2bdc4f83.js +1 -0
  36. package/out/_next/static/chunks/pages/custom-types/{[customTypeId]-3f862ad6111a1fc0.js → [customTypeId]-97ab3b90b85d645d.js} +1 -1
  37. package/out/_next/static/chunks/pages/{custom-types-94b8f8dbf7727412.js → custom-types-3c8e721ec6802127.js} +1 -1
  38. package/out/_next/static/chunks/pages/index-cf93d16e9c63b6db.js +1 -0
  39. package/out/_next/static/chunks/pages/{labs-ee206005948f8e87.js → labs-2adfb5127f9c4081.js} +1 -1
  40. package/out/_next/static/chunks/pages/page-types/{[pageTypeId]-d1ffca11c42f2603.js → [pageTypeId]-84a22c5e480d3fa9.js} +1 -1
  41. package/out/_next/static/chunks/pages/settings-94bcd7422e8b237d.js +1 -0
  42. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/{simulator-897ca93c114a1435.js → simulator-aaf65fbec8f5839c.js} +1 -1
  43. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-90bb2ea76d2abf42.js +1 -0
  44. package/out/_next/static/chunks/pages/slices-e0ce615c38e8338d.js +1 -0
  45. package/out/_next/static/css/39e089aad1742a3a.css +1 -0
  46. package/out/_next/static/css/{37153180c3b0dd66.css → 838fd8bb5a7c32b0.css} +1 -1
  47. package/out/_next/static/css/ca32882a5d2d8d88.css +1 -0
  48. package/out/_next/static/dS_xZnzzna6Y6uwcTgf90/_buildManifest.js +1 -0
  49. package/out/changelog.html +1 -1
  50. package/out/changes.html +1 -1
  51. package/out/custom-types/[customTypeId].html +1 -1
  52. package/out/custom-types.html +1 -1
  53. package/out/index.html +1 -1
  54. package/out/labs.html +1 -1
  55. package/out/page-types/[pageTypeId].html +1 -1
  56. package/out/settings.html +1 -0
  57. package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
  58. package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
  59. package/out/slices.html +1 -1
  60. package/package.json +9 -6
  61. package/pages/_app.tsx +34 -32
  62. package/pages/changes.tsx +27 -41
  63. package/pages/settings.tsx +1 -0
  64. package/pages/slices.tsx +20 -8
  65. package/postcss.config.js +10 -0
  66. package/src/apiClient.ts +1 -22
  67. package/src/components/FieldSet/FieldSet.stories.tsx +20 -11
  68. package/src/components/RelativeTime/RelativeTime.stories.tsx +25 -0
  69. package/src/components/RelativeTime/RelativeTime.tsx +40 -0
  70. package/src/components/RelativeTime/index.ts +1 -0
  71. package/src/components/SideNav/SideNav.css.ts +1 -1
  72. package/src/components/SideNav/SideNav.tsx +9 -5
  73. package/src/components/SideNav/SideNavEnvironmentSelector.tsx +31 -11
  74. package/src/domain/__tests__/customType.test.ts +205 -19
  75. package/src/domain/customType.ts +132 -7
  76. package/src/domain/slice.ts +38 -0
  77. package/src/features/autoSave/AutoSaveStatusIndicator.tsx +4 -4
  78. package/src/features/customTypes/PageTypeOnboarding.tsx +21 -26
  79. package/src/features/customTypes/actions/convertCustomToPageType.ts +14 -10
  80. package/src/features/customTypes/actions/createCustomType.ts +69 -0
  81. package/src/features/customTypes/actions/deleteCustomType.ts +13 -3
  82. package/src/features/customTypes/actions/renameCustomType.ts +10 -4
  83. package/src/features/customTypes/customTypesBuilder/CustomTypeProvider.tsx +11 -10
  84. package/src/features/customTypes/customTypesBuilder/CustomTypesBuilderPage.tsx +5 -3
  85. package/src/features/customTypes/customTypesTable/CustomTypesTable.tsx +8 -8
  86. package/src/features/customTypes/customTypesTable/CustomTypesTablePage.tsx +18 -17
  87. package/src/features/environments/actions/setEnvironment.ts +4 -4
  88. package/src/features/settings/SettingsPage.tsx +47 -0
  89. package/src/features/settings/git/ConnectGitRepository.tsx +126 -0
  90. package/src/features/settings/git/ConnectGitRepositoryBlankSlate.tsx +33 -0
  91. package/src/features/settings/git/GitOwnerSelect.tsx +71 -0
  92. package/src/features/settings/git/GitProvider.ts +40 -0
  93. package/src/features/settings/git/GitProviderConnectButtons.tsx +63 -0
  94. package/src/features/settings/git/GitRepositoriesList.tsx +76 -0
  95. package/src/features/settings/git/GitRepositoriesSearch.tsx +69 -0
  96. package/src/features/settings/git/GitRepositoryConnectDialog.tsx +85 -0
  97. package/src/features/settings/git/GitRepositoryDisconnectDialog.tsx +60 -0
  98. package/src/features/settings/git/useGitIntegrationExperiment.ts +8 -0
  99. package/src/features/settings/git/useGitOwners.ts +12 -0
  100. package/src/features/settings/git/useGitRepos.ts +24 -0
  101. package/src/features/settings/git/useLinkedGitRepos.ts +41 -0
  102. package/src/features/settings/git/useWriteAPIToken.ts +23 -0
  103. package/src/features/slices/actions/createSlice.ts +5 -29
  104. package/src/features/slices/actions/deleteSlice.ts +33 -0
  105. package/src/features/slices/actions/renameSlice.ts +37 -0
  106. package/src/features/slices/convertLegacySlice/ConvertLegacySliceAsNewSliceDialog.tsx +0 -1
  107. package/src/features/slices/convertLegacySlice/ConvertLegacySliceAsNewVariationDialog.tsx +0 -1
  108. package/src/features/slices/convertLegacySlice/ConvertLegacySliceMergeWithIdenticalDialog.tsx +0 -1
  109. package/src/features/slices/sliceBuilder/SliceBuilderProvider.tsx +12 -10
  110. package/src/features/sync/AutoSyncProvider.tsx +252 -0
  111. package/src/features/sync/components/AutoSyncStatusIndicator.module.css +17 -0
  112. package/src/features/sync/components/AutoSyncStatusIndicator.module.css.d.ts +5 -0
  113. package/src/features/sync/components/AutoSyncStatusIndicator.tsx +58 -0
  114. package/src/features/sync/fetchUnSyncChanges.ts +40 -0
  115. package/src/features/sync/getUnSyncChanges.ts +144 -0
  116. package/src/features/sync/useUnSyncChanges.ts +32 -0
  117. package/src/hooks/useActionQueue.tsx +177 -0
  118. package/src/hooks/useAuthStatus.ts +12 -0
  119. package/src/hooks/useUser.ts +14 -0
  120. package/src/icons/SettingsIcon.tsx +19 -0
  121. package/src/icons/SyncFailed.tsx +30 -0
  122. package/src/icons/Synced.tsx +19 -0
  123. package/src/icons/Syncing.tsx +23 -0
  124. package/src/modules/availableCustomTypes/index.ts +29 -135
  125. package/src/modules/loading/types.ts +0 -5
  126. package/src/modules/modal/types.ts +0 -3
  127. package/src/modules/slices/index.ts +27 -193
  128. package/src/modules/slices/selector.ts +0 -14
  129. package/src/modules/useSliceMachineActions.ts +70 -89
  130. package/src/modules/userContext/index.ts +3 -3
  131. package/src/redux/saga.ts +0 -4
  132. package/test/__testutils__/index.tsx +8 -5
  133. package/test/src/modules/__fixtures__/serverState.ts +1 -2
  134. package/test/src/modules/availableCustomTypes/index.test.ts +2 -243
  135. package/test/src/modules/slices.test.ts +1 -267
  136. package/components/Navigation/ChangesListItem.tsx +0 -92
  137. package/components/Navigation/ChangesRightElement.tsx +0 -33
  138. package/out/_next/static/chunks/18539003-5cc559566b738915.js +0 -97
  139. package/out/_next/static/chunks/25-37d6fa7f064be04b.js +0 -1
  140. package/out/_next/static/chunks/318-ce7e74f18f2d5b22.js +0 -1
  141. package/out/_next/static/chunks/376-7e784d6069e01654.js +0 -8
  142. package/out/_next/static/chunks/727-3a3bc32518778317.js +0 -1
  143. package/out/_next/static/chunks/731-501990ebe6a71b32.js +0 -1
  144. package/out/_next/static/chunks/904-9a4c1264727ae89a.js +0 -1
  145. package/out/_next/static/chunks/pages/_app-cd9d4c76a4abc11a.js +0 -432
  146. package/out/_next/static/chunks/pages/changes-2a976f9efeb719aa.js +0 -1
  147. package/out/_next/static/chunks/pages/index-64cfb8b0948ba8ef.js +0 -1
  148. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-b2a9d773ce5d7739.js +0 -1
  149. package/out/_next/static/chunks/pages/slices-e9c70c082ca3e3f9.js +0 -1
  150. package/out/_next/static/css/200244e3e0463c39.css +0 -1
  151. package/out/_next/static/m6psnC5u1xT7Y6osWHKjp/_buildManifest.js +0 -1
  152. package/src/features/autoSave/useAutoSave.tsx +0 -177
  153. package/src/features/customTypes/__tests__/createCustomType.test.ts +0 -159
  154. package/src/features/customTypes/customTypesTable/createCustomType.ts +0 -107
  155. package/src/features/legacyState/actions/getLegacySliceMachineState.ts +0 -53
  156. package/src/features/legacyState/useLegacySliceMachineState.ts +0 -7
  157. package/src/hooks/useModelStatus.ts +0 -78
  158. package/src/hooks/useUnSyncChanges.ts +0 -88
  159. package/test/components/CreateCustomTypeModal.test.tsx +0 -73
  160. package/test/components/LoginModal.test.tsx +0 -67
  161. package/test/src/hooks/useModelStatus.test.ts +0 -115
  162. /package/out/_next/static/{m6psnC5u1xT7Y6osWHKjp → dS_xZnzzna6Y6uwcTgf90}/_ssgManifest.js +0 -0
  163. /package/src/features/{changes → sync}/actions/pushChanges.ts +0 -0
  164. /package/src/features/{changes → sync}/actions/trackPushChangesSuccess.ts +0 -0
@@ -1,73 +0,0 @@
1
- // @vitest-environment jsdom
2
-
3
- import { describe, test, afterEach, expect, vi } from "vitest";
4
- import { Analytics } from "@segment/analytics-node";
5
-
6
- import { render, fireEvent, act } from "../__testutils__";
7
- import { CreateCustomTypeModal } from "../../components/Forms/CreateCustomTypeModal";
8
- import { ModalKeysEnum } from "../../src/modules/modal/types";
9
-
10
- vi.mock("next/router", () => require("next-router-mock"));
11
- global.console = { ...global.console, error: vi.fn() };
12
-
13
- describe("CreateCustomTypeModal", () => {
14
- afterEach(() => {
15
- vi.clearAllMocks();
16
- });
17
-
18
- test("when a slice is created the tracker should be called", async () => {
19
- const fakeId = "testing_id";
20
- const fakeName = "testing-name";
21
- const fakeRepo = "foo";
22
-
23
- render(<CreateCustomTypeModal format="custom" />, {
24
- preloadedState: {
25
- // @ts-expect-error TS(2739) FIXME: Type '{ repo: string; }' is missing the following ... Remove this comment to see the full error message
26
- environment: {
27
- repo: fakeRepo,
28
- },
29
- availableCustomTypes: {},
30
- // @ts-expect-error TS(2740) FIXME: Type '{ CREATE_CUSTOM_TYPE: true; }' is missing th... Remove this comment to see the full error message
31
- modal: { [ModalKeysEnum.CREATE_CUSTOM_TYPE]: true },
32
- },
33
- });
34
-
35
- const idInput = document.querySelector('[name="id"]');
36
- const labelInput = document.querySelector('[name="label"]');
37
- const submitButton = document.querySelector('[type="submit"]');
38
-
39
- await act(async () => {
40
- if (labelInput) {
41
- fireEvent.change(labelInput, { target: { value: fakeName } });
42
- }
43
- });
44
-
45
- await act(async () => {
46
- if (idInput) {
47
- fireEvent.change(idInput, { target: { value: fakeId } });
48
- }
49
- });
50
-
51
- await act(async () => {
52
- if (submitButton) {
53
- fireEvent.click(submitButton);
54
- }
55
- });
56
-
57
- expect(Analytics.prototype.track).toHaveBeenCalledOnce();
58
- expect(Analytics.prototype.track).toHaveBeenCalledWith(
59
- expect.objectContaining({
60
- event: "SliceMachine Custom Type Created",
61
- properties: {
62
- id: fakeId,
63
- name: fakeName,
64
- format: "custom",
65
- type: "repeatable",
66
- nodeVersion: process.versions.node,
67
- origin: "table",
68
- },
69
- }),
70
- expect.any(Function),
71
- );
72
- });
73
- });
@@ -1,67 +0,0 @@
1
- // @vitest-environment jsdom
2
-
3
- import { describe, test, expect, vi } from "vitest";
4
- import React from "react";
5
- import { render } from "@testing-library/react";
6
- import LoginModal from "@components/LoginModal";
7
- import { FrontEndEnvironment } from "@lib/models/common/Environment";
8
- import { useSelector } from "react-redux";
9
-
10
- const mockDispatch = vi.fn();
11
- vi.mock("react-beautiful-dnd", () => {
12
- return {};
13
- });
14
- vi.mock("react-redux", () => ({
15
- useSelector: vi.fn(),
16
- useDispatch: () => mockDispatch,
17
- }));
18
-
19
- const useSelectorMock = vi.mocked(useSelector);
20
-
21
- const App = () => <LoginModal />;
22
-
23
- describe("LoginModal", () => {
24
- window.open = vi.fn();
25
-
26
- const div = document.createElement("div");
27
- div.id = "__next";
28
- document.body.appendChild(div);
29
-
30
- test("when given a prismic url in env it should open to prismic.io/dashboard", () => {
31
- useSelectorMock.mockImplementation(() => ({
32
- env: {
33
- manifest: {
34
- apiEndpoint: "https://foo.prismic.io/api/v2",
35
- },
36
- } as FrontEndEnvironment,
37
- isOpen: true,
38
- isLoginLoading: true,
39
- }));
40
- const result = render(<App />);
41
-
42
- expect(result.getByText("Click here").closest("a")).toHaveAttribute(
43
- "href",
44
- // Since we're not using the `start-slicemachine` server proxy, port defaults to Next/React Testing Library's default port
45
- "https://prismic.io/dashboard/cli/login?source=slice-machine&port=3000&path=/api/auth",
46
- );
47
- });
48
-
49
- test("when given wroom.io url it should open to wroom.io/dashboard", () => {
50
- useSelectorMock.mockImplementation(() => ({
51
- env: {
52
- manifest: {
53
- apiEndpoint: "https://foo.wroom.io/api/v2",
54
- },
55
- } as FrontEndEnvironment,
56
- isOpen: true,
57
- isLoginLoading: true,
58
- }));
59
- const result = render(<App />);
60
-
61
- expect(result.getByText("Click here").closest("a")).toHaveAttribute(
62
- "href",
63
- // Since we're not using the `start-slicemachine` server proxy, port defaults to Next/React Testing Library's default port
64
- "https://wroom.io/dashboard/cli/login?source=slice-machine&port=3000&path=/api/auth",
65
- );
66
- });
67
- });
@@ -1,115 +0,0 @@
1
- import { describe, test, beforeEach, expect, vi } from "vitest";
2
- import { useModelStatus } from "../../../src/hooks/useModelStatus";
3
- import * as networkHook from "../../../src/hooks/useNetwork";
4
- import { AuthStatus } from "@src/modules/userContext/types";
5
-
6
- import { Slices } from "@lib/models/common/Slice";
7
- import SliceMock from "../../__fixtures__/sliceModel";
8
-
9
- import { CustomTypes } from "@lib/models/common/CustomType";
10
- import { customTypeMock } from "../../__fixtures__/customType";
11
- import { ModelStatus } from "@lib/models/common/ModelStatus";
12
-
13
- const mockSelector = vi.fn();
14
- vi.mock("react-redux", async () => {
15
- const actual: typeof import("react-redux") =
16
- await vi.importActual("react-redux");
17
-
18
- return {
19
- ...actual,
20
- useSelector: () => mockSelector(),
21
- };
22
- });
23
-
24
- const BaseSliceMock = {
25
- ...SliceMock,
26
- variations: SliceMock.variations.map((variation) => {
27
- // @ts-expect-error we know imageUrl is optional
28
- delete variation["imageUrl"];
29
- return variation;
30
- }),
31
- };
32
- const sliceModel = Slices.toSM(BaseSliceMock);
33
- const customTypeModel = CustomTypes.toSM(customTypeMock);
34
-
35
- describe("[useModelStatus hook]", () => {
36
- beforeEach(() => {
37
- vi.clearAllMocks();
38
- });
39
-
40
- test("it should return the model status correctly", () => {
41
- vi.spyOn(networkHook, "useNetwork").mockImplementation(() => true); // isOnline
42
- mockSelector.mockReturnValue({ authStatus: AuthStatus.AUTHORIZED });
43
-
44
- const result = useModelStatus({
45
- slices: [{ local: sliceModel, remote: sliceModel, localScreenshots: {} }],
46
- customTypes: [{ local: customTypeModel }],
47
- });
48
-
49
- expect(result).toEqual({
50
- modelsStatuses: {
51
- slices: { [sliceModel.id]: ModelStatus.Synced },
52
- customTypes: { [customTypeModel.id]: ModelStatus.New },
53
- },
54
- authStatus: AuthStatus.AUTHORIZED,
55
- isOnline: true,
56
- });
57
- });
58
-
59
- test("it should return Unknown status is the user doesn't have internet", () => {
60
- vi.spyOn(networkHook, "useNetwork").mockImplementation(() => false); // isOnline
61
- mockSelector.mockReturnValue({ authStatus: AuthStatus.AUTHORIZED });
62
-
63
- const result = useModelStatus({
64
- slices: [{ local: sliceModel, remote: sliceModel, localScreenshots: {} }],
65
- customTypes: [{ local: customTypeModel }],
66
- });
67
-
68
- expect(result).toEqual({
69
- modelsStatuses: {
70
- slices: { [sliceModel.id]: ModelStatus.Unknown },
71
- customTypes: { [customTypeModel.id]: ModelStatus.Unknown },
72
- },
73
- authStatus: AuthStatus.AUTHORIZED,
74
- isOnline: false,
75
- });
76
- });
77
-
78
- test("it should return Unknown status is the user is not connected to Prismic", () => {
79
- vi.spyOn(networkHook, "useNetwork").mockImplementation(() => true); // isOnline
80
- mockSelector.mockReturnValue({ authStatus: AuthStatus.UNAUTHORIZED });
81
-
82
- const result = useModelStatus({
83
- slices: [{ local: sliceModel, remote: sliceModel, localScreenshots: {} }],
84
- customTypes: [{ local: customTypeModel }],
85
- });
86
-
87
- expect(result).toEqual({
88
- modelsStatuses: {
89
- slices: { [sliceModel.id]: ModelStatus.Unknown },
90
- customTypes: { [customTypeModel.id]: ModelStatus.Unknown },
91
- },
92
- authStatus: AuthStatus.UNAUTHORIZED,
93
- isOnline: true,
94
- });
95
- });
96
-
97
- test("it should return Unknown status is the user doesn't have access to the repository", () => {
98
- vi.spyOn(networkHook, "useNetwork").mockImplementation(() => true); // isOnline
99
- mockSelector.mockReturnValue({ authStatus: AuthStatus.FORBIDDEN });
100
-
101
- const result = useModelStatus({
102
- slices: [{ local: sliceModel, remote: sliceModel, localScreenshots: {} }],
103
- customTypes: [{ local: customTypeModel }],
104
- });
105
-
106
- expect(result).toEqual({
107
- modelsStatuses: {
108
- slices: { [sliceModel.id]: ModelStatus.Unknown },
109
- customTypes: { [customTypeModel.id]: ModelStatus.Unknown },
110
- },
111
- authStatus: AuthStatus.FORBIDDEN,
112
- isOnline: true,
113
- });
114
- });
115
- });