Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Unset active tab when unmounting <Tabs>
Browse files Browse the repository at this point in the history
Issue #1312
  • Loading branch information
pablosichert authored and ottosichert committed Nov 5, 2017
1 parent f4b4425 commit 9ec8afb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/actions/WindowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ export function activateTab(scope, tabId) {
}
}

export function unselectTab(scope) {
return {
type: types.UNSELECT_TAB,
scope
}
}

export function initLayoutSuccess(layout, scope) {
return {
type: types.INIT_LAYOUT_SUCCESS,
Expand Down
6 changes: 5 additions & 1 deletion src/components/tabs/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {connect} from 'react-redux';
import PropTypes from 'prop-types';

import Tab from './Tab';
import {activateTab} from '../../actions/WindowActions';
import { activateTab, unselectTab } from '../../actions/WindowActions';

class Tabs extends Component {
constructor(props) {
Expand All @@ -24,6 +24,10 @@ class Tabs extends Component {
}
}

componentWillUnmount() {
this.props.dispatch(unselectTab('master'));
}

handleClick = (e, id) => {
e.preventDefault();
this.setState({
Expand Down
1 change: 1 addition & 0 deletions src/constants/ActionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const INIT_LAYOUT_SUCCESS = 'INIT_LAYOUT_SUCCESS';
export const ADD_ROW_DATA = 'ADD_ROW_DATA';
export const SORT_TAB = 'SORT_TAB';
export const ACTIVATE_TAB = 'ACTIVATE_TAB';
export const UNSELECT_TAB = 'UNSELECT_TAB';
export const ADD_NEW_ROW = 'ADD_NEW_ROW';
export const DELETE_ROW = 'DELETE_ROW';
export const UPDATE_ROW_PROPERTY = 'UPDATE_ROW_PROPERTY';
Expand Down
13 changes: 12 additions & 1 deletion src/reducers/windowHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const initialState = {
viewId: null
},
master: {
layout: {},
layout: {
activeTab: null
},
data: [],
rowData: {},
saveStatus: {},
Expand Down Expand Up @@ -158,6 +160,15 @@ export default function windowHandler(state = initialState, action) {
}
})

case types.UNSELECT_TAB:
return update(state, {
[action.scope]: {
layout: {
activeTab: { $set: null }
}
}
})

case types.ADD_ROW_DATA:
return Object.assign({}, state, {
[action.scope]: Object.assign({}, state[action.scope], {
Expand Down

0 comments on commit 9ec8afb

Please sign in to comment.