You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2025/03/10 18:15:50 UTC
(superset) 01/01: chore: migrate Tabs component to use antd-v5
This is an automated email from the ASF dual-hosted git repository.
maximebeauchemin pushed a commit to branch migrate_tabs
in repository https://gitbox.apache.org/repos/asf/superset.git
commit d3a4d3f39518033802750c69a461c71fbdcb2467
Author: Maxime Beauchemin <ma...@gmail.com>
AuthorDate: Wed Feb 12 14:30:15 2025 -0800
chore: migrate Tabs component to use antd-v5
This is WiP, incomplete!
I started migrating tabs but realized there are many more than I thought originally so want to open this DRAFT PR for cooperation / handoff.
My approach, step-by-step was to start by moving components using tabs to point to vanilla `antd-v5` alias one by one, while keeping `src/components/Tabs` untouched (as opposed to altering `src/components/Tabs` to point to `antd-v5` and fix the broken ones one-by-one). Once all were going to be migrated, I was planning on switching everything to make `src/components/Tabs` a very simple wrapper to `antd-v5` and pointing all of the components to it.
Looks like I did 7 so far, and there are 14 left to migrate:
```
$ git grep "src/components/Tabs"
src/SqlLab/components/TabbedSqlEditors/index.tsx:import { EditableTabs } from 'src/components/Tabs';
src/components/Chart/DrillBy/useResultsTableView.tsx:import Tabs from 'src/components/Tabs';
src/dashboard/components/BuilderComponentPane/index.tsx:import Tabs from 'src/components/Tabs';
src/dashboard/components/DashboardBuilder/DashboardContainer.tsx:import Tabs from 'src/components/Tabs';
src/dashboard/components/gridComponents/Tabs.jsx:import { LineEditableTabs } from 'src/components/Tabs';
src/explore/components/DataTablesPane/components/ResultsPaneOnDashboard.tsx:import Tabs from 'src/components/Tabs';
src/explore/components/controls/ColumnConfigControl/ColumnConfigPopover.tsx:import Tabs from 'src/components/Tabs';
src/explore/components/controls/ContourControl/ContourPopoverControl.tsx:import Tabs from 'src/components/Tabs';
src/explore/components/controls/DndColumnSelectControl/ColumnSelectPopover.tsx:import Tabs from 'src/components/Tabs';
src/explore/components/controls/FilterControl/AdhocFilterEditPopover/index.jsx:import Tabs from 'src/components/Tabs';
src/explore/components/controls/MetricControl/AdhocMetricEditPopover/index.jsx:import Tabs from 'src/components/Tabs';
src/features/databases/DatabaseModal/index.tsx:import Tabs from 'src/components/Tabs';
```
---
.../src/SqlLab/components/SouthPane/index.tsx | 148 +++++++++++----------
.../src/SqlLab/components/TablePreview/index.tsx | 2 +-
.../src/components/Datasource/DatasourceEditor.jsx | 2 +-
.../FiltersConfigForm/FiltersConfigForm.tsx | 28 +---
.../explore/components/ControlPanelsContainer.tsx | 46 +------
.../components/DataTablesPane/DataTablesPane.tsx | 2 +-
.../datasets/AddDataset/EditDataset/index.tsx | 36 +++--
7 files changed, 120 insertions(+), 144 deletions(-)
diff --git a/superset-frontend/src/SqlLab/components/SouthPane/index.tsx b/superset-frontend/src/SqlLab/components/SouthPane/index.tsx
index fe929cb080..c4b8b7ab5b 100644
--- a/superset-frontend/src/SqlLab/components/SouthPane/index.tsx
+++ b/superset-frontend/src/SqlLab/components/SouthPane/index.tsx
@@ -19,7 +19,7 @@
import { createRef, useCallback, useMemo } from 'react';
import { shallowEqual, useDispatch, useSelector } from 'react-redux';
import { nanoid } from 'nanoid';
-import Tabs from 'src/components/Tabs';
+import { Tabs } from 'antd-v5';
import { css, styled, t } from '@superset-ui/core';
import { removeTables, setActiveSouthPaneTab } from 'src/SqlLab/actions/sqlLab';
@@ -57,22 +57,9 @@ type StyledPaneProps = {
const StyledPane = styled.div<StyledPaneProps>`
width: 100%;
height: ${props => props.height}px;
- .ant-tabs .ant-tabs-content-holder {
- overflow: visible;
- }
- .SouthPaneTabs {
- height: 100%;
- display: flex;
- flex-direction: column;
- .scrollable {
- overflow-y: auto;
- }
- }
- .ant-tabs-tabpane {
- .scrollable {
- overflow-y: auto;
- }
- }
+
+ /* Removed custom tab styles since we'll use default antd-v5 styling */
+
.tab-content {
.alert {
margin-top: ${({ theme }) => theme.gridUnit * 2}px;
@@ -127,18 +114,81 @@ const SouthPane = ({
dispatch(setActiveSouthPaneTab(id));
};
const removeTable = useCallback(
- (key, action) => {
- if (action === 'remove') {
- const table = pinnedTables.find(
- ({ dbId, catalog, schema, name }) =>
- [dbId, catalog, schema, name].join(':') === key,
- );
+ (targetKey: string) => {
+ const table = pinnedTables.find(
+ ({ dbId, catalog, schema, name }) =>
+ [dbId, catalog, schema, name].join(':') === targetKey,
+ );
+ if (table) {
dispatch(removeTables([table]));
}
},
[dispatch, pinnedTables],
);
+ // Prepare tabs items for antd v5
+ const tabItems = useMemo(() => {
+ const items = [
+ {
+ key: 'Results',
+ label: t('Results'),
+ closable: false,
+ children: (
+ <Results
+ height={innerTabContentHeight}
+ latestQueryId={latestQueryId}
+ displayLimit={displayLimit}
+ defaultQueryLimit={defaultQueryLimit}
+ />
+ ),
+ },
+ {
+ key: 'History',
+ label: t('Query history'),
+ closable: false,
+ children: (
+ <QueryHistory
+ queryEditorId={queryEditorId}
+ displayLimit={displayLimit}
+ latestQueryId={latestQueryId}
+ />
+ ),
+ },
+ ...pinnedTables.map(({ id, dbId, catalog, schema, name }) => ({
+ key: pinnedTableKeys[id],
+ label: (
+ <>
+ <Icons.Table
+ iconSize="s"
+ css={css`
+ margin-bottom: 2px;
+ margin-right: 4px;
+ `}
+ />
+ {`${schema}.${decodeURIComponent(name)}`}
+ </>
+ ),
+ children: (
+ <TablePreview
+ dbId={dbId}
+ catalog={catalog}
+ schema={schema}
+ tableName={name}
+ />
+ ),
+ })),
+ ];
+ return items;
+ }, [
+ innerTabContentHeight,
+ latestQueryId,
+ displayLimit,
+ defaultQueryLimit,
+ queryEditorId,
+ pinnedTables,
+ pinnedTableKeys,
+ ]);
+
return offline ? (
<Label className="m-r-3" type={STATE_TYPE_MAP[STATUS_OPTIONS.offline]}>
{STATUS_OPTIONS_LOCALIZED.offline}
@@ -151,56 +201,18 @@ const SouthPane = ({
ref={southPaneRef}
>
<Tabs
- type="editable-card"
activeKey={pinnedTableKeys[activeSouthPaneTab] || activeSouthPaneTab}
- className="SouthPaneTabs"
onChange={switchTab}
id={nanoid(11)}
- fullWidth={false}
animated={false}
- onEdit={removeTable}
+ onEdit={(targetKey, action) => {
+ if (action === 'remove') {
+ removeTable(targetKey as string);
+ }
+ }}
hideAdd
- >
- <Tabs.TabPane tab={t('Results')} key="Results" closable={false}>
- <Results
- height={innerTabContentHeight}
- latestQueryId={latestQueryId}
- displayLimit={displayLimit}
- defaultQueryLimit={defaultQueryLimit}
- />
- </Tabs.TabPane>
- <Tabs.TabPane tab={t('Query history')} key="History" closable={false}>
- <QueryHistory
- queryEditorId={queryEditorId}
- displayLimit={displayLimit}
- latestQueryId={latestQueryId}
- />
- </Tabs.TabPane>
- {pinnedTables.map(({ id, dbId, catalog, schema, name }) => (
- <Tabs.TabPane
- tab={
- <>
- <Icons.Table
- iconSize="s"
- css={css`
- margin-bottom: 2px;
- margin-right: 4px;
- `}
- />
- {`${schema}.${decodeURIComponent(name)}`}
- </>
- }
- key={pinnedTableKeys[id]}
- >
- <TablePreview
- dbId={dbId}
- catalog={catalog}
- schema={schema}
- tableName={name}
- />
- </Tabs.TabPane>
- ))}
- </Tabs>
+ items={tabItems}
+ />
</StyledPane>
);
};
diff --git a/superset-frontend/src/SqlLab/components/TablePreview/index.tsx b/superset-frontend/src/SqlLab/components/TablePreview/index.tsx
index a52f5a71d8..8d229e2031 100644
--- a/superset-frontend/src/SqlLab/components/TablePreview/index.tsx
+++ b/superset-frontend/src/SqlLab/components/TablePreview/index.tsx
@@ -33,7 +33,7 @@ import type { SqlLabRootState } from 'src/SqlLab/types';
import { Skeleton, AntdBreadcrumb as Breadcrumb, Button } from 'src/components';
import { Dropdown } from 'src/components/Dropdown';
import FilterableTable from 'src/components/FilterableTable';
-import Tabs from 'src/components/Tabs';
+import { Tabs } from 'antd-v5';
import {
tableApiUtil,
TableMetaData,
diff --git a/superset-frontend/src/components/Datasource/DatasourceEditor.jsx b/superset-frontend/src/components/Datasource/DatasourceEditor.jsx
index fae0270828..6d73618a6a 100644
--- a/superset-frontend/src/components/Datasource/DatasourceEditor.jsx
+++ b/superset-frontend/src/components/Datasource/DatasourceEditor.jsx
@@ -38,7 +38,7 @@ import {
import { Select, AsyncSelect, Row, Col } from 'src/components';
import { FormLabel } from 'src/components/Form';
import Button from 'src/components/Button';
-import Tabs from 'src/components/Tabs';
+import { Tabs } from 'antd-v5';
import CertifiedBadge from 'src/components/CertifiedBadge';
import WarningIconWithTooltip from 'src/components/WarningIconWithTooltip';
import DatabaseSelector from 'src/components/DatabaseSelector';
diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx
index ff247daa29..d30e2f0148 100644
--- a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx
+++ b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx
@@ -35,6 +35,7 @@ import {
JsonResponse,
NativeFilterType,
styled,
+ useTheme,
SupersetApiError,
t,
ClientErrorObject,
@@ -66,7 +67,7 @@ import Icons from 'src/components/Icons';
import Loading from 'src/components/Loading';
import { addDangerToast } from 'src/components/MessageToasts/actions';
import { Radio } from 'src/components/Radio';
-import Tabs from 'src/components/Tabs';
+import { Tabs } from 'antd-v5';
import { Tooltip } from 'src/components/Tooltip';
import { cachedSupersetGet } from 'src/utils/cachedSupersetGet';
import {
@@ -240,23 +241,6 @@ const StyledCollapse = styled(Collapse)`
}
`;
-const StyledTabs = styled(Tabs)`
- .ant-tabs-nav {
- position: sticky;
- top: 0;
- background: ${({ theme }) => theme.colors.grayscale.light5};
- z-index: 1;
- }
-
- .ant-tabs-nav-list {
- padding: 0;
- }
-
- .ant-form-item-label {
- padding-bottom: 0;
- }
-`;
-
const StyledAsterisk = styled.span`
color: ${({ theme }) => theme.colors.error.base};
font-size: ${({ theme }) => theme.typography.sizes.s}px;
@@ -815,12 +799,12 @@ const FiltersConfigForm = (
/>
</StyledRowFormItem>
);
-
+ const theme = useTheme();
return (
- <StyledTabs
+ <Tabs
activeKey={activeTabKey}
onChange={activeKey => setActiveTabKey(activeKey)}
- centered
+ tabBarStyle={{ paddingLeft: theme.gridUnit * 4 }}
>
<TabPane
tab={FilterTabs.configuration.name}
@@ -1358,7 +1342,7 @@ const FiltersConfigForm = (
initiallyExcludedCharts={initiallyExcludedCharts}
/>
</TabPane>
- </StyledTabs>
+ </Tabs>
);
};
diff --git a/superset-frontend/src/explore/components/ControlPanelsContainer.tsx b/superset-frontend/src/explore/components/ControlPanelsContainer.tsx
index 77e5580fd7..db932250aa 100644
--- a/superset-frontend/src/explore/components/ControlPanelsContainer.tsx
+++ b/superset-frontend/src/explore/components/ControlPanelsContainer.tsx
@@ -57,7 +57,7 @@ import { rgba } from 'emotion-rgba';
import { kebabCase, isEqual } from 'lodash';
import Collapse from 'src/components/Collapse';
-import Tabs from 'src/components/Tabs';
+import { Tabs } from 'antd-v5';
import { PluginContext } from 'src/components/DynamicPlugins';
import Loading from 'src/components/Loading';
import Modal from 'src/components/Modal';
@@ -139,9 +139,6 @@ const Styles = styled.div`
height: 100%;
overflow: visible;
}
- .nav-tabs {
- flex: 0 0 1;
- }
.tab-content {
overflow: auto;
flex: 1 1 100%;
@@ -158,40 +155,6 @@ const Styles = styled.div`
}
`;
-const ControlPanelsTabs = styled(Tabs)`
- ${({ theme, fullWidth }) => css`
- height: 100%;
- overflow: visible;
- .ant-tabs-nav {
- margin-bottom: 0;
- }
- .ant-tabs-nav-list {
- width: ${fullWidth ? '100%' : '50%'};
- }
- .ant-tabs-tabpane {
- height: 100%;
- }
- .ant-tabs-content-holder {
- padding-top: ${theme.gridUnit * 4}px;
- }
-
- .ant-collapse-ghost > .ant-collapse-item {
- &:not(:last-child) {
- border-bottom: 1px solid ${theme.colors.grayscale.light3};
- }
-
- & > .ant-collapse-header {
- font-size: ${theme.typography.sizes.s}px;
- }
-
- & > .ant-collapse-content > .ant-collapse-content-box {
- padding-bottom: 0;
- font-size: ${theme.typography.sizes.s}px;
- }
- }
- `}
-`;
-
const isTimeSection = (section: ControlPanelSectionConfig): boolean =>
!!section.label && sections.legacyTimeseriesTime.label === section.label;
@@ -269,7 +232,7 @@ function useResetOnChangeRef(initialValue: () => any, resetOnChangeValue: any) {
}
export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
- const { colors } = useTheme();
+ const { colors, gridUnit } = useTheme();
const pluginContext = useContext(PluginContext);
const prevState = usePrevious(props.exploreState);
@@ -791,10 +754,11 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
return (
<Styles ref={containerRef}>
- <ControlPanelsTabs
+ <Tabs
id="controlSections"
data-test="control-tabs"
fullWidth={showCustomizeTab}
+ tabBarStyle={{ paddingLeft: gridUnit * 4 }}
allowOverflow={false}
>
<Tabs.TabPane key="query" tab={dataTabTitle}>
@@ -818,7 +782,7 @@ export const ControlPanelsContainer = (props: ControlPanelsContainerProps) => {
</Collapse>
</Tabs.TabPane>
)}
- </ControlPanelsTabs>
+ </Tabs>
<div css={actionButtonsContainerStyles}>
<RunQueryButton
onQuery={props.onQuery}
diff --git a/superset-frontend/src/explore/components/DataTablesPane/DataTablesPane.tsx b/superset-frontend/src/explore/components/DataTablesPane/DataTablesPane.tsx
index 640834ba94..3a39beaea6 100644
--- a/superset-frontend/src/explore/components/DataTablesPane/DataTablesPane.tsx
+++ b/superset-frontend/src/explore/components/DataTablesPane/DataTablesPane.tsx
@@ -25,7 +25,7 @@ import {
useTheme,
} from '@superset-ui/core';
import Icons from 'src/components/Icons';
-import Tabs from 'src/components/Tabs';
+import { Tabs } from 'antd-v5';
import {
getItem,
setItem,
diff --git a/superset-frontend/src/features/datasets/AddDataset/EditDataset/index.tsx b/superset-frontend/src/features/datasets/AddDataset/EditDataset/index.tsx
index b647c4532a..048465daf5 100644
--- a/superset-frontend/src/features/datasets/AddDataset/EditDataset/index.tsx
+++ b/superset-frontend/src/features/datasets/AddDataset/EditDataset/index.tsx
@@ -17,18 +17,18 @@
* under the License.
*/
import { styled, t } from '@superset-ui/core';
+import { Tabs } from 'antd-v5'; // Changed to import from antd directly
import useGetDatasetRelatedCounts from 'src/features/datasets/hooks/useGetDatasetRelatedCounts';
import Badge from 'src/components/Badge';
-import Tabs from 'src/components/Tabs';
import UsageTab from './UsageTab';
+// Updated styled component to use antd directly
const StyledTabs = styled(Tabs)`
${({ theme }) => `
margin-top: ${theme.gridUnit * 8.5}px;
padding-left: ${theme.gridUnit * 4}px;
padding-right: ${theme.gridUnit * 4}px;
-
- .ant-tabs-top > .ant-tabs-nav::before {
+ .ant-tabs-nav::before {
width: ${theme.gridUnit * 50}px;
}
`}
@@ -63,14 +63,30 @@ const EditPage = ({ id }: EditPageProps) => {
</TabStyles>
);
+ // Create items array for antd v5 Tabs
+ const items = [
+ {
+ key: '1',
+ label: TRANSLATIONS.COLUMNS_TEXT,
+ children: null,
+ },
+ {
+ key: '2',
+ label: TRANSLATIONS.METRICS_TEXT,
+ children: null,
+ },
+ {
+ key: '3',
+ label: usageTab,
+ children: <UsageTab datasetId={id} />,
+ },
+ ];
+
return (
- <StyledTabs moreIcon={null} fullWidth={false}>
- <Tabs.TabPane tab={TRANSLATIONS.COLUMNS_TEXT} key="1" />
- <Tabs.TabPane tab={TRANSLATIONS.METRICS_TEXT} key="2" />
- <Tabs.TabPane tab={usageTab} key="3">
- <UsageTab datasetId={id} />
- </Tabs.TabPane>
- </StyledTabs>
+ <StyledTabs
+ moreIcon={null}
+ items={items}
+ />
);
};