Commit 9c1472c9 authored by Matija Obreza's avatar Matija Obreza
Browse files

Descriptor.vocabulary is populated, no need to fetch

parent ab29c37b
Pipeline #4100 passed with stages
in 2 minutes and 45 seconds
......@@ -5,10 +5,9 @@ import {bindActionCreators} from 'redux';
import {withStyles} from 'material-ui/styles';
import { loadDescriptor, publishDescriptor } from 'actions/descriptors';
import { receiveVocabulary } from 'actions/vocabulary';
import { Descriptor } from 'model/descriptors.model';
import { Vocabulary } from 'model/vocabulary.model';
import { VocabularyTerm } from 'model/vocabulary.model';
import Markdown from 'ui/common/markdown';
import ContentHeaderWithButton from 'ui/common/heading/ContentHeaderWithButton';
......@@ -26,9 +25,6 @@ interface IDisplayPageProps extends React.ClassAttributes<any> {
loadDescriptor: (uuid: string) => void;
publishDescriptor: (descriptor: Descriptor) => void;
descriptor: Descriptor;
vocabulary?: Vocabulary;
receiveVocabulary: (vocabulary: Vocabulary) => void;
}
const styles = (theme) => ({
......@@ -56,19 +52,6 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
}
}
public componentWillReceiveProps(nextProps) {
const { receiveVocabulary, vocabulary } = this.props;
if (nextProps.descriptor && nextProps.descriptor.vocabulary) {
console.log('Descriptor has vocabulary', nextProps.descriptor.vocabulary);
if (! vocabulary || vocabulary.uuid !== nextProps.descriptor.vocabulary.uuid) {
receiveVocabulary(nextProps.descriptor.vocabulary);
}
} else {
receiveVocabulary(null);
}
}
public onPublish = (e) => {
const {descriptor, publishDescriptor} = this.props;
......@@ -77,14 +60,14 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
}
public render() {
const {classes, descriptor, vocabulary} = this.props;
const {classes, descriptor} = this.props;
if (! descriptor) {
console.log('No descriptor.');
return null;
}
const terms = descriptor.terms || (vocabulary ? vocabulary.terms : null);
const terms: VocabularyTerm[] = descriptor.terms || (descriptor.vocabulary ? descriptor.vocabulary.terms : null);
return (
<div>
......@@ -122,13 +105,11 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
const mapStateToProps = (state, ownProps) => ({
uuid: ownProps.params.uuid,
descriptor: state.descriptors.currentDescriptor,
vocabulary: state.vocabulary.currentVocabulary,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
loadDescriptor,
publishDescriptor,
receiveVocabulary,
}, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)((withStyles as any)(styles)(DisplayPage));
......@@ -6,14 +6,12 @@ import {withStyles} from 'material-ui/styles';
import {loadDescriptor, saveDescriptor, publishDescriptor} from 'actions/descriptors';
import {loadMyPartners} from 'actions/partner';
import { receiveVocabulary, saveVocabulary } from 'actions/vocabulary';
import { Descriptor } from 'model/descriptors.model';
import { Vocabulary } from 'model/vocabulary.model';
import { Partner } from 'model/partner.model';
import DescriptorForm from './c/DescriptorForm';
import VocabularyForm from './c/VocabularyForm';
import VocabularyCard from 'ui/pages/vocabulary/c/VocabularyCard';
import Grid from 'material-ui/Grid';
import Paper from 'material-ui/Paper';
......@@ -29,10 +27,6 @@ interface IDescriptorEditPageProps extends React.ClassAttributes<any> {
saveDescriptor: (descriptor: Descriptor) => void;
publishDescriptor: (descriptor: Descriptor) => void;
descriptor: Descriptor;
vocabulary?: Vocabulary;
receiveVocabulary: (vocabulary: Vocabulary) => void;
saveVocabulary: (vocabulary: Vocabulary) => void;
}
const styles = (theme) => ({
......@@ -65,19 +59,6 @@ class DescriptorEditPage extends React.Component<IDescriptorEditPageProps, any>
}
}
public componentWillReceiveProps(nextProps) {
const { receiveVocabulary, vocabulary } = this.props;
if (nextProps.descriptor && nextProps.descriptor.vocabulary) {
console.log('Descriptor has vocabulary', nextProps.descriptor.vocabulary);
if (! vocabulary || vocabulary.uuid !== nextProps.descriptor.vocabulary.uuid) {
receiveVocabulary(nextProps.descriptor.vocabulary);
}
} else {
receiveVocabulary(null);
}
}
public onSave = (updatedDescriptor: Descriptor) => {
const {saveDescriptor} = this.props;
......@@ -91,15 +72,6 @@ class DescriptorEditPage extends React.Component<IDescriptorEditPageProps, any>
saveDescriptor(updatedDescriptor);
}
private onSaveVocabulary = (vocabulary: Vocabulary) => {
const { saveVocabulary } = this.props;
console.log('onSave', vocabulary);
console.log('Saving vocabulary', vocabulary);
saveVocabulary(vocabulary);
}
public onPublish = (e) => {
const {descriptor, publishDescriptor} = this.props;
......@@ -108,7 +80,7 @@ class DescriptorEditPage extends React.Component<IDescriptorEditPageProps, any>
}
public render() {
const {classes, uuid, myPartners, vocabulary} = this.props;
const {classes, uuid, myPartners} = this.props;
let {descriptor} = this.props;
if (! descriptor && ! uuid) {
......@@ -129,9 +101,9 @@ class DescriptorEditPage extends React.Component<IDescriptorEditPageProps, any>
<Paper className={ classes.form }>
<DescriptorForm partners={ myPartners } initialValues={ descriptor } onPublish={ this.onPublish } onSubmit={ this.onSave }/>
</Paper>
{ vocabulary && (
{ descriptor.vocabulary && (
<Paper className={ classes.form }>
<VocabularyForm initialValues={ vocabulary } onSubmit={ this.onSaveVocabulary } />
<VocabularyCard vocabulary={ descriptor.vocabulary } />
</Paper>
) }
</Grid>
......@@ -144,7 +116,6 @@ const mapStateToProps = (state, ownProps) => ({
uuid: ownProps.params.uuid,
myPartners: state.partner.myPartners,
descriptor: state.descriptors.currentDescriptor,
vocabulary: state.vocabulary.currentVocabulary,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
......@@ -152,8 +123,6 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({
loadDescriptor,
saveDescriptor,
publishDescriptor,
receiveVocabulary,
saveVocabulary,
}, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)((withStyles as any)(styles)(DescriptorEditPage));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment