From d00c17dde2b80c2deb64ae8f8585cf5c225f3275 Mon Sep 17 00:00:00 2001 From: Kamil Gabryjelski Date: Thu, 30 Nov 2023 12:27:40 +0100 Subject: [PATCH] chore: Rename SET_ACTIVE_TABS action, add a new action (#26147) --- .../src/dashboard/actions/dashboardState.js | 9 ++++++-- .../DashboardBuilder.test.tsx | 6 ++--- .../components/gridComponents/Tabs.jsx | 8 +++---- .../containers/DashboardComponent.jsx | 4 ++-- .../src/dashboard/reducers/dashboardState.js | 9 +++++++- .../dashboard/reducers/dashboardState.test.ts | 22 ++++++++++++++----- 6 files changed, 41 insertions(+), 17 deletions(-) diff --git a/superset-frontend/src/dashboard/actions/dashboardState.js b/superset-frontend/src/dashboard/actions/dashboardState.js index dcf1020e6..b461275d8 100644 --- a/superset-frontend/src/dashboard/actions/dashboardState.js +++ b/superset-frontend/src/dashboard/actions/dashboardState.js @@ -611,9 +611,14 @@ export function setDirectPathToChild(path) { return { type: SET_DIRECT_PATH, path }; } +export const SET_ACTIVE_TAB = 'SET_ACTIVE_TAB'; +export function setActiveTab(tabId, prevTabId) { + return { type: SET_ACTIVE_TAB, tabId, prevTabId }; +} + export const SET_ACTIVE_TABS = 'SET_ACTIVE_TABS'; -export function setActiveTabs(tabId, prevTabId) { - return { type: SET_ACTIVE_TABS, tabId, prevTabId }; +export function setActiveTabs(activeTabs) { + return { type: SET_ACTIVE_TABS, activeTabs }; } export const SET_FOCUSED_FILTER_FIELD = 'SET_FOCUSED_FILTER_FIELD'; diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx index 7c3dd2339..02a3a4997 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx @@ -25,7 +25,7 @@ import DashboardBuilder from 'src/dashboard/components/DashboardBuilder/Dashboar import useStoredSidebarWidth from 'src/components/ResizableSidebar/useStoredSidebarWidth'; import { fetchFaveStar, - setActiveTabs, + setActiveTab, setDirectPathToChild, } from 'src/dashboard/actions/dashboardState'; import { @@ -41,7 +41,7 @@ fetchMock.get('glob:*/csstemplateasyncmodelview/api/read', {}); jest.mock('src/dashboard/actions/dashboardState', () => ({ ...jest.requireActual('src/dashboard/actions/dashboardState'), fetchFaveStar: jest.fn(), - setActiveTabs: jest.fn(), + setActiveTab: jest.fn(), setDirectPathToChild: jest.fn(), })); jest.mock('src/components/ResizableSidebar/useStoredSidebarWidth'); @@ -90,7 +90,7 @@ describe('DashboardBuilder', () => { favStarStub = (fetchFaveStar as jest.Mock).mockReturnValue({ type: 'mock-action', }); - activeTabsStub = (setActiveTabs as jest.Mock).mockReturnValue({ + activeTabsStub = (setActiveTab as jest.Mock).mockReturnValue({ type: 'mock-action', }); (useStoredSidebarWidth as jest.Mock).mockImplementation(() => [ diff --git a/superset-frontend/src/dashboard/components/gridComponents/Tabs.jsx b/superset-frontend/src/dashboard/components/gridComponents/Tabs.jsx index 7d9a46b75..67f4b3c59 100644 --- a/superset-frontend/src/dashboard/components/gridComponents/Tabs.jsx +++ b/superset-frontend/src/dashboard/components/gridComponents/Tabs.jsx @@ -51,7 +51,7 @@ const propTypes = { // actions (from DashboardComponent.jsx) logEvent: PropTypes.func.isRequired, - setActiveTabs: PropTypes.func, + setActiveTab: PropTypes.func, // grid related availableColumnCount: PropTypes.number, @@ -75,7 +75,7 @@ const defaultProps = { columnWidth: 0, activeTabs: [], directPathToChild: [], - setActiveTabs() {}, + setActiveTab() {}, onResizeStart() {}, onResize() {}, onResizeStop() {}, @@ -125,12 +125,12 @@ export class Tabs extends React.PureComponent { } componentDidMount() { - this.props.setActiveTabs(this.state.activeKey); + this.props.setActiveTab(this.state.activeKey); } componentDidUpdate(prevProps, prevState) { if (prevState.activeKey !== this.state.activeKey) { - this.props.setActiveTabs(this.state.activeKey, prevState.activeKey); + this.props.setActiveTab(this.state.activeKey, prevState.activeKey); } } diff --git a/superset-frontend/src/dashboard/containers/DashboardComponent.jsx b/superset-frontend/src/dashboard/containers/DashboardComponent.jsx index 08b7ed9f8..68478adb0 100644 --- a/superset-frontend/src/dashboard/containers/DashboardComponent.jsx +++ b/superset-frontend/src/dashboard/containers/DashboardComponent.jsx @@ -35,7 +35,7 @@ import { } from 'src/dashboard/actions/dashboardLayout'; import { setDirectPathToChild, - setActiveTabs, + setActiveTab, setFullSizeChartId, } from 'src/dashboard/actions/dashboardState'; @@ -109,7 +109,7 @@ function mapDispatchToProps(dispatch) { handleComponentDrop, setDirectPathToChild, setFullSizeChartId, - setActiveTabs, + setActiveTab, logEvent, }, dispatch, diff --git a/superset-frontend/src/dashboard/reducers/dashboardState.js b/superset-frontend/src/dashboard/reducers/dashboardState.js index 5d81cd8ac..015cb9822 100644 --- a/superset-frontend/src/dashboard/reducers/dashboardState.js +++ b/superset-frontend/src/dashboard/reducers/dashboardState.js @@ -37,6 +37,7 @@ import { SET_DIRECT_PATH, SET_FOCUSED_FILTER_FIELD, UNSET_FOCUSED_FILTER_FIELD, + SET_ACTIVE_TAB, SET_ACTIVE_TABS, SET_FULL_SIZE_CHART_ID, ON_FILTERS_REFRESH, @@ -179,7 +180,7 @@ export default function dashboardStateReducer(state = {}, action) { directPathLastUpdated: Date.now(), }; }, - [SET_ACTIVE_TABS]() { + [SET_ACTIVE_TAB]() { const newActiveTabs = new Set(state.activeTabs); newActiveTabs.delete(action.prevTabId); newActiveTabs.add(action.tabId); @@ -188,6 +189,12 @@ export default function dashboardStateReducer(state = {}, action) { activeTabs: Array.from(newActiveTabs), }; }, + [SET_ACTIVE_TABS]() { + return { + ...state, + activeTabs: action.activeTabs, + }; + }, [SET_OVERRIDE_CONFIRM]() { return { ...state, diff --git a/superset-frontend/src/dashboard/reducers/dashboardState.test.ts b/superset-frontend/src/dashboard/reducers/dashboardState.test.ts index 274b26733..3a8adc6cb 100644 --- a/superset-frontend/src/dashboard/reducers/dashboardState.test.ts +++ b/superset-frontend/src/dashboard/reducers/dashboardState.test.ts @@ -18,21 +18,33 @@ */ import dashboardStateReducer from './dashboardState'; -import { setActiveTabs } from '../actions/dashboardState'; +import { setActiveTab, setActiveTabs } from '../actions/dashboardState'; describe('DashboardState reducer', () => { - it('SET_ACTIVE_TABS', () => { + it('SET_ACTIVE_TAB', () => { expect( - dashboardStateReducer({ activeTabs: [] }, setActiveTabs('tab1')), + dashboardStateReducer({ activeTabs: [] }, setActiveTab('tab1')), ).toEqual({ activeTabs: ['tab1'] }); expect( - dashboardStateReducer({ activeTabs: ['tab1'] }, setActiveTabs('tab1')), + dashboardStateReducer({ activeTabs: ['tab1'] }, setActiveTab('tab1')), ).toEqual({ activeTabs: ['tab1'] }); expect( dashboardStateReducer( { activeTabs: ['tab1'] }, - setActiveTabs('tab2', 'tab1'), + setActiveTab('tab2', 'tab1'), ), ).toEqual({ activeTabs: ['tab2'] }); }); + + it('SET_ACTIVE_TABS', () => { + expect( + dashboardStateReducer({ activeTabs: [] }, setActiveTabs(['tab1'])), + ).toEqual({ activeTabs: ['tab1'] }); + expect( + dashboardStateReducer( + { activeTabs: ['tab1', 'tab2'] }, + setActiveTabs(['tab3', 'tab4']), + ), + ).toEqual({ activeTabs: ['tab3', 'tab4'] }); + }); });