diff --git a/src/components/Collection/index.js b/src/components/Collection/index.js index 73354494..e3f43776 100644 --- a/src/components/Collection/index.js +++ b/src/components/Collection/index.js @@ -36,7 +36,7 @@ import withContext from '../hoc/withContext'; // Components import { ItemMenu, ItemHeader, CreationFeedback } from '../common'; import CollectionDetails from './Details'; -import { CommentList, ContactPersonList, IdentifierList, TagList, MachineTagList, MasterSource } from '../common/subtypes'; +import { CommentList, ContactPersonList, GrSciCollIdentifierList, TagList, MachineTagList, MasterSource } from '../common/subtypes'; import DescriptorGroups from './subtypes/DescriptorGroups'; import Exception404 from '../exception/404'; import Actions from './collection.actions'; @@ -411,7 +411,7 @@ class Collection extends Component { } /> - createIdentifier(key, data)} diff --git a/src/components/Institution/index.js b/src/components/Institution/index.js index 27cc2226..7cff0785 100644 --- a/src/components/Institution/index.js +++ b/src/components/Institution/index.js @@ -33,7 +33,7 @@ import PageWrapper from '../hoc/PageWrapper'; // Components import { CreationFeedback, ItemHeader, ItemMenu } from '../common'; import InstitutionDetails from './Details'; -import { CommentList, ContactPersonList, IdentifierList, TagList, MachineTagList, MasterSource } from '../common/subtypes'; +import { CommentList, ContactPersonList, GrSciCollIdentifierList, TagList, MachineTagList, MasterSource } from '../common/subtypes'; import Exception404 from '../exception/404'; import { Collections } from './institutionSubtypes'; import Actions from './institution.actions'; @@ -334,7 +334,7 @@ class Institution extends Component { } /> - createIdentifier(key, data)} diff --git a/src/components/common/subtypes/GrSciCollIdentifierList/IdentifierCreateForm.js b/src/components/common/subtypes/GrSciCollIdentifierList/IdentifierCreateForm.js new file mode 100644 index 00000000..339359ac --- /dev/null +++ b/src/components/common/subtypes/GrSciCollIdentifierList/IdentifierCreateForm.js @@ -0,0 +1,115 @@ +import React, {useState, useEffect} from "react"; +import { Modal, Input, Select, Spin, Form, Checkbox } from "antd"; +import { FormattedMessage } from "react-intl"; +import PropTypes from "prop-types"; + +// APIs +import { getIdentifierTypes } from "../../../../api/enumeration"; +// Components +import { FormItem } from "../../index"; +const IdentifierCreateForm = (props) => { + const [identifierTypes, setIdentifierTypes] = useState([]); + const [fetching, setFetching] = useState(true); + const [form] = Form.useForm(); + useEffect(() => { + getIdentifierTypes().then((types) => { + setIdentifierTypes(types); + setFetching(false); + }); + }, []); + + const { visible, onCancel, onCreate } = props; + + return ( + + } + okText={} + onCancel={onCancel} + onOk={() => onCreate(form)} + destroyOnClose={true} + maskClosable={false} + closable={false} + > +
+ } + helpText={ + + } + > + + + + ), + }, + ]} + label={ + + } + helpText={ + + } + > + + + } + helpText={ + + } + > + + +
+
+ ); +}; + +IdentifierCreateForm.propTypes = { + visible: PropTypes.bool.isRequired, + onCancel: PropTypes.func.isRequired, + onCreate: PropTypes.func.isRequired, +}; + +export default IdentifierCreateForm; diff --git a/src/components/common/subtypes/GrSciCollIdentifierList/index.js b/src/components/common/subtypes/GrSciCollIdentifierList/index.js new file mode 100644 index 00000000..6fc9956f --- /dev/null +++ b/src/components/common/subtypes/GrSciCollIdentifierList/index.js @@ -0,0 +1,173 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { List, Row, Col } from 'antd'; +import { FormattedMessage, injectIntl, FormattedNumber } from 'react-intl'; + +// Wrappers +import { HasAccess } from '../../../auth'; +import withWidth, { MEDIUM } from '../../../hoc/Width'; +import withContext from '../../../hoc/withContext'; +// Components +import IdentifierCreateForm from './IdentifierCreateForm'; +import { ConfirmButton, FormattedRelativeDate } from '../../index'; +import { CreateButton } from '../../CreateMessage'; + +class IdentifierList extends React.Component { + state = { + isModalVisible: false, + identifiers: this.props.identifiers || [] + }; + + showModal = () => { + this.setState({ isModalVisible: true }); + }; + + handleCancel = () => { + this.setState({ isModalVisible: false }); + }; + + deleteIdentifier = item => { + this.props.deleteIdentifier(item.key).then(() => { + // Updating identifiers + const { identifiers } = this.state; + this.setState({ + identifiers: identifiers.filter(el => el.key !== item.key) + }); + this.props.updateCounts('identifiers', identifiers.length - 1); + this.props.addSuccess({ + status: 200, + statusText: this.props.intl.formatMessage({ + id: 'beenDeleted.identifier', + defaultMessage: 'Identifier has been deleted' + }) + }); + }).catch(error => { + this.props.addError({ status: error.response.status, statusText: error.response.data }); + }); + }; + + handleSave = form => { + form.validateFields().then((values) => { + + + this.props.createIdentifier(values).then(response => { + form.resetFields(); + + const { identifiers } = this.state; + identifiers.unshift({ + ...values, + key: response.data, + created: new Date().toISOString(), + createdBy: this.props.user.userName + }); + this.props.updateCounts('identifiers', identifiers.length); + this.props.addSuccess({ + status: 200, + statusText: this.props.intl.formatMessage({ + id: 'beenSaved.identifier', + defaultMessage: 'Identifier has been saved' + }) + }); + + this.setState({ + isModalVisible: false, + identifiers + }); + }).catch(error => { + this.props.addError({ status: error.response.status, statusText: error.response.data }); + }); + }); + }; + + render() { + const { identifiers, isModalVisible } = this.state; + const { intl, width } = this.props; + const confirmTitle = intl.formatMessage({ + id: 'delete.confirmation.identifier', + defaultMessage: 'Are you sure to delete this identifier?' + }); + + return ( + +
+ + +

