Commit c1224f9b authored by Matija Obreza's avatar Matija Obreza
Browse files

`DescriptorList` with select partner

parent c18b0bb7
......@@ -3,10 +3,14 @@ import * as React from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {Page} from 'model/common.model';
import {loadMyPartners} from 'actions/partner';
import {Partner} from 'model/partner.model';
import {loadDescriptors} from 'actions/descriptors';
import {loadDescriptorList, saveDescriptorList, publishDescriptorList, addDescriptorToDescriptorList, removeDescriptorFromDescriptorList} from 'actions/descriptorList';
import {DescriptorList, Descriptor} from 'model/descriptors.model';
import {Page} from 'model/common.model';
import DescriptorListForm from './c/DescriptorListForm';
import DescriptorPicker from 'ui/catalog/descriptor/DescriptorPicker';
......@@ -26,6 +30,10 @@ interface IDescriptorListEditPageProps extends React.ClassAttributes<any> {
publishDescriptorList: any;
addDescriptorToDescriptorList: any;
removeDescriptorFromDescriptorList: any;
myPartners: Partner[];
loadMyPartners: any;
loadDescriptors: any;
matchingDescriptors: Page<Descriptor>;
}
......@@ -46,10 +54,15 @@ class DescriptorListEditPage extends React.Component<IDescriptorListEditPageProp
protected static needs = [
({ params: { uuid } } ) => loadDescriptorList(uuid),
loadDescriptors,
loadMyPartners,
];
public componentWillMount() {
const {uuid, descriptorList, loadDescriptorList, loadDescriptors, matchingDescriptors} = this.props;
const {uuid, descriptorList, loadDescriptorList, myPartners, loadMyPartners, loadDescriptors, matchingDescriptors} = this.props;
if (!myPartners || myPartners.length === 0) {
loadMyPartners();
}
/*console.log(`componentWillMount... ${tab}`, this.props);*/
if (uuid && ! descriptorList) {
......@@ -86,7 +99,7 @@ class DescriptorListEditPage extends React.Component<IDescriptorListEditPageProp
}
public render() {
const {classes, loadDescriptors, matchingDescriptors} = this.props;
const {classes, myPartners, loadDescriptors, matchingDescriptors} = this.props;
let { descriptorList } = this.props;
// console.log('Editing descriptor list', descriptorList);
......@@ -101,7 +114,8 @@ class DescriptorListEditPage extends React.Component<IDescriptorListEditPageProp
<Grid container className={ classes.contentContainer }>
<Grid item xs={ 12 }>
<Paper className={ classes.form }>
<DescriptorListForm initialValues={ descriptorList } onPublish={ this.onPublish } onSubmit={ this.onSave } />
<DescriptorListForm initialValues={ descriptorList }
onPublish={ this.onPublish } onSubmit={ this.onSave } partners={ myPartners } />
</Paper>
</Grid>
......@@ -126,12 +140,14 @@ class DescriptorListEditPage extends React.Component<IDescriptorListEditPageProp
const mapStateToProps = (state, ownProps) => ({
uuid: ownProps.params.uuid,
descriptorList: state.descriptorList.currentDescriptorList,
myPartners: state.partners.myPartners,
matchingDescriptors: state.pagination.descriptorPage,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
loadDescriptorList, saveDescriptorList, publishDescriptorList,
loadDescriptors, addDescriptorToDescriptorList, removeDescriptorFromDescriptorList,
loadMyPartners,
}, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(DescriptorListEditPage));
......@@ -10,13 +10,17 @@ import { Link } from 'react-router';
import { TextField } from 'ui/common/text-field';
import { MarkdownField } from 'ui/common/markdown';
import Heading from 'ui/common/heading';
import SelectPartner from 'ui/catalog/partner/SelectPartner';
const DescriptorListForm = ({error, handleSubmit, initialValues, onPublish}) => {
const DescriptorListForm = ({error, handleSubmit, initialValues, onPublish, partners}) => {
return (
<form onSubmit={ handleSubmit }>
{ initialValues && initialValues.version && <div>Version: { initialValues.version }</div> }
<Field required name="owner" label="Select Partner"
editable={ ! (initialValues.uuid && initialValues.version) }
component={ SelectPartner } partners={ partners } />
<Field name="crop" label="Crop code" placeholder="maize" component={ TextField } />
<Field required name="title" label="Descriptor list title" placeholder="My descriptor" component={ TextField } />
<Field name="description" label="Description" placeholder="Full description of the descriptor list" component={ MarkdownField } />
......
Supports Markdown
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