Skip to content

chore: remove most usage of PropsWithChildren #11859

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 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 9 additions & 7 deletions site/src/components/Conditionals/ChooseOne.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Children, PropsWithChildren } from "react";
import {
Children,
type FC,
type PropsWithChildren,
type ReactNode,
} from "react";

export interface CondProps {
condition?: boolean;
children?: ReactNode;
}

/**
Expand All @@ -11,9 +17,7 @@ export interface CondProps {
* @param condition boolean expression indicating whether the child should be rendered, or undefined
* @returns child. Note that Cond alone does not enforce the condition; it should be used inside ChooseOne.
*/
export const Cond = ({
children,
}: PropsWithChildren<CondProps>): JSX.Element => {
export const Cond: FC<CondProps> = ({ children }) => {
return <>{children}</>;
};

Expand All @@ -24,9 +28,7 @@ export const Cond = ({
* @returns one of its children, or null if there are no children
* @throws an error if its last child has a condition prop, or any non-final children do not have a condition prop
*/
export const ChooseOne = ({
children,
}: PropsWithChildren): JSX.Element | null => {
export const ChooseOne: FC<PropsWithChildren> = ({ children }) => {
const childArray = Children.toArray(children) as JSX.Element[];
if (childArray.length === 0) {
return null;
Expand Down
6 changes: 3 additions & 3 deletions site/src/components/Dialogs/ConfirmDialog/ConfirmDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import DialogActions from "@mui/material/DialogActions";
import { type Interpolation, type Theme } from "@emotion/react";
import { type FC, type PropsWithChildren, type ReactNode } from "react";
import { type FC, type ReactNode } from "react";
import {
Dialog,
DialogActionButtons,
DialogActionButtonsProps,
type DialogActionButtonsProps,
} from "../Dialog";
import type { ConfirmDialogType } from "../types";

Expand Down Expand Up @@ -98,7 +98,7 @@ const styles = {
* Quick-use version of the Dialog component with slightly alternative styles,
* great to use for dialogs that don't have any interaction beyond yes / no.
*/
export const ConfirmDialog: FC<PropsWithChildren<ConfirmDialogProps>> = ({
export const ConfirmDialog: FC<ConfirmDialogProps> = ({
cancelText,
confirmLoading,
confirmText,
Expand Down
5 changes: 3 additions & 2 deletions site/src/components/Expander/Expander.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { type Interpolation, type Theme } from "@emotion/react";
import Collapse from "@mui/material/Collapse";
import Link from "@mui/material/Link";
import { type FC, type ReactNode } from "react";
import { DropdownArrow } from "components/DropdownArrow/DropdownArrow";
import { type FC, type PropsWithChildren } from "react";

export interface ExpanderProps {
expanded: boolean;
setExpanded: (val: boolean) => void;
children?: ReactNode;
}

export const Expander: FC<PropsWithChildren<ExpanderProps>> = ({
export const Expander: FC<ExpanderProps> = ({
expanded,
setExpanded,
children,
Expand Down
30 changes: 16 additions & 14 deletions site/src/components/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type HTMLProps,
type PropsWithChildren,
useContext,
ReactNode,
} from "react";
import { AlphaBadge, DeprecatedBadge } from "components/Badges/Badges";
import { Stack } from "components/Stack/Stack";
Expand Down Expand Up @@ -67,19 +68,20 @@ export const VerticalForm: FC<HTMLProps<HTMLFormElement>> = ({
);
};

export const FormSection: FC<
PropsWithChildren & {
title: string | JSX.Element;
description: string | JSX.Element;
classes?: {
root?: string;
sectionInfo?: string;
infoTitle?: string;
};
alpha?: boolean;
deprecated?: boolean;
}
> = ({
interface FormSectionProps {
children?: ReactNode;
title: ReactNode;
description: ReactNode;
classes?: {
root?: string;
sectionInfo?: string;
infoTitle?: string;
};
alpha?: boolean;
deprecated?: boolean;
}

export const FormSection: FC<FormSectionProps> = ({
children,
title,
description,
Expand Down Expand Up @@ -166,7 +168,7 @@ const styles = {
},
} satisfies Record<string, Interpolation<Theme>>;

export const FormFooter = (props: Exclude<FormFooterProps, "styles">) => (
export const FormFooter: FC<Exclude<FormFooterProps, "styles">> = (props) => (
<BaseFormFooter {...props} styles={footerStyles} />
);

Expand Down
3 changes: 2 additions & 1 deletion site/src/components/FullPageForm/FullPageForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import {
export interface FullPageFormProps {
title: string;
detail?: ReactNode;
children?: ReactNode;
}

export const FullPageForm: FC<React.PropsWithChildren<FullPageFormProps>> = ({
export const FullPageForm: FC<FullPageFormProps> = ({
title,
detail,
children,
Expand Down
14 changes: 9 additions & 5 deletions site/src/components/FullPageForm/FullPageHorizontalForm.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import Button from "@mui/material/Button";
import { type FC, type ReactNode } from "react";
import { Margins } from "components/Margins/Margins";
import { FC, ReactNode } from "react";
import {
PageHeader,
PageHeaderTitle,
PageHeaderSubtitle,
} from "components/PageHeader/PageHeader";
import Button from "@mui/material/Button";

export interface FullPageHorizontalFormProps {
title: string;
detail?: ReactNode;
onCancel?: () => void;
children?: ReactNode;
}

export const FullPageHorizontalForm: FC<
React.PropsWithChildren<FullPageHorizontalFormProps>
> = ({ title, detail, onCancel, children }) => {
export const FullPageHorizontalForm: FC<FullPageHorizontalFormProps> = ({
title,
detail,
onCancel,
children,
}) => {
return (
<Margins size="medium">
<PageHeader
Expand Down
19 changes: 10 additions & 9 deletions site/src/components/HelpTooltip/HelpTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import {
type HTMLAttributes,
type ReactNode,
forwardRef,
ComponentProps,
} from "react";
import { Stack } from "components/Stack/Stack";
import { type CSSObject } from "@emotion/css";
import { css, type Interpolation, type Theme, useTheme } from "@emotion/react";
import {
Popover,
type PopoverProps,
PopoverContent,
type PopoverContentProps,
PopoverTrigger,
usePopover,
} from "components/Popover/Popover";
Expand All @@ -25,13 +26,11 @@ type Size = "small" | "medium";

export const HelpTooltipIcon = HelpIcon;

export const HelpTooltip: FC<ComponentProps<typeof Popover>> = (props) => {
export const HelpTooltip: FC<PopoverProps> = (props) => {
return <Popover mode="hover" {...props} />;
};

export const HelpTooltipContent = (
props: ComponentProps<typeof PopoverContent>,
) => {
export const HelpTooltipContent: FC<PopoverContentProps> = (props) => {
const theme = useTheme();

return (
Expand Down Expand Up @@ -125,10 +124,12 @@ export const HelpTooltipText: FC<HTMLAttributes<HTMLParagraphElement>> = ({
);
};

export const HelpTooltipLink: FC<PropsWithChildren<{ href: string }>> = ({
children,
href,
}) => {
interface HelpTooltipLink {
children?: ReactNode;
href: string;
}

export const HelpTooltipLink: FC<HelpTooltipLink> = ({ children, href }) => {
return (
<Link href={href} target="_blank" rel="noreferrer" css={styles.link}>
<OpenInNewIcon css={styles.linkIcon} />
Expand Down
14 changes: 10 additions & 4 deletions site/src/components/PageHeader/FullWidthPageHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { type CSSObject, useTheme } from "@emotion/react";
import { type FC, type PropsWithChildren } from "react";
import { type FC, type PropsWithChildren, type ReactNode } from "react";

export const FullWidthPageHeader: FC<
PropsWithChildren & { sticky?: boolean }
> = ({ children, sticky = true }) => {
interface FullWidthPageHeaderProps {
children?: ReactNode;
sticky?: boolean;
}

export const FullWidthPageHeader: FC<FullWidthPageHeaderProps> = ({
children,
sticky = true,
}) => {
const theme = useTheme();
return (
<header
Expand Down
19 changes: 12 additions & 7 deletions site/src/components/PageHeader/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { Stack } from "../Stack/Stack";
export interface PageHeaderProps {
actions?: ReactNode;
className?: string;
children?: ReactNode;
}

export const PageHeader: FC<PropsWithChildren<PageHeaderProps>> = ({
export const PageHeader: FC<PageHeaderProps> = ({
children,
actions,
className,
Expand Down Expand Up @@ -48,9 +49,7 @@ export const PageHeader: FC<PropsWithChildren<PageHeaderProps>> = ({
);
};

export const PageHeaderTitle: FC<PropsWithChildren<unknown>> = ({
children,
}) => {
export const PageHeaderTitle: FC<PropsWithChildren> = ({ children }) => {
return (
<h1
css={{
Expand All @@ -67,9 +66,15 @@ export const PageHeaderTitle: FC<PropsWithChildren<unknown>> = ({
);
};

export const PageHeaderSubtitle: FC<
PropsWithChildren<{ condensed?: boolean }>
> = ({ children, condensed }) => {
interface PageHeaderSubtitleProps {
children?: ReactNode;
condensed?: boolean;
}

export const PageHeaderSubtitle: FC<PageHeaderSubtitleProps> = ({
children,
condensed,
}) => {
return (
<h2
css={(theme) => ({
Expand Down
15 changes: 8 additions & 7 deletions site/src/components/PaginationWidget/PageButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type FC, type PropsWithChildren } from "react";
import Button from "@mui/material/Button";
import { useTheme } from "@emotion/react";
import { type FC, type ReactNode } from "react";

type NumberedPageButtonProps = {
pageNumber: number;
Expand Down Expand Up @@ -31,9 +31,10 @@ export const NumberedPageButton: FC<NumberedPageButtonProps> = ({
);
};

type PlaceholderPageButtonProps = PropsWithChildren<{
type PlaceholderPageButtonProps = {
pagesOmitted: number;
}>;
children?: ReactNode;
};

export const PlaceholderPageButton: FC<PlaceholderPageButtonProps> = ({
pagesOmitted,
Expand All @@ -50,14 +51,14 @@ export const PlaceholderPageButton: FC<PlaceholderPageButtonProps> = ({
);
};

type BasePageButtonProps = PropsWithChildren<{
type BasePageButtonProps = {
children?: ReactNode;
onClick?: () => void;
name: string;
"aria-label": string;

onClick?: () => void;
highlighted?: boolean;
disabled?: boolean;
}>;
};

const BasePageButton: FC<BasePageButtonProps> = ({
children,
Expand Down
4 changes: 2 additions & 2 deletions site/src/components/Popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const PopoverContext = createContext<PopoverContextValue | undefined>(
undefined,
);

interface PopoverProps {
export interface PopoverProps {
children: ReactNode | ((popover: PopoverContextValue) => ReactNode); // Allows inline usage
mode?: TriggerMode;
isDefaultOpen?: boolean;
Expand Down Expand Up @@ -112,7 +112,7 @@ export const PopoverTrigger = (

type Horizontal = "left" | "right";

type PopoverContentProps = Omit<
export type PopoverContentProps = Omit<
MuiPopoverProps,
"open" | "onClose" | "anchorEl"
> & {
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/Resources/ResourceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export interface ResourceCardProps {
agentRow: (agent: WorkspaceAgent) => JSX.Element;
}

const p = ({ children }: PropsWithChildren) => {
const p: FC<PropsWithChildren> = ({ children }) => {
const childrens = Children.toArray(children);
if (childrens.every((child) => typeof child === "string")) {
return <CopyableValue value={childrens.join("")}>{children}</CopyableValue>;
Expand Down
8 changes: 2 additions & 6 deletions site/src/components/Resources/Resources.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { type Interpolation, type Theme } from "@emotion/react";
import Button from "@mui/material/Button";
import { type Interpolation, type Theme, useTheme } from "@emotion/react";
import { type FC, useState } from "react";
import type { WorkspaceAgent, WorkspaceResource } from "api/typesGenerated";
import { DropdownArrow } from "components/DropdownArrow/DropdownArrow";
import { Stack } from "../Stack/Stack";
import { ResourceCard } from "./ResourceCard";
import { useTheme } from "@mui/material/styles";

const countAgents = (resource: WorkspaceResource) => {
return resource.agents ? resource.agents.length : 0;
Expand All @@ -16,10 +15,7 @@ interface ResourcesProps {
agentRow: (agent: WorkspaceAgent, numberOfAgents: number) => JSX.Element;
}

export const Resources: FC<React.PropsWithChildren<ResourcesProps>> = ({
resources,
agentRow,
}) => {
export const Resources: FC<ResourcesProps> = ({ resources, agentRow }) => {
const theme = useTheme();
const [shouldDisplayHideResources, setShouldDisplayHideResources] =
useState(false);
Expand Down
4 changes: 2 additions & 2 deletions site/src/components/Resources/SSHButton/SSHButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Interpolation, type Theme } from "@emotion/react";
import { type FC, type PropsWithChildren } from "react";
import { type FC } from "react";
import {
HelpTooltipLink,
HelpTooltipLinksGroup,
Expand All @@ -24,7 +24,7 @@ export interface SSHButtonProps {
sshPrefix?: string;
}

export const SSHButton: FC<PropsWithChildren<SSHButtonProps>> = ({
export const SSHButton: FC<SSHButtonProps> = ({
workspaceName,
agentName,
isDefaultOpen = false,
Expand Down
Loading