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

Commit

Permalink
#769 Advanced edit updates also master doc && after modal closing sta…
Browse files Browse the repository at this point in the history
…le tabs are refetched
  • Loading branch information
damianprzygodzki committed May 22, 2017
1 parent 7843ea9 commit 21aa3be
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
20 changes: 12 additions & 8 deletions src/actions/WindowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,14 @@ export function patch(
)).then(response => {
responsed = true;
dispatch(mapDataToState(
response.data, isModal, rowId, id, windowType
response.data, isModal, rowId, id, windowType, isAdvanced
));
}).catch(() => {
dispatch(getData(
entity, windowType, id, tabId, rowId, null, null, isAdvanced
)).then(response => {
dispatch(mapDataToState(
response.data, isModal, rowId, id, windowType
response.data, isModal, rowId, id, windowType, isAdvanced
));
});
});
Expand Down Expand Up @@ -462,7 +462,7 @@ function updateRow(row, scope){
}
}

function mapDataToState(data, isModal, rowId, id, windowType) {
function mapDataToState(data, isModal, rowId, id, windowType, isAdvanced) {
return (dispatch) => {
let staleTabIds = [];

Expand All @@ -474,7 +474,7 @@ function mapDataToState(data, isModal, rowId, id, windowType) {
if(
tabInfo.stale &&
staleTabIds.indexOf(tabInfo.tabid) === -1
){
){
staleTabIds.push(tabInfo.tabid);
}
})
Expand All @@ -490,10 +490,15 @@ function mapDataToState(data, isModal, rowId, id, windowType) {
))
}else{
if (item.rowId && !isModal) {
// Update directly to a row by the widget in cell
dispatch(updateRow(parsedItem, 'master'));
} else {
// Update by a modal
item.rowId && dispatch(updateRow(parsedItem, 'master'));

// Advanced edit
isAdvanced && dispatch(updateData(parsedItem, 'master'));

dispatch(updateData(
parsedItem, getScope(isModal && index === 0)
));
Expand All @@ -502,12 +507,11 @@ function mapDataToState(data, isModal, rowId, id, windowType) {
})

//Handling staleTabIds
staleTabIds.map(staleTabId => {
!isModal && staleTabIds.map(staleTabId => {
dispatch(getTab(staleTabId, windowType, id)).then(tab => {
dispatch(addRowData({[staleTabId]: tab}, getScope('master')));
})
dispatch(addRowData({[staleTabId]: tab}, 'master'));
});
})

}
}

Expand Down
16 changes: 14 additions & 2 deletions src/containers/MasterWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {push} from 'react-router-redux';
import {
findRowByPropName,
attachFileAction,
clearMasterData
clearMasterData,
getTab,
addRowData
} from '../actions/WindowActions';

import {
Expand Down Expand Up @@ -42,7 +44,7 @@ class MasterWindow extends Component {
}

componentDidUpdate(prevProps) {
const {master} = this.props;
const {master, modal, params, dispatch} = this.props;
const isDocumentNotSaved = !master.saveStatus.saved;
const isDocumentSaved = master.saveStatus.saved;

Expand All @@ -52,6 +54,16 @@ class MasterWindow extends Component {
if (!prevProps.master.saveStatus.saved && isDocumentSaved) {
window.removeEventListener('beforeunload', this.confirm)
}

// When closing modal, we need to update the stale tabs
if(!modal.visible && modal.visible !== prevProps.modal.visible){
Object.keys(master.includedTabsInfo).map(tabId => {
dispatch(getTab(tabId, params.windowType, master.docId))
.then(tab => {
dispatch(addRowData({[tabId]: tab}, 'master'));
});
})
}
}

componentWillUnmount() {
Expand Down

0 comments on commit 21aa3be

Please sign in to comment.