slice-machine-ui 2.17.3-beta.9 → 2.18.1-alpha.dani-mcp.1

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 (87) hide show
  1. package/out/404.html +1 -1
  2. package/out/_next/static/SYZmtCXDQQhzEqpdfRb9-/_buildManifest.js +1 -0
  3. package/out/_next/static/chunks/04ad993f.d7f986af0f739cc9.js +28 -0
  4. package/out/_next/static/chunks/248-43faecb386a16518.js +1 -0
  5. package/out/_next/static/chunks/{34-6c3125e6f01c62c7.js → 34-8d9d9b2944824750.js} +1 -1
  6. package/out/_next/static/chunks/422-c9192a1dbdd2ae0e.js +1 -0
  7. package/out/_next/static/chunks/489-234ed5471aa694b3.js +1 -0
  8. package/out/_next/static/chunks/50-586dc7ab5e584e76.js +1 -0
  9. package/out/_next/static/chunks/630-bb6e3db525588f16.js +1 -0
  10. package/out/_next/static/chunks/{647-7b9b5aa9468f9e4b.js → 647-4379a741c8d85d9e.js} +1 -1
  11. package/out/_next/static/chunks/{907-a42dc5698d5dc000.js → 907-445266211c48b1a5.js} +1 -1
  12. package/out/_next/static/chunks/pages/{_app-13d39ac1e1c9aa27.js → _app-0d5ae0ab4cbc0245.js} +220 -222
  13. package/out/_next/static/chunks/pages/changelog-ba55ed247c20dc21.js +1 -0
  14. package/out/_next/static/chunks/pages/changes-4c23263cdc8e59c6.js +1 -0
  15. package/out/_next/static/chunks/pages/custom-types/{[customTypeId]-4024560ca59ad2be.js → [customTypeId]-816acb31b652239b.js} +1 -1
  16. package/out/_next/static/chunks/pages/labs-78ac01d97ab02cd7.js +1 -0
  17. package/out/_next/static/chunks/pages/page-types/{[pageTypeId]-0d2416da0958eb40.js → [pageTypeId]-669d5479e81b638b.js} +1 -1
  18. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/{simulator-0ecd552897e61e29.js → simulator-b127d948a17968d3.js} +1 -1
  19. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-93e6cb0c4429ce10.js +1 -0
  20. package/out/_next/static/chunks/pages/slices-f6552e2fbc491c4d.js +1 -0
  21. package/out/_next/static/chunks/webpack-e0c07a2fe4908d81.js +1 -0
  22. package/out/_next/static/css/303dad78be1eb854.css +1 -0
  23. package/out/changelog.html +1 -1
  24. package/out/changes.html +1 -1
  25. package/out/custom-types/[customTypeId].html +1 -1
  26. package/out/custom-types.html +1 -1
  27. package/out/index.html +1 -1
  28. package/out/labs.html +1 -1
  29. package/out/page-types/[pageTypeId].html +1 -1
  30. package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
  31. package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
  32. package/out/slices.html +1 -1
  33. package/package.json +7 -10
  34. package/src/apiClient.ts +1 -1
  35. package/src/domain/fields.ts +7 -7
  36. package/src/features/auth/LogoutButton.tsx +63 -0
  37. package/src/features/builder/AddFieldDropdown.tsx +2 -2
  38. package/src/features/environments/actions/getActiveEnvironment.ts +2 -8
  39. package/src/features/environments/useActiveEnvironment.ts +8 -1
  40. package/src/features/environments/useEnvironments.ts +8 -1
  41. package/src/features/navigation/Navigation.tsx +25 -1
  42. package/src/features/navigation/NavigationItem.tsx +9 -3
  43. package/src/features/sync/actions/pushChanges.ts +1 -0
  44. package/src/features/sync/getUnSyncChanges.ts +22 -4
  45. package/src/legacy/components/AppLayout/index.tsx +42 -2
  46. package/src/legacy/components/ChangesEmptyState/AuthErrorPage.tsx +2 -12
  47. package/src/legacy/components/ListItem/Header.tsx +18 -12
  48. package/src/legacy/components/ListItem/index.tsx +1 -0
  49. package/src/legacy/components/LoginModal/index.tsx +11 -3
  50. package/src/legacy/components/Navigation/Environment.tsx +2 -10
  51. package/src/legacy/components/Navigation/SideNavEnvironmentSelector/SideNavEnvironmentSelector.tsx +8 -0
  52. package/src/legacy/lib/builders/common/EditModal/index.jsx +3 -10
  53. package/src/legacy/lib/models/common/ModelStatus/index.ts +6 -1
  54. package/src/legacy/lib/models/common/widgets/Boolean/index.ts +3 -0
  55. package/src/legacy/lib/models/common/widgets/Color/index.ts +3 -0
  56. package/src/legacy/lib/models/common/widgets/ContentRelationship/index.ts +3 -0
  57. package/src/legacy/lib/models/common/widgets/Date/index.ts +3 -0
  58. package/src/legacy/lib/models/common/widgets/Embed/index.ts +3 -0
  59. package/src/legacy/lib/models/common/widgets/GeoPoint/index.ts +3 -0
  60. package/src/legacy/lib/models/common/widgets/Group/createGroupWidget.ts +2 -0
  61. package/src/legacy/lib/models/common/widgets/Image/index.ts +3 -0
  62. package/src/legacy/lib/models/common/widgets/Link/index.ts +3 -0
  63. package/src/legacy/lib/models/common/widgets/LinkToMedia/index.ts +2 -0
  64. package/src/legacy/lib/models/common/widgets/Number/index.ts +3 -0
  65. package/src/legacy/lib/models/common/widgets/Select/index.ts +3 -0
  66. package/src/legacy/lib/models/common/widgets/StructuredText/index.ts +3 -0
  67. package/src/legacy/lib/models/common/widgets/Table/index.ts +3 -0
  68. package/src/legacy/lib/models/common/widgets/Text/index.ts +3 -0
  69. package/src/legacy/lib/models/common/widgets/Timestamp/index.ts +3 -0
  70. package/src/legacy/lib/models/common/widgets/UID/index.ts +3 -0
  71. package/src/legacy/lib/models/common/widgets/Widget.ts +1 -0
  72. package/src/pages/changes.tsx +1 -4
  73. package/out/_next/static/UBLEqMkM94kXQpW0VSAQo/_buildManifest.js +0 -1
  74. package/out/_next/static/chunks/248-6f20227ad4764216.js +0 -1
  75. package/out/_next/static/chunks/33641354.3864aefb6106ae71.js +0 -28
  76. package/out/_next/static/chunks/385-b949173dfa03dd3e.js +0 -1
  77. package/out/_next/static/chunks/44-a2056f993381ad0f.js +0 -1
  78. package/out/_next/static/chunks/489-a42bd4eeb1350d97.js +0 -1
  79. package/out/_next/static/chunks/630-799c128fd87fa645.js +0 -1
  80. package/out/_next/static/chunks/pages/changelog-98836c22c6a40c5d.js +0 -1
  81. package/out/_next/static/chunks/pages/changes-2bd69f3877d60b26.js +0 -1
  82. package/out/_next/static/chunks/pages/labs-ad7f36c6f544c1a8.js +0 -1
  83. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-8b6e7854cb3466d4.js +0 -1
  84. package/out/_next/static/chunks/pages/slices-fe1bb16ff3020762.js +0 -1
  85. package/out/_next/static/chunks/webpack-b3522fdebabf510a.js +0 -1
  86. package/out/_next/static/css/cc9b10286400c2b9.css +0 -1
  87. /package/out/_next/static/{UBLEqMkM94kXQpW0VSAQo → SYZmtCXDQQhzEqpdfRb9-}/_ssgManifest.js +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slice-machine-ui",
