slice-machine-ui 1.20.1-dev-next-release.1 → 1.20.1-dev-environments.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/AppLayout/index.tsx +34 -10
- package/components/Navigation/Environment.tsx +47 -0
- package/components/Navigation/index.css.ts +6 -0
- package/components/Navigation/index.tsx +15 -2
- package/out/404.html +1 -1
- package/out/_next/static/chunks/840-5b485c737b24324b.js +1 -0
- package/out/_next/static/chunks/904-6204ab2ad8798857.js +1 -0
- package/out/_next/static/chunks/pages/{_app-990b6afa681c1060.js → _app-61dfd5e4a504dad6.js} +7 -7
- package/out/_next/static/chunks/pages/{changelog-fa36b9995c26e1d7.js → changelog-4b8369d91d82b28b.js} +1 -1
- package/out/_next/static/chunks/pages/changes-db6e8c6be5ae076e.js +1 -0
- package/out/_next/static/chunks/pages/labs-2922105ab714d32a.js +1 -0
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/{[variation]-481c9b569db5ca0e.js → [variation]-724893d27ffa426c.js} +1 -1
- package/out/_next/static/chunks/pages/slices-93b7af2624c85b8e.js +1 -0
- package/out/_next/static/css/{412af4286eb0b283.css → 009bd7f5ac85fc6a.css} +1 -1
- package/out/_next/static/eEMbH0pyO9pWG3REga3T2/_buildManifest.js +1 -0
- package/out/changelog.html +1 -1
- package/out/changes.html +1 -1
- package/out/custom-types/[customTypeId].html +1 -1
- package/out/custom-types.html +1 -1
- package/out/index.html +1 -1
- package/out/labs.html +1 -1
- package/out/page-types/[pageTypeId].html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
- package/out/slices.html +1 -1
- package/package.json +4 -4
- package/pages/_app.tsx +7 -4
- package/pages/slices.tsx +1 -0
- package/src/components/Divider/Divider.css.ts +31 -0
- package/src/components/Divider/Divider.stories.tsx +27 -0
- package/src/components/Divider/Divider.tsx +25 -0
- package/src/components/Divider/index.ts +1 -0
- package/src/components/PageLayout/PageLayout.css.ts +8 -3
- package/src/components/PageLayout/PageLayout.stories.tsx +10 -1
- package/src/components/PageLayout/PageLayout.tsx +7 -2
- package/src/components/SideNav/SideNav.css.ts +3 -10
- package/src/components/SideNav/SideNav.stories.tsx +29 -2
- package/src/components/SideNav/SideNav.tsx +5 -1
- package/src/components/SideNav/SideNavEnvironmentSelector.css.ts +69 -0
- package/src/components/SideNav/SideNavEnvironmentSelector.tsx +163 -0
- package/src/components/SideNav/index.ts +1 -0
- package/src/features/customTypes/__tests__/CustomTypeBuilderPage.test.tsx +4 -3
- package/src/features/environments/actions/getActiveEnvironmentDomain.ts +11 -0
- package/src/features/environments/actions/getEnvironments.ts +12 -0
- package/src/features/environments/actions/setEnvironment.ts +18 -0
- package/src/features/environments/useActiveEnvironment.ts +38 -0
- package/src/features/environments/useEnvironments.ts +7 -0
- package/src/features/legacyState/actions/getLegacySliceMachineState.ts +53 -0
- package/src/features/legacyState/useLegacySliceMachineState.ts +7 -0
- package/test/pages/slices.test.tsx +4 -8
- package/test/src/modules/__fixtures__/serverState.ts +2 -0
- package/out/_next/static/chunks/840-884e41a48b92e5d3.js +0 -1
- package/out/_next/static/chunks/904-69cc3c4be2bff626.js +0 -1
- package/out/_next/static/chunks/pages/changes-e388be4457a43c3a.js +0 -1
- package/out/_next/static/chunks/pages/labs-ebce03a4e7a95a4e.js +0 -1
- package/out/_next/static/chunks/pages/slices-22db04643850c1d8.js +0 -1
- package/out/_next/static/mHdomNE5ByJ1GIQgA7J-S/_buildManifest.js +0 -1
- /package/out/_next/static/{mHdomNE5ByJ1GIQgA7J-S → eEMbH0pyO9pWG3REga3T2}/_ssgManifest.js +0 -0
|
@@ -101,7 +101,6 @@ export const repositoryLinkIcon = style([
|
|
|
101
101
|
borderWidth: 1,
|
|
102
102
|
cursor: "pointer",
|
|
103
103
|
height: 32,
|
|
104
|
-
marginRight: 8,
|
|
105
104
|
width: 32,
|
|
106
105
|
color: colors.grey12,
|
|
107
106
|
backgroundColor: {
|
|
@@ -163,15 +162,9 @@ export const listTitle = style([
|
|
|
163
162
|
},
|
|
164
163
|
]);
|
|
165
164
|
|
|
166
|
-
export const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
borderColor: colors.grey6,
|
|
170
|
-
borderTopStyle: "dashed",
|
|
171
|
-
borderWidth: 1,
|
|
172
|
-
marginTop: 8,
|
|
173
|
-
}),
|
|
174
|
-
]);
|
|
165
|
+
export const separator = sprinkles({
|
|
166
|
+
marginTop: 8,
|
|
167
|
+
});
|
|
175
168
|
|
|
176
169
|
export const link = style([
|
|
177
170
|
block,
|
|
@@ -5,7 +5,6 @@ import { LightningIcon } from "@src/icons/Lightning";
|
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
SideNav,
|
|
8
|
-
SideNavLogo,
|
|
9
8
|
SideNavList,
|
|
10
9
|
SideNavListItem,
|
|
11
10
|
SideNavLink,
|
|
@@ -15,6 +14,7 @@ import {
|
|
|
15
14
|
SideNavRepository,
|
|
16
15
|
RightElement,
|
|
17
16
|
} from "./SideNav";
|
|
17
|
+
import { SideNavEnvironmentSelector } from "./SideNavEnvironmentSelector";
|
|
18
18
|
|
|
19
19
|
type Story = StoryObj<typeof meta>;
|
|
20
20
|
|
|
@@ -33,7 +33,34 @@ export const Default = {
|
|
|
33
33
|
args: {
|
|
34
34
|
children: (
|
|
35
35
|
<>
|
|
36
|
-
<
|
|
36
|
+
<SideNavEnvironmentSelector
|
|
37
|
+
environments={[
|
|
38
|
+
{
|
|
39
|
+
name: "Production",
|
|
40
|
+
domain: "example-prismic-repo",
|
|
41
|
+
kind: "prod",
|
|
42
|
+
users: [{ id: "id" }],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "Staging",
|
|
46
|
+
domain: "example-prismic-repo-staging",
|
|
47
|
+
kind: "stage",
|
|
48
|
+
users: [{ id: "id" }],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "Development",
|
|
52
|
+
domain: "example-prismic-repo-development",
|
|
53
|
+
kind: "dev",
|
|
54
|
+
users: [{ id: "id" }],
|
|
55
|
+
},
|
|
56
|
+
]}
|
|
57
|
+
activeEnvironment={{
|
|
58
|
+
name: "Production",
|
|
59
|
+
domain: "example-prismic-repo",
|
|
60
|
+
kind: "prod",
|
|
61
|
+
users: [{ id: "id" }],
|
|
62
|
+
}}
|
|
63
|
+
/>
|
|
37
64
|
|
|
38
65
|
<SideNavRepository
|
|
39
66
|
repositoryName="really long repository name"
|
|
@@ -16,6 +16,8 @@ import type { UrlObject } from "node:url";
|
|
|
16
16
|
import LogoIcon from "@src/icons/LogoIcon";
|
|
17
17
|
import OpenIcon from "@src/icons/OpenIcon";
|
|
18
18
|
|
|
19
|
+
import { Divider } from "../Divider";
|
|
20
|
+
|
|
19
21
|
import * as styles from "./SideNav.css";
|
|
20
22
|
|
|
21
23
|
type SideNavProps = PropsWithChildren<{ style?: CSSProperties }>;
|
|
@@ -90,7 +92,9 @@ export const SideNavListTitle: FC<PropsWithChildren> = (props) => (
|
|
|
90
92
|
<h3 {...props} className={styles.listTitle} />
|
|
91
93
|
);
|
|
92
94
|
|
|
93
|
-
export const SideNavSeparator = () =>
|
|
95
|
+
export const SideNavSeparator = () => (
|
|
96
|
+
<Divider color="grey6" className={styles.separator} />
|
|
97
|
+
);
|
|
94
98
|
|
|
95
99
|
export type SideNavLinkProps = {
|
|
96
100
|
title: string;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { colors, sprinkles } from "@prismicio/editor-ui";
|
|
2
|
+
import { style, styleVariants } from "@vanilla-extract/css";
|
|
3
|
+
|
|
4
|
+
export const logo = style([
|
|
5
|
+
sprinkles({
|
|
6
|
+
height: 40,
|
|
7
|
+
width: 40,
|
|
8
|
+
}),
|
|
9
|
+
{
|
|
10
|
+
display: "block",
|
|
11
|
+
},
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const environmentDotBase = style([
|
|
15
|
+
sprinkles({
|
|
16
|
+
flexShrink: 0,
|
|
17
|
+
borderRadius: "50%",
|
|
18
|
+
}),
|
|
19
|
+
{
|
|
20
|
+
width: 10,
|
|
21
|
+
height: 10,
|
|
22
|
+
},
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
export const environmentDot = styleVariants({
|
|
26
|
+
prod: [environmentDotBase, sprinkles({ backgroundColor: colors.purple10 })],
|
|
27
|
+
stage: [environmentDotBase, sprinkles({ backgroundColor: colors.indigo10 })],
|
|
28
|
+
dev: [environmentDotBase, sprinkles({ backgroundColor: colors.amber10 })],
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const menuItemEnvironmentDot = sprinkles({
|
|
32
|
+
marginRight: 2,
|
|
33
|
+
marginLeft: 2,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const activeEnvironmentDot = style([
|
|
37
|
+
sprinkles({
|
|
38
|
+
position: "absolute",
|
|
39
|
+
bottom: 0,
|
|
40
|
+
right: 0,
|
|
41
|
+
outlineWidth: 3,
|
|
42
|
+
outlineColor: colors.grey2,
|
|
43
|
+
outlineStyle: "solid",
|
|
44
|
+
}),
|
|
45
|
+
{
|
|
46
|
+
transform: "translate(50%, 50%)",
|
|
47
|
+
},
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
export const activeEnvironmentName = style([
|
|
51
|
+
sprinkles({
|
|
52
|
+
overflow: "hidden",
|
|
53
|
+
textOverflow: "ellipsis",
|
|
54
|
+
whiteSpace: "nowrap",
|
|
55
|
+
}),
|
|
56
|
+
{
|
|
57
|
+
fontWeight: 500,
|
|
58
|
+
lineHeight: "1.25rem",
|
|
59
|
+
},
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
export const actionRequiredLabel = style([
|
|
63
|
+
sprinkles({
|
|
64
|
+
color: colors.purple10,
|
|
65
|
+
}),
|
|
66
|
+
{
|
|
67
|
+
fontWeight: 500,
|
|
68
|
+
},
|
|
69
|
+
]);
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Box,
|
|
3
|
+
DropdownMenu,
|
|
4
|
+
DropdownMenuContent,
|
|
5
|
+
DropdownMenuItem,
|
|
6
|
+
DropdownMenuLabel,
|
|
7
|
+
DropdownMenuTrigger,
|
|
8
|
+
Icon,
|
|
9
|
+
IconButton,
|
|
10
|
+
Text,
|
|
11
|
+
} from "@prismicio/editor-ui";
|
|
12
|
+
import { Environment } from "@slicemachine/manager/client";
|
|
13
|
+
import type { FC } from "react";
|
|
14
|
+
import clsx from "clsx";
|
|
15
|
+
|
|
16
|
+
import LogoIcon from "@src/icons/LogoIcon";
|
|
17
|
+
|
|
18
|
+
import * as styles from "./SideNavEnvironmentSelector.css";
|
|
19
|
+
|
|
20
|
+
type SideNavEnvironmentSelectorProps = {
|
|
21
|
+
variant?: "default" | "unauthorized";
|
|
22
|
+
environments?: Environment[];
|
|
23
|
+
activeEnvironment?: Environment;
|
|
24
|
+
onSelect?: (environment: Environment) => void | Promise<void>;
|
|
25
|
+
onLogInClick?: () => void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const SideNavEnvironmentSelector: FC<SideNavEnvironmentSelectorProps> = (
|
|
29
|
+
props,
|
|
30
|
+
) => {
|
|
31
|
+
const {
|
|
32
|
+
variant = "default",
|
|
33
|
+
environments = [],
|
|
34
|
+
activeEnvironment,
|
|
35
|
+
onSelect,
|
|
36
|
+
onLogInClick,
|
|
37
|
+
} = props;
|
|
38
|
+
|
|
39
|
+
const isProductionEnvironmentActive = activeEnvironment?.kind === "prod";
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Box alignItems="center" gap={16}>
|
|
43
|
+
<Box position="relative">
|
|
44
|
+
<LogoIcon className={styles.logo} />
|
|
45
|
+
{activeEnvironment !== undefined && (
|
|
46
|
+
<EnvironmentDot
|
|
47
|
+
kind={activeEnvironment.kind}
|
|
48
|
+
className={styles.activeEnvironmentDot}
|
|
49
|
+
/>
|
|
50
|
+
)}
|
|
51
|
+
</Box>
|
|
52
|
+
<Box flexGrow={1} flexDirection="column" overflow="hidden">
|
|
53
|
+
<Text component="span" variant="small" color="grey11">
|
|
54
|
+
Environment
|
|
55
|
+
</Text>
|
|
56
|
+
{variant === "unauthorized" ? (
|
|
57
|
+
<Text component="span" className={styles.actionRequiredLabel}>
|
|
58
|
+
Login required
|
|
59
|
+
</Text>
|
|
60
|
+
) : activeEnvironment === undefined ? (
|
|
61
|
+
<Text component="span" className={styles.actionRequiredLabel}>
|
|
62
|
+
Select environment
|
|
63
|
+
</Text>
|
|
64
|
+
) : (
|
|
65
|
+
<Text component="span" className={styles.activeEnvironmentName}>
|
|
66
|
+
{isProductionEnvironmentActive
|
|
67
|
+
? "Production"
|
|
68
|
+
: activeEnvironment?.name}
|
|
69
|
+
</Text>
|
|
70
|
+
)}
|
|
71
|
+
</Box>
|
|
72
|
+
<Box flexShrink={0}>
|
|
73
|
+
{variant === "unauthorized" ? (
|
|
74
|
+
<IconButton icon="arrowForward" onClick={onLogInClick} />
|
|
75
|
+
) : !activeEnvironment || environments.length > 1 ? (
|
|
76
|
+
<EnvironmentDropdownMenu
|
|
77
|
+
environments={environments}
|
|
78
|
+
activeEnvironment={activeEnvironment}
|
|
79
|
+
onSelect={onSelect}
|
|
80
|
+
/>
|
|
81
|
+
) : null}
|
|
82
|
+
</Box>
|
|
83
|
+
</Box>
|
|
84
|
+
);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
type EnvironmentDropdownMenuProps = Pick<
|
|
88
|
+
SideNavEnvironmentSelectorProps,
|
|
89
|
+
"environments" | "activeEnvironment" | "onSelect"
|
|
90
|
+
>;
|
|
91
|
+
|
|
92
|
+
const EnvironmentDropdownMenu: FC<EnvironmentDropdownMenuProps> = (props) => {
|
|
93
|
+
const { environments = [], activeEnvironment, onSelect } = props;
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<DropdownMenu modal>
|
|
97
|
+
<DropdownMenuTrigger disabled={environments.length < 2}>
|
|
98
|
+
<IconButton icon="unfoldMore" />
|
|
99
|
+
</DropdownMenuTrigger>
|
|
100
|
+
<DropdownMenuContent align="end" minWidth={256}>
|
|
101
|
+
<DropdownMenuLabel>Regular Environments</DropdownMenuLabel>
|
|
102
|
+
{environments.map((environment) =>
|
|
103
|
+
environment.kind !== "dev" ? (
|
|
104
|
+
<EnvironmentDropdownMenuItem
|
|
105
|
+
key={environment.domain}
|
|
106
|
+
environment={environment}
|
|
107
|
+
onSelect={onSelect}
|
|
108
|
+
isActive={environment.domain === activeEnvironment?.domain}
|
|
109
|
+
/>
|
|
110
|
+
) : (
|
|
111
|
+
<>
|
|
112
|
+
<DropdownMenuLabel>Personal Environment</DropdownMenuLabel>
|
|
113
|
+
<EnvironmentDropdownMenuItem
|
|
114
|
+
key={environment.domain}
|
|
115
|
+
environment={environment}
|
|
116
|
+
onSelect={onSelect}
|
|
117
|
+
isActive={environment.domain === activeEnvironment?.domain}
|
|
118
|
+
/>
|
|
119
|
+
</>
|
|
120
|
+
),
|
|
121
|
+
)}
|
|
122
|
+
</DropdownMenuContent>
|
|
123
|
+
</DropdownMenu>
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
type EnvironmentDropdownMenuItemProps = {
|
|
128
|
+
environment: Environment;
|
|
129
|
+
isActive?: boolean;
|
|
130
|
+
} & Pick<SideNavEnvironmentSelectorProps, "onSelect">;
|
|
131
|
+
|
|
132
|
+
const EnvironmentDropdownMenuItem: FC<EnvironmentDropdownMenuItemProps> = (
|
|
133
|
+
props,
|
|
134
|
+
) => {
|
|
135
|
+
const { environment, onSelect, isActive } = props;
|
|
136
|
+
const isProductionEnvironment = environment.kind === "prod";
|
|
137
|
+
|
|
138
|
+
return (
|
|
139
|
+
<DropdownMenuItem
|
|
140
|
+
startIcon={
|
|
141
|
+
<EnvironmentDot
|
|
142
|
+
kind={environment.kind}
|
|
143
|
+
className={styles.menuItemEnvironmentDot}
|
|
144
|
+
/>
|
|
145
|
+
}
|
|
146
|
+
endIcon={Boolean(isActive) ? <Icon name="check" /> : undefined}
|
|
147
|
+
onSelect={() => void onSelect?.(environment)}
|
|
148
|
+
>
|
|
149
|
+
{isProductionEnvironment ? "Production" : environment.name}
|
|
150
|
+
</DropdownMenuItem>
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
type EnvironmentDotProps = {
|
|
155
|
+
kind: Environment["kind"];
|
|
156
|
+
className?: string;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const EnvironmentDot: FC<EnvironmentDotProps> = (props) => {
|
|
160
|
+
const { kind, className } = props;
|
|
161
|
+
|
|
162
|
+
return <div className={clsx(styles.environmentDot[kind], className)} />;
|
|
163
|
+
};
|
|
@@ -178,9 +178,10 @@ async function renderCustomTypesBuilderPage({
|
|
|
178
178
|
const renderResults = render(<CustomTypesBuilderPage />, customTypeMockStore);
|
|
179
179
|
|
|
180
180
|
const folder = customType.format === "page" ? "Page types" : "Custom types";
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
)
|
|
181
|
+
const breadcrumb = await screen.findByTestId(
|
|
182
|
+
`breadcrumb-${folder}-${customType.label as string}`,
|
|
183
|
+
);
|
|
184
|
+
expect(breadcrumb).toBeVisible();
|
|
184
185
|
|
|
185
186
|
return renderResults;
|
|
186
187
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { managerClient } from "@src/managerClient";
|
|
2
|
+
|
|
3
|
+
export async function getActiveEnvironmentDomain() {
|
|
4
|
+
try {
|
|
5
|
+
const { environment } = await managerClient.project.readEnvironment();
|
|
6
|
+
|
|
7
|
+
return { activeEnvironmentDomain: environment };
|
|
8
|
+
} catch (error) {
|
|
9
|
+
return { error };
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { managerClient } from "@src/managerClient";
|
|
2
|
+
|
|
3
|
+
export async function getEnvironments() {
|
|
4
|
+
try {
|
|
5
|
+
const environments =
|
|
6
|
+
await managerClient.prismicRepository.fetchEnvironments();
|
|
7
|
+
|
|
8
|
+
return { environments };
|
|
9
|
+
} catch (error) {
|
|
10
|
+
return { error };
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { revalidateData } from "@prismicio/editor-support/Suspense";
|
|
2
|
+
import { Environment } from "@slicemachine/manager/client";
|
|
3
|
+
|
|
4
|
+
import { getLegacySliceMachineState } from "@src/features/legacyState/actions/getLegacySliceMachineState";
|
|
5
|
+
import { managerClient } from "@src/managerClient";
|
|
6
|
+
|
|
7
|
+
import { getActiveEnvironmentDomain } from "./getActiveEnvironmentDomain";
|
|
8
|
+
|
|
9
|
+
export async function setEnvironment(
|
|
10
|
+
environment: Pick<Environment, "domain">,
|
|
11
|
+
): Promise<void> {
|
|
12
|
+
await managerClient.project.updateEnvironment({
|
|
13
|
+
environment: environment.domain,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
revalidateData(getActiveEnvironmentDomain, []);
|
|
17
|
+
revalidateData(getLegacySliceMachineState, []);
|
|
18
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useRequest } from "@prismicio/editor-support/Suspense";
|
|
2
|
+
|
|
3
|
+
import { getActiveEnvironmentDomain } from "./actions/getActiveEnvironmentDomain";
|
|
4
|
+
import { useEnvironments } from "./useEnvironments";
|
|
5
|
+
|
|
6
|
+
export function useActiveEnvironment() {
|
|
7
|
+
const { environments, error: useEnvironmentsError } = useEnvironments();
|
|
8
|
+
const { activeEnvironmentDomain, error: getActiveEnvironmentError } =
|
|
9
|
+
useRequest(getActiveEnvironmentDomain, []);
|
|
10
|
+
|
|
11
|
+
if (useEnvironmentsError !== undefined) {
|
|
12
|
+
return { error: useEnvironmentsError };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (getActiveEnvironmentError !== undefined) {
|
|
16
|
+
return { error: getActiveEnvironmentError };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const activeEnvironment = environments?.find((environment) => {
|
|
20
|
+
if (activeEnvironmentDomain === undefined) {
|
|
21
|
+
return environment.kind === "prod";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return environment.domain === activeEnvironmentDomain;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (!activeEnvironment) {
|
|
28
|
+
return {
|
|
29
|
+
error: new Error(
|
|
30
|
+
`The active environment (${
|
|
31
|
+
activeEnvironmentDomain ?? "Production"
|
|
32
|
+
}) does not match one of the repository's environments.`,
|
|
33
|
+
),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return { activeEnvironment };
|
|
38
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import ServerState from "@models/server/ServerState";
|
|
2
|
+
import { Slices } from "@lib/models/common/Slice";
|
|
3
|
+
import { CustomTypes } from "@lib/models/common/CustomType";
|
|
4
|
+
import { managerClient } from "@src/managerClient";
|
|
5
|
+
|
|
6
|
+
export async function getLegacySliceMachineState() {
|
|
7
|
+
const rawState = await managerClient.getState();
|
|
8
|
+
|
|
9
|
+
// `rawState` from the client contains non-SM-specific models. We need to
|
|
10
|
+
// transform the data to something SM recognizes.
|
|
11
|
+
const state: ServerState = {
|
|
12
|
+
...rawState,
|
|
13
|
+
libraries: rawState.libraries.map((library) => {
|
|
14
|
+
return {
|
|
15
|
+
...library,
|
|
16
|
+
components: library.components.map((component) => {
|
|
17
|
+
return {
|
|
18
|
+
...component,
|
|
19
|
+
model: Slices.toSM(component.model),
|
|
20
|
+
|
|
21
|
+
// Replace screnshot Blobs with URLs.
|
|
22
|
+
screenshots: Object.fromEntries(
|
|
23
|
+
Object.entries(component.screenshots).map(
|
|
24
|
+
([variationID, screenshot]) => {
|
|
25
|
+
return [
|
|
26
|
+
variationID,
|
|
27
|
+
{
|
|
28
|
+
...screenshot,
|
|
29
|
+
url: URL.createObjectURL(screenshot.data),
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
},
|
|
33
|
+
),
|
|
34
|
+
),
|
|
35
|
+
};
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
}),
|
|
39
|
+
customTypes: rawState.customTypes.map((customTypeModel) => {
|
|
40
|
+
return CustomTypes.toSM(customTypeModel);
|
|
41
|
+
}),
|
|
42
|
+
remoteCustomTypes: rawState.remoteCustomTypes.map(
|
|
43
|
+
(remoteCustomTypeModel) => {
|
|
44
|
+
return CustomTypes.toSM(remoteCustomTypeModel);
|
|
45
|
+
},
|
|
46
|
+
),
|
|
47
|
+
remoteSlices: rawState.remoteSlices.map((remoteSliceModel) => {
|
|
48
|
+
return Slices.toSM(remoteSliceModel);
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return state;
|
|
53
|
+
}
|
|
@@ -167,18 +167,14 @@ describe("slices", () => {
|
|
|
167
167
|
},
|
|
168
168
|
});
|
|
169
169
|
|
|
170
|
-
const createOneButton =
|
|
170
|
+
const createOneButton = await screen.findByTestId("create-slice");
|
|
171
171
|
await act(async () => {
|
|
172
|
-
|
|
173
|
-
fireEvent.click(createOneButton);
|
|
174
|
-
}
|
|
172
|
+
fireEvent.click(createOneButton);
|
|
175
173
|
});
|
|
176
174
|
|
|
177
|
-
const nameInput =
|
|
175
|
+
const nameInput = await screen.findByPlaceholderText(/slice api id/i);
|
|
178
176
|
await act(async () => {
|
|
179
|
-
|
|
180
|
-
fireEvent.change(nameInput, { target: { value: "FooBar" } });
|
|
181
|
-
}
|
|
177
|
+
fireEvent.change(nameInput, { target: { value: "FooBar" } });
|
|
182
178
|
});
|
|
183
179
|
|
|
184
180
|
const createSliceModal = screen.getByLabelText("Create a new slice");
|
|
@@ -36,6 +36,8 @@ export const dummyServerState: Pick<
|
|
|
36
36
|
"https://0yyeb2g040.execute-api.us-east-1.amazonaws.com/prod/",
|
|
37
37
|
PrismicOembed: "https://oembed.prismic.io",
|
|
38
38
|
PrismicUnsplash: "https://unsplash.prismic.io",
|
|
39
|
+
SliceMachineV1:
|
|
40
|
+
"https://21vvgrh0s6.execute-api.us-east-1.amazonaws.com/v1/",
|
|
39
41
|
},
|
|
40
42
|
shortId: "shortId",
|
|
41
43
|
supportsSliceSimulator: true,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[840],{80131:function(e,n,t){"use strict";t.d(n,{M:function(){return w}});var r=t(62230),s=t(85244),a=t(52322),l=t(2784),c=t(75289),i=t(56580),d=t(68780),o=t(70041),u=t(17064),h=t(63397),x=t(78656),C=t(98240),f=function(e){var n=e.selected,t=(0,C.Z)(e,["selected"]);return(0,a.jsx)(c.kC,(0,r.Z)({sx:{p:"24px",mb:3,alignItems:"top",cursor:"pointer",borderRadius:"6px",backgroundColor:"grayLight",boxShadow:n?function(e){var n;return"0 0 0 2px ".concat(String(null===(n=e.colors)||void 0===n?void 0:n.primary))}:"none","&:hover":{boxShadow:function(e){var n;return"0 0 0 2px ".concat(String(null===(n=e.colors)||void 0===n?void 0:n.primary))}}}},t))},p=function(e){var n=e.format,t=(0,u.Z)((0,h.U$)("repeatable"),3),r=t[0],s=t[2],l=x.$[n];return(0,a.jsxs)(c.xu,{mb:2,children:[(0,a.jsxs)(f,{selected:r.value,onClick:function(){return s.setValue(!0)},children:[(0,a.jsx)(c.Y8,{checked:r.value,onChange:function(){},"data-cy":"repeatable-type-radio-btn"}),(0,a.jsxs)(c.xu,{sx:{marginLeft:2},children:["Reusable type",(0,a.jsx)(c.xu,{as:"p",sx:{fontSize:"12px",color:"textClear",mt:1},children:l.hintRepeatable})]})]}),(0,a.jsxs)(f,{selected:!r.value,onClick:function(){return s.setValue(!1)},children:[(0,a.jsx)(c.Y8,{checked:!r.value,onChange:function(){},"data-cy":"single-type-radio-btn"}),(0,a.jsxs)(c.xu,{sx:{marginLeft:2},children:["Single type",(0,a.jsx)(c.xu,{as:"p",sx:{fontSize:"12px",color:"textClear",mt:1},children:l.hintSingle})]})]})]})},m=t(90374),j=t(49471),g=t(77174),v=t(24340),_=t(32665),y=t(3098),b=t(82770),T=t(38876),L=t(75329),w=function(e){var n=e.format,t=e.origin,u=void 0===t?"table":t,h=(0,m.Z)(),C=h.createCustomType,f=h.closeModals,w=(0,i.v9)(function(e){return{customTypeIds:(0,j.W6)(e),customTypeLabels:(0,j.YS)(e),isCreateCustomTypeModalOpen:(0,g.gP)(e,v.q.CREATE_CUSTOM_TYPE),isCreatingCustomType:(0,_.hg)(e,y.z.CREATE_CUSTOM_TYPE)}}),S=w.customTypeIds,k=w.isCreateCustomTypeModalOpen,Z=w.isCreatingCustomType,H=w.customTypeLabels,M=x.$[n],N=(0,l.useState)(!0),E=N[0],I=N[1],R=function(e){var t=e.id,r=e.label,s=e.repeatable,a=r||t;b.Xe.track({event:"custom-type:created",id:t,name:a,format:n,type:s?"repeatable":"single",origin:u}),C(t,a,s,n),f(),I(!0)},V=function(e,n,t){t(E?(0,s.Z)((0,r.Z)({},n),{label:e.target.value,id:(0,T.lV)(e.target.value)}):(0,s.Z)((0,r.Z)({},n),{label:e.target.value}))},z=function(e,n){n("id",e.target.value),I(!1)};return(0,a.jsx)(d.Z,{dataCy:"create-ct-modal",isOpen:k,widthInPx:"530px",formId:"create-custom-type",buttonLabel:"Create",close:function(){f(),I(!0)},onSubmit:R,isLoading:Z,initialValues:{repeatable:!0,id:"",label:""},validate:function(e){var n=e.id,t=e.label,r={};return t&&t.length||(r.label="Cannot be empty."),!r.label&&H.includes(t)&&(r.label="".concat(M.name({start:!0,plural:!1})," name is already taken.")),n&&n.length||(r.id="ID cannot be empty."),r.id||!n||L.xo.exec(n)||(r.id="Invalid id: No special characters allowed."),!r.id&&n&&S.map(function(e){return e.toLowerCase()}).includes(n)&&(r.id='ID "'.concat(n,'" exists already.')),Object.keys(r).length>0?r:void 0},content:{title:"Create a new ".concat(M.name({start:!1,plural:!1}))},children:function(e){var t=e.errors,r=e.setValues,s=e.setFieldValue,l=e.values,i=e.touched;return(0,a.jsxs)(c.xu,{children:[(0,a.jsx)(p,{format:n}),(0,a.jsx)(o.W,{name:"label",label:"".concat(M.name({start:!0,plural:!1})," Name"),dataCy:"ct-name-input",placeholder:"A display name for the ".concat(M.name({start:!1,plural:!1})),error:i.label?t.label:void 0,onChange:function(e){return V(e,l,r)}}),(0,a.jsx)(o.W,{name:"id",dataCy:"ct-id-input",label:"".concat(M.name({start:!0,plural:!1})," ID"),placeholder:M.inputPlaceholder,error:i.id?t.id:void 0,onChange:function(e){return z(e,s)}})]})}})}},840:function(e,n,t){"use strict";t.d(n,{F:function(){return D}});var r=t(52322),s=t(2784),a=t(22715),l=t(97729),c=t.n(l),i=t(56580),d=t(22031),o=t(90374),u=t(32665),h=t(3098),x=t(80131),C=t(78656),f=t(5632),p=t(67557),m=t(50002),j=t(6277);t(80207);var g=function(e){var n=e.children;return(0,r.jsx)("div",{className:"_1ecs97de7i _1ecs97de7n _1ecs97d39c _1ecs97d3gp _1ecs97de99 _1ecs97deal _1ecs97deaz _1ecs97de89",children:(0,r.jsx)("table",{className:"gdfsm51 _1ecs97de7i _1ecs97de7n _1ecs97dec6 _1ecs97ded9",children:n})})},v=(0,s.createContext)("body");function _(){return(0,s.useContext)(v)}var y=function(e){var n=e.children;return(0,r.jsx)(v.Provider,{value:"head",children:(0,r.jsx)("thead",{className:"gdfsm52 _1ecs97de7i _1ecs97de7n _1ecs97d18 _1ecs97d8l",children:n})})},b=function(e){var n=e.children;return(0,r.jsx)(v.Provider,{value:"body",children:(0,r.jsx)("tbody",{className:"gdfsm53 _1ecs97de7i _1ecs97de7n",children:n})})},T=function(e){var n,t=e.children,s=e.onClick,a=_();return(0,r.jsx)("tr",{className:(0,j.W)("_1ecs97de7i _1ecs97de7n _1ecs97deff",(n={},(0,p.Z)(n,"_1ecs97decf",!!s),(0,p.Z)(n,"_1ecs97dm _1ecs97d7z _1ecs97d3c _1ecs97dap _1ecs97d2w _1ecs97da9 _1ecs97defi _1ecs97der0 _1ecs97de8v _1ecs97der3","body"===a),n)),onClick:function(e){var n,t=e.target;if(s&&e.currentTarget.contains(t)){var r=(0,m.JY)(t);(null===(n=null==r?void 0:r.contains(e.currentTarget))||void 0===n||n)&&s(e)}},children:t})},L=function(e){var n=e.children,t=_();return(0,r.jsx)("head"===t?"th":"td",{className:"gdfsm55 _1ecs97de7i _1ecs97de7n _1ecs97d39c _1ecs97d3gp _1ecs97deaz _1ecs97de7j _1ecs97d9nq _1ecs97d9v3 _1ecs97decj _1ecs97depd",children:(0,r.jsx)("div",{className:"gdfsm56 _1ecs97de7i _1ecs97de7k",children:n})})},w=function(){return(0,r.jsxs)("svg",{width:"32",height:"32",viewBox:"0 0 32 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,r.jsx)("path",{d:"M8 28H24C25.1046 28 26 27.1046 26 26V9L21 4H8C6.89543 4 6 4.89543 6 6V26C6 27.1046 6.89543 28 8 28Z",fill:"#6E56CF"}),(0,r.jsx)("path",{d:"M23 9H26L21 4V7C21 8.10457 21.8954 9 23 9Z",fill:"#9E8CFC"}),(0,r.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M16.0912 12C13.2794 12 11 14.2794 11 17.0912C11 19.903 13.2794 22.1824 16.0912 22.1824C17.9763 22.1824 19.6215 21.1577 20.501 19.6372C20.6563 19.3688 20.7878 19.0849 20.8926 18.7883C20.9846 18.5279 20.8482 18.2422 20.5878 18.1502C20.3275 18.0582 20.0418 18.1947 19.9498 18.455C19.8657 18.693 19.7601 18.9209 19.6354 19.1365C18.9273 20.3606 17.6049 21.1824 16.0912 21.1824C13.8317 21.1824 12 19.3507 12 17.0912C12 14.8317 13.8317 13 16.0912 13C17.4478 13 18.6507 13.66 19.3955 14.6782H17.6216C17.3455 14.6782 17.1216 14.9021 17.1216 15.1782C17.1216 15.4544 17.3455 15.6782 17.6216 15.6782H20.2998C20.576 15.6782 20.7998 15.4544 20.7998 15.1782V12.5C20.7998 12.2239 20.576 12 20.2998 12C20.0237 12 19.7998 12.2239 19.7998 12.5V13.6032C18.8717 12.6167 17.5536 12 16.0912 12Z",fill:"white"})]})},S=function(){return(0,r.jsxs)("svg",{width:"32",height:"32",viewBox:"0 0 32 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,r.jsx)("path",{d:"M8 28H24C25.1046 28 26 27.1046 26 26V9L21 4H8C6.89543 4 6 4.89543 6 6V26C6 27.1046 6.89543 28 8 28Z",fill:"#6E56CF"}),(0,r.jsx)("path",{d:"M23 9H26L21 4V7C21 8.10457 21.8954 9 23 9Z",fill:"#9E8CFC"}),(0,r.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M14.0869 14.6818L14.6627 12.3787C14.7183 12.1561 14.9183 12 15.1477 12C15.473 12 15.7117 12.3057 15.6328 12.6213L15.1177 14.6818H17.7232L18.299 12.3787C18.3547 12.1561 18.5547 12 18.7841 12C19.1094 12 19.3481 12.3057 19.2692 12.6213L18.754 14.6818H21C21.2761 14.6818 21.5 14.9057 21.5 15.1818C21.5 15.458 21.2761 15.6818 21 15.6818H18.504L17.8449 18.3182H20C20.2761 18.3182 20.5 18.542 20.5 18.8182C20.5 19.0943 20.2761 19.3182 20 19.3182H17.5949L17.0192 21.6213C16.9635 21.8439 16.7635 22 16.5341 22C16.2088 22 15.9701 21.6943 16.049 21.3787L16.5642 19.3182H13.9586L13.3828 21.6213C13.3272 21.8439 13.1272 22 12.8977 22C12.5724 22 12.3338 21.6943 12.4127 21.3787L12.9278 19.3182H11C10.7239 19.3182 10.5 19.0943 10.5 18.8182C10.5 18.542 10.7239 18.3182 11 18.3182H13.1778L13.8369 15.6818H12C11.7239 15.6818 11.5 15.458 11.5 15.1818C11.5 14.9057 11.7239 14.6818 12 14.6818H14.0869ZM16.8142 18.3182L17.4732 15.6818H14.8677L14.2086 18.3182H16.8142Z",fill:"white"})]})},k=t(67445),Z=t(22710),H=t(99267),M=t(17329),N=t(40147),E=t(49471),I=t(7819),R=t(75708);function V(e){return z.apply(this,arguments)}function z(){return(z=(0,Z.Z)(function(e){var n,t,r;return(0,H.__generator)(this,function(s){switch(s.label){case 0:return[4,N.j.customTypes.readAllCustomTypes({format:e})];case 1:if(t=(n=s.sent()).errors,r=n.models,t.length>0)throw t;return[2,r.map(function(e){return e.model})]}})})).apply(this,arguments)}var P=t(2754),O=t(62607),A=function(e){var n,t,l,c,d,u,h=e.format,x=e.isCreatingCustomType,p=(0,o.Z)().openCreateCustomTypeModal,m=(0,f.useRouter)(),j=(t=(0,s.useCallback)(function(e){return(0,M.VA)(V,[h],e)},[h]),{customTypes:(0,M.QT)(V,[h]),updateCustomTypes:t}),v=j.customTypes,_=j.updateCustomTypes,Z=v.sort(function(e,n){return e.id.localeCompare(n.id)}),H=k.cd[h],N=C.$[h];return(u=(0,i.v9)(function(e){return{storeCustomTypes:(0,E.Ch)(e).filter(I.TG)}}).storeCustomTypes,(0,s.useEffect)(function(){var e=u.filter(function(e){return e.local.format===h});(e.length!==v.length||e.some(function(e){var n=v.find(function(n){return n.id===e.local.id});return!n||JSON.stringify(R.Dc.fromSM(e.local))!==JSON.stringify(n)}))&&_(e.map(function(e){var n=e.local;return R.Dc.fromSM(n)}))},[h,_,v,u]),0===Z.length)?(0,r.jsxs)(P.R$,{style:{alignSelf:"center",marginTop:a.TV.size[72]},children:[(0,r.jsx)(P.u2,{children:(0,r.jsx)(a.Ee,{src:H.blankSlateImage,sizing:"cover"})}),(0,r.jsxs)(P.T9,{children:[(0,r.jsx)(P._T,{children:N.name({start:!0,plural:!0})}),(0,r.jsx)(P.nf,{children:N.blankSlateDescription}),(0,r.jsx)(P.Qj,{children:(0,r.jsx)(a.zx,{onClick:p,loading:x,children:"Create"})})]})]}):(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(g,{children:[(0,r.jsx)(y,{children:(0,r.jsxs)(T,{children:[(0,r.jsx)(L,{children:(0,r.jsx)(a.I5,{name:"notes",size:"medium"})}),(0,r.jsx)(L,{children:"Label"}),(0,r.jsx)(L,{children:"API ID"}),(0,r.jsx)(L,{children:"Limit"}),(0,r.jsx)(L,{})]})}),(0,r.jsx)(b,{children:Z.map(function(e){var n=e.repeatable,t=e.label,s=e.id;return(0,r.jsxs)(T,{onClick:function(){m.push(k.cd[h].getBuilderPagePathname(s))},children:[(0,r.jsx)(L,{children:n?(0,r.jsx)(w,{}):(0,r.jsx)(S,{})}),(0,r.jsx)(L,{children:t}),(0,r.jsx)(L,{children:s}),(0,r.jsx)(L,{children:n?"Reusable":"Single"}),(0,r.jsx)(L,{children:(0,r.jsx)(O._,{isChangesLocal:!1,format:h,customType:e})})]},s)})})]})})},D=function(e){var n=e.format,t=C.$[n],l=(0,o.Z)().openCreateCustomTypeModal,f=(0,i.v9)(function(e){return{isCreatingCustomType:(0,u.hg)(e,h.z.CREATE_CUSTOM_TYPE)}}).isCreatingCustomType;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(c(),{children:(0,r.jsxs)("title",{children:[t.name({start:!0,plural:!0})," - Slice Machine"]})}),(0,r.jsx)(a.SV,{renderError:function(){return(0,r.jsx)(d.LN,{children:(0,r.jsx)(d.RN,{children:(0,r.jsx)(a.xu,{alignItems:"center",justifyContent:"center",children:(0,r.jsx)(a.Iq,{title:"Request failed",description:"An error occurred while fetching your ".concat(t.name({start:!1,plural:!0}),".")})})})})},children:(0,r.jsx)(s.Suspense,{fallback:(0,r.jsxs)(d.LN,{children:[(0,r.jsxs)(d.wd,{children:[(0,r.jsx)(d.Cx,{folder:t.name({start:!0,plural:!0})}),(0,r.jsx)(d.K2,{children:(0,r.jsx)(a.zx,{disabled:!0,startIcon:"add",children:"Create"})})]}),(0,r.jsx)(d.RN,{children:(0,r.jsx)(a._3,{})})]}),children:(0,r.jsxs)(d.LN,{children:[(0,r.jsxs)(d.wd,{children:[(0,r.jsx)(d.Cx,{folder:t.name({start:!0,plural:!0})}),(0,r.jsx)(d.K2,{children:(0,r.jsx)(a.zx,{"data-cy":"create-ct",loading:f,onClick:l,startIcon:"add",children:"Create"})})]}),(0,r.jsx)(d.RN,{children:(0,r.jsxs)(a.xu,{flexDirection:"column",children:[(0,r.jsx)(A,{format:n,isCreatingCustomType:f}),(0,r.jsx)(x.M,{format:n})]})})]})})})]})}},80207:function(){}}]);
|