You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2023/12/04 21:05:50 UTC

(superset) 05/15: chore: Rename SET_ACTIVE_TABS action, add a new action (#26147)

This is an automated email from the ASF dual-hosted git repository.

michaelsmolina pushed a commit to branch 3.1
in repository https://gitbox.apache.org/repos/asf/superset.git

commit fad4616d2f8a4a66769f5dbb11ddf93f85f71166
Author: Kamil Gabryjelski <ka...@gmail.com>
AuthorDate: Thu Nov 30 12:27:40 2023 +0100

    chore: Rename SET_ACTIVE_TABS action, add a new action (#26147)
    
    (cherry picked from commit d00c17dde2b80c2deb64ae8f8585cf5c225f3275)
---
 .../src/dashboard/actions/dashboardState.js        |  9 +++++++--
 .../DashboardBuilder/DashboardBuilder.test.tsx     |  6 +++---
 .../dashboard/components/gridComponents/Tabs.jsx   |  8 ++++----
 .../dashboard/containers/DashboardComponent.jsx    |  4 ++--
 .../src/dashboard/reducers/dashboardState.js       |  9 ++++++++-
 .../src/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 dcf1020e6d..b461275d8c 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 7c3dd23392..02a3a49971 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 7d9a46b75d..67f4b3c598 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 08b7ed9f82..68478adb07 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 5d81cd8ac1..015cb9822c 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 274b26733c..3a8adc6cbb 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'] });
+  });
 });