3
- "version": "2.17.3-beta.9",
3
+ "version": "2.18.1-alpha.dani-mcp.1",
4
4
  "license": "MIT",
5
5
  "description": "A visual builder for your Slice Models with all the tools you need to generate data models and mock CMS content locally.",
6
6
  "repository": {
@@ -35,23 +35,20 @@
35
35
  "start-slicemachine": "./bin/start-slicemachine.cjs"
36
36
  },
37
37
  "dependencies": {
38
- "@slicemachine/manager": "0.25.2-beta.13",
39
- "start-slicemachine": "0.12.60-beta.13"
38
+ "@slicemachine/manager": "0.25.3-alpha.dani-mcp.1",
39
+ "start-slicemachine": "0.12.61-alpha.dani-mcp.1"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@emotion/react": "11.11.1",
43
43
  "@extractus/oembed-extractor": "3.1.8",
44
44
  "@prismicio/client": "7.17.0",
45
- "@prismicio/editor-fields": "0.4.77",
46
- "@prismicio/editor-support": "0.4.77",
47
- "@prismicio/editor-ui": "0.4.77",
45
+ "@prismicio/editor-fields": "0.4.87",
46
+ "@prismicio/editor-support": "0.4.87",
47
+ "@prismicio/editor-ui": "0.4.87",
48
48
  "@prismicio/mock": "0.7.1",
49
49
  "@prismicio/mocks": "2.14.0",
50
50
  "@prismicio/simulator": "0.1.4",
51
51
  "@prismicio/types-internal": "3.11.2",
52
- "@radix-ui/react-hover-card": "1.0.6",
53
- "@radix-ui/react-tabs": "1.0.4",
54
- "@radix-ui/react-visually-hidden": "1.1.1",
55
52
  "@reach/menu-button": "0.18.0",
56
53
  "@sentry/nextjs": "7.43.0",
57
54
  "@storybook/addon-essentials": "7.0.10",
@@ -137,5 +134,5 @@
137
134
  "yup": "0.32.11",
138
135
  "zod": "3.23.8"
139
136
  },
