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 #800 from metasfresh/revert-792-dev-773
Browse files Browse the repository at this point in the history
Revert "Dev 773"
  • Loading branch information
damianprzygodzki authored May 26, 2017
2 parents 7d2c163 + 64a747d commit cbb63b2
Show file tree
Hide file tree
Showing 16 changed files with 186 additions and 136 deletions.
62 changes: 28 additions & 34 deletions src/actions/WindowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export function createWindow(
docId = response.data[elem].id;

dispatch(initDataSuccess(
parseToDisplay(response.data[elem].fieldsByName),
parseToDisplay(response.data[elem].fields),
getScope(isModal), docId,
response.data[0].saveStatus, response.data[0].validStatus,
response.data[0].includedTabsInfo
Expand Down Expand Up @@ -338,7 +338,7 @@ export function getTab(tabId, windowType, docId) {
if(res.data){
let tab = {};
res.data.map(row => {
row.fieldsByName = parseToDisplay(row.fieldsByName);
row.fields = parseToDisplay(row.fields);
tab[row.rowId] = row;
});
return tab;
Expand Down Expand Up @@ -427,10 +427,10 @@ export function patch(
function updateData(doc, scope){
return dispatch => {
Object.keys(doc).map(key => {
if(key === 'fieldsByName'){
Object.keys(doc.fieldsByName).map(fieldName => {
if(key === 'fields'){
doc.fields.map(field => {
dispatch(updateDataFieldProperty(
fieldName, doc.fieldsByName[fieldName], scope
field.field, field, scope
))
})
}else if(key === 'includedTabsInfo'){
Expand All @@ -447,11 +447,10 @@ function updateData(doc, scope){
function updateRow(row, scope){
return dispatch => {
Object.keys(row).map(key => {
if(key === 'fieldsByName'){
Object.keys(row.fieldsByName).map(fieldName => {
if(key === 'fields'){
row.fields.map(field => {
dispatch(updateRowFieldProperty(
fieldName, row.fieldsByName[fieldName], row.tabid,
row.rowId, scope
field.field, field, row.tabid, row.rowId, scope
))
});
}else{
Expand Down Expand Up @@ -480,8 +479,8 @@ function mapDataToState(data, isModal, rowId, id, windowType, isAdvanced) {
}
})

const parsedItem = item.fieldsByName ? Object.assign({}, item, {
fieldsByName: parseToDisplay(item.fieldsByName)
const parsedItem = item.fields ? Object.assign({}, item, {
fields: parseToDisplay(item.fields)
}) : item;

// First item in response is direct one for action that called it.
Expand Down Expand Up @@ -618,10 +617,9 @@ export function createProcess(processType, viewId, type, ids, tabId, rowId) {
getProcessData(processType, viewId, type, ids, tabId, rowId)
).then(response => {
const preparedData = parseToDisplay(response.data.parameters);

pid = response.data.pinstanceId;

if (Object.keys(preparedData).length === 0) {
if (preparedData.length === 0) {
dispatch(startProcess(processType, pid)).then(response => {
dispatch(setProcessSaved());
dispatch(handleProcessResponse(response, processType, pid));
Expand Down Expand Up @@ -755,30 +753,26 @@ function getScope(isModal) {
return isModal ? 'modal' : 'master';
}

export function parseToDisplay(obj) {
return parseDateToReadable(nullToEmptyStrings(obj));
export function parseToDisplay(arr) {
return parseDateToReadable(nullToEmptyStrings(arr));
}

function parseDateToReadable(obj) {
function parseDateToReadable(arr) {
const dateParse = ['Date', 'DateTime', 'Time'];

return Object.keys(obj).reduce((acc, key) => {
acc[key] =
(dateParse.indexOf(obj[key].widgetType) > -1 && obj[key].value) ?
Object.assign({}, obj[key], {
value: obj[key].value ? new Date(obj[key].value) : ''
}) : obj[key];
return acc;
}, {});
}

function nullToEmptyStrings(obj) {
return Object.keys(obj).reduce((acc, key) => {
acc[key] = (obj[key].value === null) ?
Object.assign({}, obj[key], { value: '' }) :
obj[key];
return acc;
}, {})
return arr.map(item =>
(dateParse.indexOf(item.widgetType) > -1 && item.value) ?
Object.assign({}, item, {
value: item.value ? new Date(item.value) : ''
}) : item
)
}

function nullToEmptyStrings(arr) {
return arr.map(item =>
(item.value === null) ?
Object.assign({}, item, { value: '' }) :
item
)
}

export function findRowByPropName(arr, name) {
Expand Down
34 changes: 20 additions & 14 deletions src/components/DataLayoutWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ class DataLayoutWrapper extends Component {
handleChange = (field, value) => {
const {data} = this.state;

this.setState(prevState => ({
data: Object.assign({}, prevState.data, {
[field]: Object.assign({}, prevState.data[field], {
value
})
this.setState({
data: data.map(item => {
if(item.field === field){
return Object.assign({}, item, {
value: value
})
}else{
return item;
}
})
}))
})
}

handlePatch = (prop, value, cb) => {
Expand All @@ -48,15 +52,17 @@ class DataLayoutWrapper extends Component {
entity, windowType, dataId, null, null, prop, value, null, null,
null, viewId
)).then(response => {
const preparedData = parseToDisplay(response.data[0].fieldsByName);
preparedData && Object.keys(preparedData).map(key => {
this.setState(prevState => ({
data: Object.assign({}, prevState.data, {
[key]: Object.assign(
{}, prevState.data[key], preparedData[key]
)
const preparedData = parseToDisplay(response.data[0].fields);
preparedData && preparedData.map(item => {
this.setState({
data: this.state.data.map(field => {
if(field.field === item.field){
return Object.assign({}, field, item);
}else{
return field;
}
})
}))
});
})
});

Expand Down
8 changes: 7 additions & 1 deletion src/components/Process.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import {connect} from 'react-redux';

import MasterWidget from './widget/MasterWidget';

import {
findRowByPropName
} from '../actions/WindowActions';

export class Process extends Component {
constructor(props){
super(props);
Expand All @@ -13,7 +17,9 @@ export class Process extends Component {
const {disabled} = this.props;
const elements = layout.elements;
return elements.map((elem, id) => {
const widgetData = elem.fields.map(item => data[item.field] || -1);
const widgetData = elem.fields.map(item =>
findRowByPropName(data, item.field)
);
return (
<MasterWidget
entity="process"
Expand Down
12 changes: 9 additions & 3 deletions src/components/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import React, { Component } from 'react';
import Dropzone from './Dropzone';
import Separator from './Separator';

import {
findRowByPropName
} from '../actions/WindowActions';

import MasterWidget from '../components/widget/MasterWidget';
import Tabs from '../components/tabs/Tabs';
import Table from '../components/table/Table';
Expand Down Expand Up @@ -41,7 +45,7 @@ class Window extends Component {
const {type} = this.props.layout;
const {data, rowData, newRow, tabsInfo} = this.props;
const {fullScreen} = this.state;
const dataId = data.ID.value;
const dataId = findRowByPropName(data, 'ID').value;

return(
<Tabs
Expand Down Expand Up @@ -161,8 +165,10 @@ class Window extends Component {

return elements.map((elem, id)=> {
const autoFocus = isFocused && (id === 0);
const widgetData = elem.fields.map(item => data[item.field] || -1);
const relativeDocId = data.ID && data.ID.value;
const widgetData = elem.fields.map(item =>
findRowByPropName(data, item.field)
);
const relativeDocId = findRowByPropName(data, 'ID').value;
return (
<MasterWidget
entity="window"
Expand Down
1 change: 1 addition & 0 deletions src/components/app/DocumentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ class DocumentList extends Component {
return dispatch(browseViewRequest(
id, page, this.pageLength, sortingQuery, windowType
)).then(response => {

this.mounted && this.setState(Object.assign({}, {
data: response.data,
filters: response.data.filters
Expand Down
3 changes: 2 additions & 1 deletion src/components/app/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class Modal extends Component {
)
).catch(err => {
this.handleClose();

if(err.toString() !== 'Error: close_modal'){
throw err;
}
Expand Down Expand Up @@ -262,7 +263,7 @@ class Modal extends Component {
} = this.state;

return(
Object.keys(data).length > 0 && <div
data.length > 0 && <div
className="screen-freeze js-not-unselect"
>
<div className="panel panel-modal panel-modal-primary">
Expand Down
9 changes: 7 additions & 2 deletions src/components/app/OverlayField.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import React, { Component } from 'react';
import MasterWidget from '../widget/MasterWidget';
import RawWidget from '../widget/RawWidget';

import {
findRowByPropName
} from '../../actions/WindowActions';

class OverlayField extends Component {
constructor(props) {
super(props);
Expand All @@ -24,8 +28,9 @@ class OverlayField extends Component {
const {disabled} = this.props;
const elements = layout.elements;
return elements.map((elem, id) => {
const widgetData = elem.fields.map(item =>
data[item.field] || -1);
const widgetData = elem.fields.map(item =>
findRowByPropName(data, item.field)
);
return (
<MasterWidget
entity="process"
Expand Down
13 changes: 9 additions & 4 deletions src/components/app/SelectionAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
getData
} from '../../actions/GenericActions';

import {
findRowByPropName
} from '../../actions/WindowActions';

import RawWidget from '../widget/RawWidget';

class SelectionAttributes extends Component {
Expand Down Expand Up @@ -53,7 +57,7 @@ class SelectionAttributes extends Component {
getData(entity, windowType, viewId, selected[0])
);
}).then(response => {
DLWrapperSetData(response.data.fieldsByName, response.data.id);
DLWrapperSetData(response.data.fields, response.data.id);
}).catch(() => {});
}

Expand Down Expand Up @@ -101,7 +105,7 @@ class SelectionAttributes extends Component {
windowType={windowType}
viewId={viewId}
widgetData={item.fields.map(elem =>
DLWrapperData[elem.field] || -1
findRowByPropName(DLWrapperData, elem.field)
)}
gridAlign={item.gridAlign}
key={id}
Expand All @@ -112,8 +116,9 @@ class SelectionAttributes extends Component {
handlePatch={DLWrapperHandlePatch}
handleChange={DLWrapperHandleChange}
tabIndex={this.getTabId(
item.fields.map(elem =>
DLWrapperData[elem.field] || -1
item.fields.map(elem =>
findRowByPropName(
DLWrapperData, elem.field)
)
)}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ class Table extends Component {
odd={i & 1}
item={item[key]}
entity={entity}
fields={item[key].fieldsByName}
fields={item[key].fields}
rowId={item[key][keyProp]}
tabId={tabid}
cols={cols}
Expand Down
1 change: 0 additions & 1 deletion src/components/table/TableCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class TableCell extends Component {

componentWillReceiveProps(nextProps) {
const {widgetData, updateRow, readonly} = this.props;

if(!readonly &&
JSON.stringify(widgetData[0].value) !==
JSON.stringify(nextProps.widgetData[0].value)
Expand Down
8 changes: 7 additions & 1 deletion src/components/table/TableItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import TableCell from './TableCell';

import {
findRowByPropName
} from '../../actions/WindowActions';

class TableItem extends Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -109,7 +113,9 @@ class TableItem extends Component {
// Iterate over layout settings
return cols && cols.map((item, index) => {
const property = item.fields[0].field;
const widgetData = item.fields.map(prop => cells[prop.field] || -1);
const widgetData = item.fields.map(property =>
findRowByPropName(cells, property.field)
);
const {supportZoomInto} = item.fields[0];

return (
Expand Down
Loading

0 comments on commit cbb63b2

Please sign in to comment.