diff --git a/src/components/LayerCollection/LayerPO.js b/src/components/LayerCollection/LayerPO.js
index 75e2436b4..c15688492 100644
--- a/src/components/LayerCollection/LayerPO.js
+++ b/src/components/LayerCollection/LayerPO.js
@@ -45,12 +45,12 @@ class LayerPO extends Component {
render() {
const { initialValues, location } = this.props;
- const query = location.search ? queryString.parse(location.search) : {};
+ const { layer } = location.search ? queryString.parse(location.search) : {};
- return (
-
+ if (layer === 'edit') {
+ return (
+ );
+ } else if (layer === 'receive-items') {
+ return (
+ );
+ } else if (layer === 'received') {
+ return (
-
- );
+ );
+ }
+
+ return null;
}
}
diff --git a/src/components/LayerCollection/LayerPOLine.js b/src/components/LayerCollection/LayerPOLine.js
index 46cbfdcca..f71b74bcf 100644
--- a/src/components/LayerCollection/LayerPOLine.js
+++ b/src/components/LayerCollection/LayerPOLine.js
@@ -72,12 +72,12 @@ class LayerPOLine extends Component {
render() {
const { initialValues, location } = this.props;
- const query = location.search ? queryString.parse(location.search) : {};
+ const { layer } = location.search ? queryString.parse(location.search) : {};
- return (
-
+ if (layer === 'create-po-line') {
+ return (
+ );
+ } else if (layer === 'edit-po-line') {
+ return (
-
- );
+ );
+ }
+
+ return null;
}
}
diff --git a/src/components/POLine/POLine.js b/src/components/POLine/POLine.js
index aa468d660..1bd046a51 100644
--- a/src/components/POLine/POLine.js
+++ b/src/components/POLine/POLine.js
@@ -125,6 +125,7 @@ class POLine extends Component {
Required fields!
diff --git a/src/components/PurchaseOrder/PO.js b/src/components/PurchaseOrder/PO.js
index ae071c6de..52a6435a9 100644
--- a/src/components/PurchaseOrder/PO.js
+++ b/src/components/PurchaseOrder/PO.js
@@ -1,12 +1,7 @@
import React, { Component } from 'react';
import { FormattedMessage } from 'react-intl';
import PropTypes from 'prop-types';
-
-import {
- get,
- isEmpty,
- isEqual,
-} from 'lodash';
+import { get } from 'lodash';
import { IfPermission } from '@folio/stripes/core';
import {
@@ -75,49 +70,6 @@ class PO extends Component {
resources: PropTypes.object.isRequired,
}
- static getDerivedStateFromProps(props, state) {
- const { parentMutator, parentResources, resources } = props;
- const initialValues = get(resources, ['order', 'records', 0]);
-
- // Set initialValues
- if (initialValues) {
- if (!isEqual(initialValues, state.initialValues)) {
- return { initialValues };
- }
- }
- // Check if initialValues STATE before updating child;
- if (!isEmpty(state.initialValues)) {
- const createdBy = get(parentResources, 'createdBy.records', []);
- const vendor = get(parentResources, 'vendor.records', []);
- const user = get(parentResources, 'user.records', []);
- const isAnyDataLoaded = vendor.length > 0 || user.length > 0 || createdBy.length > 0;
-
- if (isAnyDataLoaded) {
- const initData = state.initialValues;
- const vendorName = vendor[0] && vendor[0].name ? `${vendor[0].name}` : '';
- const assignToName = user[0] && user[0].personal ? `${user[0].personal.firstName} ${user[0].personal.lastName}` : '';
- const createdByPersonal = get(createdBy, '0.personal');
- const createdByName = createdByPersonal ? `${createdByPersonal.firstName} ${createdByPersonal.lastName}` : '';
- const isDataChanged = vendorName !== initData.vendor_name || assignToName !== initData.assigned_to_user || createdByName !== initData.created_by_name;
-
- if (isDataChanged) {
- parentMutator.queryII.update({
- createdByID: initData.created_by,
- vendorID: initData.vendor,
- userID: initData.assigned_to,
- });
- initData.vendor_name = vendorName;
- initData.assigned_to_user = assignToName;
- initData.created_by_name = createdByName;
-
- return { initialValues: initData };
- }
- }
- }
-
- return null;
- }
-
constructor(props) {
super(props);
this.state = {
@@ -126,7 +78,6 @@ class PO extends Component {
POSummary: true,
POListing: true,
},
- initialValues: {},
};
this.onAddPOLine = this.onAddPOLine.bind(this);
this.transitionToParams = transitionToParams.bind(this);
@@ -181,8 +132,8 @@ class PO extends Component {
}
render() {
- const { location, history, match, resources } = this.props;
- const initialValues = this.state.initialValues || {};
+ const { location, history, match, resources, parentResources } = this.props;
+ const initialValues = get(resources, ['order', 'records', 0]);
const poLines = get(resources, ['poLine', 'records'], []);
const lastMenu = (
@@ -196,7 +147,6 @@ class PO extends Component {
style={{ visibility: !initialValues ? 'hidden' : 'visible' }}
onClick={this.props.onEdit}
href={this.props.editLink}
- title={ariaLabel}
/>
)}
@@ -220,6 +170,18 @@ class PO extends Component {
);
}
+ const vendor = get(parentResources, 'vendors.records', []).find(d => d.id === initialValues.vendor);
+ const assignedTo = get(parentResources, 'users.records', []).find(d => d.id === initialValues.assigned_to);
+ const createdBy = get(parentResources, 'users.records', []).find(d => d.id === initialValues.created_by);
+
+ initialValues.vendor_name = get(vendor, 'name');
+ initialValues.assigned_to_user = assignedTo && assignedTo.personal
+ ? `${assignedTo.personal.firstName} ${assignedTo.personal.lastName}`
+ : '';
+ initialValues.created_by_name = createdBy && createdBy.personal
+ ? `${createdBy.personal.firstName} ${createdBy.personal.lastName}`
+ : '';
+
return (
{
- const resourceData = args[2];
- const cql = `(id="${resourceData.queryII.vendorID}")`;
-
- return cql;
- },
- },
- limit: 1,
- staticFallback: { params: {} },
- },
+ perRequest: 1000,
},
- vendors: {
+ users: {
type: 'okapi',
- path: 'vendor',
- records: 'vendors',
+ path: 'users',
+ records: 'users',
perRequest: 1000,
},
fund: {
@@ -144,45 +126,6 @@ class Main extends Component {
records: 'funds',
perRequest: 1000,
},
- user: {
- type: 'okapi',
- path: 'users',
- records: 'users',
- GET: {
- params: {
- query: (...args) => {
- const resourceData = args[2];
- const cql = `(id="${resourceData.queryII.userID}")`;
-
- return cql;
- },
- },
- limit: 1,
- staticFallback: { params: {} },
- },
- },
- createdBy: {
- type: 'okapi',
- path: 'users',
- records: 'users',
- GET: {
- params: {
- query: (...args) => {
- const resourceData = args[2];
- const cql = `(id="${resourceData.queryII.createdByID}")`;
-
- return cql;
- },
- },
- limit: 1,
- staticFallback: { params: {} },
- },
- },
- source: {
- type: 'okapi',
- path: 'source?query=cql.allRecords=1 sortby desc',
- records: 'sources',
- },
materialTypes: {
type: 'okapi',
path: 'material-types',
@@ -281,11 +224,19 @@ class Main extends Component {
},
},
} = this.props;
+ const users = get(resources, 'users.records', []);
const resultsFormatter = {
'po_number': data => toString(get(data, ['po_number'], '')),
'created': data => ,
- 'notes': data => toString(get(data, ['notes'], '')),
- 'assigned_to': data => toString(get(data, ['assigned_to'], '')),
+ 'notes': data => get(data, 'notes', []).join(', '),
+ 'assigned_to': data => {
+ const assignedToId = get(data, 'assigned_to', '');
+ const assignedTo = users.find(d => d.id === assignedToId);
+
+ return assignedTo && assignedTo.personal
+ ? `${assignedTo.personal.firstName} ${assignedTo.personal.lastName}`
+ : '';
+ },
};
const newRecordInitialValues = {
created_by: id || '',