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
@@ -0,0 +1,126 @@
1
+ import {
2
+ Button,
3
+ ErrorBoundary,
4
+ IconButton,
5
+ Tooltip,
6
+ } from "@prismicio/editor-ui";
7
+ import {
8
+ // isUnauthenticatedError,
9
+ isUnauthorizedError,
10
+ } from "@slicemachine/manager/client";
11
+ import { type FC, type ReactNode, Suspense } from "react";
12
+
13
+ import {
14
+ FieldSet,
15
+ FieldSetContent,
16
+ FieldSetFooter,
17
+ FieldSetLegend,
18
+ } from "@src/components/FieldSet";
19
+ import { ConnectGitRepositoryBlankSlate } from "@src/features/settings/git/ConnectGitRepositoryBlankSlate";
20
+ import { GitProviderConnectButtons } from "@src/features/settings/git/GitProviderConnectButtons";
21
+ import { GitRepositoriesList } from "@src/features/settings/git/GitRepositoriesList";
22
+ import {
23
+ GitRepositoriesSearch,
24
+ GitRepositoriesSearchSkeleton,
25
+ } from "@src/features/settings/git/GitRepositoriesSearch";
26
+ import { useGitOwners } from "@src/features/settings/git/useGitOwners";
27
+ import { useLinkedGitRepos } from "@src/features/settings/git/useLinkedGitRepos";
28
+ import { useUser } from "@src/hooks/useUser";
29
+ import useSliceMachineActions from "@src/modules/useSliceMachineActions";
30
+
31
+ export const ConnectGitRepository: FC = () => (
32
+ <FieldSet>
33
+ <FieldSetLegend>Connected Git Repository</FieldSetLegend>
34
+ <ErrorBoundary renderError={renderError}>
35
+ <Suspense fallback={<GitRepositoriesSearchSkeleton gitOwnerSelect />}>
36
+ <Content />
37
+ </Suspense>
38
+ </ErrorBoundary>
39
+ <FieldSetFooter
40
+ action={
41
+ <Tooltip content="Documentation is coming soon." side="bottom">
42
+ <IconButton disabled icon="openInNew" />
43
+ </Tooltip>
44
+ }
45
+ >
46
+ Learn more about Prismic for Git
47
+ </FieldSetFooter>
48
+ </FieldSet>
49
+ );
50
+
51
+ const Content: FC = () => {
52
+ // TODO(TD-1952): the `useUser` hook should be replaced with a mechanism that
53
+ // automatically revalidates the `Suspense` cache whenever the Redux
54
+ // authentication status changes.
55
+ const { isLoggedIn } = useUser();
56
+ return isLoggedIn ? <LoggedInContent /> : <UnauthenticatedErrorContent />;
57
+ };
58
+
59
+ const LoggedInContent: FC = () => {
60
+ const { linkedGitRepos } = useLinkedGitRepos();
61
+ return linkedGitRepos.length > 0 ? (
62
+ <GitRepositoriesList mode="unlink" repos={linkedGitRepos} />
63
+ ) : (
64
+ <UnlinkedRepositoryContent />
65
+ );
66
+ };
67
+
68
+ const UnlinkedRepositoryContent: FC = () => {
69
+ const owners = useGitOwners();
70
+ return owners.length > 0 ? (
71
+ <GitRepositoriesSearch owners={owners} />
72
+ ) : (
73
+ <FieldSetContent>
74
+ <GitProviderConnectButtons />
75
+ </FieldSetContent>
76
+ );
77
+ };
78
+
79
+ function renderError(error: unknown, reset: () => void): ReactNode {
80
+ // if (isUnauthenticatedError(error)) {
81
+ // return <UnauthenticatedErrorContent />;
82
+ // } else
83
+ if (isUnauthorizedError(error)) {
84
+ return <UnauthorizedErrorContent />;
85
+ } else {
86
+ return <UnknownErrorContent reset={reset} />;
87
+ }
88
+ }
89
+
90
+ const UnauthenticatedErrorContent: FC = () => {
91
+ const { openLoginModal } = useSliceMachineActions();
92
+ return (
93
+ <FieldSetContent>
94
+ <ConnectGitRepositoryBlankSlate
95
+ title="It seems like you are logged out"
96
+ description="Log in to connect a Git repository."
97
+ action={<Button onClick={openLoginModal}>Log in to Prismic</Button>}
98
+ />
99
+ </FieldSetContent>
100
+ );
101
+ };
102
+
103
+ const UnauthorizedErrorContent: FC = () => (
104
+ <FieldSetContent>
105
+ <ConnectGitRepositoryBlankSlate
106
+ title="It seems like you do not have permission"
107
+ description="An owner or admin is required to connect a Git repository."
108
+ />
109
+ </FieldSetContent>
110
+ );
111
+
112
+ type UnknownErrorContentProps = { reset: () => void };
113
+
114
+ const UnknownErrorContent: FC<UnknownErrorContentProps> = ({ reset }) => (
115
+ <FieldSetContent>
116
+ <ConnectGitRepositoryBlankSlate
117
+ title="Unable to fetch data"
118
+ description="An error occurred while fetching the list of connected Git repositories."
119
+ action={
120
+ <Button color="grey" onClick={reset}>
121
+ Retry
122
+ </Button>
123
+ }
124
+ />
125
+ </FieldSetContent>
126
+ );
@@ -0,0 +1,33 @@
1
+ import { Box, ButtonGroup, Text } from "@prismicio/editor-ui";
2
+ import type { FC, ReactNode } from "react";
3
+
4
+ type ConnectGitRepositoryBlankSlateProps = {
5
+ title: string;
6
+ description: string;
7
+ action?: ReactNode;
8
+ };
9
+
10
+ export const ConnectGitRepositoryBlankSlate: FC<
11
+ ConnectGitRepositoryBlankSlateProps
12
+ > = ({ title, description, action }) => (
13
+ <Box
14
+ flexDirection="column"
15
+ /*
16
+ * TODO: these `padding` values actually don't match Figma, but they are the
17
+ * closest allowed by the `Box` component.
18
+ */
19
+ padding={{ block: 72, inline: 100 }}
20
+ >
21
+ <Text align="center" variant="emphasized">
22
+ {title}
23
+ </Text>
24
+ <Text align="center" color="grey11">
25
+ {description}
26
+ </Text>
27
+ {Boolean(action) ? (
28
+ <ButtonGroup sx={{ alignSelf: "center", marginTop: 8 }}>
29
+ {action}
30
+ </ButtonGroup>
31
+ ) : undefined}
32
+ </Box>
33
+ );
@@ -0,0 +1,71 @@
1
+ import { Select, SelectItem, tokens } from "@prismicio/editor-ui";
2
+ import type { GitOwner } from "@slicemachine/manager";
3
+ import type { ComponentProps, FC } from "react";
4
+
5
+ import { gitProviderToConfig } from "@src/features/settings/git/GitProvider";
6
+
7
+ type GitOwnerSelectProps = {
8
+ disabled?: boolean;
9
+ owners?: GitOwner[];
10
+ selectedOwner?: GitOwner;
11
+ onSelectedOwnerChange?: (selectedOwner: GitOwner) => void;
12
+ sx?: SX;
13
+ };
14
+
15
+ export const GitOwnerSelect: FC<GitOwnerSelectProps> = ({
16
+ disabled,
17
+ owners = [],
18
+ selectedOwner,
19
+ onSelectedOwnerChange,
20
+ sx,
21
+ }) => (
22
+ <Select
23
+ color="grey"
24
+ constrainContentWidth
25
+ disabled={disabled}
26
+ flexContent
27
+ onValueChange={(value) => {
28
+ const [provider, id] = parseGitOwnerKey(value);
29
+ const selectedOwner = owners.find(
30
+ (owner) => owner.provider === provider && owner.id === id,
31
+ );
32
+ if (selectedOwner) {
33
+ onSelectedOwnerChange?.(selectedOwner);
34
+ }
35
+ }}
36
+ placeholder="Owner"
37
+ renderStartIcon={() => <GitOwnerIcon owner={selectedOwner} />}
38
+ size="large"
39
+ sx={sx}
40
+ value={selectedOwner ? formatGitOwnerKey(selectedOwner) : undefined}
41
+ >
42
+ {owners.map((owner) => (
43
+ <SelectItem
44
+ key={formatGitOwnerKey(owner)}
45
+ renderStartIcon={() => <GitOwnerIcon owner={owner} />}
46
+ size="large"
47
+ value={formatGitOwnerKey(owner)}
48
+ >
49
+ {owner.name}
50
+ </SelectItem>
51
+ ))}
52
+ </Select>
53
+ );
54
+
55
+ type GitOwnerIconProps = { owner: GitOwner | undefined };
56
+
57
+ const GitOwnerIcon: FC<GitOwnerIconProps> = ({ owner }) => {
58
+ const { Icon } = gitProviderToConfig[owner?.provider ?? "gitHub"];
59
+ return <Icon color={tokens.color.greyLight11} />;
60
+ };
61
+
62
+ function formatGitOwnerKey(owner: GitOwner): string {
63
+ return `${owner.provider}@${owner.id}`;
64
+ }
65
+
66
+ function parseGitOwnerKey(key: string): string[] {
67
+ return key.split("@");
68
+ }
69
+
70
+ // TODO(DT-1928): export the `SX` type from `@prismicio/editor-ui`.
71
+ type SX = ComponentProps<typeof Select>["sx"];
@@ -0,0 +1,40 @@
1
+ import { BitbucketIcon } from "@src/icons/BitbucketIcon";
2
+ import { GitHubIcon } from "@src/icons/GitHubIcon";
3
+ import { GitLabIcon } from "@src/icons/GitLabIcon";
4
+ import { managerClient } from "@src/managerClient";
5
+
6
+ export type GitProvider = keyof typeof gitProviderToConfig;
7
+
8
+ const GITHUB_APP_SLUG = "prismic-io";
9
+
10
+ export const gitProviderToConfig = {
11
+ gitHub: {
12
+ connect: async () => {
13
+ const state = await managerClient.git.createGitHubAuthState();
14
+ const url = new URL(
15
+ `https://github.com/apps/${GITHUB_APP_SLUG}/installations/new`,
16
+ );
17
+ url.searchParams.set("state", state.key);
18
+ window.open(url, "git-hub-app-installation");
19
+ },
20
+ Icon: GitHubIcon,
21
+ name: "GitHub",
22
+ supported: true,
23
+ },
24
+ bitbucket: {
25
+ connect: () => {
26
+ throw new Error("Not implemented.");
27
+ },
28
+ Icon: BitbucketIcon,
29
+ name: "Bitbucket",
30
+ supported: false,
31
+ },
32
+ gitLab: {
33
+ connect: () => {
34
+ throw new Error("Not implemented.");
35
+ },
36
+ Icon: GitLabIcon,
37
+ name: "GitLab",
38
+ supported: false,
39
+ },
40
+ };
@@ -0,0 +1,63 @@
1
+ import { keys } from "@prismicio/editor-support/Object";
2
+ import { Button, ButtonGroup, Text, tokens } from "@prismicio/editor-ui";
3
+ import { type ComponentProps, type FC, useState } from "react";
4
+ import { toast } from "react-toastify";
5
+
6
+ import {
7
+ type GitProvider,
8
+ gitProviderToConfig,
9
+ } from "@src/features/settings/git/GitProvider";
10
+
11
+ export const GitProviderConnectButtons: FC = () => (
12
+ <ButtonGroup>
13
+ {keys(gitProviderToConfig).map((provider) => (
14
+ <GitProviderConnectButton
15
+ key={provider}
16
+ provider={provider}
17
+ sx={{ flexBasis: 0, flexGrow: 1 }}
18
+ />
19
+ ))}
20
+ </ButtonGroup>
21
+ );
22
+
23
+ type GitProviderConnectButtonProps = { provider: GitProvider; sx?: SX };
24
+
25
+ const GitProviderConnectButton: FC<GitProviderConnectButtonProps> = ({
26
+ provider,
27
+ sx,
28
+ }) => {
29
+ const { connect, Icon, name, supported } = gitProviderToConfig[provider];
30
+ const [loading, setLoading] = useState(false);
31
+ return (
32
+ <Button
33
+ color="grey"
34
+ disabled={!supported}
35
+ loading={loading}
36
+ onClick={() => {
37
+ void (async () => {
38
+ setLoading(true);
39
+ try {
40
+ await connect();
41
+ } catch (error) {
42
+ const message = `Could not connect to ${name}`;
43
+ console.error(message, error);
44
+ toast.error(message);
45
+ setLoading(false);
46
+ }
47
+ })();
48
+ }}
49
+ renderStartIcon={() => <Icon color={tokens.color.greyLight11} />}
50
+ sx={sx}
51
+ >
52
+ {name}
53
+ {supported ? undefined : (
54
+ <Text color="inherit" variant="small">
55
+ {" (soon)"}
56
+ </Text>
57
+ )}
58
+ </Button>
59
+ );
60
+ };
61
+
62
+ // TODO(DT-1928): export the `SX` type from `@prismicio/editor-ui`.
63
+ type SX = ComponentProps<typeof Button>["sx"];
@@ -0,0 +1,76 @@
1
+ import { Button, Skeleton, Text } from "@prismicio/editor-ui";
2
+ import type { GitRepo, GitRepoSpecifier } from "@slicemachine/manager";
3
+ import type { FC } from "react";
4
+
5
+ import { FieldSetList, FieldSetListItem } from "@src/components/FieldSet";
6
+ import { RelativeTime } from "@src/components/RelativeTime";
7
+ import { GitRepositoryConnectDialog } from "@src/features/settings/git/GitRepositoryConnectDialog";
8
+ import { GitRepositoryDisconnectDialog } from "@src/features/settings/git/GitRepositoryDisconnectDialog";
9
+ import { useLinkedGitRepos } from "@src/features/settings/git/useLinkedGitRepos";
10
+
11
+ type GitRepositoriesListProps =
12
+ | { mode: "link"; repos: GitRepo[] }
13
+ | { mode: "unlink"; repos: GitRepoSpecifier[] };
14
+
15
+ export const GitRepositoriesList: FC<GitRepositoriesListProps> = ({
16
+ mode,
17
+ repos,
18
+ }) => {
19
+ const { linkRepo, unlinkRepo } = useLinkedGitRepos();
20
+ return (
21
+ <FieldSetList>
22
+ {mode === "link"
23
+ ? repos.map((repo) => (
24
+ <FieldSetListItem
25
+ action={
26
+ <GitRepositoryConnectDialog
27
+ linkRepo={linkRepo}
28
+ repo={repo}
29
+ trigger={<Button color="grey">Connect</Button>}
30
+ />
31
+ }
32
+ key={`${repo.provider}@${repo.id}`}
33
+ >
34
+ {repo.name}
35
+ <Text color="grey11">
36
+ {" • "}
37
+ <RelativeTime date={repo.pushedAt} />
38
+ </Text>
39
+ </FieldSetListItem>
40
+ ))
41
+ : repos.map((repo) => (
42
+ <FieldSetListItem
43
+ action={
44
+ <GitRepositoryDisconnectDialog
45
+ repo={repo}
46
+ trigger={<Button color="grey">Disconnect</Button>}
47
+ unlinkRepo={unlinkRepo}
48
+ />
49
+ }
50
+ key={`${repo.provider}@${repo.owner}/${repo.name}`}
51
+ >
52
+ {repo.name}
53
+ </FieldSetListItem>
54
+ ))}
55
+ </FieldSetList>
56
+ );
57
+ };
58
+
59
+ export const GitRepositoriesListSkeleton: FC = () => (
60
+ <FieldSetList>
61
+ {[...Array(4).keys()].map((index) => (
62
+ <FieldSetListItem
63
+ action={<Skeleton height={32} width={67.59} />}
64
+ key={index}
65
+ >
66
+ <Skeleton
67
+ height={24}
68
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
69
+ // @ts-ignore TODO(DT-1918): add `verticalAlign: "middle"` to the `sx` prop.
70
+ sx={{ verticalAlign: "middle" }}
71
+ width={129.92}
72
+ />
73
+ </FieldSetListItem>
74
+ ))}
75
+ </FieldSetList>
76
+ );
@@ -0,0 +1,69 @@
1
+ import type { GitOwner } from "@slicemachine/manager";
2
+ import { type FC, Suspense, useState } from "react";
3
+
4
+ import { FieldSetContent, FieldSetHeader } from "@src/components/FieldSet";
5
+ import { ConnectGitRepositoryBlankSlate } from "@src/features/settings/git/ConnectGitRepositoryBlankSlate";
6
+ import { GitOwnerSelect } from "@src/features/settings/git/GitOwnerSelect";
7
+ import {
8
+ GitRepositoriesList,
9
+ GitRepositoriesListSkeleton,
10
+ } from "@src/features/settings/git/GitRepositoriesList";
11
+ import { useGitRepos } from "@src/features/settings/git/useGitRepos";
12
+
13
+ type GitRepositoriesSearchProps = { owners: GitOwner[] };
14
+
15
+ export const GitRepositoriesSearch: FC<GitRepositoriesSearchProps> = ({
16
+ owners,
17
+ }) => {
18
+ const [selectedOwner, setSelectedOwner] = useState(owners[0]);
19
+ return (
20
+ <>
21
+ <FieldSetHeader>
22
+ <GitOwnerSelect
23
+ owners={owners}
24
+ selectedOwner={selectedOwner}
25
+ onSelectedOwnerChange={setSelectedOwner}
26
+ sx={{ width: "calc(50% - 8px)" }}
27
+ />
28
+ </FieldSetHeader>
29
+ <Suspense
30
+ fallback={<GitRepositoriesSearchSkeleton gitOwnerSelect={false} />}
31
+ >
32
+ <GitRepositoriesSearchResults owner={selectedOwner} />
33
+ </Suspense>
34
+ </>
35
+ );
36
+ };
37
+
38
+ type GitRepositoriesSearchResultsProps = { owner: GitOwner };
39
+
40
+ const GitRepositoriesSearchResults: FC<GitRepositoriesSearchResultsProps> = ({
41
+ owner,
42
+ }) => {
43
+ const repos = useGitRepos({ provider: owner.provider, owner: owner.name });
44
+ return repos.length > 0 ? (
45
+ <GitRepositoriesList mode="link" repos={repos} />
46
+ ) : (
47
+ <FieldSetContent>
48
+ <ConnectGitRepositoryBlankSlate
49
+ title="No Results Found"
50
+ description="Try selecting a different Git account or organization on the top left."
51
+ />
52
+ </FieldSetContent>
53
+ );
54
+ };
55
+
56
+ type GitRepositoriesSearchSkeletonProps = { gitOwnerSelect: boolean };
57
+
58
+ export const GitRepositoriesSearchSkeleton: FC<
59
+ GitRepositoriesSearchSkeletonProps
60
+ > = ({ gitOwnerSelect }) => (
61
+ <>
62
+ {gitOwnerSelect ? (
63
+ <FieldSetHeader>
64
+ <GitOwnerSelect disabled sx={{ width: "calc(50% - 8px)" }} />
65
+ </FieldSetHeader>
66
+ ) : undefined}
67
+ <GitRepositoriesListSkeleton />
68
+ </>
69
+ );
@@ -0,0 +1,85 @@
1
+ import {
2
+ Box,
3
+ Dialog,
4
+ DialogActions,
5
+ DialogContent,
6
+ DialogHeader,
7
+ FormInput,
8
+ Text,
9
+ } from "@prismicio/editor-ui";
10
+ import type { GitRepo, GitRepoSpecifier } from "@slicemachine/manager";
11
+ import { Formik } from "formik";
12
+ import type { FC, ReactNode } from "react";
13
+ import { toast } from "react-toastify";
14
+
15
+ import { gitProviderToConfig } from "@src/features/settings/git/GitProvider";
16
+ import { useWriteAPIToken } from "@src/features/settings/git/useWriteAPIToken";
17
+
18
+ type GitRepositoryConnectDialogProps = {
19
+ linkRepo: (repo: GitRepoSpecifier) => Promise<void>;
20
+ repo: GitRepo;
21
+ trigger: ReactNode;
22
+ };
23
+
24
+ export const GitRepositoryConnectDialog: FC<
25
+ GitRepositoryConnectDialogProps
26
+ > = ({ linkRepo, repo, trigger }) => {
27
+ const providerConfig = gitProviderToConfig[repo.provider];
28
+ const { updateToken } = useWriteAPIToken({ git: repo });
29
+ return (
30
+ <Dialog size={{ width: 448, height: "auto" }} trigger={trigger}>
31
+ <DialogHeader title="Prismic Write API token required" />
32
+ <DialogContent>
33
+ <Formik
34
+ initialValues={{ writeAPIToken: "" }}
35
+ validate={(values) => {
36
+ if (values.writeAPIToken.length === 0) {
37
+ return { writeAPIToken: "Cannot be empty" };
38
+ }
39
+ }}
40
+ onSubmit={async (values) => {
41
+ try {
42
+ await linkRepo(repo);
43
+ await updateToken(values.writeAPIToken);
44
+ } catch (error) {
45
+ const message = `Could not connect to ${repo.name}`;
46
+ console.error(message, error);
47
+ toast.error(message);
48
+ }
49
+ }}
50
+ >
51
+ {(formikProps) => (
52
+ <form onSubmit={formikProps.handleSubmit}>
53
+ <Box flexDirection="column" gap={4} padding={16}>
54
+ <FormInput
55
+ disabled={formikProps.isSubmitting}
56
+ error={typeof formikProps.errors.writeAPIToken === "string"}
57
+ label="Paste your Write API token"
58
+ onValueChange={(value) => {
59
+ void formikProps.setFieldValue("writeAPIToken", value);
60
+ }}
61
+ placeholder="Write API token"
62
+ size="large"
63
+ value={formikProps.values.writeAPIToken}
64
+ />
65
+ <Text color="grey11">
66
+ Required to sync models from {providerConfig.name} to Prismic.
67
+ </Text>
68
+ </Box>
69
+ <DialogActions
70
+ cancel={{ text: "Cancel" }}
71
+ ok={{
72
+ disabled: !formikProps.isValid,
73
+ loading: formikProps.isSubmitting,
74
+ onClick: () => void formikProps.submitForm(),
75
+ text: "Save Token",
76
+ }}
77
+ size="medium"
78
+ />
79
+ </form>
80
+ )}
81
+ </Formik>
82
+ </DialogContent>
83
+ </Dialog>
84
+ );
85
+ };
@@ -0,0 +1,60 @@
1
+ import {
2
+ Box,
3
+ Dialog,
4
+ DialogActions,
5
+ DialogContent,
6
+ DialogHeader,
7
+ Text,
8
+ } from "@prismicio/editor-ui";
9
+ import type { GitRepoSpecifier } from "@slicemachine/manager";
10
+ import { type FC, type ReactNode, useState } from "react";
11
+ import { toast } from "react-toastify";
12
+
13
+ type GitRepositoryDisconnectDialogProps = {
14
+ repo: GitRepoSpecifier;
15
+ trigger: ReactNode;
16
+ unlinkRepo: (repo: GitRepoSpecifier) => Promise<void>;
17
+ };
18
+
19
+ export const GitRepositoryDisconnectDialog: FC<
20
+ GitRepositoryDisconnectDialogProps
21
+ > = ({ repo, trigger, unlinkRepo }) => {
22
+ const [loading, setLoading] = useState(false);
23
+ return (
24
+ <Dialog size={{ width: 448, height: "auto" }} trigger={trigger}>
25
+ <DialogHeader title="Remove Git Connection" />
26
+ <DialogContent>
27
+ <Box flexDirection="column" padding={16}>
28
+ <Text>
29
+ You will not be able to push your code alongside your models
30
+ anymore. Note that you can reconnect your Git repository at any
31
+ time. Are you sure you want to continue?
32
+ </Text>
33
+ </Box>
34
+ </DialogContent>
35
+ <DialogActions
36
+ asFooter
37
+ cancel={{ text: "Cancel" }}
38
+ ok={{
39
+ color: "tomato",
40
+ loading,
41
+ onClick: () => {
42
+ void (async () => {
43
+ setLoading(true);
44
+ try {
45
+ await unlinkRepo(repo);
46
+ } catch (error) {
47
+ const message = `Could not disconnect from ${repo.name}`;
48
+ console.error(message, error);
49
+ toast.error(message);
50
+ }
51
+ setLoading(false);
52
+ })();
53
+ },
54
+ text: "Disconnect",
55
+ }}
56
+ size="medium"
57
+ />
58
+ </Dialog>
59
+ );
60
+ };
@@ -0,0 +1,8 @@
1
+ import { useExperimentVariant } from "@src/hooks/useExperimentVariant";
2
+
3
+ type UseGitIntegrationExperimentReturnType = { eligible: boolean };
4
+
5
+ export function useGitIntegrationExperiment(): UseGitIntegrationExperimentReturnType {
6
+ const variant = useExperimentVariant("slicemachine-git-integration");
7
+ return { eligible: variant?.value === "on" };
8
+ }
@@ -0,0 +1,12 @@
1
+ import { useRequest } from "@prismicio/editor-support/Suspense";
2
+ import type { GitOwner } from "@slicemachine/manager";
3
+
4
+ import { managerClient } from "@src/managerClient";
5
+
6
+ export function useGitOwners(): GitOwner[] {
7
+ return useRequest(getGitOwners, []);
8
+ }
9
+
10
+ async function getGitOwners(): Promise<GitOwner[]> {
11
+ return await managerClient.git.fetchOwners();
12
+ }
@@ -0,0 +1,24 @@
1
+ import { useRequest } from "@prismicio/editor-support/Suspense";
2
+ import type { GitRepo } from "@slicemachine/manager";
3
+
4
+ import { managerClient } from "@src/managerClient";
5
+
6
+ type UseGitReposArgs = Parameters<typeof managerClient.git.fetchRepos>[0];
7
+
8
+ export function useGitRepos(args: UseGitReposArgs): GitRepo[] {
9
+ return useRequest(getGitRepos, [
10
+ args.provider,
11
+ args.owner,
12
+ args.query,
13
+ args.page,
14
+ ]);
15
+ }
16
+
17
+ async function getGitRepos(
18
+ provider: "gitHub",
19
+ owner: string,
20
+ query?: string,
21
+ page?: number,
22
+ ): Promise<GitRepo[]> {
23
+ return await managerClient.git.fetchRepos({ provider, owner, query, page });
24
+ }