Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

chore: migrate to FormSubmitButton from metabase/forms (#75709)

Uladzimir Havenchyk09726c60c728
diff --git a/enterprise/frontend/src/metabase-enterprise/advanced_permissions/components/ImpersonationModal/ImpersonationModalView.tsx b/enterprise/frontend/src/metabase-enterprise/advanced_permissions/components/ImpersonationModal/ImpersonationModalView.tsx
index 2e9e8efd27e..96593b0abf3 100644
--- a/enterprise/frontend/src/metabase-enterprise/advanced_permissions/components/ImpersonationModal/ImpersonationModalView.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/advanced_permissions/components/ImpersonationModal/ImpersonationModalView.tsx
@@ -6,11 +6,15 @@ import { Alert } from "metabase/common/components/Alert";
import { ExternalLink } from "metabase/common/components/ExternalLink/ExternalLink";
import { FormErrorMessage } from "metabase/common/components/FormErrorMessage";
import { FormFooter } from "metabase/common/components/FormFooter";
-import { FormSubmitButton } from "metabase/common/components/FormSubmitButton";
import { Link } from "metabase/common/components/Link/Link";
import { useDocsUrl } from "metabase/common/hooks";
import CS from "metabase/css/core/index.css";
-import { Form, FormProvider, FormSelect } from "metabase/forms";
+import {
+ Form,
+ FormProvider,
+ FormSelect,
+ FormSubmitButton,
+} from "metabase/forms";
import { Button, Stack, Text } from "metabase/ui";
import * as Errors from "metabase/utils/errors";
import { renderUserAttributesForSelect } from "metabase-enterprise/sandboxes/utils";
@@ -129,7 +133,11 @@ export const ImpersonationModalView = ({
<FormFooter hasTopBorder>
<FormErrorMessage inline />
<Button type="button" onClick={onCancel}>{t`Cancel`}</Button>
- <FormSubmitButton title={t`Save`} disabled={!isValid} primary />
+ <FormSubmitButton
+ label={t`Save`}
+ disabled={!isValid}
+ variant="filled"
+ />
</FormFooter>
</Form>
)}
diff --git a/frontend/src/metabase/actions/components/ActionForm/ActionForm.tsx b/frontend/src/metabase/actions/components/ActionForm/ActionForm.tsx
index 41e7bc1ebee..9b67d1b13b9 100644
--- a/frontend/src/metabase/actions/components/ActionForm/ActionForm.tsx
+++ b/frontend/src/metabase/actions/components/ActionForm/ActionForm.tsx
@@ -8,8 +8,7 @@ import {
getSubmitButtonLabel,
} from "metabase/actions/utils";
import { FormErrorMessage } from "metabase/common/components/FormErrorMessage";
-import { FormSubmitButton } from "metabase/common/components/FormSubmitButton";
-import { Form, FormProvider } from "metabase/forms";
+import { Form, FormProvider, FormSubmitButton } from "metabase/forms";
import { Button, Flex } from "metabase/ui";
import type {
ActionFormInitialValues,
@@ -31,6 +30,8 @@ interface ActionFormProps {
// and they will be submitted together in batch.
hiddenFields?: ParameterId[];
+ submitButtonFullWidth?: boolean;
+
onSubmit: (
parameters: ParametersForActionExecution,
actions: FormikHelpers<ParametersForActionExecution>,
@@ -42,6 +43,7 @@ function ActionForm({
action,
initialValues: rawInitialValues = {},
hiddenFields = [],
+ submitButtonFullWidth,
onSubmit,
onClose,
}: ActionFormProps): JSX.Element {
@@ -56,14 +58,6 @@ function ActionForm({
[form, hiddenFields],
);
- const submitButtonProps = useMemo(() => {
- const variant = getSubmitButtonColor(action);
- return {
- title: getSubmitButtonLabel(action),
- [variant]: true,
- };
- }, [action]);
-
const handleSubmit = useCallback(
(
values: ParametersForActionExecution,
@@ -88,7 +82,12 @@ function ActionForm({
{onClose && (
<Button type="button" onClick={onClose}>{t`Cancel`}</Button>
)}
- <FormSubmitButton {...submitButtonProps} />
+ <FormSubmitButton
+ label={getSubmitButtonLabel(action)}
+ variant="filled"
+ color={getSubmitButtonColor(action)}
+ fullWidth={submitButtonFullWidth}
+ />
</Flex>
<FormErrorMessage />
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/CreateActionForm/CreateActionForm.tsx b/frontend/src/metabase/actions/containers/ActionCreator/CreateActionForm/CreateActionForm.tsx
index c25ecd43cb3..bfc770adfd3 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/CreateActionForm/CreateActionForm.tsx
+++ b/frontend/src/metabase/actions/containers/ActionCreator/CreateActionForm/CreateActionForm.tsx
@@ -7,9 +7,8 @@ import type { CreateQueryActionParams } from "metabase/actions/types";
import { FormErrorMessage } from "metabase/common/components/FormErrorMessage";
import { FormFooter } from "metabase/common/components/FormFooter";
import { FormInput } from "metabase/common/components/FormInput";
-import { FormSubmitButton } from "metabase/common/components/FormSubmitButton";
import { FormTextArea } from "metabase/common/components/FormTextArea";
-import { Form, FormProvider } from "metabase/forms";
+import { Form, FormProvider, FormSubmitButton } from "metabase/forms";
import { Button } from "metabase/ui";
import * as Errors from "metabase/utils/errors";
@@ -74,7 +73,11 @@ function CreateActionForm({
{!!onCancel && (
<Button type="button" onClick={onCancel}>{t`Cancel`}</Button>
)}
- <FormSubmitButton title={t`Create`} disabled={!isValid} primary />
+ <FormSubmitButton
+ label={t`Create`}
+ disabled={!isValid}
+ variant="filled"
+ />
</FormFooter>
</Form>
)}
diff --git a/frontend/src/metabase/actions/utils.ts b/frontend/src/metabase/actions/utils.ts
index 47144aa1ee4..614944b76ac 100644
--- a/frontend/src/metabase/actions/utils.ts
+++ b/frontend/src/metabase/actions/utils.ts
@@ -1,6 +1,8 @@
+import { match } from "ts-pattern";
import { t } from "ttag";
import * as Yup from "yup";
+import type { ButtonProps } from "metabase/ui";
import * as Errors from "metabase/utils/errors";
import type Field from "metabase-lib/v1/metadata/Field";
import { TYPE } from "metabase-lib/v1/types/constants";
@@ -304,11 +306,18 @@ export const getFormValidationSchema = (
return Yup.object(Object.fromEntries(schema));
};
-export const getSubmitButtonColor = (action: WritebackAction): string => {
+export const getSubmitButtonColor = (
+ action: WritebackAction,
+): ButtonProps["color"] => {
if (isImplicitDeleteAction(action)) {
- return "danger";
+ return "error";
}
- return action.visualization_settings?.submitButtonColor ?? "primary";
+
+ return match(action.visualization_settings?.submitButtonColor)
+ .returnType<ButtonProps["color"]>()
+ .with("danger", () => "error")
+ .with("success", "warning", (color) => color)
+ .otherwise(() => "brand");
};
export const getSubmitButtonLabel = (action: WritebackAction): string => {
diff --git a/frontend/src/metabase/auth/components/ForgotPasswordForm/ForgotPasswordForm.tsx b/frontend/src/metabase/auth/components/ForgotPasswordForm/ForgotPasswordForm.tsx
index 953e25f90e5..7e0670eefeb 100644
--- a/frontend/src/metabase/auth/components/ForgotPasswordForm/ForgotPasswordForm.tsx
+++ b/frontend/src/metabase/auth/components/ForgotPasswordForm/ForgotPasswordForm.tsx
@@ -4,8 +4,7 @@ import * as Yup from "yup";
import { FormErrorMessage } from "metabase/common/components/FormErrorMessage";
import { FormInput } from "metabase/common/components/FormInput";
-import { FormSubmitButton } from "metabase/common/components/FormSubmitButton";
-import { Form, FormProvider } from "metabase/forms";
+import { Form, FormProvider, FormSubmitButton } from "metabase/forms";
import { useSelector } from "metabase/redux";
import { getApplicationName } from "metabase/selectors/whitelabel";
import * as Errors from "metabase/utils/errors";
@@ -59,8 +58,8 @@ export const ForgotPasswordForm = ({
autoFocus
/>
<FormSubmitButton
- title={t`Send password reset email`}
- primary
+ label={t`Send password reset email`}
+ variant="filled"
fullWidth
/>
<FormErrorMessage />
diff --git a/frontend/src/metabase/auth/components/ResetPasswordForm/ResetPasswordForm.tsx b/frontend/src/metabase/auth/components/ResetPasswordForm/ResetPasswordForm.tsx
index 50d76c7c430..b06ab5edee3 100644
--- a/frontend/src/metabase/auth/components/ResetPasswordForm/ResetPasswordForm.tsx
+++ b/frontend/src/metabase/auth/components/ResetPasswordForm/ResetPasswordForm.tsx
@@ -5,8 +5,7 @@ import * as Yup from "yup";
import { FormErrorMessage } from "metabase/common/components/FormErrorMessage";
import { FormInput } from "metabase/common/components/FormInput";
-import { FormSubmitButton } from "metabase/common/components/FormSubmitButton";
-import { Form, FormProvider } from "metabase/forms";
+import { Form, FormProvider, FormSubmitButton } from "metabase/forms";
import * as Errors from "metabase/utils/errors";
import { passwordComplexityDescription } from "metabase/utils/password";
@@ -82,7 +81,11 @@ export const ResetPasswordForm = ({
placeholder={t`Shhh... but one more time so we get it right`}
autoComplete="new-password"
/>
- <FormSubmitButton title={t`Save new password`} primary fullWidth />
+ <FormSubmitButton
+ label={t`Save new password`}
+ variant="filled"
+ fullWidth
+ />
<FormErrorMessage />
</Form>
</FormProvider>
diff --git a/frontend/src/metabase/common/collections/components/CreateCollectionForm/CreateCollectionForm.tsx b/frontend/src/metabase/common/collections/components/CreateCollectionForm/CreateCollectionForm.tsx
index e9d7579deea..a925e5c439e 100644
--- a/frontend/src/metabase/common/collections/components/CreateCollectionForm/CreateCollectionForm.tsx
+++ b/frontend/src/metabase/common/collections/components/CreateCollectionForm/CreateCollectionForm.tsx
@@ -10,14 +10,13 @@ import { useInitialCollectionId } from "metabase/common/collections/hooks";
import { FormErrorMessage } from "metabase/common/components/FormErrorMessage";
import { FormFooter } from "metabase/common/components/FormFooter";
import { FormInput } from "metabase/common/components/FormInput";
-import { FormSubmitButton } from "metabase/common/components/FormSubmitButton";
import { FormTextArea } from "metabase/common/components/FormTextArea";
import type {
EntityPickerOptions,
FilterItemsInPersonalCollection,
OmniPickerItem,
} from "metabase/common/components/Pickers";
-import { Form, FormProvider } from "metabase/forms";
+import { Form, FormProvider, FormSubmitButton } from "metabase/forms";
import { PLUGIN_TENANTS } from "metabase/plugins";
import { Button, Flex } from "metabase/ui";
import * as Errors from "metabase/utils/errors";
@@ -162,7 +161,11 @@ function CreateCollectionForm({
{!!onCancel && (
<Button type="button" onClick={onCancel}>{t`Cancel`}</Button>
)}
- <FormSubmitButton title={t`Create`} disabled={!dirty} primary />
+ <FormSubmitButton
+ label={t`Create`}
+ disabled={!dirty}
+ variant="filled"
+ />
</Flex>
</FormFooter>
</Form>
diff --git a/frontend/src/metabase/common/components/FormSubmitButton/FormSubmitButton.tsx b/frontend/src/metabase/common/components/FormSubmitButton/FormSubmitButton.tsx
deleted file mode 100644
index 59a923f83d7..00000000000
--- a/frontend/src/metabase/common/components/FormSubmitButton/FormSubmitButton.tsx
+++ /dev/null
@@ -1,65 +0,0 @@
-import type { Ref } from "react";
-import { forwardRef } from "react";
-import { t } from "ttag";
-
-import type { ButtonProps } from "metabase/common/components/Button";
-import { Button } from "metabase/common/components/Button";
-import type { FormStatus } from "metabase/forms";
-import { useFormSubmitButton } from "metabase/forms";
-
-export interface FormSubmitButtonProps extends Omit<ButtonProps, "children"> {
- title?: string;
- activeTitle?: string;
- successTitle?: string;
- failedTitle?: string;
-}
-
-/**
- * @deprecated: use FormSubmitButton from "metabase/forms"
- */
-const FormSubmitButtonInner = forwardRef(function FormSubmitButton(
- { primary, success, danger, disabled, ...props }: FormSubmitButtonProps,
- ref: Ref<HTMLButtonElement>,
-) {
- const { status, isDisabled } = useFormSubmitButton({ isDisabled: disabled });
- const submitTitle = getSubmitButtonTitle(status, props);
-
- return (
- <Button
- {...props}
- ref={ref}
- type="submit"
- primary={primary && !isDisabled}
- success={success || status === "fulfilled"}
- danger={danger || status === "rejected"}
- disabled={isDisabled}
- >
- {submitTitle}
- </Button>
- );
-});
-
-const getSubmitButtonTitle = (
- status: FormStatus | undefined,
- {
- title = t`Submit`,
- activeTitle = title,
- successTitle = t`Success`,
- failedTitle = t`Failed`,
- }: FormSubmitButtonProps,
-) => {
- switch (status) {
- case "pending":
- return activeTitle;
- case "fulfilled":
- return successTitle;
- case "rejected":
- return failedTitle;
- default:
- return title;
- }
-};
-
-export const FormSubmitButton = Object.assign(FormSubmitButtonInner, {
- Button: Button.Root,
-});
diff --git a/frontend/src/metabase/common/components/FormSubmitButton/index.ts b/frontend/src/metabase/common/components/FormSubmitButton/index.ts
deleted file mode 100644
index b99c09f9a0d..00000000000
--- a/frontend/src/metabase/common/components/FormSubmitButton/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export { FormSubmitButton } from "./FormSubmitButton";
-export type { FormSubmitButtonProps } from "./FormSubmitButton";
diff --git a/frontend/src/metabase/public/containers/PublicAction/PublicAction.styled.tsx b/frontend/src/metabase/public/containers/PublicAction/PublicAction.styled.tsx
index 98f1518fef6..d75b2eb97cf 100644
--- a/frontend/src/metabase/public/containers/PublicAction/PublicAction.styled.tsx
+++ b/frontend/src/metabase/public/containers/PublicAction/PublicAction.styled.tsx
@@ -3,7 +3,6 @@ import { css } from "@emotion/react";
// eslint-disable-next-line no-restricted-imports
import styled from "@emotion/styled";
-import { FormSubmitButton } from "metabase/common/components/FormSubmitButton";
import { LoadingAndErrorWrapper as BaseLoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
import { breakpointMaxSmall } from "metabase/styled-components/theme";
@@ -25,10 +24,6 @@ export const FormContainer = styled.div`
flex-direction: column;
width: 430px;
- ${FormSubmitButton.Button} {
- width: 100%;
- }
-
${breakpointMaxSmall} {
width: 100%;
padding: 0 0.5rem;
diff --git a/frontend/src/metabase/public/containers/PublicAction/PublicAction.tsx b/frontend/src/metabase/public/containers/PublicAction/PublicAction.tsx
index 0d427af8cf3..5c64152531b 100644
--- a/frontend/src/metabase/public/containers/PublicAction/PublicAction.tsx
+++ b/frontend/src/metabase/public/containers/PublicAction/PublicAction.tsx
@@ -54,7 +54,11 @@ function PublicAction({ action, publicId, onError }: Props) {
return (
<FormContainer>
<FormTitle>{action.name}</FormTitle>
- <ActionForm action={action} onSubmit={handleSubmit} />
+ <ActionForm
+ action={action}
+ submitButtonFullWidth
+ onSubmit={handleSubmit}
+ />
</FormContainer>
);
}
diff --git a/frontend/src/metabase/setup/components/InviteUserForm/InviteUserForm.tsx b/frontend/src/metabase/setup/components/InviteUserForm/InviteUserForm.tsx
index ea6be7eeffa..f298b0c3905 100644
--- a/frontend/src/metabase/setup/components/InviteUserForm/InviteUserForm.tsx
+++ b/frontend/src/metabase/setup/components/InviteUserForm/InviteUserForm.tsx
@@ -3,8 +3,7 @@ import { t } from "ttag";
import * as Yup from "yup";
import { FormInput } from "metabase/common/components/FormInput";
-import { FormSubmitButton } from "metabase/common/components/FormSubmitButton";
-import { Form, FormProvider } from "metabase/forms";
+import { Form, FormProvider, FormSubmitButton } from "metabase/forms";
import type { InviteInfo, UserInfo } from "metabase/redux/store";
import * as Errors from "metabase/utils/errors";
@@ -67,7 +66,7 @@ export const InviteUserForm = ({
title={t`Email`}
placeholder={"[email protected]"}
/>
- <FormSubmitButton title={t`Send invitation`} primary />
+ <FormSubmitButton label={t`Send invitation`} variant="filled" />
</Form>
</FormProvider>
);
diff --git a/frontend/src/metabase/setup/components/LicenseTokenStep/LicenseTokenForm.tsx b/frontend/src/metabase/setup/components/LicenseTokenStep/LicenseTokenForm.tsx
index 3d87318f79d..89c90e0afd6 100644
--- a/frontend/src/metabase/setup/components/LicenseTokenStep/LicenseTokenForm.tsx
+++ b/frontend/src/metabase/setup/components/LicenseTokenStep/LicenseTokenForm.tsx
@@ -1,12 +1,12 @@
import { c, t } from "ttag";
import { ExternalLink } from "metabase/common/components/ExternalLink";
-import { FormSubmitButton } from "metabase/common/components/FormSubmitButton";
import { useStoreUrl } from "metabase/common/hooks";
import {
Form,
FormErrorMessage,
FormProvider,
+ FormSubmitButton,
FormTextInput,
} from "metabase/forms";
import {
@@ -94,10 +94,10 @@ export const LicenseTokenForm = ({
</Box>
<Flex gap="sm">
<FormSubmitButton
- title={t`Activate`}
- activeTitle={t`Activating`}
+ label={t`Activate`}
+ activeLabel={t`Activating`}
disabled={!!errors.license_token}
- primary
+ variant="filled"
/>
</Flex>
<Divider mx={{ base: "-2rem", sm: "-4rem" }} mt="xl" mb="md" />
diff --git a/frontend/src/metabase/setup/components/UserForm/UserForm.tsx b/frontend/src/metabase/setup/components/UserForm/UserForm.tsx
index 9a599bfe675..514191d73ea 100644
--- a/frontend/src/metabase/setup/components/UserForm/UserForm.tsx
+++ b/frontend/src/metabase/setup/components/UserForm/UserForm.tsx
@@ -4,9 +4,8 @@ import _ from "underscore";
import * as Yup from "yup";
import { FormInput } from "metabase/common/components/FormInput";
-import { FormSubmitButton } from "metabase/common/components/FormSubmitButton";
import { useValidatePassword } from "metabase/common/hooks";
-import { Form, FormProvider, useFormSubmitButton } from "metabase/forms";
+import { Form, FormProvider, FormSubmitButton } from "metabase/forms";
import type { UserInfo } from "metabase/redux/store";
import { Flex } from "metabase/ui";
import * as Errors from "metabase/utils/errors";
@@ -98,22 +97,14 @@ export const UserForm = ({ user, isHosted, onSubmit }: UserFormProps) => {
title={t`Confirm your password`}
placeholder={t`Shhh... but one more time so we get it right`}
/>
- <UserFormSubmitButton />
+ <Flex align="center">
+ <FormSubmitButton
+ label={t`Next`}
+ activeLabel={t`Saving`}
+ variant="filled"
+ />
+ </Flex>
</Form>
</FormProvider>
);
};
-
-const UserFormSubmitButton = () => {
- const { status } = useFormSubmitButton({ isDisabled: false });
-
- return (
- <Flex align="center">
- <FormSubmitButton
- title={t`Next`}
- activeTitle={t`Saving`}
- primary={status === "idle"}
- />
- </Flex>
- );
-};
diff --git a/frontend/src/metabase/timelines/common/components/TimelineForm/TimelineForm.tsx b/frontend/src/metabase/timelines/common/components/TimelineForm/TimelineForm.tsx
index 395f47948de..aa1d7b4e95b 100644
--- a/frontend/src/metabase/timelines/common/components/TimelineForm/TimelineForm.tsx
+++ b/frontend/src/metabase/timelines/common/components/TimelineForm/TimelineForm.tsx
@@ -4,10 +4,9 @@ import * as Yup from "yup";
import { FormErrorMessage } from "metabase/common/components/FormErrorMessage";
import { FormInput } from "metabase/common/components/FormInput";
-import { FormSubmitButton } from "metabase/common/components/FormSubmitButton";
import { FormTextArea } from "metabase/common/components/FormTextArea";
import { getTimelineIcons } from "metabase/common/utils/timelines";
-import { Form, FormProvider } from "metabase/forms";
+import { Form, FormProvider, FormSubmitButton } from "metabase/forms";
import { Button } from "metabase/ui";
import * as Errors from "metabase/utils/errors";
import type { TimelineData } from "metabase-types/api";
@@ -66,9 +65,9 @@ const TimelineForm = ({
{t`Cancel`}
</Button>
<FormSubmitButton
- title={isNew ? t`Create` : t`Update`}
+ label={isNew ? t`Create` : t`Update`}
disabled={!dirty}
- primary
+ variant="filled"
/>
</TimelineFormFooter>
</Form>