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 #1356 from metasfresh/dev-1351
Browse files Browse the repository at this point in the history
Update wrong api handler for table cell updates #1351
  • Loading branch information
teosarca authored Nov 20, 2017
2 parents 919bd74 + 8509a33 commit 68b9e78
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 21 deletions.
9 changes: 6 additions & 3 deletions src/actions/GenericActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ export function initLayout(

export function getData(
entity, docType, docId, tabId, rowId, subentity, subentityId, isAdvanced,
orderBy
orderBy, viewId
) {
return axios.get(
config.API_URL +
'/' + entity +
'/' + docType +
(viewId ? '/' + viewId : '') +
(docId ? '/' + docId : '') +
(tabId ? '/' + tabId : '') +
(rowId ? '/' + rowId : '') +
Expand Down Expand Up @@ -62,7 +63,8 @@ export function patchRequest({
subentityId,
tabId,
value,
viewId
viewId,
isEdit
}) {
let payload = [];

Expand Down Expand Up @@ -98,7 +100,8 @@ export function patchRequest({
(rowId ? '/' + rowId : '') +
(subentity ? '/' + subentity : '') +
(subentityId ? '/' + subentityId : '') +
(isAdvanced ? '?advanced=true' : ''), payload);
(isAdvanced ? '?advanced=true' : '') +
(isEdit ? '/edit' : ''), payload);
}

export function getDataByIds(entity, docType, viewId, docIds) {
Expand Down
33 changes: 22 additions & 11 deletions src/actions/WindowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ export function initWindow(windowType, docId, tabId, rowId = null, isAdvanced) {
*/
export function patch(
entity, windowType, id = 'NEW', tabId, rowId, property, value, isModal,
isAdvanced
isAdvanced, viewId, isEdit
) {
return dispatch => {
dispatch(indicatorState('pending'));
Expand All @@ -468,7 +468,9 @@ export function patch(
rowId,
property,
value,
isAdvanced
isAdvanced,
viewId,
isEdit
}).then(response => {
dispatch(mapDataToState(
response.data, isModal, rowId, id, windowType, isAdvanced
Expand All @@ -479,7 +481,8 @@ export function patch(
return response.data;
}).catch(() => {
getData(
entity, windowType, id, tabId, rowId, null, null, isAdvanced
entity, windowType, id, tabId, rowId, null, null, isAdvanced,
null, viewId
).then(response => {
dispatch(mapDataToState(
response.data, isModal, rowId, id, windowType, isAdvanced
Expand Down Expand Up @@ -630,35 +633,42 @@ export function updatePropertyValue(property, value, tabid, rowid, isModal) {
}

function handleUploadProgress(dispatch, notificationTitle, progressEvent) {
let percentLeft = Math.min(Math.floor((progressEvent.loaded * 100) / progressEvent.total), 98);
let percentLeft = Math.min(
Math.floor((progressEvent.loaded * 100) / progressEvent.total), 98);

dispatch(setNotificationProgress(notificationTitle, percentLeft));
}

export function attachFileAction(windowType, docId, data){
return (dispatch) => {
const notificationTitle = counterpart.translate('window.attachment.title');
const notificationTitle =
counterpart.translate('window.attachment.title');

dispatch(addNotification(
notificationTitle, counterpart.translate('window.attachment.uploading'), 0, 'primary'
notificationTitle, counterpart.translate(
'window.attachment.uploading'), 0, 'primary'
));

let requestConfig = {
onUploadProgress: handleUploadProgress.bind(this, dispatch, notificationTitle)
onUploadProgress: handleUploadProgress.bind(this,
dispatch, notificationTitle)
};

return axios.post(
`${config.API_URL}/window/${windowType}/${docId}/attachments`, data, requestConfig
`${config.API_URL}/window/${windowType}/${docId}/attachments`,
data, requestConfig
).then(() => {
dispatch(setNotificationProgress(notificationTitle, 100));

dispatch(addNotification(
notificationTitle, counterpart.translate('window.attachment.upload.success'), 5000, 'primary'
notificationTitle, counterpart.translate(
'window.attachment.upload.success'), 5000, 'primary'
))
})
.catch(() => {
dispatch(addNotification(
notificationTitle, counterpart.translate('window.attachment.upload.error'), 5000, 'error'
notificationTitle, counterpart.translate(
'window.attachment.upload.error'), 5000, 'error'
))
})
}
Expand Down Expand Up @@ -800,7 +810,8 @@ export function handleProcessResponse(response, type, id) {
await dispatch(closeModal());

if (action.modal) {
// Do not close process modal, since it will be re-used with document view
// Do not close process modal,
// since it will be re-used with document view
keepProcessModal = true;

await dispatch(
Expand Down
5 changes: 3 additions & 2 deletions src/components/table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ class Table extends Component {
const {
tabid, cols, type, docId, readonly, keyProperty, onDoubleClick,
mainTable, newRow, tabIndex, entity, indentSupported, collapsible,
showIncludedViewOnSelect, openIncludedViewOnSelect
showIncludedViewOnSelect, openIncludedViewOnSelect, viewId
} = this.props;

const {
Expand All @@ -914,7 +914,8 @@ class Table extends Component {
<TableItem
{...item}
{...{entity, cols, type, mainTable, indentSupported,
selected, docId, tabIndex, readonly, collapsible
selected, docId, tabIndex, readonly, collapsible,
viewId
}}
collapsed={
collapsedParentsRows
Expand Down
3 changes: 2 additions & 1 deletion src/components/table/TableCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class TableCell extends Component {
isEdited, widgetData, item, docId, type, rowId, tabId,
onDoubleClick, onKeyDown, readonly, updatedRow, tabIndex, entity,
listenOnKeys, listenOnKeysFalse, closeTableField, getSizeClass,
handleRightClick, mainTable, onCellChange
handleRightClick, mainTable, onCellChange, viewId
} = this.props;

let tdValue = (!isEdited) ?
Expand Down Expand Up @@ -150,6 +150,7 @@ class TableCell extends Component {
windowType={type}
isMainTable={mainTable}
rowId={rowId}
viewId={viewId}
tabId={mainTable ? null : tabId}
noLabel={true}
gridAlign={item.gridAlign}
Expand Down
4 changes: 2 additions & 2 deletions src/components/table/TableItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class TableItem extends Component {
const {
type, docId, rowId, tabId, readonly, mainTable, newRow,
changeListenOnTrue, tabIndex, entity, getSizeClass,
handleRightClick, caption, colspan, onItemChange
handleRightClick, caption, colspan, onItemChange, viewId
} = this.props;

const {
Expand Down Expand Up @@ -194,7 +194,7 @@ class TableItem extends Component {
<TableCell
{...{getSizeClass, entity, type, docId, rowId,
tabId, item, readonly, widgetData, tabIndex,
listenOnKeys, caption, mainTable
listenOnKeys, caption, mainTable, viewId
}}
key={index}
isEdited={isEditable || edited === property}
Expand Down
12 changes: 10 additions & 2 deletions src/components/widget/MasterWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ class MasterWidget extends Component {
handlePatch = (property, value) => {
const {
isModal, widgetType, dataId, windowType, dispatch, rowId, tabId,
onChange, relativeDocId, isAdvanced = false, entity
onChange, relativeDocId, isAdvanced = false, viewId
} = this.props;

let {entity} = this.props;

let currRowId = rowId;
let ret = null;
let isEdit = false;

if(rowId === 'NEW'){
currRowId = relativeDocId;
Expand All @@ -89,9 +92,14 @@ class MasterWidget extends Component {
);
}

if (viewId) {
entity = 'documentView';
isEdit = true;
}

ret = dispatch(patch(
entity, windowType, dataId, tabId, currRowId, property, value,
isModal, isAdvanced
isModal, isAdvanced, viewId, isEdit
));

//callback
Expand Down

0 comments on commit 68b9e78

Please sign in to comment.