From a28ea4f82d48080f5ac2e9fb9fece372fb16a907 Mon Sep 17 00:00:00 2001 From: Enzo Martellucci Date: Fri, 25 Apr 2025 18:53:22 +0200 Subject: [PATCH] refactor(Components): Use named imports --- .../SqlLab/components/QueryHistory/index.tsx | 3 +-- .../src/SqlLab/components/SqlEditor/index.tsx | 2 +- .../SqlLab/components/TablePreview/index.tsx | 2 +- .../src/components/ListViewCard/index.tsx | 4 ++-- .../src/components/Radio/Radio.stories.tsx | 4 ++-- .../src/components/Radio/index.tsx | 23 +++++++++---------- .../components/Skeleton/Skeleton.stories.tsx | 4 ++-- .../src/components/Skeleton/Skeleton.test.tsx | 2 +- .../src/components/Skeleton/index.tsx | 5 +--- .../src/components/Space/Space.stories.tsx | 9 +------- .../src/components/Space/index.tsx | 10 +------- .../src/components/Steps/Steps.stories.tsx | 2 +- .../src/components/Steps/index.tsx | 16 +------------ .../src/components/Switch/Switch.stories.tsx | 2 +- .../src/components/Switch/index.tsx | 6 +---- .../TreeSelect/TreeSelect.stories.tsx | 2 +- .../components/TreeSelect/TreeSelect.test.tsx | 2 +- .../src/components/TreeSelect/index.tsx | 6 +---- superset-frontend/src/components/index.ts | 16 ++++++++++++- .../explore/components/EmbedCodeContent.jsx | 4 +--- .../src/features/alerts/AlertReportModal.tsx | 4 ++-- .../components/Select/SelectFilterPlugin.tsx | 3 +-- .../src/pages/ChartCreation/index.tsx | 3 +-- 23 files changed, 51 insertions(+), 83 deletions(-) diff --git a/superset-frontend/src/SqlLab/components/QueryHistory/index.tsx b/superset-frontend/src/SqlLab/components/QueryHistory/index.tsx index 870ea87e0b8..dddba24a7d0 100644 --- a/superset-frontend/src/SqlLab/components/QueryHistory/index.tsx +++ b/superset-frontend/src/SqlLab/components/QueryHistory/index.tsx @@ -20,7 +20,7 @@ import { useEffect, useMemo, useState } from 'react'; import { shallowEqual, useSelector } from 'react-redux'; import { useInView } from 'react-intersection-observer'; import { omit } from 'lodash'; -import { EmptyState } from 'src/components'; +import { EmptyState, Skeleton } from 'src/components'; import { t, styled, @@ -31,7 +31,6 @@ import { import QueryTable from 'src/SqlLab/components/QueryTable'; import { SqlLabRootState } from 'src/SqlLab/types'; import { useEditorQueriesQuery } from 'src/hooks/apiResources/queries'; -import Skeleton from 'src/components/Skeleton'; import useEffectEvent from 'src/hooks/useEffectEvent'; interface QueryHistoryProps { diff --git a/superset-frontend/src/SqlLab/components/SqlEditor/index.tsx b/superset-frontend/src/SqlLab/components/SqlEditor/index.tsx index 893fd627b18..cc5c1e2c6f1 100644 --- a/superset-frontend/src/SqlLab/components/SqlEditor/index.tsx +++ b/superset-frontend/src/SqlLab/components/SqlEditor/index.tsx @@ -62,7 +62,7 @@ import { } from 'src/components'; import Timer from 'src/components/Timer'; import ResizableSidebar from 'src/components/ResizableSidebar'; -import Skeleton from 'src/components/Skeleton'; +import { Skeleton } from 'src/components/Skeleton'; import { Switch } from 'src/components/Switch'; import { Menu } from 'src/components/Menu'; import { Icons } from 'src/components/Icons'; diff --git a/superset-frontend/src/SqlLab/components/TablePreview/index.tsx b/superset-frontend/src/SqlLab/components/TablePreview/index.tsx index f453bfac9e0..d0364fcde52 100644 --- a/superset-frontend/src/SqlLab/components/TablePreview/index.tsx +++ b/superset-frontend/src/SqlLab/components/TablePreview/index.tsx @@ -40,8 +40,8 @@ import { CopyToClipboard, Dropdown, FilterableTable, + Skeleton, } from 'src/components'; -import Skeleton from 'src/components/Skeleton'; import Tabs from 'src/components/Tabs'; import { tableApiUtil, diff --git a/superset-frontend/src/components/ListViewCard/index.tsx b/superset-frontend/src/components/ListViewCard/index.tsx index bb487cac850..1f35688bc6f 100644 --- a/superset-frontend/src/components/ListViewCard/index.tsx +++ b/superset-frontend/src/components/ListViewCard/index.tsx @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -import { styled, useTheme } from '@superset-ui/core'; -import Skeleton from 'src/components/Skeleton'; import { FC } from 'react'; +import { styled, useTheme } from '@superset-ui/core'; +import { Skeleton } from '../Skeleton'; import { Card } from '../Card'; import { CertifiedBadge } from '../CertifiedBadge'; import { Tooltip } from '../Tooltip'; diff --git a/superset-frontend/src/components/Radio/Radio.stories.tsx b/superset-frontend/src/components/Radio/Radio.stories.tsx index 5394bd64861..d7fb4056dad 100644 --- a/superset-frontend/src/components/Radio/Radio.stories.tsx +++ b/superset-frontend/src/components/Radio/Radio.stories.tsx @@ -16,10 +16,10 @@ * specific language governing permissions and limitations * under the License. */ -import { Icons } from 'src/components/Icons'; import { css } from '@superset-ui/core'; +import { Icons } from 'src/components/Icons'; import { Space } from '../Space'; -import { Radio, RadioProps, RadioGroupWrapperProps } from './index'; +import { Radio, type RadioProps, type RadioGroupWrapperProps } from '.'; export default { title: 'Components/Radio', diff --git a/superset-frontend/src/components/Radio/index.tsx b/superset-frontend/src/components/Radio/index.tsx index 1778e89d369..034f10b561c 100644 --- a/superset-frontend/src/components/Radio/index.tsx +++ b/superset-frontend/src/components/Radio/index.tsx @@ -16,14 +16,13 @@ * specific language governing permissions and limitations * under the License. */ -import { Radio as Antd5Radio, CheckboxOptionType } from 'antd-v5'; -import type { - RadioChangeEvent, - RadioProps, - RadioGroupProps, -} from 'antd-v5/es/radio'; +import { + Radio as Antd5Radio, + type CheckboxOptionType, + type RadioGroupProps, +} from 'antd-v5'; -import { Space, SpaceProps } from '../Space'; +import { Space, type SpaceProps } from '../Space'; export type RadioGroupWrapperProps = RadioGroupProps & { spaceConfig?: { @@ -51,13 +50,13 @@ const RadioGroup = ({ ); }; +export const Radio = Object.assign(Antd5Radio, { + GroupWrapper: RadioGroup, + Button: Antd5Radio.Button, +}); export type { RadioChangeEvent, RadioGroupProps, RadioProps, CheckboxOptionType, -}; -export const Radio = Object.assign(Antd5Radio, { - GroupWrapper: RadioGroup, - Button: Antd5Radio.Button, -}); +} from 'antd-v5'; diff --git a/superset-frontend/src/components/Skeleton/Skeleton.stories.tsx b/superset-frontend/src/components/Skeleton/Skeleton.stories.tsx index d6a3f990d7d..db73abbc684 100644 --- a/superset-frontend/src/components/Skeleton/Skeleton.stories.tsx +++ b/superset-frontend/src/components/Skeleton/Skeleton.stories.tsx @@ -17,10 +17,10 @@ * under the License. */ import type { Meta, StoryObj } from '@storybook/react'; -import { SkeletonButtonProps } from 'antd-v5/es/skeleton/Button'; +import { type SkeletonButtonProps } from 'antd-v5/es/skeleton/Button'; import { Space } from '../Space'; import { AvatarProps } from '../Avatar/types'; -import Skeleton, { type SkeletonProps } from './index'; +import { Skeleton, type SkeletonProps } from '.'; const { Avatar, Button, Input, Image } = Skeleton; diff --git a/superset-frontend/src/components/Skeleton/Skeleton.test.tsx b/superset-frontend/src/components/Skeleton/Skeleton.test.tsx index 0201e165190..fff2acd854e 100644 --- a/superset-frontend/src/components/Skeleton/Skeleton.test.tsx +++ b/superset-frontend/src/components/Skeleton/Skeleton.test.tsx @@ -18,7 +18,7 @@ */ import { render, screen } from '@testing-library/react'; import '@testing-library/jest-dom'; -import { Skeleton } from 'antd'; +import { Skeleton } from '.'; describe('Skeleton Component', () => { test('renders skeleton', () => { diff --git a/superset-frontend/src/components/Skeleton/index.tsx b/superset-frontend/src/components/Skeleton/index.tsx index 4c4ff1110f2..47aee164812 100644 --- a/superset-frontend/src/components/Skeleton/index.tsx +++ b/superset-frontend/src/components/Skeleton/index.tsx @@ -16,7 +16,4 @@ * specific language governing permissions and limitations * under the License. */ -import { Skeleton, type SkeletonProps } from 'antd-v5'; - -export type { SkeletonProps }; -export default Skeleton; +export { Skeleton, type SkeletonProps } from 'antd-v5'; diff --git a/superset-frontend/src/components/Space/Space.stories.tsx b/superset-frontend/src/components/Space/Space.stories.tsx index 76478f59d1b..c6e935521d7 100644 --- a/superset-frontend/src/components/Space/Space.stories.tsx +++ b/superset-frontend/src/components/Space/Space.stories.tsx @@ -16,14 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -/* - * Re-exporting of components in src/components to facilitate - * their imports by other components. - * E.g. import { Select } from 'src/components' - */ - -import { Space, SpaceProps } from 'src/components/Space'; +import { Space, type SpaceProps } from '.'; export default { title: 'Design System/Components/Space', diff --git a/superset-frontend/src/components/Space/index.tsx b/superset-frontend/src/components/Space/index.tsx index 56b58413ab3..e7942cf0e47 100644 --- a/superset-frontend/src/components/Space/index.tsx +++ b/superset-frontend/src/components/Space/index.tsx @@ -16,12 +16,4 @@ * specific language governing permissions and limitations * under the License. */ - -/* - * Re-exporting of components in src/components to facilitate - * their imports by other components. - * E.g. import { Select } from 'src/components' - */ - -export { Space } from 'antd-v5'; -export type { SpaceProps } from 'antd-v5/es/space'; +export { Space, type SpaceProps } from 'antd-v5'; diff --git a/superset-frontend/src/components/Steps/Steps.stories.tsx b/superset-frontend/src/components/Steps/Steps.stories.tsx index d8fa4d4d5e8..3afdc70a699 100644 --- a/superset-frontend/src/components/Steps/Steps.stories.tsx +++ b/superset-frontend/src/components/Steps/Steps.stories.tsx @@ -17,7 +17,7 @@ * under the License. */ import { Steps as AntdSteps } from 'antd-v5'; -import { Steps, StepsProps } from '.'; +import { Steps, type StepsProps } from '.'; export default { title: 'Components/Steps', diff --git a/superset-frontend/src/components/Steps/index.tsx b/superset-frontend/src/components/Steps/index.tsx index e582e125cf0..80723e23b81 100644 --- a/superset-frontend/src/components/Steps/index.tsx +++ b/superset-frontend/src/components/Steps/index.tsx @@ -16,18 +16,4 @@ * specific language governing permissions and limitations * under the License. */ - -/* - * Re-exporting of components in src/components to facilitate - * their imports by other components. - * E.g. import { Select } from 'src/components' - */ - -import { Steps as AntdSteps } from 'antd-v5'; -import { StepsProps as AntdStepsProps } from 'antd-v5/es/steps'; - -export type StepsProps = AntdStepsProps; - -export const Steps: typeof AntdSteps = Object.assign(AntdSteps, { - Step: AntdSteps.Step, -}); +export { Steps, type StepsProps } from 'antd-v5'; diff --git a/superset-frontend/src/components/Switch/Switch.stories.tsx b/superset-frontend/src/components/Switch/Switch.stories.tsx index 0cb4b03fc22..508549ac0e3 100644 --- a/superset-frontend/src/components/Switch/Switch.stories.tsx +++ b/superset-frontend/src/components/Switch/Switch.stories.tsx @@ -17,7 +17,7 @@ * under the License. */ import { useArgs } from '@storybook/preview-api'; -import { Switch, SwitchProps } from '.'; +import { Switch, type SwitchProps } from '.'; export default { title: 'Components/Switch', diff --git a/superset-frontend/src/components/Switch/index.tsx b/superset-frontend/src/components/Switch/index.tsx index f7753844724..61b34f5de7a 100644 --- a/superset-frontend/src/components/Switch/index.tsx +++ b/superset-frontend/src/components/Switch/index.tsx @@ -16,8 +16,4 @@ * specific language governing permissions and limitations * under the License. */ -import { SwitchProps } from 'antd-v5/es/switch'; -import { Switch as AntdSwitch } from 'antd-v5'; - -export const Switch = (props: SwitchProps) => ; -export type { SwitchProps }; +export { Switch, type SwitchProps } from 'antd-v5'; diff --git a/superset-frontend/src/components/TreeSelect/TreeSelect.stories.tsx b/superset-frontend/src/components/TreeSelect/TreeSelect.stories.tsx index 2a72c3834ce..7c0f6e33e0a 100644 --- a/superset-frontend/src/components/TreeSelect/TreeSelect.stories.tsx +++ b/superset-frontend/src/components/TreeSelect/TreeSelect.stories.tsx @@ -17,7 +17,7 @@ * under the License. */ import { Meta, StoryObj } from '@storybook/react'; -import TreeSelect, { type TreeSelectProps } from 'src/components/TreeSelect'; +import { TreeSelect, type TreeSelectProps } from '.'; export default { title: 'Components/TreeSelect', diff --git a/superset-frontend/src/components/TreeSelect/TreeSelect.test.tsx b/superset-frontend/src/components/TreeSelect/TreeSelect.test.tsx index 1fb24cbc7f7..ce01d0affef 100644 --- a/superset-frontend/src/components/TreeSelect/TreeSelect.test.tsx +++ b/superset-frontend/src/components/TreeSelect/TreeSelect.test.tsx @@ -18,7 +18,7 @@ */ import { render, fireEvent, screen } from '@testing-library/react'; import '@testing-library/jest-dom'; -import TreeSelect from '.'; +import { TreeSelect } from '.'; const treeData = [ { diff --git a/superset-frontend/src/components/TreeSelect/index.tsx b/superset-frontend/src/components/TreeSelect/index.tsx index 688a4c7ff41..a2b1d584f19 100644 --- a/superset-frontend/src/components/TreeSelect/index.tsx +++ b/superset-frontend/src/components/TreeSelect/index.tsx @@ -16,8 +16,4 @@ * specific language governing permissions and limitations * under the License. */ -import { TreeSelect } from 'antd-v5'; -import type { TreeSelectProps } from 'antd-v5/es/tree-select'; - -export default TreeSelect; -export type { TreeSelectProps }; +export { TreeSelect, type TreeSelectProps } from 'antd-v5'; diff --git a/superset-frontend/src/components/index.ts b/superset-frontend/src/components/index.ts index 7a4cc73f531..5b1c3335d03 100644 --- a/superset-frontend/src/components/index.ts +++ b/superset-frontend/src/components/index.ts @@ -21,6 +21,9 @@ * Re-exporting of components in src/components to facilitate * their imports by other components. * E.g. import { Select } from 'src/components', probably in the future from '@superset-ui/components' +import { StepsProps, type TreeSelectProps } from '.'; +import { SwitchProps } from '../features/databases/types'; +import TreeSelect from '.'; */ export { AntdThemeProvider } from './AntdThemeProvider'; export { Alert, type AlertProps } from './Alert'; @@ -188,6 +191,17 @@ export { type RefSelectProps, } from './Select'; -export { Image, type ImageProps } from './Image'; +export { Steps, StepsProps } from './Steps'; +export { Space, type SpaceProps } from './Space'; + +export { Skeleton, type SkeletonProps } from './Skeleton'; + +export { Switch, type SwitchProps } from './Switch'; + +export { TreeSelect, type TreeSelectProps } from './TreeSelect'; + +export { Typography, type TypographyProps } from './Typography'; + +export { Image, type ImageProps } from './Image'; export { Upload, type UploadFile, type UploadChangeParam } from './Upload'; diff --git a/superset-frontend/src/explore/components/EmbedCodeContent.jsx b/superset-frontend/src/explore/components/EmbedCodeContent.jsx index 98fc02c7f6c..65077b889d7 100644 --- a/superset-frontend/src/explore/components/EmbedCodeContent.jsx +++ b/superset-frontend/src/explore/components/EmbedCodeContent.jsx @@ -18,12 +18,10 @@ */ import { useCallback, useEffect, useMemo, useState } from 'react'; import { css, t } from '@superset-ui/core'; -import { Input, CopyToClipboard } from 'src/components'; +import { Input, CopyToClipboard, Space, Typography } from 'src/components'; import { URL_PARAMS } from 'src/constants'; import { getChartPermalink } from 'src/utils/urlUtils'; -import { Typography } from 'src/components/Typography'; import { Icons } from 'src/components/Icons'; -import { Space } from 'src/components/Space'; const EmbedCodeContent = ({ formData, addDangerToast }) => { const [height, setHeight] = useState('400'); diff --git a/superset-frontend/src/features/alerts/AlertReportModal.tsx b/superset-frontend/src/features/alerts/AlertReportModal.tsx index 098741a2f81..9a600993158 100644 --- a/superset-frontend/src/features/alerts/AlertReportModal.tsx +++ b/superset-frontend/src/features/alerts/AlertReportModal.tsx @@ -42,18 +42,18 @@ import { Input, InputNumber, Modal, + Switch, Collapse, Select, AsyncSelect, Checkbox, + TreeSelect, type CheckboxChangeEvent, } from 'src/components'; -import { Switch } from 'src/components/Switch'; import TimezoneSelector from 'src/components/TimezoneSelector'; import { propertyComparator } from 'src/components/Select/utils'; import withToasts from 'src/components/MessageToasts/withToasts'; import Owner from 'src/types/Owner'; -import TreeSelect from 'src/components/TreeSelect'; import TextAreaControl from 'src/explore/components/controls/TextAreaControl'; import { useCommonConf } from 'src/features/databases/state'; import { InfoTooltipWithTrigger } from '@superset-ui/chart-controls'; diff --git a/superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx b/superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx index e7189b342ac..a51d55623f8 100644 --- a/superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx +++ b/superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx @@ -33,8 +33,7 @@ import { } from '@superset-ui/core'; import { debounce, isUndefined } from 'lodash'; import { useImmerReducer } from 'use-immer'; -import { FormItem, LabeledValue, Select } from 'src/components'; -import { Space } from 'src/components/Space'; +import { FormItem, LabeledValue, Select, Space } from 'src/components'; import { SLOW_DEBOUNCE } from 'src/constants'; import { hasOption, propertyComparator } from 'src/components/Select/utils'; import { FilterBarOrientation } from 'src/dashboard/types'; diff --git a/superset-frontend/src/pages/ChartCreation/index.tsx b/superset-frontend/src/pages/ChartCreation/index.tsx index 13cb990902e..98c6c1dd02c 100644 --- a/superset-frontend/src/pages/ChartCreation/index.tsx +++ b/superset-frontend/src/pages/ChartCreation/index.tsx @@ -30,8 +30,7 @@ import { withTheme, Theme } from '@emotion/react'; import { getUrlParam } from 'src/utils/urlUtils'; import { FilterPlugins, URL_PARAMS } from 'src/constants'; import { Link, withRouter, RouteComponentProps } from 'react-router-dom'; -import { AsyncSelect, Button } from 'src/components'; -import { Steps } from 'src/components/Steps'; +import { AsyncSelect, Button, Steps } from 'src/components'; import withToasts from 'src/components/MessageToasts/withToasts'; import VizTypeGallery, {