Skip to content

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

Migrate normal-variant Radio usages to metabase/ui Radio (#76405)

Oleh K30811cfc49d8
diff --git a/enterprise/frontend/src/metabase-enterprise/sandboxes/components/EditSandboxingModal/EditSandboxingModal.tsx b/enterprise/frontend/src/metabase-enterprise/sandboxes/components/EditSandboxingModal/EditSandboxingModal.tsx
index 509666a41fd..6467f82564f 100644
--- a/enterprise/frontend/src/metabase-enterprise/sandboxes/components/EditSandboxingModal/EditSandboxingModal.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/sandboxes/components/EditSandboxingModal/EditSandboxingModal.tsx
@@ -18,11 +18,10 @@ import {
} from "metabase/common/components/Pickers/QuestionPicker";
import { QuestionLoader } from "metabase/common/components/QuestionLoader";
import { QuestionName } from "metabase/common/components/QuestionName";
-import { Radio } from "metabase/common/components/Radio";
import { useToggle } from "metabase/common/hooks/use-toggle";
import CS from "metabase/css/core/index.css";
import { useTranslateContent } from "metabase/i18n/hooks";
-import { Button, Center, Icon, Loader } from "metabase/ui";
+import { Button, Center, Icon, Loader, Radio, Stack } from "metabase/ui";
import { getName } from "metabase/utils/name";
import type {
GroupTableAccessPolicyDraft,
@@ -172,20 +171,23 @@ const EditSandboxingModal = ({
<h4
className={CS.pb1}
>{t`How do you want to filter this table?`}</h4>
- <Radio
- value={!shouldUseSavedQuestion}
- options={[
- { name: t`Filter by a column in the table`, value: true },
- {
- name: t`Use a saved question to create a custom view for this table`,
- value: false,
- },
- ]}
- onChange={(shouldUseSavedQuestion) =>
- setShouldUseSavedQuestion(!shouldUseSavedQuestion)
+ <Radio.Group
+ value={shouldUseSavedQuestion ? "saved-question" : "column"}
+ onChange={(value) =>
+ setShouldUseSavedQuestion(value === "saved-question")
}
- vertical
- />
+ >
+ <Stack gap="sm">
+ <Radio
+ value="column"
+ label={t`Filter by a column in the table`}
+ />
+ <Radio
+ value="saved-question"
+ label={t`Use a saved question to create a custom view for this table`}
+ />
+ </Stack>
+ </Radio.Group>
</div>
) : (
<div>
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/FormCreator/FieldSettingsPopover.tsx b/frontend/src/metabase/actions/containers/ActionCreator/FormCreator/FieldSettingsPopover.tsx
index 70ec2787cf3..4b307d1a918 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/FormCreator/FieldSettingsPopover.tsx
+++ b/frontend/src/metabase/actions/containers/ActionCreator/FormCreator/FieldSettingsPopover.tsx
@@ -4,10 +4,9 @@ import { useMemo } from "react";
import { t } from "ttag";
import { getInputTypes } from "metabase/actions/constants";
-import { Radio } from "metabase/common/components/Radio";
import { Toggle } from "metabase/common/components/Toggle";
import { useUniqueId } from "metabase/common/hooks/use-unique-id";
-import { Popover, UnstyledButton } from "metabase/ui";
+import { Popover, Radio, Stack, UnstyledButton } from "metabase/ui";
import { TextInput } from "metabase/ui/components/inputs/TextInput";
import type {
FieldSettings,
@@ -135,14 +134,20 @@ function InputTypeSelect({
onChange: (newInputType: InputSettingType) => void;
}) {
const inputTypes = useMemo(getInputTypes, []);
+ const options = inputTypes[fieldType ?? "string"];
return (
- <Radio
- vertical
+ <Radio.Group
value={value}
- options={inputTypes[fieldType ?? "string"]}
- onChange={onChange}
- />
+ // Mantine's radio uses broad `string` type for value even though we supply specifically InputSettingType
+ onChange={(newInputType) => onChange(newInputType as InputSettingType)}
+ >
+ <Stack gap="sm">
+ {options.map((option) => (
+ <Radio key={option.value} value={option.value} label={option.name} />
+ ))}
+ </Stack>
+ </Radio.Group>
);
}
diff --git a/frontend/src/metabase/parameters/components/ValuesSourceModal/ValuesSourceTypeModal.tsx b/frontend/src/metabase/parameters/components/ValuesSourceModal/ValuesSourceTypeModal.tsx
index 3cf9c0d98e9..d6b9372a60d 100644
--- a/frontend/src/metabase/parameters/components/ValuesSourceModal/ValuesSourceTypeModal.tsx
+++ b/frontend/src/metabase/parameters/components/ValuesSourceModal/ValuesSourceTypeModal.tsx
@@ -10,8 +10,6 @@ import {
} from "metabase/api";
import { ExternalLink } from "metabase/common/components/ExternalLink";
import { ModalContent } from "metabase/common/components/ModalContent";
-import type { RadioOption } from "metabase/common/components/Radio";
-import { Radio } from "metabase/common/components/Radio";
import type { SelectChangeEvent } from "metabase/common/components/Select";
import { Option, Select } from "metabase/common/components/Select";
import { SelectButton } from "metabase/common/components/SelectButton";
@@ -19,7 +17,7 @@ import { connect, useSelector } from "metabase/redux";
import { getMetadata } from "metabase/selectors/metadata";
import { getLearnUrl } from "metabase/selectors/settings";
import { getShowMetabaseLinks } from "metabase/selectors/whitelabel";
-import { Box, Button, Flex, Icon } from "metabase/ui";
+import { Box, Button, Flex, Icon, Radio, Stack } from "metabase/ui";
import * as Lib from "metabase-lib";
import type Question from "metabase-lib/v1/Question";
import { getQuestionVirtualTableId } from "metabase-lib/v1/metadata/utils/saved-questions";
@@ -152,6 +150,23 @@ interface SourceTypeOptionsProps {
onChangeSourceConfig: (sourceConfig: ValuesSourceConfig) => void;
}
+type SourceTypeOption = {
+ name: string;
+ value: ValuesSourceType;
+};
+
+// Mantine's Radio.Group only handles string values, so the null source type
+// ("From connected fields") is mapped to a sentinel string.
+const CONNECTED_FIELDS_SENTINEL_VALUE = "connected-fields";
+
+const serializeSourceType = (sourceType: ValuesSourceType): string =>
+ sourceType ?? CONNECTED_FIELDS_SENTINEL_VALUE;
+
+const deserializeSourceType = (value: string): ValuesSourceType =>
+ value === CONNECTED_FIELDS_SENTINEL_VALUE
+ ? null
+ : (value as ValuesSourceType);
+
const SourceTypeOptions = ({
parameter,
parameterValues = [],
@@ -177,12 +192,20 @@ const SourceTypeOptions = ({
);
return (
- <Radio
- value={sourceType}
- options={sourceTypeOptions}
- vertical
- onChange={handleSourceTypeChange}
- />
+ <Radio.Group
+ value={serializeSourceType(sourceType)}
+ onChange={(value) => handleSourceTypeChange(deserializeSourceType(value))}
+ >
+ <Stack gap="sm">
+ {sourceTypeOptions.map((option) => (
+ <Radio
+ key={serializeSourceType(option.value)}
+ value={serializeSourceType(option.value)}
+ label={option.name}
+ />
+ ))}
+ </Stack>
+ </Radio.Group>
);
};
@@ -605,9 +628,7 @@ const getLabelColumns = (query: Lib.Query) => {
* if !hasFields(parameter) then exclude the option to set the source type to
* "From connected fields" i.e. values_source_type=null
*/
-const getSourceTypeOptions = (
- parameter: UiParameter,
-): RadioOption<ValuesSourceType>[] => {
+const getSourceTypeOptions = (parameter: UiParameter): SourceTypeOption[] => {
return [
...(hasFields(parameter)
? [{ name: t`From connected fields`, value: null }]
diff --git a/frontend/src/metabase/query_builder/components/LimitPopover.tsx b/frontend/src/metabase/query_builder/components/LimitPopover.tsx
index 8775673017f..90b863b4dfb 100644
--- a/frontend/src/metabase/query_builder/components/LimitPopover.tsx
+++ b/frontend/src/metabase/query_builder/components/LimitPopover.tsx
@@ -3,10 +3,9 @@ import { useEffect, useRef, useState } from "react";
import { useLatest } from "react-use";
import { t } from "ttag";
-import { Radio } from "metabase/common/components/Radio";
import CS from "metabase/css/core/index.css";
import { LimitInput } from "metabase/querying/components/LimitInput";
-import { Box } from "metabase/ui";
+import { Box, Radio, Stack } from "metabase/ui";
import { formatNumber } from "metabase/utils/formatting";
import { HARD_ROW_LIMIT } from "metabase-lib/v1/queries/utils";
@@ -60,20 +59,9 @@ export const LimitPopover = ({
}
}}
>
- <Radio
- vertical
+ <Radio.Group
value={isCustom ? "custom" : "maximum"}
- options={[
- {
- name: t`Show maximum (first ${formatNumber(HARD_ROW_LIMIT)})`,
- value: "maximum",
- },
- {
- name: t`Set custom limit`,
- value: "custom",
- },
- ]}
- onChange={(selected: string) => {
+ onChange={(selected) => {
if (selected === "maximum") {
setIsCustom(false);
} else {
@@ -82,8 +70,16 @@ export const LimitPopover = ({
inputRef.current?.select();
}
}}
- />
- <Box mt="sm" ml="1.25rem">
+ >
+ <Stack gap="sm">
+ <Radio
+ value="maximum"
+ label={t`Show maximum (first ${formatNumber(HARD_ROW_LIMIT)})`}
+ />
+ <Radio value="custom" label={t`Set custom limit`} />
+ </Stack>
+ </Radio.Group>
+ <Box mt="sm" ml="1.7rem">
<LimitInput
ref={inputRef}
small