Skip to content

Commit 2ec489c

Browse files
committed
refactor: simplify, cleanup and reuse existing components
1 parent dabe00a commit 2ec489c

12 files changed

Lines changed: 100 additions & 160 deletions

File tree

packages/manager/src/constants/API_ENDPOINTS.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const API_ENDPOINTS: APIEndpoints = (() => {
4949
"https://api.internal.wroom.io/custom-type/",
5050
),
5151
GitService: addTrailingSlash(
52-
process.env.git_service_endpoint ?? "https://git.internal.wroom.io/",
52+
process.env.git_service_api ?? "https://api.internal.wroom.io/git/",
5353
),
5454
};
5555

@@ -100,7 +100,7 @@ If you didn't intend to run Slice Machine this way, stop it immediately and unse
100100
RepositoryService: "https://api.internal.wroom.io/repository/",
101101
LocaleService: "https://api.internal.wroom.io/locale/",
102102
CustomTypeService: "https://api.internal.wroom.io/custom-type/",
103-
GitService: "https://git.internal.wroom.io/",
103+
GitService: "https://api.internal.wroom.io/git/",
104104
};
105105
}
106106

@@ -119,7 +119,7 @@ If you didn't intend to run Slice Machine this way, stop it immediately and unse
119119
RepositoryService: `https://api.internal.${process.env.SM_ENV}-wroom.com/repository/`,
120120
LocaleService: `https://api.internal.${process.env.SM_ENV}-wroom.com/locale/`,
121121
CustomTypeService: `https://api.internal.${process.env.SM_ENV}-wroom.com/custom-type/`,
122-
GitService: `https://git.internal.${process.env.SM_ENV}-wroom.com/`,
122+
GitService: `https://api.internal.${process.env.SM_ENV}-wroom.com/git/`,
123123
};
124124
}
125125

@@ -137,7 +137,7 @@ If you didn't intend to run Slice Machine this way, stop it immediately and unse
137137
RepositoryService: "https://api.internal.prismic.io/repository/",
138138
LocaleService: "https://api.internal.prismic.io/locale/",
139139
CustomTypeService: "https://api.internal.prismic.io/custom-type/",
140-
GitService: "https://git.internal.prismic.io/",
140+
GitService: "https://api.internal.prismic.io/git/",
141141
};
142142
}
143143
}

packages/manager/src/managers/prismicRepository/PrismicRepositoryManager.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -758,20 +758,17 @@ export class PrismicRepositoryManager extends BaseManager {
758758
);
759759
}
760760

761-
if (value) {
762-
return value;
763-
}
764-
765-
throw new Error("Failed to fetch integrations.");
761+
return value;
766762
}
767763