140
- "stableVersion": "2.17.2"
137
+ "stableVersion": "2.18.0"
141
138
  }
package/src/apiClient.ts CHANGED
@@ -163,7 +163,7 @@ export const pushChanges: SliceMachineManagerClient["prismicRepository"]["pushCh
163
163
 
164
164
  /** Auth Routes * */
165
165
 
166
- export const startAuth = async (): Promise<void> => {
166
+ export const clearAuth = async (): Promise<void> => {
167
167
  return await managerClient.user.logout();
168
168
  };
169
169
 
@@ -92,7 +92,7 @@ export const imageField: NestableField = {
92
92
  type: "Image",
93
93
  };
94
94
 
95
- export const LinkField: NestableField = {
95
+ export const linkField: NestableField = {
96
96
  name: "Link",
97
97
  description: "A link to a website, asset, or document.",
98
98
  icon: "link",
@@ -111,8 +111,8 @@ export const contentRelationshipField: NestableField = {
111
111
  variant: "ContentRelationship",
112
112
  };
113
113
 
114
- export const LinkToMediaField: NestableField = {
115
- name: "Link To Media",
114
+ export const linkToMediaField: NestableField = {
115
+ name: "Link to Media",
116
116
  description: "A link to a media asset.",
117
117
  icon: "attachFile",
118
118
  thumbnail:
@@ -182,8 +182,8 @@ export const nestableFields: NestableField[] = [
182
182
  booleanField,
183
183
  numberField,
184
184
  selectField,
185
- LinkField,
186
- LinkToMediaField,
185
+ linkField,
186
+ linkToMediaField,
187
187
  colorField,
188
188
  dateField,
189
189
  tableField,
@@ -197,7 +197,7 @@ export const nestableFields: NestableField[] = [
197
197
  * UID
198
198
  */
199
199
 
200
- export const UIDField: UIDField = {
200
+ export const uidField: UIDField = {
201
201
  name: "UID",
202
202
  description: "Unique Identifier",
203
203
  icon: "tag",
@@ -230,4 +230,4 @@ export const groupFields: GroupField[] = [groupField, nestedGroupField];
230
230
  * All fields
231
231
  */
232
232
 
233
- export const fields = [...nestableFields, UIDField, ...groupFields];
233
+ export const fields = [...nestableFields, uidField, ...groupFields];
@@ -0,0 +1,63 @@
1
+ import { Button, Icon, IconButton, Tooltip } from "@prismicio/editor-ui";
2
+ import { SX } from "@prismicio/editor-ui/dist/theme";
3
+ import * as Sentry from "@sentry/nextjs";
4
+ import { ReactNode } from "react";
5
+
6
+ import { clearAuth as managerLogout, getState } from "@/apiClient";
7
+ import { invalidateActiveEnvironmentData } from "@/features/environments/useActiveEnvironment";
8
+ import { invalidateEnvironmentsData } from "@/features/environments/useEnvironments";
9
+ import useSliceMachineActions from "@/modules/useSliceMachineActions";
10
+
11
+ interface LogoutButtonProps {
12
+ children?: ReactNode;
13
+ onLogoutSuccess?: () => void;
14
+ isLoading?: boolean;
15
+ sx?: SX;
16
+ }
17
+
18
+ export function LogoutButton(props: LogoutButtonProps) {
19
+ const { children, onLogoutSuccess, isLoading, sx } = props;
20
+
21
+ const { refreshState } = useSliceMachineActions();
22
+
23
+ async function onClick() {
24
+ await managerLogout();
25
+
26
+ const serverState = await getState();
27
+ refreshState(serverState);
28
+
29
+ Sentry.setUser({ id: serverState.env.shortId });
30
+
31
+ // refresh queries to update the UI
32
+ invalidateEnvironmentsData();
33
+ invalidateActiveEnvironmentData();
34
+
35
+ onLogoutSuccess?.();
36
+ }
37
+
38
+ if (children !== undefined) {
39
+ return (
40
+ <Button
41
+ onClick={() => void onClick()}
42
+ renderEndIcon={() => <Icon name="logout" size="extraSmall" />}
43
+ color="grey"
44
+ loading={isLoading}
45
+ sx={sx}
46
+ >
47
+ {children}
48
+ </Button>
49
+ );
50
+ }
51
+
52
+ return (
53
+ <Tooltip content="Log out" side="right">
54
+ <IconButton
55
+ icon="logout"
56
+ onClick={() => void onClick()}
57
+ hiddenLabel="Log out"
58
+ loading={isLoading}
59
+ sx={sx}
60
+ />
61
+ </Tooltip>
62
+ );
63
+ }
@@ -18,7 +18,7 @@ import {
18
18
  FieldVariant,
19
19
  groupField,
20
20
  nestableFields,
21
- UIDField,
21
+ uidField,
22
22
  } from "@/domain/fields";
23
23
 
24
24
  export type AddFieldDropdownProps = {
@@ -47,7 +47,7 @@ export function AddFieldDropdown(props: AddFieldDropdownProps) {
47
47
  (field) =>
48
48
  nestableFields.some(
49
49
  (nestableField) => nestableField.name === field.name,
50
- ) || field.name === UIDField.name,
50
+ ) || field.name === uidField.name,
51
51
  );
52
52
  const groupFieldToRender = fields.find(
53
53
  (field) => field.name === groupField.name,
@@ -5,10 +5,6 @@ import {
5
5
 
6
6
  import { managerClient } from "@/managerClient";
7
7
 
8
- type GetActiveEnvironmentArgs = {
9
- retried?: boolean;
10
- };
11
-
12
8
  type GetActiveEnvironmentReturnType =
13
9
  | {
14
10
  activeEnvironment: Environment;
@@ -20,10 +16,8 @@ type GetActiveEnvironmentReturnType =
20
16
  };
21
17
 
22
18
  export async function getActiveEnvironment(
23
- args?: GetActiveEnvironmentArgs,
19
+ retried = false,
24
20
  ): Promise<GetActiveEnvironmentReturnType> {
25
- const { retried = false } = args ?? {};
26
-
27
21
  try {
28
22
  const activeEnvironmentResult =
29
23
  await managerClient.project.fetchActiveEnvironment();
@@ -41,7 +35,7 @@ export async function getActiveEnvironment(
41
35
  await managerClient.project.updateEnvironment({ environment: undefined });
42
36
 
43
37
  // Call recursively with isRetry=true to prevent infinite loop if it fails again and again.
44
- return await getActiveEnvironment({ retried: true });
38
+ return await getActiveEnvironment(true);
45
39
  }
46
40
 
47
41
  return { error };
@@ -1,7 +1,14 @@
1
- import { useRequest } from "@prismicio/editor-support/Suspense";
1
+ import {
2
+ invalidateFetcherData,
3
+ useRequest,
4
+ } from "@prismicio/editor-support/Suspense";
2
5
 
3
6
  import { getActiveEnvironment } from "./actions/getActiveEnvironment";
4
7
 
8
+ export function invalidateActiveEnvironmentData() {
9
+ invalidateFetcherData(getActiveEnvironment);
10
+ }
11
+
5
12
  export function useActiveEnvironment() {
6
13
  return useRequest(getActiveEnvironment, []);
7
14
  }
@@ -1,7 +1,14 @@
1
- import { useRequest } from "@prismicio/editor-support/Suspense";
1
+ import {
2
+ invalidateFetcherData,
3
+ useRequest,
4
+ } from "@prismicio/editor-support/Suspense";
2
5
 
3
6
  import { getEnvironments } from "./actions/getEnvironments";
4
7
 
8
+ export function invalidateEnvironmentsData() {
9
+ invalidateFetcherData(getEnvironments);
10
+ }
11
+
5
12
  export function useEnvironments() {
6
13
  return useRequest(getEnvironments, []);
7
14
  }
@@ -1,4 +1,10 @@
1
- import { ActionList, Box, Separator, Skeleton } from "@prismicio/editor-ui";
1
+ import {
2
+ ActionList,
3
+ Badge,
4
+ Box,
5
+ Separator,
6
+ Skeleton,
7
+ } from "@prismicio/editor-ui";
2
8
  import { useRouter } from "next/router";
3
9
  import { Suspense } from "react";
4
10
 
@@ -10,6 +16,7 @@ import { RepositoryInfo } from "@/features/navigation/RepositoryInfo";
10
16
  import { OnboardingGuide } from "@/features/onboarding";
11
17
  import { useAdapterName } from "@/hooks/useAdapterName";
12
18
  import { useMarketingContent } from "@/hooks/useMarketingContent";
19
+ import { CodeIcon } from "@/icons/CodeIcon";
13
20
  import { FolderIcon } from "@/icons/FolderIcon";
14
21
  import { LightningIcon } from "@/icons/Lightning";
15
22
  import { MenuBookIcon } from "@/icons/MenuBookIcon";
@@ -93,6 +100,23 @@ export function Navigation() {
93
100
  <OnboardingGuide />
94
101
  </Suspense>
95
102
  </ErrorBoundary>
103
+
104
+ <NavigationItem
105
+ title="Prismic MCP"
106
+ href="https://prismic.io/docs/ai#code-with-prismics-mcp-server"
107
+ target="_blank"
108
+ Icon={CodeIcon}
109
+ RightElement={<Badge title="New" color="indigo" />}
110
+ tooltip="Connect Prismic MCP to your editor (like Cursor) for AI-powered coding."
111
+ onClick={() => {
112
+ void telemetry.track({
113
+ event: "sidebar:link-clicked",
114
+ link_name: "prismic_mcp",
115
+ source: "slice_machine_sidebar",
116
+ });
117
+ }}
118
+ />
119
+
96
120
  <NavigationItem
97
121
  title="Documentation"
98
122
  href={documentationLink}
@@ -13,6 +13,7 @@ type NavigationItemPropsBase = {
13
13
  active?: boolean;
14
14
  Icon: FC<SVGProps<SVGSVGElement>>;
15
15
  RightElement?: ReactNode;
16
+ tooltip?: string;
16
17
  };
17
18
 
18
19
  type NavigationLinkItemProps = NavigationItemPropsBase & {
@@ -32,7 +33,8 @@ type NavigationButtonItemProps = NavigationItemPropsBase & {
32
33
  type NavigationItemProps = NavigationLinkItemProps | NavigationButtonItemProps;
33
34
 
34
35
  export function NavigationItem(props: NavigationItemProps) {
35
- const { title, href, target, active, Icon, RightElement, onClick } = props;
36
+ const { title, href, target, active, Icon, RightElement, onClick, tooltip } =
37
+ props;
36
38
 
37
39
  const isCollapsed = useMediaQuery({ max: "medium" });
38
40
 
@@ -45,7 +47,7 @@ export function NavigationItem(props: NavigationItemProps) {
45
47
  textVariant="normal"
46
48
  backgroundColor="transparent"
47
49
  renderStartIcon={ItemIcon}
48
- endAdornment={RightElement}
50
+ endAdornment={isCollapsed ? undefined : RightElement}
49
51
  selected={active}
50
52
  >
51
53
  {isCollapsed ? null : title}
@@ -53,7 +55,11 @@ export function NavigationItem(props: NavigationItemProps) {
53
55
  );
54
56
 
55
57
  return (
56
- <Tooltip content={title} side="right" visible={isCollapsed}>
58
+ <Tooltip
59
+ content={Boolean(tooltip) ? tooltip ?? "" : title}
60
+ side="right"
61
+ visible={Boolean(tooltip) ? undefined : isCollapsed}
62
+ >
57
63
  {href !== undefined ? (
58
64
  <Link
59
65
  href={href}
@@ -29,6 +29,7 @@ export async function pushChanges(
29
29
  type: "Slice" as const,
30
30
  libraryID: sliceChange.slice.from,
31
31
  status: sliceChange.status,
32
+ variationImageUrlMap: sliceChange.variationImageUrlMap,
32
33
  }));
33
34
  const customTypeChanges = changedCustomTypes.map((customTypeChange) => ({
34
35
  id: customTypeChange.customType.id,
@@ -3,6 +3,7 @@ import { LibraryUI } from "@/legacy/lib/models/common/LibraryUI";
3
3
  import {
4
4
  getModelId,
5
5
  hasLocal,
6
+ hasRemote,
6
7
  isRemoteOnly,
7
8
  LocalOrRemoteCustomType,
8
9
  LocalOrRemoteSlice,
@@ -76,11 +77,23 @@ export function getUnSyncedChanges(
76
77
  );
77
78
 
78
79
  const changedSlices = unSyncedSlices
79
- .map((s) => ({
80
- slice: s,
81
- status: modelsStatuses.slices[s.model.id],
82
- }))
80
+ .map((slice) => {
81
+ const status = modelsStatuses.slices[slice.model.id];
82
+
83
+ const imageUrlMap = findRemoteSlice(
84
+ slices,
85
+ slice.model.id,
86
+ )?.variations.reduce<Record<string, string>>((result, variation) => {
87
+ const { imageUrl } = variation;
88
+ if (imageUrl === undefined || imageUrl === "") return result;
89
+ result[variation.id] = imageUrl;
90
+ return result;
91
+ }, {});
92
+
93
+ return { status, slice, variationImageUrlMap: imageUrlMap ?? {} };
94
+ })
83
95
  .filter((s): s is ChangedSlice => unSyncStatuses.includes(s.status));
96
+
84
97
  const changedCustomTypes = unSyncedCustomTypes
85
98
  .map((model) => (hasLocal(model) ? model.local : model.remote))
86
99
  .map((ct) => ({
@@ -98,6 +111,11 @@ export function getUnSyncedChanges(
98
111
  };
99
112
  }
100
113
 
114
+ function findRemoteSlice(slices: LocalOrRemoteSlice[], sliceId: string) {
115
+ const slice = slices.find((s) => hasRemote(s) && s.remote.id === sliceId);
116
+ return slice && hasRemote(slice) ? slice.remote : undefined;
117
+ }
118
+
101
119
  // ComponentUI are manipulated on all the relevant pages
102
120
  // But the data is not available for remote only slices
103
121
  // which have been deleted locally
@@ -6,9 +6,11 @@ import {
6
6
  Box,
7
7
  Button,
8
8
  ButtonGroup,
9
+ Text,
9
10
  } from "@prismicio/editor-ui";
11
+ import { isUnauthorizedError } from "@slicemachine/manager/client";
10
12
  import { useRouter } from "next/router";
11
- import { FC, PropsWithChildren, Suspense } from "react";
13
+ import { FC, PropsWithChildren, Suspense, useState } from "react";
12
14
 
13
15
  import { Breadcrumb } from "@/components/Breadcrumb";
14
16
  import {
@@ -18,6 +20,7 @@ import {
18
20
  PageLayoutPane,
19
21
  } from "@/components/PageLayout";
20
22
  import { ErrorBoundary } from "@/ErrorBoundary";
23
+ import { LogoutButton } from "@/features/auth/LogoutButton";
21
24
  import { useActiveEnvironment } from "@/features/environments/useActiveEnvironment";
22
25
  import { Navigation } from "@/features/navigation/Navigation";
23
26
 
@@ -44,7 +47,7 @@ export const AppLayout: FC<PropsWithChildren> = ({
44
47
  />
45
48
  <BlankSlateTitle>Failed to load Slice Machine</BlankSlateTitle>
46
49
  <BlankSlateDescription>
47
- {JSON.stringify(error)}
50
+ <RenderError error={error} />
48
51
  </BlankSlateDescription>
49
52
  </BlankSlate>
50
53
  </Box>
@@ -63,6 +66,43 @@ export const AppLayout: FC<PropsWithChildren> = ({
63
66
  );
64
67
  };
65
68
 
69
+ function RenderError(args: { error: unknown }) {
70
+ const { error } = args;
71
+
72
+ if (isUnauthorizedError(error)) {
73
+ return <UnauthorizedErrorView />;
74
+ }
75
+ return <>{JSON.stringify(error)}</>;
76
+ }
77
+
78
+ function UnauthorizedErrorView() {
79
+ const [isLoggingOut, setIsLoggingOut] = useState(false);
80
+
81
+ return (
82
+ <Box flexDirection="column" gap={16} margin={{ top: 8 }}>
83
+ <Box flexDirection="column" gap={8} alignItems="center">
84
+ <Text variant="h3" align="center">
85
+ It seems like you don't have access to this repository
86
+ </Text>
87
+ <Text align="center">
88
+ Check that the repository name is correct, then contact your
89
+ repository administrator.
90
+ </Text>
91
+ </Box>
92
+ <LogoutButton
93
+ isLoading={isLoggingOut}
94
+ onLogoutSuccess={() => {
95
+ setIsLoggingOut(true);
96
+ window.location.reload();
97
+ }}
98
+ sx={{ alignSelf: "center" }}
99
+ >
100
+ Log out
101
+ </LogoutButton>
102
+ </Box>
103
+ );
104
+ }
105
+
66
106
  const environmentTopBorderColorMap = {
67
107
  prod: "purple",
68
108
  stage: "indigo",
@@ -5,7 +5,7 @@ import { AuthStatus } from "@/modules/userContext/types";
5
5
  import useSliceMachineActions from "@/modules/useSliceMachineActions";
6
6
 
7
7
  export type AuthErrorPageProps = {
8
- authStatus: AuthStatus.UNAUTHORIZED | AuthStatus.FORBIDDEN;
8
+ authStatus: AuthStatus.FORBIDDEN;
9
9
  };
10
10
 
11
11
  export const AuthErrorPage: FC<AuthErrorPageProps> = (props) => {
@@ -20,23 +20,13 @@ export const AuthErrorPage: FC<AuthErrorPageProps> = (props) => {
20
20
  justifyContent="center"
21
21
  gap={8}
22
22
  >
23
- {authStatus === AuthStatus.FORBIDDEN ? (
23
+ {authStatus === AuthStatus.FORBIDDEN && (
24
24
  <>
25
25
  <Text variant="h3" align="center">
26
26
  It seems like you are logged out
27
27
  </Text>
28
28
  <Text align="center">Log in to connect to your repository.</Text>
29
29
  </>
30
- ) : (
31
- <>
32
- <Text variant="h3" align="center">
33
- It seems like you don't have access to this repository
34
- </Text>
35
- <Text align="center">
36
- Check that the repository name is correct, then contact your
37
- repository administrator.
38
- </Text>
39
- </>
40
30
  )}
41
31
  <Text align="center">
42
32
  If that doesn't work, it's possible that Slice Machine is having trouble
@@ -1,3 +1,4 @@
1
+ import { Box, Tooltip } from "@prismicio/editor-ui";
1
2
  import * as CSS from "csstype";
2
3
  import { IconType } from "react-icons";
3
4
  import { Flex, Text, Theme } from "theme-ui";
@@ -9,6 +10,7 @@ interface ItemHeaderProps {
9
10
  sliceFieldName: string | undefined;
10
11
  theme: Theme;
11
12
  WidgetIcon: IconType;
13
+ widgetIconTooltip: string;
12
14
  }
13
15
 
14
16
  const ItemHeader: React.FC<ItemHeaderProps> = ({
@@ -16,20 +18,24 @@ const ItemHeader: React.FC<ItemHeaderProps> = ({
16
18
  sliceFieldName,
17
19
  theme,
18
20
  WidgetIcon,
21
+ widgetIconTooltip,
19
22
  }) => (
20
23
  <Flex sx={{ alignItems: "center", position: "relative" }}>
21
- <WidgetIcon
22
- size={28}
23
- style={{
24
- color: theme.colors?.primary as CSS.Property.Color,
25
- marginRight: "8px",
26
- borderRadius: "4px",
27
- padding: "4px",
28
- border: "2px solid",
29
- borderColor: theme.colors?.primary as CSS.Property.Color,
30
- flexShrink: 0,
31
- }}
32
- />
24
+ <Tooltip content={widgetIconTooltip} sideOffset={2} disableHoverableContent>
25
+ <Box margin={{ right: 8 }}>
26
+ <WidgetIcon
27
+ size={28}
28
+ style={{
29
+ color: theme.colors?.primary as CSS.Property.Color,
30
+ borderRadius: "4px",
31
+ padding: "4px",
32
+ border: "2px solid",
33
+ borderColor: theme.colors?.primary as CSS.Property.Color,
34
+ flexShrink: 0,
35
+ }}
36
+ />
37
+ </Box>
38
+ </Tooltip>
33
39
  <TextWithTooltip
34
40
  text={text}
35
41
  as="p"
@@ -114,6 +114,7 @@ function ListItem<F extends TabField, S extends AnyObjectSchema>({
114
114
  renderFieldAccessor && renderFieldAccessor(key)
115
115
  }
116
116
  WidgetIcon={widget.Meta.icon}
117
+ widgetIconTooltip={widget.label}
117
118
  />
118
119
  <Flex sx={{ flex: "0 0 auto" }}>
119
120
  {shouldDisplayRepeatableBadge && (
@@ -13,8 +13,10 @@ import {
13
13
  Text,
14
14
  } from "theme-ui";
15
15
 
16
- import { checkAuthStatus, getState, startAuth } from "@/apiClient";
16
+ import { checkAuthStatus, clearAuth, getState } from "@/apiClient";
17
17
  import { getActiveEnvironment } from "@/features/environments/actions/getActiveEnvironment";
18
+ import { invalidateActiveEnvironmentData } from "@/features/environments/useActiveEnvironment";
19
+ import { invalidateEnvironmentsData } from "@/features/environments/useEnvironments";
18
20
  import { useAutoSync } from "@/features/sync/AutoSyncProvider";
19
21
  import { getUnSyncedChanges } from "@/features/sync/getUnSyncChanges";
20
22
  import SliceMachineModal from "@/legacy/components/SliceMachineModal";
@@ -50,7 +52,7 @@ const LoginModal: React.FunctionComponent = () => {
50
52
  }),
51
53
  );
52
54
  const { syncChanges } = useAutoSync();
53
- const { closeModals, startLoadingLogin, stopLoadingLogin } =
55
+ const { closeModals, startLoadingLogin, stopLoadingLogin, refreshState } =
54
56
  useSliceMachineActions();
55
57
 
56
58
  const prismicBase = preferWroomBase(env.manifest.apiEndpoint);
@@ -64,7 +66,7 @@ const LoginModal: React.FunctionComponent = () => {
64
66
 
65
67
  try {
66
68
  startLoadingLogin();
67
- await startAuth();
69
+ await clearAuth();
68
70
  window.open(loginRedirectUrl, "_blank");
69
71
  await startPolling<CheckAuthStatusResponse, ValidAuthStatus>(
70
72
  checkAuthStatus,
@@ -76,11 +78,17 @@ const LoginModal: React.FunctionComponent = () => {
76
78
  60,
77
79
  );
78
80
 
81
+ // refresh queries to update the UI
82
+ invalidateEnvironmentsData();
83
+ invalidateActiveEnvironmentData();
84
+
79
85
  toast.success("Logged in");
80
86
  stopLoadingLogin();
81
87
  closeModals();
82
88
 
83
89
  const serverState = await getState();
90
+ refreshState(serverState);
91
+
84
92
  const slices = normalizeFrontendSlices(
85
93
  serverState.libraries,
86
94
  serverState.remoteSlices,
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  Environment as EnvironmentType,
3
3
  isUnauthenticatedError,
4
- isUnauthorizedError,
5
4
  } from "@slicemachine/manager/client";
6
5
  import { useState } from "react";
7
6
 
@@ -98,17 +97,10 @@ export function Environment() {
98
97
  );
99
98
  }
100
99
 
101
- if (
102
- isUnauthenticatedError(useEnvironmentsError) ||
103
- isUnauthorizedError(useEnvironmentsError)
104
- ) {
100
+ if (isUnauthenticatedError(useEnvironmentsError)) {
105
101
  return (
106
102
  <SideNavEnvironmentSelector
107
- variant={
108
- isUnauthenticatedError(useEnvironmentsError)
109
- ? "unauthenticated"
110
- : "unauthorized"
111
- }
103
+ variant="unauthenticated"
112
104
  onLogInClick={() => openLoginModal()}
113
105
  />
114
106
  );
@@ -17,7 +17,9 @@ import * as VisuallyHidden from "@radix-ui/react-visually-hidden";
17
17
  import type { Environment } from "@slicemachine/manager/client";
18
18
  import { clsx } from "clsx";
19
19
  import type { FC, ReactNode } from "react";
20
+ import { toast } from "react-toastify";
20
21
 
22
+ import { LogoutButton } from "@/features/auth/LogoutButton";
21
23
  import { LoginIcon } from "@/icons/LoginIcon";
22
24
  import { LogoIcon } from "@/icons/LogoIcon";
23
25
 
@@ -138,6 +140,12 @@ export const SideNavEnvironmentSelector: FC<SideNavEnvironmentSelectorProps> = (
138
140
  }
139
141
  />
140
142
  ) : undefined}
143
+
144
+ {variant === "default" && (
145
+ <LogoutButton
146
+ onLogoutSuccess={() => toast.success("Logged out")}
147
+ />
148
+ )}
141
149
  </Box>
142
150
  </>
143
151
  )}