DescriptorListForm.tsx 4.55 KB
Newer Older
1
2
3
import * as React from 'react';
import {Field, reduxForm} from 'redux-form';

4
import { DESCRIPTORLIST_FORM } from 'descriptors/constants';
5
import { TextField } from 'ui/common/text-field';
6
import { MarkdownField } from 'ui/catalog/markdown';
7
import Authorize from 'ui/common/authorized/Authorize';
Matija Obreza's avatar
Matija Obreza committed
8
import SelectPartner from 'partners/ui/c/SelectPartner';
9
import Validators from 'utilities/Validators';
10
import remoteSubmit from 'descriptorlists/ui/descriptorlist-stepper/steps/basic-info/RemoteSubmit';
Matija Obreza's avatar
Matija Obreza committed
11
import CropSelector from 'crops/ui/c/CropSelector';
12

13
14
15
16
17
18
19
20
21
22
class DescriptorListForm extends React.Component<any, any> {

    public render() {
        const {error, handleSubmit, initialValues, partners} = this.props;
        return (
            <form onSubmit={ handleSubmit } className="p-20 m-20 even-row">
                { initialValues && initialValues.version && <div>Version: { initialValues.version }</div> }

                <Field required
                       name="owner"
23
                       onlyMine
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
                       label="Select Partner"
                       editable={ !(initialValues.uuid && initialValues.version) }
                       component={ SelectPartner } partners={ partners }
                       validate={ [Validators.required] }
                />

                <Authorize role="ROLE_ADMINISTRATOR">
                    { !(initialValues.uuid && initialValues.version) &&
                    <div>
                        <div className="p-20 even-row">
                            <p>
                                You're <b>ADMINISTRATOR</b> and you get to pick the <code>UUID</code> if you want to.
                                Leave field blank to have it automatically assigned.
                                Standard codes used by the Catalog:
                            </p>
                            <ul>
                                <li><code>dc1d4e81-a6dd-4f03-b682-53a3a1383988</code> Genesys PGR descriptors</li>
                            </ul>
                        </div>
                        <Field name="uuid"
                               label="UUID"
                               placeholder="ihope-youk-noww-hatyouredoing"
                               component={ TextField }
                        />
                    </div>
                    }
                </Authorize>

                <Field name="crop"
Nora Castaneda-Alvarez's avatar
Nora Castaneda-Alvarez committed
53
                    label="Crop"
54
                    placeholder="maize"
Maxym Borodenko's avatar
Maxym Borodenko committed
55
56
                    component={ CropSelector }
                    single
57
58
59
60
                />
                <Field required
                       name="title"
                       label="Descriptor list title"
Nora Castaneda-Alvarez's avatar
Nora Castaneda-Alvarez committed
61
                       placeholder="Descriptors for pearl millet"
62
63
64
65
66
                       basicMarkdown
                       component={ MarkdownField }
                       validate={ [Validators.required] }
                />
                <Field required
Maxym Borodenko's avatar
Maxym Borodenko committed
67
                       disabled={ !!initialValues.uuid }
68
                       name="versionTag"
Nora Castaneda-Alvarez's avatar
Nora Castaneda-Alvarez committed
69
                       label="Version"
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
                       placeholder="1.0"
                       component={ TextField }
                       validate={ [Validators.required] }
                />
                <Field name="description"
                       label="Description"
                       placeholder="Full description of the descriptor list"
                       component={ MarkdownField }
                />
                <Field name="url"
                       label="URL to definition"
                       placeholder="https://"
                       component={ TextField }
                       validate={ [Validators.url] }
                />
                <Field name="publisher"
Nora Castaneda-Alvarez's avatar
Nora Castaneda-Alvarez committed
86
87
                       label="Original publisher"
                       placeholder="IPGRI"
88
89
90
91
                       component={ TextField }
                />
                <Field name="bibliographicCitation"
                       label="Bibliographic citation"
Nora Castaneda-Alvarez's avatar
Nora Castaneda-Alvarez committed
92
                       placeholder="Complete bibliographic citation of the crop descriptor. Use APA formatting style (https://owl.english.purdue.edu/owl/resource/560/01/)"
Matija Obreza's avatar
Matija Obreza committed
93
94
                       component={ MarkdownField }
                       basicMarkdown
95
96
97
98
99
100
101
102
                       multiline
                />

                <div>{ error && <strong>{ error }</strong> }</div>
            </form>
        );
    }
}
103
104
105
106

export default reduxForm({
  enableReinitialize: true, // https://redux-form.com/7.1.0/examples/initializefromstate/
  form: DESCRIPTORLIST_FORM,
107
  onSubmit: remoteSubmit,
108
})(DescriptorListForm);