+ + + + this.showModal()} /> + + +
+ + , count: identifiers.length }} + />) : null + } + renderItem={item => ( + this.props.canDelete(item.key)}> + } + onConfirm={() => this.deleteIdentifier(item)} + type={'link'} + /> + + ]} + style={width < MEDIUM ? { flexDirection: 'column' } : {}} + > + + {item.identifier} + {item.type} + {item.primary && Is primary} + + } + description={ + + , author: item.createdBy }} + /> + + } + /> + + )} + /> + + +
+
+ ); + } +} + +IdentifierList.propTypes = { + identifiers: PropTypes.array.isRequired, + createIdentifier: PropTypes.func, + deleteIdentifier: PropTypes.func, + updateCounts: PropTypes.func, + canCreate: PropTypes.func.isRequired, + canDelete: PropTypes.func.isRequired +}; + +const mapContextToProps = ({ user, addSuccess, addError }) => ({ user, addSuccess, addError }); + +export default withContext(mapContextToProps)(withWidth()(injectIntl(IdentifierList))); \ No newline at end of file diff --git a/src/components/common/subtypes/index.js b/src/components/common/subtypes/index.js index b667a743..e95f7229 100644 --- a/src/components/common/subtypes/index.js +++ b/src/components/common/subtypes/index.js @@ -3,6 +3,7 @@ import ContactList from './ContactList'; import DefaultValueList from './DefaultValueList'; import EndpointList from './EndpointList'; import IdentifierList from './IdentifierList'; +import GrSciCollIdentifierList from './GrSciCollIdentifierList'; import MachineTagList from './MachineTagList'; import PersonList from './PersonList'; import ContactPersonList from './ContactPersonList'; @@ -16,6 +17,7 @@ export { DefaultValueList, EndpointList, IdentifierList, + GrSciCollIdentifierList, MachineTagList, PersonList, ContactPersonList,