768764
async fetchGitIntegrationToken(args: {
769765
integrationId: string;
770766
}): Promise<z.infer<typeof GitIntegrationTokenSchema>> {
767+
const { integrationId } = args;
771768
const repositoryName = await this.project.getRepositoryName();
772769

773770
const url = new URL(
774-
`integrations/${args.integrationId}/token`,
771+
`integrations/${integrationId}/token`,
775772
API_ENDPOINTS.GitService,
776773
);
777774
url.searchParams.set("repository", repositoryName);
@@ -781,7 +778,7 @@ export class PrismicRepositoryManager extends BaseManager {
781778
if (!res.ok) {
782779
const text = await res.text();
783780
throw new Error(
784-
`Failed to fetch token for integration ${args.integrationId}`,
781+
`Failed to fetch token for integration ${integrationId}`,
785782
{ cause: text },
786783
);
787784
}

packages/manager/test/SliceMachineManager-getState.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ it("returns global Slice Machine state", async () => {
2828
RepositoryService: "https://api.internal.prismic.io/repository/",
2929
LocaleService: "https://api.internal.prismic.io/locale/",
3030
CustomTypeService: "https://api.internal.prismic.io/custom-type/",
31-
GitService: "https://git.internal.prismic.io/",
31+
GitService: "https://api.internal.prismic.io/git/",
3232
});
3333
expect(result.clientError).toStrictEqual({
3434
name: new UnauthenticatedError().name,
Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Box, Icon, Text, ThemeKeys } from "@prismicio/editor-ui";
1+
import {
2+
BlankSlate,
3+
BlankSlateActions,
4+
BlankSlateDescription,
5+
BlankSlateIcon,
6+
BlankSlateTitle,
7+
Box,
8+
ThemeKeys,
9+
} from "@prismicio/editor-ui";
210
import { ReactNode } from "react";
311

412
type EmptyViewProps = {
@@ -7,13 +15,25 @@ type EmptyViewProps = {
715
// TODO: Replace prismic with github icon when available
816
icon: "prismic" | "alert" | "logout";
917
color?: "purple" | "tomato";
10-
children?: ReactNode;
18+
actions?: ReactNode;
1119
};
1220

1321
export function EmptyView(props: EmptyViewProps) {
14-
const { title, description, icon, children, color = "purple" } = props;
22+
const { title, description, icon, actions, color = "purple" } = props;
1523

16-
const colors = getColors(color);
24+
let iconColor: ThemeKeys<"color">;
25+
let iconBackgroundColor: ThemeKeys<"color">;
26+
27+
switch (color) {
28+
case "purple":
29+
iconColor = "purple11";
30+
iconBackgroundColor = "purple3";
31+
break;
32+
case "tomato":
33+
iconColor = "tomato11";
34+
iconBackgroundColor = "tomato3";
35+
break;
36+
}
1737

1838
return (
1939
<Box
@@ -23,50 +43,20 @@ export function EmptyView(props: EmptyViewProps) {
2343
gap={16}
2444
flexGrow={1}
2545
>
26-
<Box
27-
flexDirection="column"
28-
justifyContent="center"
29-
alignItems="center"
30-
gap={8}
31-
maxWidth={324}
32-
>
33-
<Box
34-
borderRadius="100%"
35-
backgroundColor={colors.iconBackgroundColor}
36-
padding={8}
37-
>
38-
<Icon name={icon} size="small" color={colors.iconColor} />
39-
</Box>
40-
<Box flexDirection="column" alignItems="center">
41-
<Text variant="bold" align="center">
42-
{title}
43-
</Text>
44-
{description !== undefined && (
45-
<Text align="center" color="grey11">
46-
{description}
47-
</Text>
48-
)}
49-
</Box>
50-
</Box>
51-
{children}
46+
<BlankSlate>
47+
<BlankSlateIcon
48+
lineColor={iconColor}
49+
backgroundColor={iconBackgroundColor}
50+
name={icon}
51+
/>
52+
<BlankSlateTitle size="medium">{title}</BlankSlateTitle>
53+
{description !== undefined && (
54+
<BlankSlateDescription>{description}</BlankSlateDescription>
55+
)}
56+
{actions !== undefined && (
57+
<BlankSlateActions>{actions}</BlankSlateActions>
58+
)}
59+
</BlankSlate>
5260
</Box>
5361
);
5462
}
55-
56-
function getColors(color: "purple" | "tomato"): {
57-
iconBackgroundColor: ThemeKeys<"color">;
58-
iconColor: ThemeKeys<"color">;
59-
} {
60-
switch (color) {
61-
case "purple":
62-
return {
63-
iconBackgroundColor: "purple3",
64-
iconColor: "purple11",
65-
};
66-
case "tomato":
67-
return {
68-
iconBackgroundColor: "tomato3",
69-
iconColor: "tomato11",
70-
};
71-
}
72-
}

packages/slice-machine/src/features/customTypes/customTypesBuilder/ImportSlicesFromLibraryModal/ImportSlicesFromLibraryModal.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { LocalSlicesDialogContent } from "./LocalSlicesDialogContent";
1212
import { CommonDialogProps, DialogTab } from "./types";
1313

1414
type ImportSlicesFromLibraryModalProps = CommonDialogProps & {
15+
open: boolean;
1516
localSlices: (SharedSlice & { thumbnailUrl?: string })[];
1617
isEveryLocalSliceAdded: boolean;
1718
onSuccess: (args: {
@@ -34,7 +35,14 @@ export function ImportSlicesFromLibraryModal(
3435
const [selectedTab, setSelectedTab] = useState<DialogTab>("local");
3536

3637
useEffect(() => {
37-
if (!open) setTimeout(() => setSelectedTab("local"), 250); // wait for the modal fade animation
38+
if (!open) {
39+
// wait for the modal fade animation
40+
const timeout = setTimeout(() => {
41+
setSelectedTab("local");
42+
}, 250);
43+
44+
return () => clearTimeout(timeout);
45+
}
3846
}, [open]);
3947

4048
return (
@@ -46,7 +54,6 @@ export function ImportSlicesFromLibraryModal(
4654
</DialogDescription>
4755
<LocalSlicesDialogContent
4856
{...contentProps}
49-
open={open}
5057
selected={selectedTab === "local"}
5158
onSelectTab={setSelectedTab}
5259
slices={localSlices}
@@ -55,7 +62,6 @@ export function ImportSlicesFromLibraryModal(
5562
/>
5663
<LibrarySlicesDialogContent
5764
{...contentProps}
58-
open={open}
5965
selected={selectedTab === "library"}
6066
onSelectTab={setSelectedTab}
6167
onClose={onClose}

0 commit comments

Comments
 (0)