Skip to content

chore: use emotion for styling (pt. 6) #10298

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
Oct 17, 2023
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
23 changes: 10 additions & 13 deletions site/src/components/Resources/AgentOutdatedTooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentProps, FC } from "react";
import { makeStyles } from "@mui/styles";
import { type ComponentProps, type FC } from "react";
import { useTheme } from "@emotion/react";
import RefreshIcon from "@mui/icons-material/RefreshOutlined";
import {
HelpTooltipText,
Expand All @@ -9,7 +9,7 @@ import {
HelpTooltipLinksGroup,
HelpTooltipContext,
} from "components/HelpTooltip/HelpTooltip";
import { WorkspaceAgent } from "api/typesGenerated";
import type { WorkspaceAgent } from "api/typesGenerated";
import { Stack } from "components/Stack/Stack";

type AgentOutdatedTooltipProps = ComponentProps<typeof HelpPopover> & {
Expand All @@ -28,7 +28,11 @@ export const AgentOutdatedTooltip: FC<AgentOutdatedTooltipProps> = ({
onClose,
anchorEl,
}) => {
const styles = useStyles();
const theme = useTheme();
const versionLabelStyles = {
fontWeight: 600,
color: theme.palette.text.primary,
};

return (
<HelpPopover
Expand All @@ -50,12 +54,12 @@ export const AgentOutdatedTooltip: FC<AgentOutdatedTooltipProps> = ({
</div>

<Stack spacing={0.5}>
<span className={styles.versionLabel}>Agent version</span>
<span css={versionLabelStyles}>Agent version</span>
<span>{agent.version}</span>
</Stack>

<Stack spacing={0.5}>
<span className={styles.versionLabel}>Server version</span>
<span css={versionLabelStyles}>Server version</span>
<span>{serverVersion}</span>
</Stack>

Expand All @@ -73,10 +77,3 @@ export const AgentOutdatedTooltip: FC<AgentOutdatedTooltipProps> = ({
</HelpPopover>
);
};

const useStyles = makeStyles((theme) => ({
versionLabel: {
fontWeight: 600,
color: theme.palette.text.primary,
},
}));
61 changes: 26 additions & 35 deletions site/src/components/Resources/AppLink/AppLink.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import CircularProgress from "@mui/material/CircularProgress";
import Link from "@mui/material/Link";
import { makeStyles } from "@mui/styles";
import Tooltip from "@mui/material/Tooltip";
import ErrorOutlineIcon from "@mui/icons-material/ErrorOutline";
import { type FC, useState } from "react";
import { useTheme } from "@emotion/react";
import { getApiKey } from "api/api";
import type * as TypesGen from "api/typesGenerated";
import { useProxy } from "contexts/ProxyContext";
import { PrimaryAgentButton } from "components/Resources/AgentButton";
import { FC, useState } from "react";
import { combineClasses } from "utils/combineClasses";
import * as TypesGen from "api/typesGenerated";
import { createAppLinkHref } from "utils/apps";
import { generateRandomString } from "utils/random";
import { BaseIcon } from "./BaseIcon";
import { ShareIcon } from "./ShareIcon";
import { useProxy } from "contexts/ProxyContext";
import { createAppLinkHref } from "utils/apps";
import { getApiKey } from "api/api";

const Language = {
appTitle: (appName: string, identifier: string): string =>
Expand All @@ -31,7 +30,7 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
const appsHost = proxy.preferredWildcardHostname;
const [fetchingSessionToken, setFetchingSessionToken] = useState(false);

const styles = useStyles();
const theme = useTheme();
const username = workspace.owner_name;

let appSlug = app.slug;
Expand Down Expand Up @@ -65,12 +64,18 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
}
if (app.health === "unhealthy") {
canClick = false;
icon = <ErrorOutlineIcon className={styles.unhealthyIcon} />;
icon = <ErrorOutlineIcon css={{ color: theme.palette.warning.light }} />;
primaryTooltip = "Unhealthy";
}
if (!appsHost && app.subdomain) {
canClick = false;
icon = <ErrorOutlineIcon className={styles.notConfiguredIcon} />;
icon = (
<ErrorOutlineIcon
css={{
color: theme.palette.grey[300],
}}
/>
);
primaryTooltip =
"Your admin has not configured subdomain application access";
}
Expand All @@ -86,7 +91,13 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
endIcon={isPrivateApp ? undefined : <ShareIcon app={app} />}
disabled={!canClick}
>
<span className={combineClasses({ [styles.appName]: !isPrivateApp })}>
<span
css={
!isPrivateApp && {
marginRight: theme.spacing(1),
}
}
>
{appDisplayName}
</span>
</PrimaryAgentButton>
Expand All @@ -98,7 +109,10 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
<Link
href={href}
target="_blank"
className={canClick ? styles.link : styles.disabledLink}
css={{
pointerEvents: canClick ? undefined : "none",
textDecoration: "none !important",
}}
onClick={
canClick
? async (event) => {
Expand Down Expand Up @@ -143,26 +157,3 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
</Tooltip>
);
};

const useStyles = makeStyles((theme) => ({
link: {
textDecoration: "none !important",
},

disabledLink: {
pointerEvents: "none",
textDecoration: "none !important",
},

unhealthyIcon: {
color: theme.palette.warning.light,
},

notConfiguredIcon: {
color: theme.palette.grey[300],
},

appName: {
marginRight: theme.spacing(1),
},
}));
52 changes: 16 additions & 36 deletions site/src/components/Resources/PortForwardButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import Box from "@mui/material/Box";
import Link from "@mui/material/Link";
import Popover from "@mui/material/Popover";
import { makeStyles } from "@mui/styles";
import CircularProgress from "@mui/material/CircularProgress";
import OpenInNewOutlined from "@mui/icons-material/OpenInNewOutlined";
import { css } from "@emotion/css";
import { useTheme } from "@emotion/react";
import { useRef, useState } from "react";
import { useQuery } from "react-query";
import { colors } from "theme/colors";
import {
HelpTooltipLink,
Expand All @@ -11,16 +16,12 @@ import {
} from "components/HelpTooltip/HelpTooltip";
import { SecondaryAgentButton } from "components/Resources/AgentButton";
import { docs } from "utils/docs";
import Box from "@mui/material/Box";
import { useQuery } from "react-query";
import { getAgentListeningPorts } from "api/api";
import {
import type {
WorkspaceAgent,
WorkspaceAgentListeningPort,
} from "api/typesGenerated";
import CircularProgress from "@mui/material/CircularProgress";
import { portForwardURL } from "utils/portForward";
import OpenInNewOutlined from "@mui/icons-material/OpenInNewOutlined";

export interface PortForwardButtonProps {
host: string;
Expand All @@ -30,10 +31,10 @@ export interface PortForwardButtonProps {
}

export const PortForwardButton: React.FC<PortForwardButtonProps> = (props) => {
const theme = useTheme();
const anchorRef = useRef<HTMLButtonElement>(null);
const [isOpen, setIsOpen] = useState(false);
const id = isOpen ? "schedule-popover" : undefined;
const styles = useStyles();
const portsQuery = useQuery({
queryKey: ["portForward", props.agent.id],
queryFn: () => getAgentListeningPorts(props.agent.id),
Expand Down Expand Up @@ -78,7 +79,14 @@ export const PortForwardButton: React.FC<PortForwardButtonProps> = (props) => {
)}
</SecondaryAgentButton>
<Popover
classes={{ paper: styles.popoverPaper }}
classes={{
paper: css`
padding: 0;
width: ${theme.spacing(38)};
color: ${theme.palette.text.secondary};
margin-top: ${theme.spacing(0.5)};
`,
}}
id={id}
open={isOpen}
anchorEl={anchorRef.current}
Expand Down Expand Up @@ -245,31 +253,3 @@ export const PortForwardPopoverView: React.FC<
</>
);
};

const useStyles = makeStyles((theme) => ({
popoverPaper: {
padding: 0,
width: theme.spacing(38),
color: theme.palette.text.secondary,
marginTop: theme.spacing(0.5),
},

openUrlButton: {
flexShrink: 0,
},

portField: {
// The default border don't contrast well with the popover
"& .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline": {
borderColor: colors.gray[10],
},
},

code: {
margin: theme.spacing(2, 0),
},

form: {
margin: theme.spacing(2, 0),
},
}));
38 changes: 16 additions & 22 deletions site/src/components/SettingsLayout/Section.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { makeStyles } from "@mui/styles";
import { useTheme } from "@emotion/react";
import Typography from "@mui/material/Typography";
import { FC, ReactNode, PropsWithChildren } from "react";
import { type FC, type ReactNode, type PropsWithChildren } from "react";
import { SectionAction } from "./SectionAction";
import { type Interpolation, type Theme } from "@emotion/react";

type SectionLayout = "fixed" | "fluid";

Expand Down Expand Up @@ -31,31 +32,30 @@ export const Section: SectionFC = ({
children,
layout = "fixed",
}) => {
const styles = useStyles({ layout });
const theme = useTheme();

return (
<section className={className} id={id} data-testid={id}>
<div className={styles.inner}>
<div css={{ maxWidth: layout === "fluid" ? "100%" : 500 }}>
{(title || description) && (
<div className={styles.header}>
<div css={styles.header}>
<div>
{title && (
<Typography variant="h4" sx={{ fontSize: 24 }}>
{title}
</Typography>
)}
{description && typeof description === "string" && (
<Typography className={styles.description}>
{description}
</Typography>
<Typography css={styles.description}>{description}</Typography>
)}
{description && typeof description !== "string" && (
<div className={styles.description}>{description}</div>
<div css={styles.description}>{description}</div>
)}
</div>
{toolbar && <div>{toolbar}</div>}
</div>
)}
{alert && <div className={styles.alert}>{alert}</div>}
{alert && <div css={{ marginBottom: theme.spacing(1) }}>{alert}</div>}
{children}
</div>
</section>
Expand All @@ -65,23 +65,17 @@ export const Section: SectionFC = ({
// Sub-components
Section.Action = SectionAction;

const useStyles = makeStyles((theme) => ({
inner: ({ layout }: { layout: SectionLayout }) => ({
maxWidth: layout === "fluid" ? "100%" : 500,
}),
alert: {
marginBottom: theme.spacing(1),
},
header: {
const styles = {
header: (theme) => ({
marginBottom: theme.spacing(3),
display: "flex",
flexDirection: "row",
justifyContent: "space-between",
},
description: {
}),
description: (theme) => ({
color: theme.palette.text.secondary,
fontSize: 16,
marginTop: theme.spacing(0.5),
lineHeight: "140%",
},
}));
}),
} satisfies Record<string, Interpolation<Theme>>;