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

Commit

Permalink
Merge pull request #770 from metasfresh/dev-769
Browse files Browse the repository at this point in the history
#769 Reverting changes from #704
  • Loading branch information
damianprzygodzki authored May 22, 2017
2 parents 7d92cda + 21aa3be commit 57198b9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
18 changes: 11 additions & 7 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 @@ -504,10 +509,9 @@ function mapDataToState(data, isModal, rowId, id, windowType) {
//Handling staleTabIds
!isModal && staleTabIds.map(staleTabId => {
dispatch(getTab(staleTabId, windowType, id)).then(tab => {
dispatch(addRowData({[staleTabId]: tab}, getScope(isModal)));
})
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 57198b9

Please sign in to comment.