Skip to content

chore(site): replace custom LoadingButton from the one in MUI #10351

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 9 commits into from
Oct 20, 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
5 changes: 1 addition & 4 deletions site/src/components/Dialogs/Dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import MuiDialog, { DialogProps as MuiDialogProps } from "@mui/material/Dialog";
import { type ReactNode } from "react";
import { colors } from "theme/colors";
import {
LoadingButton,
LoadingButtonProps,
} from "../LoadingButton/LoadingButton";
import { ConfirmDialogType } from "./types";
import { type Interpolation, type Theme } from "@emotion/react";
import LoadingButton, { LoadingButtonProps } from "@mui/lab/LoadingButton";

export interface DialogActionButtonsProps {
/** Text to display in the cancel button */
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/FormFooter/FormFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Button from "@mui/material/Button";
import { type FC } from "react";
import { LoadingButton } from "../LoadingButton/LoadingButton";
import { Interpolation, Theme } from "@emotion/react";
import LoadingButton from "@mui/lab/LoadingButton";

export const Language = {
cancelLabel: "Cancel",
Expand Down
25 changes: 0 additions & 25 deletions site/src/components/LoadingButton/LoadingButton.stories.tsx

This file was deleted.

25 changes: 0 additions & 25 deletions site/src/components/LoadingButton/LoadingButton.tsx

This file was deleted.

7 changes: 4 additions & 3 deletions site/src/pages/CreateWorkspacePage/ExternalAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import Button from "@mui/material/Button";
import FormHelperText from "@mui/material/FormHelperText";
import Tooltip from "@mui/material/Tooltip";
import { type FC } from "react";
import { LoadingButton } from "components/LoadingButton/LoadingButton";
import { Stack } from "components/Stack/Stack";
import { type ExternalAuthPollingState } from "./CreateWorkspacePage";
import LoadingButton from "@mui/lab/LoadingButton";

export interface ExternalAuthProps {
displayName: string;
Expand Down Expand Up @@ -34,6 +34,7 @@ export const ExternalAuth: FC<ExternalAuthProps> = (props) => {
>
<Stack alignItems="center" spacing={1}>
<LoadingButton
loadingPosition="start"
loading={externalAuthPollingState === "polling"}
href={authenticateURL}
variant="contained"
Expand All @@ -42,8 +43,8 @@ export const ExternalAuth: FC<ExternalAuthProps> = (props) => {
<img
src={displayIcon}
alt={`${displayName} Icon`}
width={24}
height={24}
width={16}
height={16}
/>
}
disabled={authenticated}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Link } from "react-router-dom";
import useWindowSize from "react-use/lib/useWindowSize";
import MuiLink from "@mui/material/Link";
import Tooltip from "@mui/material/Tooltip";
import { LoadingButton } from "components/LoadingButton/LoadingButton";
import LoadingButton from "@mui/lab/LoadingButton";

type Props = {
showConfetti: boolean;
Expand Down Expand Up @@ -72,6 +72,7 @@ const LicensesSettingsPageView: FC<Props> = ({
</Button>
<Tooltip title="Refresh license entitlements. This is done automatically every 10 minutes.">
<LoadingButton
loadingPosition="start"
loading={isRefreshing}
onClick={refreshEntitlements}
startIcon={<RefreshIcon />}
Expand Down
3 changes: 2 additions & 1 deletion site/src/pages/GroupsPage/GroupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { AvatarData } from "components/AvatarData/AvatarData";
import { DeleteDialog } from "components/Dialogs/DeleteDialog/DeleteDialog";
import { EmptyState } from "components/EmptyState/EmptyState";
import { Loader } from "components/Loader/Loader";
import { LoadingButton } from "components/LoadingButton/LoadingButton";
import { Margins } from "components/Margins/Margins";
import {
PageHeader,
Expand Down Expand Up @@ -44,6 +43,7 @@ import {
} from "api/queries/groups";
import { displayError, displaySuccess } from "components/GlobalSnackbar/utils";
import { getErrorMessage } from "api/errors";
import LoadingButton from "@mui/lab/LoadingButton";

export const GroupPage: FC = () => {
const { groupId } = useParams() as { groupId: string };
Expand Down Expand Up @@ -235,6 +235,7 @@ const AddGroupMember: React.FC<{
/>

<LoadingButton
loadingPosition="start"
disabled={!selectedUser}
type="submit"
startIcon={<PersonAdd />}
Expand Down
4 changes: 2 additions & 2 deletions site/src/pages/LoginPage/PasswordSignInForm.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Stack } from "components/Stack/Stack";
import TextField from "@mui/material/TextField";
import { getFormHelpers, onChangeTrimmed } from "utils/formUtils";
import { LoadingButton } from "components/LoadingButton/LoadingButton";
import { Language } from "./SignInForm";
import { FormikContextType, FormikTouched, useFormik } from "formik";
import * as Yup from "yup";
import { FC } from "react";
import { BuiltInAuthFormValues } from "./SignInForm.types";
import LoadingButton from "@mui/lab/LoadingButton";

type PasswordSignInFormProps = {
onSubmit: (credentials: { email: string; password: string }) => void;
Expand Down Expand Up @@ -66,7 +66,7 @@ export const PasswordSignInForm: FC<PasswordSignInFormProps> = ({
fullWidth
type="submit"
>
{isSigningIn ? "" : Language.passwordSignIn}
{Language.passwordSignIn}
</LoadingButton>
</div>
</Stack>
Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/SetupPage/SetupPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Box from "@mui/material/Box";
import Checkbox from "@mui/material/Checkbox";
import TextField from "@mui/material/TextField";
import Typography from "@mui/material/Typography";
import { LoadingButton } from "components/LoadingButton/LoadingButton";
import { SignInLayout } from "components/SignInLayout/SignInLayout";
import { Stack } from "components/Stack/Stack";
import { Welcome } from "components/Welcome/Welcome";
Expand All @@ -14,6 +13,7 @@ import {
} from "utils/formUtils";
import * as Yup from "yup";
import type * as TypesGen from "api/typesGenerated";
import LoadingButton from "@mui/lab/LoadingButton";

export const Language = {
emailLabel: "Email",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type {
import { AvatarData } from "components/AvatarData/AvatarData";
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne";
import { EmptyState } from "components/EmptyState/EmptyState";
import { LoadingButton } from "components/LoadingButton/LoadingButton";
import { Stack } from "components/Stack/Stack";
import { TableLoader } from "components/TableLoader/TableLoader";
import { TableRowMenu } from "components/TableRowMenu/TableRowMenu";
Expand All @@ -30,6 +29,7 @@ import { type FC, useState } from "react";
import { GroupAvatar } from "components/GroupAvatar/GroupAvatar";
import { getGroupSubtitle } from "utils/groups";
import { PageHeader, PageHeaderTitle } from "components/PageHeader/PageHeader";
import LoadingButton from "@mui/lab/LoadingButton";

type AddTemplateUserOrGroupProps = {
organizationId: string;
Expand Down Expand Up @@ -108,6 +108,7 @@ const AddTemplateUserOrGroup: React.FC<AddTemplateUserOrGroupProps> = ({
</Select>

<LoadingButton
loadingPosition="start"
disabled={!selectedRole || !selectedOption}
type="submit"
startIcon={<PersonAdd />}
Expand Down
5 changes: 2 additions & 3 deletions site/src/pages/UserSettingsPage/AccountPage/AccountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
nameValidator,
onChangeTrimmed,
} from "utils/formUtils";
import { LoadingButton } from "components/LoadingButton/LoadingButton";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { Form, FormFields } from "components/Form/Form";
import { UpdateUserProfileRequest } from "api/typesGenerated";
import LoadingButton from "@mui/lab/LoadingButton";

export const Language = {
usernameLabel: "Username",
Expand Down Expand Up @@ -76,12 +76,11 @@ export const AccountForm: FC<AccountFormProps> = ({
<div>
<LoadingButton
loading={isLoading}
aria-disabled={!editable}
disabled={!editable}
type="submit"
variant="contained"
>
{isLoading ? "" : Language.updateSettings}
{Language.updateSettings}
</LoadingButton>
</div>
</FormFields>
Expand Down
4 changes: 2 additions & 2 deletions site/src/pages/UserSettingsPage/SchedulePage/ScheduleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { FormikContextType, useFormik } from "formik";
import { FC, useEffect, useState } from "react";
import * as Yup from "yup";
import { getFormHelpers } from "utils/formUtils";
import { LoadingButton } from "components/LoadingButton/LoadingButton";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { Form, FormFields } from "components/Form/Form";
import {
Expand All @@ -15,6 +14,7 @@ import { Stack } from "components/Stack/Stack";
import { timeZones, getPreferredTimezone } from "utils/timeZones";
import { Alert } from "components/Alert/Alert";
import { timeToCron, quietHoursDisplay, validTime } from "utils/schedule";
import LoadingButton from "@mui/lab/LoadingButton";

export interface ScheduleFormValues {
time: string;
Expand Down Expand Up @@ -130,7 +130,7 @@ export const ScheduleForm: FC<React.PropsWithChildren<ScheduleFormProps>> = ({
type="submit"
variant="contained"
>
{!isLoading && "Update schedule"}
Update schedule
</LoadingButton>
</div>
</FormFields>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ErrorAlert } from "components/Alert/ErrorAlert";
import { Form, FormFields } from "components/Form/Form";
import { Alert } from "components/Alert/Alert";
import { getFormHelpers } from "utils/formUtils";
import { LoadingButton } from "components/LoadingButton/LoadingButton";
import LoadingButton from "@mui/lab/LoadingButton";

interface SecurityFormValues {
old_password: string;
Expand Down Expand Up @@ -107,7 +107,7 @@ export const SecurityForm: FC<SecurityFormProps> = ({
type="submit"
variant="contained"
>
{isLoading ? "" : Language.updatePassword}
{Language.updatePassword}
</LoadingButton>
</div>
</FormFields>
Expand Down
27 changes: 9 additions & 18 deletions site/src/pages/WorkspacePage/WorkspaceActions/Buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import CloudQueueIcon from "@mui/icons-material/CloudQueue";
import CropSquareIcon from "@mui/icons-material/CropSquare";
import PlayCircleOutlineIcon from "@mui/icons-material/PlayCircleOutline";
import ReplayIcon from "@mui/icons-material/Replay";
import { LoadingButton } from "components/LoadingButton/LoadingButton";
import { FC } from "react";
import BlockOutlined from "@mui/icons-material/BlockOutlined";
import ButtonGroup from "@mui/material/ButtonGroup";
import { Workspace, WorkspaceBuildParameter } from "api/typesGenerated";
import { BuildParametersPopover } from "./BuildParametersPopover";
import PowerSettingsNewIcon from "@mui/icons-material/PowerSettingsNew";
import LoadingButton from "@mui/lab/LoadingButton";

interface WorkspaceAction {
loading?: boolean;
Expand All @@ -24,13 +24,12 @@ export const UpdateButton: FC<WorkspaceAction> = ({
return (
<LoadingButton
loading={loading}
loadingIndicator={<>Updating&hellip;</>}
loadingPosition="start"
data-testid="workspace-update-button"
startIcon={<CloudQueueIcon />}
onClick={handleAction}
>
Update&hellip;
{loading ? <>Updating&hellip;</> : <>Update&hellip;</>}
</LoadingButton>
);
};
Expand All @@ -42,12 +41,11 @@ export const ActivateButton: FC<WorkspaceAction> = ({
return (
<LoadingButton
loading={loading}
loadingIndicator={<>Activating&hellip;</>}
loadingPosition="start"
startIcon={<PowerSettingsNewIcon />}
onClick={handleAction}
>
Activate
{loading ? <>Activating&hellip;</> : "Activate"}
</LoadingButton>
);
};
Expand All @@ -70,12 +68,11 @@ export const StartButton: FC<
>
<LoadingButton
loading={loading}
loadingIndicator={<>Starting&hellip;</>}
loadingPosition="start"
startIcon={<PlayCircleOutlineIcon />}
onClick={() => handleAction()}
>
Start
{loading ? <>Starting&hellip;</> : "Start"}
</LoadingButton>
<BuildParametersPopover
workspace={workspace}
Expand All @@ -90,13 +87,12 @@ export const StopButton: FC<WorkspaceAction> = ({ handleAction, loading }) => {
return (
<LoadingButton
loading={loading}
loadingIndicator={<>Stopping&hellip;</>}
loadingPosition="start"
startIcon={<CropSquareIcon />}
onClick={handleAction}
data-testid="workspace-stop-button"
>
Stop
{loading ? <>Stopping&hellip;</> : "Stop"}
</LoadingButton>
);
};
Expand All @@ -119,13 +115,12 @@ export const RestartButton: FC<
>
<LoadingButton
loading={loading}
loadingIndicator={<>Restarting&hellip;</>}
loadingPosition="start"
startIcon={<ReplayIcon />}
onClick={() => handleAction()}
data-testid="workspace-restart-button"
>
Restart&hellip;
{loading ? <>Restarting&hellip;</> : <>Restart&hellip;</>}
</LoadingButton>
<BuildParametersPopover
workspace={workspace}
Expand Down Expand Up @@ -162,12 +157,8 @@ interface LoadingProps {

export const ActionLoadingButton: FC<LoadingProps> = ({ label }) => {
return (
<LoadingButton
loading
loadingPosition="start"
loadingIndicator={label}
// This icon can be anything
startIcon={<ReplayIcon />}
/>
<LoadingButton loading loadingPosition="start" startIcon={<ReplayIcon />}>
{label}
</LoadingButton>
);
};
6 changes: 6 additions & 0 deletions site/src/theme/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ dark = createTheme(dark, {
},
},
},
MuiLoadingButton: {
defaultProps: {
variant: "outlined",
color: "neutral",
},
},
MuiTableContainer: {
styleOverrides: {
root: {
Expand Down