Skip to content

Commit

Permalink
chore: Rename SET_ACTIVE_TABS action, add a new action (apache#26147)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje authored Nov 30, 2023
1 parent d002dcd commit 59eb505
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
9 changes: 7 additions & 2 deletions superset-frontend/src/dashboard/actions/dashboardState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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');
Expand Down Expand Up @@ -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(() => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -75,7 +75,7 @@ const defaultProps = {
columnWidth: 0,
activeTabs: [],
directPathToChild: [],
setActiveTabs() {},
setActiveTab() {},
onResizeStart() {},
onResize() {},
onResizeStop() {},
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
} from 'src/dashboard/actions/dashboardLayout';
import {
setDirectPathToChild,
setActiveTabs,
setActiveTab,
setFullSizeChartId,
} from 'src/dashboard/actions/dashboardState';

Expand Down Expand Up @@ -109,7 +109,7 @@ function mapDispatchToProps(dispatch) {
handleComponentDrop,
setDirectPathToChild,
setFullSizeChartId,
setActiveTabs,
setActiveTab,
logEvent,
},
dispatch,
Expand Down
9 changes: 8 additions & 1 deletion superset-frontend/src/dashboard/reducers/dashboardState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
22 changes: 17 additions & 5 deletions superset-frontend/src/dashboard/reducers/dashboardState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'] });
});
});

0 comments on commit 59eb505

Please sign in to comment.