Skip to content

chore: remove Maybe #9880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions site/src/components/Conditionals/Maybe.stories.tsx

This file was deleted.

17 changes: 0 additions & 17 deletions site/src/components/Conditionals/Maybe.tsx

This file was deleted.

5 changes: 1 addition & 4 deletions site/src/components/Dialogs/DeleteDialog/DeleteDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import makeStyles from "@mui/styles/makeStyles";
import TextField from "@mui/material/TextField";
import { Maybe } from "components/Conditionals/Maybe";
import { ChangeEvent, useState, PropsWithChildren, FC } from "react";
import { ConfirmDialog } from "../ConfirmDialog/ConfirmDialog";

Expand Down Expand Up @@ -34,9 +33,7 @@ export const DeleteDialog: FC<PropsWithChildren<DeleteDialogProps>> = ({
const content = (
<>
<p>Deleting this {entity} is irreversible!</p>
<Maybe condition={info !== undefined}>
<p className={styles.warning}>{info}</p>
</Maybe>
{info !== undefined && <p className={styles.warning}>{info}</p>}
<p>Are you sure you want to proceed?</p>
<p>Type {name} below to confirm.</p>

Expand Down
4 changes: 2 additions & 2 deletions site/src/components/PageHeader/PageHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { makeStyles } from "@mui/styles";
import { PropsWithChildren, FC } from "react";
import { type FC, type PropsWithChildren, type ReactNode } from "react";
import { combineClasses } from "../../utils/combineClasses";
import { Stack } from "../Stack/Stack";

export interface PageHeaderProps {
actions?: JSX.Element;
actions?: ReactNode;
className?: string;
}

Expand Down
103 changes: 52 additions & 51 deletions site/src/components/PaginationWidget/PaginationWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import KeyboardArrowLeft from "@mui/icons-material/KeyboardArrowLeft";
import KeyboardArrowRight from "@mui/icons-material/KeyboardArrowRight";
import { useActor } from "@xstate/react";
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne";
import { Maybe } from "components/Conditionals/Maybe";
import { CSSProperties } from "react";
import { PaginationMachineRef } from "xServices/pagination/paginationXService";
import { PageButton } from "./PageButton";
Expand Down Expand Up @@ -40,57 +39,59 @@ export const PaginationWidget = ({
// if beyond page 1, show pagination widget even if there's only one true page, so user can navigate back
const showWidget = numPages > 1 || currentPage > 1;

if (!showWidget) {
return null;
}

return (
<Maybe condition={showWidget}>
<div style={containerStyle} className={styles.defaultContainerStyles}>
<Button
className={styles.prevLabelStyles}
aria-label="Previous page"
disabled={firstPageActive}
onClick={() => send({ type: "PREVIOUS_PAGE" })}
>
<KeyboardArrowLeft />
<div>{prevLabel}</div>
</Button>
<ChooseOne>
<Cond condition={isMobile}>
<PageButton
activePage={currentPage}
page={currentPage}
numPages={numPages}
/>
</Cond>
<Cond>
{buildPagedList(numPages, currentPage).map((page) =>
typeof page !== "number" ? (
<PageButton
key={`Page${page}`}
activePage={currentPage}
placeholder="..."
disabled
/>
) : (
<PageButton
key={`Page${page}`}
activePage={currentPage}
page={page}
numPages={numPages}
onPageClick={() => send({ type: "GO_TO_PAGE", page })}
/>
),
)}
</Cond>
</ChooseOne>
<Button
aria-label="Next page"
disabled={lastPageActive}
onClick={() => send({ type: "NEXT_PAGE" })}
>
<div>{nextLabel}</div>
<KeyboardArrowRight />
</Button>
</div>
</Maybe>
<div style={containerStyle} className={styles.defaultContainerStyles}>
<Button
className={styles.prevLabelStyles}
aria-label="Previous page"
disabled={firstPageActive}
onClick={() => send({ type: "PREVIOUS_PAGE" })}
>
<KeyboardArrowLeft />
<div>{prevLabel}</div>
</Button>
<ChooseOne>
<Cond condition={isMobile}>
<PageButton
activePage={currentPage}
page={currentPage}
numPages={numPages}
/>
</Cond>
<Cond>
{buildPagedList(numPages, currentPage).map((page) =>
typeof page !== "number" ? (
<PageButton
key={`Page${page}`}
activePage={currentPage}
placeholder="..."
disabled
/>
) : (
<PageButton
key={`Page${page}`}
activePage={currentPage}
page={page}
numPages={numPages}
onPageClick={() => send({ type: "GO_TO_PAGE", page })}
/>
),
)}
</Cond>
</ChooseOne>
<Button
aria-label="Next page"
disabled={lastPageActive}
onClick={() => send({ type: "NEXT_PAGE" })}
>
<div>{nextLabel}</div>
<KeyboardArrowRight />
</Button>
</div>
);
};

Expand Down
7 changes: 3 additions & 4 deletions site/src/components/Resources/AgentRowPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { makeStyles } from "@mui/styles";
import { AppPreviewLink } from "components/Resources/AppLink/AppPreviewLink";
import { Maybe } from "components/Conditionals/Maybe";
import { FC } from "react";
import { combineClasses } from "utils/combineClasses";
import { WorkspaceAgent } from "../../api/typesGenerated";
import { WorkspaceAgent } from "api/typesGenerated";
import { Stack } from "../Stack/Stack";

interface AgentRowPreviewStyles {
Expand Down Expand Up @@ -90,9 +89,9 @@ export const AgentRowPreview: FC<AgentRowPreviewProps> = ({
{agent.apps.map((app) => (
<AppPreviewLink key={app.slug} app={app} />
))}
<Maybe condition={agent.apps.length === 0}>
{agent.apps.length === 0 && (
<span className={styles.agentDataValue}>None</span>
</Maybe>
)}
</Stack>
</Stack>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { FC } from "react";
import * as TypesGen from "api/typesGenerated";
import { Alert } from "components/Alert/Alert";
import { Maybe } from "components/Conditionals/Maybe";

export interface TemplateVersionWarningsProps {
warnings?: TypesGen.TemplateVersionWarning[];
Expand All @@ -14,14 +13,16 @@ export const TemplateVersionWarnings: FC<
return <></>;
}

if (!warnings.includes("UNSUPPORTED_WORKSPACES")) {
return null;
}

return (
<Maybe condition={Boolean(warnings.includes("UNSUPPORTED_WORKSPACES"))}>
<div data-testid="error-unsupported-workspaces">
<Alert severity="error">
This template uses legacy parameters which are not supported anymore.
Contact your administrator for assistance.
</Alert>
</div>
</Maybe>
<div data-testid="error-unsupported-workspaces">
<Alert severity="error">
This template uses legacy parameters which are not supported anymore.
Contact your administrator for assistance.
</Alert>
</div>
);
};
58 changes: 31 additions & 27 deletions site/src/components/WorkspaceDeletion/DormantDeletionStat.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
import { Maybe } from "components/Conditionals/Maybe";
import { StatsItem } from "components/Stats/Stats";
import Link from "@mui/material/Link";
import { Link as RouterLink } from "react-router-dom";
import styled from "@emotion/styled";
import { Workspace } from "api/typesGenerated";
import { displayDormantDeletion } from "./utils";
import { useDashboard } from "components/Dashboard/DashboardProvider";
import { type FC } from "react";

export const DormantDeletionStat = ({
workspace,
}: {
interface DormantDeletionStatProps {
workspace: Workspace;
}): JSX.Element => {
}

export const DormantDeletionStat: FC<DormantDeletionStatProps> = ({
workspace,
}) => {
const { entitlements, experiments } = useDashboard();
const allowAdvancedScheduling =
entitlements.features["advanced_template_scheduling"].enabled;
// This check can be removed when https://github.com/coder/coder/milestone/19
// is merged up
const allowWorkspaceActions = experiments.includes("workspace_actions");

if (
!displayDormantDeletion(
workspace,
allowAdvancedScheduling,
allowWorkspaceActions,
)
) {
return null;
}

return (
<Maybe
condition={displayDormantDeletion(
workspace,
allowAdvancedScheduling,
allowWorkspaceActions,
)}
>
<StyledStatsItem
label="Deletion on"
className="containerClass"
value={
<Link
component={RouterLink}
to={`/templates/${workspace.template_name}/settings/schedule`}
title="Schedule settings"
>
{/* We check for string existence in the conditional */}
{new Date(workspace.deleting_at as string).toLocaleString()}
</Link>
}
/>
</Maybe>
<StyledStatsItem
label="Deletion on"
className="containerClass"
value={
<Link
component={RouterLink}
to={`/templates/${workspace.template_name}/settings/schedule`}
title="Schedule settings"
>
{/* We check for string existence in the conditional */}
{new Date(workspace.deleting_at!).toLocaleString()}
</Link>
}
/>
);
};

Expand Down
9 changes: 3 additions & 6 deletions site/src/pages/CreateTemplatePage/CreateTemplatePage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useMachine } from "@xstate/react";
import { isApiValidationError } from "api/errors";
import { Maybe } from "components/Conditionals/Maybe";
import { useDashboard } from "components/Dashboard/DashboardProvider";
import { FullPageHorizontalForm } from "components/FullPageForm/FullPageHorizontalForm";
import { Loader } from "components/Loader/Loader";
Expand Down Expand Up @@ -55,14 +54,12 @@ const CreateTemplatePage: FC = () => {
</Helmet>

<FullPageHorizontalForm title="Create Template" onCancel={onCancel}>
<Maybe condition={state.hasTag("loading")}>
<Loader />
</Maybe>
{state.hasTag("loading") && <Loader />}

<Stack spacing={6}>
<Maybe condition={Boolean(error && !isApiValidationError(error))}>
{Boolean(error) && !isApiValidationError(error) && (
<ErrorAlert error={error} />
</Maybe>
)}

{shouldDisplayForm && (
<CreateTemplateForm
Expand Down
Loading