Skip to content

Commit a1cd9c1

Browse files
committed
Fix data fetching process for ManageCatalogPage.js
1 parent 61d9709 commit a1cd9c1

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/components/catalog/ManageCatalogPage.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import { NavLink } from 'react-router-dom';
43
import CatalogForm from '../../../../react2/src/components/catalog/CatalogForm';
54
import CatalogApi from '../../api/catalogApi';
65
import { Breadcrumb, Spin, notification, Modal } from 'antd';
@@ -24,8 +23,23 @@ export class ManageCatalogPage extends React.Component {
2423
};
2524
}
2625

27-
componentWillMount() {
28-
CatalogApi.getCatalogInfo(this.props.match.params.name)
26+
componentDidMount() {
27+
const id = this.props.match.params.id;
28+
const name = this.props.match.params.name;
29+
30+
this.fetchCatalogData(name, id);
31+
}
32+
33+
componentWillReceiveProps(nextProps) {
34+
const nextId = nextProps.match.params.id;
35+
if (nextId === this.props.match.params.id) return;
36+
37+
const name = this.props.match.params.name;
38+
this.fetchCatalogData(name, nextId);
39+
}
40+
41+
fetchCatalogData = (name, id) => {
42+
CatalogApi.getCatalogInfo(name)
2943
.then((response) => {
3044
this.setState({catalog: response.data});
3145

@@ -37,9 +51,6 @@ export class ManageCatalogPage extends React.Component {
3751
}
3852
});
3953

40-
const id = this.props.match.params.id;
41-
const name = this.props.match.params.name;
42-
4354
if (id) {
4455
return CatalogApi.getFormObjectById(name, id);
4556
}
@@ -58,7 +69,7 @@ export class ManageCatalogPage extends React.Component {
5869
message: 'An error has occurred: ' + summary
5970
});
6071
});
61-
}
72+
};
6273

6374
loadCollection = (catalogClass) => {
6475
return CatalogApi.getCatalogExtendWithClass(catalogClass)
@@ -80,10 +91,8 @@ export class ManageCatalogPage extends React.Component {
8091
let errors = {};
8192

8293
/*
83-
if (this.state.form.title.length < 5) {
84-
errors.title = 'Title must be at least 5 characters.';
85-
formIsValid = false;
86-
}*/
94+
Put validation logic here
95+
*/
8796

8897
this.setState({ errors });
8998
return formIsValid;

src/components/common/GenericInput.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ const GenericInput = ({ category, collection = [], collectionType,
111111

112112
if (!collectionType) {
113113
if (readOnly) {
114-
input = <Input name={name} value={value.name} readOnly style={{ width: '200px' }}/>;
114+
let displayValue = (value && value.name);
115+
input = <Input name={name} value={displayValue} readOnly style={{ width: '200px' }}/>;
115116
}
116117
else {
117118
let options = collection.map(item => {

0 commit comments

Comments
 (0)