The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Gdgt 2587 2581 replace deprecated numericinput components (#77117)
Egor Grushinfe6bc8a40871
diff --git a/e2e/test/scenarios/actions/actions-on-dashboards.cy.spec.js b/e2e/test/scenarios/actions/actions-on-dashboards.cy.spec.jsindex 326bd05298b..9de4f12aa36 100644--- a/e2e/test/scenarios/actions/actions-on-dashboards.cy.spec.js+++ b/e2e/test/scenarios/actions/actions-on-dashboards.cy.spec.js@@ -618,14 +618,14 @@ const MODEL_NAME = "Test Action Model";changeValue({fieldName: "Integer",- fieldType: "number",+ fieldType: "text",oldValue: oldRow.integer,newValue: 123,});changeValue({fieldName: "Float",- fieldType: "number",+ fieldType: "text",oldValue: oldRow.float,newValue: 2.2,});diff --git a/e2e/test/scenarios/actions/model-actions.cy.spec.js b/e2e/test/scenarios/actions/model-actions.cy.spec.jsindex 4af990f1807..ecab205a9d8 100644--- a/e2e/test/scenarios/actions/model-actions.cy.spec.js+++ b/e2e/test/scenarios/actions/model-actions.cy.spec.js@@ -280,10 +280,10 @@ describe(cy.button(actionName).click();cy.wait("@executeAction");- cy.findByLabelText("User ID").should("not.exist");- cy.findByLabelText(- 'User ID: This value does not exist in table "people".',- ).should("exist");+ cy.findByLabelText("User ID").should("exist");+ cy.findByText('This value does not exist in table "people".').should(+ "exist",+ );cy.findByText("Unable to update the record.").should("exist");});diff --git a/frontend/src/metabase/actions/components/ActionForm/ActionForm.unit.spec.tsx b/frontend/src/metabase/actions/components/ActionForm/ActionForm.unit.spec.tsxindex d9159f9411a..15a2079a0a3 100644--- a/frontend/src/metabase/actions/components/ActionForm/ActionForm.unit.spec.tsx+++ b/frontend/src/metabase/actions/components/ActionForm/ActionForm.unit.spec.tsx@@ -117,7 +117,7 @@ describe("Actions > ActionForm", () => {expect(screen.getByLabelText(/form field name/i, { selector: "input" }),- ).toHaveAttribute("type", "number");+ ).toHaveAttribute("inputmode", "decimal");});it("displays a textarea input", () => {diff --git a/frontend/src/metabase/actions/components/ActionFormFieldWidget/ActionFormFieldWidget.tsx b/frontend/src/metabase/actions/components/ActionFormFieldWidget/ActionFormFieldWidget.tsxindex 28343b2ce01..37680c85f1c 100644--- a/frontend/src/metabase/actions/components/ActionFormFieldWidget/ActionFormFieldWidget.tsx+++ b/frontend/src/metabase/actions/components/ActionFormFieldWidget/ActionFormFieldWidget.tsx@@ -3,12 +3,12 @@ import { forwardRef } from "react";import type { ActionFormFieldProps } from "metabase/actions/types";import { FormInput as FormInputWidget } from "metabase/common/components/FormInput";-import { FormNumericInput as FormNumericInputWidget } from "metabase/common/components/FormNumericInput";import { FormToggle as FormBooleanWidget } from "metabase/common/components/FormToggle";import { FormRadioGroup, type FormRadioGroupProps } from "metabase/forms";import { Radio, Stack } from "metabase/ui";import type { InputComponentType } from "metabase-types/api";+import { FormNumberInputWidget } from "./FormNumberInputWidget";import { FormSelectWidget } from "./FormSelectWidget";import { FormTextareaWidget } from "./FormTextareaWidget";@@ -49,7 +49,7 @@ const WIDGETS: Record<InputComponentType, FunctionComponent<any>> = {time: FormInputWidget,"datetime-local": FormInputWidget,textarea: FormTextareaWidget,- number: FormNumericInputWidget,+ number: FormNumberInputWidget,boolean: FormBooleanWidget,radio: VerticalRadio,select: FormSelectWidget,diff --git a/frontend/src/metabase/actions/components/ActionFormFieldWidget/FormNumberInputWidget.tsx b/frontend/src/metabase/actions/components/ActionFormFieldWidget/FormNumberInputWidget.tsxnew file mode 100644index 00000000000..8af764f9bb3--- /dev/null+++ b/frontend/src/metabase/actions/components/ActionFormFieldWidget/FormNumberInputWidget.tsx@@ -0,0 +1,48 @@+import type { ReactNode, Ref } from "react";+import { forwardRef } from "react";++import type { ActionFormFieldProps } from "metabase/actions/types";+import { useUniqueId } from "metabase/common/hooks/use-unique-id";+import { FormField, FormNumberInput } from "metabase/forms";++type FormNumberInputWidgetProps = ActionFormFieldProps & {+ actions?: ReactNode;+ disabled?: boolean;+ nullable?: boolean;+};++export const FormNumberInputWidget = forwardRef(function FormNumberInputWidget(+ {+ name,+ title,+ description,+ actions,+ optional,+ nullable,+ disabled,+ placeholder,+ }: FormNumberInputWidgetProps,+ ref: Ref<HTMLInputElement>,+) {+ const id = useUniqueId();++ return (+ <FormField+ title={title}+ actions={actions}+ description={description}+ optional={optional}+ htmlFor={id}+ >+ <FormNumberInput+ ref={ref}+ id={id}+ name={name}+ nullable={nullable}+ disabled={disabled}+ placeholder={placeholder}+ size="sm"+ />+ </FormField>+ );+});diff --git a/frontend/src/metabase/actions/containers/ActionParametersInputForm/ActionParametersInputForm.unit.spec.tsx b/frontend/src/metabase/actions/containers/ActionParametersInputForm/ActionParametersInputForm.unit.spec.tsxindex a0ffb124ea7..672c353fcd8 100644--- a/frontend/src/metabase/actions/containers/ActionParametersInputForm/ActionParametersInputForm.unit.spec.tsx+++ b/frontend/src/metabase/actions/containers/ActionParametersInputForm/ActionParametersInputForm.unit.spec.tsx@@ -140,7 +140,7 @@ describe("Actions > ActionParametersInputForm", () => {);expect(screen.getByPlaceholderText("Parameter 2")).toHaveAttribute("type",- "number",+ "text",);});diff --git a/frontend/src/metabase/common/components/FormNumericInput/FormNumericInput.stories.tsx b/frontend/src/metabase/common/components/FormNumericInput/FormNumericInput.stories.tsxdeleted file mode 100644index 970f985d0e5..00000000000--- a/frontend/src/metabase/common/components/FormNumericInput/FormNumericInput.stories.tsx+++ /dev/null@@ -1,40 +0,0 @@-import type { StoryFn } from "@storybook/react";--import { Form, FormProvider } from "metabase/forms";--import { FormNumericInput } from "./FormNumericInput";--export default {- title: "Components/Ask Before Using/FormNumericInput",- component: FormNumericInput,-};--const Template: StoryFn<typeof FormNumericInput> = (args) => {- const initialValues = { value: undefined };- const handleSubmit = () => undefined;-- return (- <FormProvider initialValues={initialValues} onSubmit={handleSubmit}>- <Form>- <FormNumericInput {...args} name="value" />- </Form>- </FormProvider>- );-};--export const Default = {- render: Template,-- args: {- title: "Title",- },-};--export const WithDescription = {- render: Template,-- args: {- title: "Title",- description: "Description",- },-};diff --git a/frontend/src/metabase/common/components/FormNumericInput/FormNumericInput.tsx b/frontend/src/metabase/common/components/FormNumericInput/FormNumericInput.tsxdeleted file mode 100644index 89130aeabad..00000000000--- a/frontend/src/metabase/common/components/FormNumericInput/FormNumericInput.tsx+++ /dev/null@@ -1,73 +0,0 @@-import { useField } from "formik";-import type { ReactNode, Ref } from "react";-import { forwardRef, useCallback } from "react";--import { FormField } from "metabase/common/components/FormField";-import type { NumericInputProps } from "metabase/common/components/NumericInput";-import { NumericInput } from "metabase/common/components/NumericInput";-import { useUniqueId } from "metabase/common/hooks/use-unique-id";--export interface FormNumericInputProps extends Omit<- NumericInputProps,- "value" | "error" | "fullWidth" | "onChange" | "onBlur"-> {- name: string;- title?: string;- actions?: ReactNode;- description?: ReactNode;- nullable?: boolean;- optional?: boolean;-}--/**- * @deprecated: use FormNumberInput from "metabase/forms"- */-export const FormNumericInput = forwardRef(function FormNumericInput(- {- name,- className,- style,- title,- actions,- description,- nullable,- optional,- ...props- }: FormNumericInputProps,- ref: Ref<HTMLDivElement>,-) {- const id = useUniqueId();- const [{ value, onBlur }, { error, touched }, { setValue }] = useField(name);-- const handleChange = useCallback(- (value: number | undefined) => {- setValue(value === undefined && nullable ? null : value);- },- [nullable, setValue],- );-- return (- <FormField- ref={ref}- className={className}- style={style}- title={title}- actions={actions}- description={description}- htmlFor={id}- error={touched ? error : undefined}- optional={optional}- >- <NumericInput- {...props}- id={id}- name={name}- value={value ?? undefined}- error={touched && error != null}- fullWidth- onChange={handleChange}- onBlur={onBlur}- />- </FormField>- );-});diff --git a/frontend/src/metabase/common/components/FormNumericInput/FormNumericInput.unit.spec.tsx b/frontend/src/metabase/common/components/FormNumericInput/FormNumericInput.unit.spec.tsxdeleted file mode 100644index 098c7b49603..00000000000--- a/frontend/src/metabase/common/components/FormNumericInput/FormNumericInput.unit.spec.tsx+++ /dev/null@@ -1,75 +0,0 @@-import userEvent from "@testing-library/user-event";-import { Form, Formik } from "formik";-import * as Yup from "yup";--import { render, screen, waitFor } from "__support__/ui";--import { FormNumericInput } from "./FormNumericInput";--const TEST_SCHEMA = Yup.object({- value: Yup.number().required("error"),-});--interface TestFormNumericInputProps {- initialValue?: number;- onSubmit: () => void;-}--const TestFormNumericInput = ({- initialValue,- onSubmit,-}: TestFormNumericInputProps) => {- return (- <Formik- initialValues={{ value: initialValue }}- validationSchema={TEST_SCHEMA}- onSubmit={onSubmit}- >- <Form>- <FormNumericInput name="value" title="Label" />- <button type="submit">Submit</button>- </Form>- </Formik>- );-};--describe("FormNumericInput", () => {- it("should use the initial value from the form", () => {- const onSubmit = jest.fn();-- render(<TestFormNumericInput initialValue={10} onSubmit={onSubmit} />);-- expect(screen.getByRole("textbox")).toHaveValue("10");- });-- it("should propagate the changed value to the form", async () => {- const onSubmit = jest.fn();-- render(<TestFormNumericInput onSubmit={onSubmit} />);- await userEvent.type(screen.getByRole("textbox"), "10");- await userEvent.click(screen.getByText("Submit"));-- await waitFor(() => {- const values = { value: 10 };- expect(onSubmit).toHaveBeenCalledWith(values, expect.anything());- });- });-- it("should be referenced by the label", () => {- const onSubmit = jest.fn();-- render(<TestFormNumericInput onSubmit={onSubmit} />);-- expect(screen.getByLabelText("Label")).toBeInTheDocument();- });-- it("should be validated on blur", async () => {- const onSubmit = jest.fn();-- render(<TestFormNumericInput initialValue={10} onSubmit={onSubmit} />);- await userEvent.clear(screen.getByRole("textbox"));- await userEvent.tab();-- expect(await screen.findByText(": error")).toBeInTheDocument();- });-});diff --git a/frontend/src/metabase/common/components/FormNumericInput/index.ts b/frontend/src/metabase/common/components/FormNumericInput/index.tsdeleted file mode 100644index 71a2eec98d8..00000000000--- a/frontend/src/metabase/common/components/FormNumericInput/index.ts+++ /dev/null@@ -1,2 +0,0 @@-export { FormNumericInput } from "./FormNumericInput";-export type { FormNumericInputProps } from "./FormNumericInput";diff --git a/frontend/src/metabase/common/components/NumericInput/NumericInput.stories.tsx b/frontend/src/metabase/common/components/NumericInput/NumericInput.stories.tsxdeleted file mode 100644index 51c65d10c8a..00000000000--- a/frontend/src/metabase/common/components/NumericInput/NumericInput.stories.tsx+++ /dev/null@@ -1,18 +0,0 @@-import type { StoryFn } from "@storybook/react";-import { useState } from "react";--import { NumericInput } from "./NumericInput";--export default {- title: "Components/Ask Before Using/NumericInput",- component: NumericInput,-};--const Template: StoryFn<typeof NumericInput> = (args) => {- const [value, setValue] = useState<number>();- return <NumericInput {...args} value={value} onChange={setValue} />;-};--export const Default = {- render: Template,-};diff --git a/frontend/src/metabase/common/components/NumericInput/NumericInput.tsx b/frontend/src/metabase/common/components/NumericInput/NumericInput.tsxdeleted file mode 100644index 79c1fe59299..00000000000--- a/frontend/src/metabase/common/components/NumericInput/NumericInput.tsx+++ /dev/null@@ -1,71 +0,0 @@-import type { ChangeEvent, FocusEvent, InputHTMLAttributes, Ref } from "react";-import { forwardRef, useCallback, useMemo, useState } from "react";--import { Input } from "metabase/common/components/Input";--export type NumericInputAttributes = Omit<- InputHTMLAttributes<HTMLDivElement>,- "value" | "size" | "onChange"->;--export interface NumericInputProps extends NumericInputAttributes {- value?: number | string;- error?: boolean;- fullWidth?: boolean;- onChange?: (value: number | undefined, inputValue: string) => void;-}--/**- * @deprecated: use NumberInput from "metabase/ui"- */-export const NumericInput = forwardRef(function NumericInput(- { value, onFocus, onBlur, onChange, ...props }: NumericInputProps,- ref: Ref<HTMLDivElement>,-) {- const valueText = useMemo(() => value?.toString() ?? "", [value]);- const [inputText, setInputText] = useState(valueText);- const [isFocused, setIsFocused] = useState(false);-- const handleFocus = useCallback(- (event: FocusEvent<HTMLInputElement>) => {- setIsFocused(true);- setInputText(valueText);- onFocus?.(event);- },- [valueText, onFocus],- );-- const handleBlur = useCallback(- (event: FocusEvent<HTMLInputElement>) => {- setIsFocused(false);- onBlur?.(event);- },- [onBlur],- );-- const handleChange = useCallback(- (event: ChangeEvent<HTMLInputElement>) => {- const newText = event.target.value;- const newValue = parseFloat(newText);- setInputText(newText);-- if (!isNaN(newValue)) {- onChange?.(newValue, newText);- } else {- onChange?.(undefined, newText);- }- },- [onChange],- );-- return (- <Input- {...props}- ref={ref}- value={isFocused ? inputText : valueText}- onFocus={handleFocus}- onBlur={handleBlur}- onChange={handleChange}- />- );-});diff --git a/frontend/src/metabase/common/components/NumericInput/NumericInput.unit.spec.tsx b/frontend/src/metabase/common/components/NumericInput/NumericInput.unit.spec.tsxdeleted file mode 100644index b50f8762ba0..00000000000--- a/frontend/src/metabase/common/components/NumericInput/NumericInput.unit.spec.tsx+++ /dev/null@@ -1,42 +0,0 @@-import userEvent from "@testing-library/user-event";-import { useCallback, useState } from "react";--import { render, screen } from "__support__/ui";--import type { NumericInputProps } from "./NumericInput";-import { NumericInput } from "./NumericInput";--const NumericInputTest = ({ onChange, ...props }: NumericInputProps) => {- const [value, setValue] = useState<number>();-- const handleChange = useCallback(- (value: number | undefined, inputValue: string) => {- setValue(value);- onChange?.(value, inputValue);- },- [onChange],- );-- return <NumericInput {...props} value={value} onChange={handleChange} />;-};--describe("NumericInput", () => {- it("should set number", async () => {- const onChange = jest.fn();-- render(<NumericInputTest onChange={onChange} />);- await userEvent.type(screen.getByRole("textbox"), "123");-- expect(onChange).toHaveBeenLastCalledWith(123, "123");- });-- it("should clear number", async () => {- const onChange = jest.fn();-- render(<NumericInputTest onChange={onChange} />);- await userEvent.type(screen.getByRole("textbox"), "123");- await userEvent.clear(screen.getByRole("textbox"));-- expect(onChange).toHaveBeenLastCalledWith(undefined, "");- });-});diff --git a/frontend/src/metabase/common/components/NumericInput/index.ts b/frontend/src/metabase/common/components/NumericInput/index.tsdeleted file mode 100644index d9f7fc30613..00000000000--- a/frontend/src/metabase/common/components/NumericInput/index.ts+++ /dev/null@@ -1,2 +0,0 @@-export { NumericInput } from "./NumericInput";-export type { NumericInputProps } from "./NumericInput";diff --git a/frontend/src/metabase/dashboard/components/ActionViz/Action.unit.spec.tsx b/frontend/src/metabase/dashboard/components/ActionViz/Action.unit.spec.tsxindex f5edb784442..7499670e79f 100644--- a/frontend/src/metabase/dashboard/components/ActionViz/Action.unit.spec.tsx+++ b/frontend/src/metabase/dashboard/components/ActionViz/Action.unit.spec.tsx@@ -470,7 +470,7 @@ describe("Actions > ActionViz > Action", () => {await userEvent.type(screen.getByLabelText("Parameter 2"), "5");await waitFor(() =>- expect(screen.getByLabelText("Parameter 2")).toHaveValue(5),+ expect(screen.getByLabelText("Parameter 2")).toHaveValue("5"),);await userEvent.click(screen.getByRole("button", { name: ACTION.name }));diff --git a/frontend/src/metabase/forms/components/FormNumberInput/FormNumberInput.tsx b/frontend/src/metabase/forms/components/FormNumberInput/FormNumberInput.tsxindex 989aa85fef0..92b5a0a0a39 100644--- a/frontend/src/metabase/forms/components/FormNumberInput/FormNumberInput.tsx+++ b/frontend/src/metabase/forms/components/FormNumberInput/FormNumberInput.tsx@@ -19,12 +19,12 @@ export const FormNumberInput = forwardRef(function FormNumberInput(const handleChange = useCallback((newValue: number | string) => {- if (typeof newValue === "string") {+ if (newValue === "") {setValue(nullable ? null : undefined);- } else {+ } else if (typeof newValue === "number") {setValue(newValue);}- onChange?.(typeof newValue === "number" ? newValue : 0);+ onChange?.(newValue);},[nullable, setValue, onChange],);diff --git a/frontend/src/metabase/forms/components/FormNumberInput/FormNumberInput.unit.spec.tsx b/frontend/src/metabase/forms/components/FormNumberInput/FormNumberInput.unit.spec.tsxindex 2ca2409d2f1..9e9acba44f8 100644--- a/frontend/src/metabase/forms/components/FormNumberInput/FormNumberInput.unit.spec.tsx+++ b/frontend/src/metabase/forms/components/FormNumberInput/FormNumberInput.unit.spec.tsx@@ -64,6 +64,17 @@ describe("FormNumberInput", () => {});});+ it("should submit a decimal value", async () => {+ const { onSubmit } = setup();++ await userEvent.type(screen.getByLabelText("Goal"), "3.4");+ await userEvent.click(screen.getByText("Submit"));++ await waitFor(() => {+ expect(onSubmit).toHaveBeenCalledWith({ goal: 3.4 }, expect.anything());+ });+ });+it("should submit an empty value", async () => {const { onSubmit } = setup({initialValues: { goal: 20 },diff --git a/frontend/src/metabase/monitor/tools/components/LogLevelsModal/DurationInput.tsx b/frontend/src/metabase/monitor/tools/components/LogLevelsModal/DurationInput.tsxindex 056c8a62991..e12d2701594 100644--- a/frontend/src/metabase/monitor/tools/components/LogLevelsModal/DurationInput.tsx+++ b/frontend/src/metabase/monitor/tools/components/LogLevelsModal/DurationInput.tsx@@ -26,6 +26,7 @@ export const DurationInput = () => {// rendering long error message for 80px-wide input messes up the layout// so this error message will be displayed under the form insteaderror={null}+ allowDecimal={false}id={id}name="duration"placeholder={t`Duration`}diff --git a/frontend/src/metabase/parameters/components/widgets/NumberInputWidget/NumberInputWidget.tsx b/frontend/src/metabase/parameters/components/widgets/NumberInputWidget/NumberInputWidget.tsxindex 356e72df2d3..59131ead1c4 100644--- a/frontend/src/metabase/parameters/components/widgets/NumberInputWidget/NumberInputWidget.tsx+++ b/frontend/src/metabase/parameters/components/widgets/NumberInputWidget/NumberInputWidget.tsx@@ -3,9 +3,9 @@ import { t } from "ttag";import _ from "underscore";import { MultiAutocompleteWithTranslation } from "metabase/common/components/MultiAutocomplete";-import { NumericInput } from "metabase/common/components/NumericInput";import CS from "metabase/css/core/index.css";import { UpdateFilterButton } from "metabase/parameters/components/UpdateFilterButton";+import { BigIntNumberInput } from "metabase/querying/common/components/BigIntNumberInput";import type { NumberFilterValue } from "metabase/querying/parameters/types";import {deserializeNumberParameterValue,@@ -117,15 +117,15 @@ export function NumberInputWidget({) : (_.times(arity, (i) => (<div key={i}>- <NumericInput- fullWidth+ <BigIntNumberInput+ w="100%"className={CS.p1}autoFocus={autoFocus && i === 0}- value={unsavedArrayValue[i]?.toString()}- onChange={(_newValue, newValueText) => {+ value={unsavedArrayValue[i] ?? null}+ onChange={(newValue) => {setUnsavedArrayValue((unsavedArrayValue) => {const newUnsavedValue = [...unsavedArrayValue];- newUnsavedValue[i] = parseNumber(newValueText);+ newUnsavedValue[i] = newValue;return newUnsavedValue;});}}