Skip to content

Commit 066b25f

Browse files
authored
chore: remove Maybe (#9880)
1 parent 72e8f88 commit 066b25f

File tree

19 files changed

+202
-259
lines changed

19 files changed

+202
-259
lines changed

site/src/components/Conditionals/Maybe.stories.tsx

Lines changed: 0 additions & 25 deletions
This file was deleted.

site/src/components/Conditionals/Maybe.tsx

Lines changed: 0 additions & 17 deletions
This file was deleted.

site/src/components/Dialogs/DeleteDialog/DeleteDialog.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import makeStyles from "@mui/styles/makeStyles";
22
import TextField from "@mui/material/TextField";
3-
import { Maybe } from "components/Conditionals/Maybe";
43
import { ChangeEvent, useState, PropsWithChildren, FC } from "react";
54
import { ConfirmDialog } from "../ConfirmDialog/ConfirmDialog";
65

@@ -34,9 +33,7 @@ export const DeleteDialog: FC<PropsWithChildren<DeleteDialogProps>> = ({
3433
const content = (
3534
<>
3635
<p>Deleting this {entity} is irreversible!</p>
37-
<Maybe condition={info !== undefined}>
38-
<p className={styles.warning}>{info}</p>
39-
</Maybe>
36+
{Boolean(info) && <p className={styles.warning}>{info}</p>}
4037
<p>Are you sure you want to proceed?</p>
4138
<p>Type {name} below to confirm.</p>
4239

site/src/components/PageHeader/PageHeader.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { makeStyles } from "@mui/styles";
2-
import { PropsWithChildren, FC } from "react";
3-
import { combineClasses } from "../../utils/combineClasses";
2+
import { type FC, type PropsWithChildren, type ReactNode } from "react";
3+
import { combineClasses } from "utils/combineClasses";
44
import { Stack } from "../Stack/Stack";
55

66
export interface PageHeaderProps {
7-
actions?: JSX.Element;
7+
actions?: ReactNode;
88
className?: string;
99
}
1010

site/src/components/PaginationWidget/PaginationWidget.tsx

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import KeyboardArrowLeft from "@mui/icons-material/KeyboardArrowLeft";
55
import KeyboardArrowRight from "@mui/icons-material/KeyboardArrowRight";
66
import { useActor } from "@xstate/react";
77
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne";
8-
import { Maybe } from "components/Conditionals/Maybe";
98
import { CSSProperties } from "react";
109
import { PaginationMachineRef } from "xServices/pagination/paginationXService";
1110
import { PageButton } from "./PageButton";
@@ -40,57 +39,59 @@ export const PaginationWidget = ({
4039
// if beyond page 1, show pagination widget even if there's only one true page, so user can navigate back
4140
const showWidget = numPages > 1 || currentPage > 1;
4241

42+
if (!showWidget) {
43+
return null;
44+
}
45+
4346
return (
44-
<Maybe condition={showWidget}>
45-
<div style={containerStyle} className={styles.defaultContainerStyles}>
46-
<Button
47-
className={styles.prevLabelStyles}
48-
aria-label="Previous page"
49-
disabled={firstPageActive}
50-
onClick={() => send({ type: "PREVIOUS_PAGE" })}
51-
>
52-
<KeyboardArrowLeft />
53-
<div>{prevLabel}</div>
54-
</Button>
55-
<ChooseOne>
56-
<Cond condition={isMobile}>
57-
<PageButton
58-
activePage={currentPage}
59-
page={currentPage}
60-
numPages={numPages}
61-
/>
62-
</Cond>
63-
<Cond>
64-
{buildPagedList(numPages, currentPage).map((page) =>
65-
typeof page !== "number" ? (
66-
<PageButton
67-
key={`Page${page}`}
68-
activePage={currentPage}
69-
placeholder="..."
70-
disabled
71-
/>
72-
) : (
73-
<PageButton
74-
key={`Page${page}`}
75-
activePage={currentPage}
76-
page={page}
77-
numPages={numPages}
78-
onPageClick={() => send({ type: "GO_TO_PAGE", page })}
79-
/>
80-
),
81-
)}
82-
</Cond>
83-
</ChooseOne>
84-
<Button
85-
aria-label="Next page"
86-
disabled={lastPageActive}
87-
onClick={() => send({ type: "NEXT_PAGE" })}
88-
>
89-
<div>{nextLabel}</div>
90-
<KeyboardArrowRight />
91-
</Button>
92-
</div>
93-
</Maybe>
47+
<div style={containerStyle} className={styles.defaultContainerStyles}>
48+
<Button
49+
className={styles.prevLabelStyles}
50+
aria-label="Previous page"
51+
disabled={firstPageActive}
52+
onClick={() => send({ type: "PREVIOUS_PAGE" })}
53+
>
54+
<KeyboardArrowLeft />
55+
<div>{prevLabel}</div>
56+
</Button>
57+
<ChooseOne>
58+
<Cond condition={isMobile}>
59+
<PageButton
60+
activePage={currentPage}
61+
page={currentPage}
62+
numPages={numPages}
63+
/>
64+
</Cond>
65+
<Cond>
66+
{buildPagedList(numPages, currentPage).map((page) =>
67+
typeof page !== "number" ? (
68+
<PageButton
69+
key={`Page${page}`}
70+
activePage={currentPage}
71+
placeholder="..."
72+
disabled
73+
/>
74+
) : (
75+
<PageButton
76+
key={`Page${page}`}
77+
activePage={currentPage}
78+
page={page}
79+
numPages={numPages}
80+
onPageClick={() => send({ type: "GO_TO_PAGE", page })}
81+
/>
82+
),
83+
)}
84+
</Cond>
85+
</ChooseOne>
86+
<Button
87+
aria-label="Next page"
88+
disabled={lastPageActive}
89+
onClick={() => send({ type: "NEXT_PAGE" })}
90+
>
91+
<div>{nextLabel}</div>
92+
<KeyboardArrowRight />
93+
</Button>
94+
</div>
9495
);
9596
};
9697

site/src/components/Resources/AgentRowPreview.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { makeStyles } from "@mui/styles";
22
import { AppPreviewLink } from "components/Resources/AppLink/AppPreviewLink";
3-
import { Maybe } from "components/Conditionals/Maybe";
43
import { FC } from "react";
54
import { combineClasses } from "utils/combineClasses";
6-
import { WorkspaceAgent } from "../../api/typesGenerated";
5+
import { WorkspaceAgent } from "api/typesGenerated";
76
import { Stack } from "../Stack/Stack";
87

98
interface AgentRowPreviewStyles {
@@ -90,9 +89,9 @@ export const AgentRowPreview: FC<AgentRowPreviewProps> = ({
9089
{agent.apps.map((app) => (
9190
<AppPreviewLink key={app.slug} app={app} />
9291
))}
93-
<Maybe condition={agent.apps.length === 0}>
92+
{agent.apps.length === 0 && (
9493
<span className={styles.agentDataValue}>None</span>
95-
</Maybe>
94+
)}
9695
</Stack>
9796
</Stack>
9897
</Stack>
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
import { FC } from "react";
22
import * as TypesGen from "api/typesGenerated";
33
import { Alert } from "components/Alert/Alert";
4-
import { Maybe } from "components/Conditionals/Maybe";
54

65
export interface TemplateVersionWarningsProps {
76
warnings?: TypesGen.TemplateVersionWarning[];
87
}
98

109
export const TemplateVersionWarnings: FC<
1110
React.PropsWithChildren<TemplateVersionWarningsProps>
12-
> = ({ warnings }) => {
13-
if (!warnings) {
14-
return <></>;
11+
> = (props) => {
12+
const { warnings = [] } = props;
13+
14+
if (!warnings.includes("UNSUPPORTED_WORKSPACES")) {
15+
return null;
1516
}
1617

1718
return (
18-
<Maybe condition={Boolean(warnings.includes("UNSUPPORTED_WORKSPACES"))}>
19-
<div data-testid="error-unsupported-workspaces">
20-
<Alert severity="error">
21-
This template uses legacy parameters which are not supported anymore.
22-
Contact your administrator for assistance.
23-
</Alert>
24-
</div>
25-
</Maybe>
19+
<div data-testid="error-unsupported-workspaces">
20+
<Alert severity="error">
21+
This template uses legacy parameters which are not supported anymore.
22+
Contact your administrator for assistance.
23+
</Alert>
24+
</div>
2625
);
2726
};

site/src/components/WorkspaceDeletion/DormantDeletionStat.tsx

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,51 @@
1-
import { Maybe } from "components/Conditionals/Maybe";
21
import { StatsItem } from "components/Stats/Stats";
32
import Link from "@mui/material/Link";
43
import { Link as RouterLink } from "react-router-dom";
54
import styled from "@emotion/styled";
65
import { Workspace } from "api/typesGenerated";
76
import { displayDormantDeletion } from "./utils";
87
import { useDashboard } from "components/Dashboard/DashboardProvider";
8+
import { type FC } from "react";
99

10-
export const DormantDeletionStat = ({
11-
workspace,
12-
}: {
10+
interface DormantDeletionStatProps {
1311
workspace: Workspace;
14-
}): JSX.Element => {
12+
}
13+
14+
export const DormantDeletionStat: FC<DormantDeletionStatProps> = ({
15+
workspace,
16+
}) => {
1517
const { entitlements, experiments } = useDashboard();
1618
const allowAdvancedScheduling =
1719
entitlements.features["advanced_template_scheduling"].enabled;
1820
// This check can be removed when https://github.com/coder/coder/milestone/19
1921
// is merged up
2022
const allowWorkspaceActions = experiments.includes("workspace_actions");
2123

24+
if (
25+
!displayDormantDeletion(
26+
workspace,
27+
allowAdvancedScheduling,
28+
allowWorkspaceActions,
29+
)
30+
) {
31+
return null;
32+
}
33+
2234
return (
23-
<Maybe
24-
condition={displayDormantDeletion(
25-
workspace,
26-
allowAdvancedScheduling,
27-
allowWorkspaceActions,
28-
)}
29-
>
30-
<StyledStatsItem
31-
label="Deletion on"
32-
className="containerClass"
33-
value={
34-
<Link
35-
component={RouterLink}
36-
to={`/templates/${workspace.template_name}/settings/schedule`}
37-
title="Schedule settings"
38-
>
39-
{/* We check for string existence in the conditional */}
40-
{new Date(workspace.deleting_at as string).toLocaleString()}
41-
</Link>
42-
}
43-
/>
44-
</Maybe>
35+
<StyledStatsItem
36+
label="Deletion on"
37+
className="containerClass"
38+
value={
39+
<Link
40+
component={RouterLink}
41+
to={`/templates/${workspace.template_name}/settings/schedule`}
42+
title="Schedule settings"
43+
>
44+
{/* We check for string existence in the conditional */}
45+
{new Date(workspace.deleting_at!).toLocaleString()}
46+
</Link>
47+
}
48+
/>
4549
);
4650
};
4751

site/src/pages/CreateTemplatePage/CreateTemplatePage.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useMachine } from "@xstate/react";
22
import { isApiValidationError } from "api/errors";
3-
import { Maybe } from "components/Conditionals/Maybe";
43
import { useDashboard } from "components/Dashboard/DashboardProvider";
54
import { FullPageHorizontalForm } from "components/FullPageForm/FullPageHorizontalForm";
65
import { Loader } from "components/Loader/Loader";
@@ -55,14 +54,12 @@ const CreateTemplatePage: FC = () => {
5554
</Helmet>
5655

5756
<FullPageHorizontalForm title="Create Template" onCancel={onCancel}>
58-
<Maybe condition={state.hasTag("loading")}>
59-
<Loader />
60-
</Maybe>
57+
{state.hasTag("loading") && <Loader />}
6158

6259
<Stack spacing={6}>
63-
<Maybe condition={Boolean(error && !isApiValidationError(error))}>
60+
{Boolean(error) && !isApiValidationError(error) && (
6461
<ErrorAlert error={error} />
65-
</Maybe>
62+
)}
6663

6764
{shouldDisplayForm && (
6865
<CreateTemplateForm

0 commit comments

Comments
 (0)