Skip to content

Commit

Permalink
deposit form: add references field to deposit form
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsosf authored and kpsherva committed May 4, 2023
1 parent 9d43c51 commit f9280c1
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ export class RDMDepositRecordSerializer extends DepositRecordSerializer {
},
deserializedDefault: [],
}),
references: new SchemaField({
fieldpath: "metadata.references",
schema: {
reference: new Field({
fieldpath: "reference",
}),
},
deserializedDefault: [],
}),
subjects: new AllowAdditionsVocabularyField({
fieldpath: "metadata.subjects",
deserializedDefault: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { RDMDepositRecordSerializer } from "./DepositRecordSerializer";
import { emptyDate } from "../fields/DatesField/initialValues";
import { emptyIdentifier } from "../fields/Identifiers/initialValues";
import { emptyRelatedWork } from "../fields/RelatedWorksField/initialValues";
import { emptyReference } from "../fields/ReferencesField/initialValues";

describe("RDMDepositRecordSerializer tests", () => {
const defaultLocale = "en";
Expand Down Expand Up @@ -137,6 +138,40 @@ describe("RDMDepositRecordSerializer tests", () => {
expect(serializedRecord).toEqual({ metadata: {}, custom_fields: {}, pids: {} });
});
});

describe("references", () => {
it("serializes array as-is if filled", () => {
const record = {
metadata: {
references: [
{
reference: "Test reference",
},
],
},
};

const serializedRecord = serializer.serialize(record);

expect(serializedRecord.metadata.references).toEqual([
{
reference: "Test reference",
},
]);
});

it("doesn't serialize if only default is present", () => {
const record = {
metadata: {
references: [emptyReference],
},
};

const serializedRecord = serializer.serialize(record);

expect(serializedRecord).toEqual({ metadata: {}, custom_fields: {}, pids: {} });
});
});
});

describe("deserialize", () => {
Expand All @@ -161,6 +196,7 @@ describe("RDMDepositRecordSerializer tests", () => {
languages: [],
identifiers: [],
related_identifiers: [],
references: [],
subjects: [],
rights: [],
funding: [],
Expand Down Expand Up @@ -280,6 +316,11 @@ describe("RDMDepositRecordSerializer tests", () => {
relation_type: "requires",
},
],
references: [
{
reference: "Test reference",
},
],
subjects: [
{
subject: "MeSH: Cognitive Neuroscience",
Expand Down Expand Up @@ -411,6 +452,12 @@ describe("RDMDepositRecordSerializer tests", () => {
__key: 0,
},
],
references: [
{
reference: "Test reference",
__key: 0,
},
],
subjects: [
{
id: "mesh_1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const defaultLabels = {
"metadata.version": i18next.t("Version"),
"metadata.publisher": i18next.t("Publisher"),
"metadata.related_identifiers": i18next.t("Related works"),
"metadata.references": i18next.t("References"),
"metadata.identifiers": i18next.t("Alternate identifiers"),
"access.embargo.until": i18next.t("Embargo until"),
"pids.doi": i18next.t("DOI"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// This file is part of Invenio-RDM-Records
// Copyright (C) 2020-2023 CERN.
// Copyright (C) 2020-2022 Northwestern University.
// Copyright (C) 2021 Graz University of Technology.
//
// Invenio-RDM-Records is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

import React, { Component } from "react";
import PropTypes from "prop-types";

import { TextField, GroupField, ArrayField, FieldLabel } from "react-invenio-forms";
import { Button, Form, Icon } from "semantic-ui-react";

import { emptyReference } from "./initialValues";
import { i18next } from "@translations/invenio_rdm_records/i18next";

export class ReferencesField extends Component {
render() {
const { fieldPath, label, labelIcon, required, showEmptyValue } = this.props;

return (
<>

Check warning on line 23 in invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/ReferencesField/ReferencesField.js

View workflow job for this annotation

GitHub Actions / Tests (3.7, pypi, postgresql13, opensearch2, 16.x)

Fragments should contain more than one child - otherwise, there’s no need for a Fragment at all

Check warning on line 23 in invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/ReferencesField/ReferencesField.js

View workflow job for this annotation

GitHub Actions / Tests (3.7, pypi, postgresql13, elasticsearch7, 16.x)

Fragments should contain more than one child - otherwise, there’s no need for a Fragment at all

Check warning on line 23 in invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/ReferencesField/ReferencesField.js

View workflow job for this annotation

GitHub Actions / Tests (3.8, pypi, postgresql13, opensearch2, 16.x)

Fragments should contain more than one child - otherwise, there’s no need for a Fragment at all

Check warning on line 23 in invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/ReferencesField/ReferencesField.js

View workflow job for this annotation

GitHub Actions / Tests (3.8, pypi, postgresql13, elasticsearch7, 16.x)

Fragments should contain more than one child - otherwise, there’s no need for a Fragment at all

Check warning on line 23 in invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/ReferencesField/ReferencesField.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, pypi, postgresql13, opensearch2, 16.x)

Fragments should contain more than one child - otherwise, there’s no need for a Fragment at all

Check warning on line 23 in invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/ReferencesField/ReferencesField.js

View workflow job for this annotation

GitHub Actions / Tests (3.9, pypi, postgresql13, elasticsearch7, 16.x)

Fragments should contain more than one child - otherwise, there’s no need for a Fragment at all
<ArrayField
addButtonLabel={i18next.t("Add reference")}
defaultNewValue={emptyReference}
fieldPath={fieldPath}
label={<FieldLabel htmlFor={fieldPath} icon={labelIcon} label={label} />}
required={required}
showEmptyValue={showEmptyValue}
>
{({ arrayHelpers, indexPath }) => {
const fieldPathPrefix = `${fieldPath}.${indexPath}`;

return (
<GroupField optimized>
<TextField
fieldPath={`${fieldPathPrefix}.reference`}
label={i18next.t("Reference string")}
required
width={16}
/>

<Form.Field>
<Button
aria-label={i18next.t("Remove field")}
className="close-btn"
icon
onClick={() => arrayHelpers.remove(indexPath)}
>
<Icon name="close" />
</Button>
</Form.Field>
</GroupField>
);
}}
</ArrayField>
</>
);
}
}

ReferencesField.propTypes = {
fieldPath: PropTypes.string.isRequired,
label: PropTypes.string,
labelIcon: PropTypes.string,
required: PropTypes.bool,
showEmptyValue: PropTypes.bool,
};

ReferencesField.defaultProps = {
label: i18next.t("References"),
labelIcon: "bookmark",
required: undefined,
showEmptyValue: false,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This file is part of Invenio-RDM-Records
// Copyright (C) 2020-2023 CERN.
// Copyright (C) 2020-2022 Northwestern University.
//
// Invenio-RDM-Records is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

import React from "react";
import ReactDOM from "react-dom";

import { Form, Formik } from "formik";

import { ReferencesField } from "./ReferencesField";

it("renders without crashing", () => {
const div = document.createElement("div");

ReactDOM.render(
<Formik>
{() => (
<Form>
<ReferencesField fieldPath="fieldPath" />
</Form>
)}
</Formik>,
div
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is part of Invenio-RDM-Records
// Copyright (C) 2020-2023 CERN.
// Copyright (C) 2020-2022 Northwestern University.
//
// Invenio-RDM-Records is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

export { ReferencesField } from "./ReferencesField";
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This file is part of Invenio-RDM-Records
// Copyright (C) 2020-2023 CERN.
// Copyright (C) 2020-2022 Northwestern University.
//
// Invenio-RDM-Records is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.
export const emptyReference = {
reference: "",
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export { PIDField, IdentifiersField } from "./Identifiers";
export { LicenseField } from "./License";
export { PublicationDateField } from "./PublicationDateField";
export { PublisherField } from "./PublisherField";
export { ReferencesField } from "./ReferencesField";
export { RelatedWorksField } from "./RelatedWorksField";
export { ResourceTypeField } from "./ResourceTypeField";
export { SubjectsField } from "./SubjectsField";
Expand Down
17 changes: 9 additions & 8 deletions invenio_rdm_records/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,23 @@ def always_valid(identifier):
"validator": idutils.is_ads,
"datacite": "bibcode",
},
"crossreffunderid": {
"label": _("Crossref Funder ID"),
"validator": always_valid,
"datacite": "Crossref Funder ID",
},
"doi": {"label": _("DOI"), "validator": idutils.is_doi, "datacite": "DOI"},
"ean13": {"label": _("EAN13"), "validator": idutils.is_ean13, "datacite": "EAN13"},
"eissn": {"label": _("EISSN"), "validator": idutils.is_issn, "datacite": "EISSN"},
"grid": {"label": _("GRID"), "validator": always_valid, "datacite": "GRID"},
"handle": {
"label": _("Handle"),
"validator": idutils.is_handle,
"datacite": "Handle",
},
"igsn": {"label": _("IGSN"), "validator": always_valid, "datacite": "IGSN"},
"isbn": {"label": _("ISBN"), "validator": idutils.is_isbn, "datacite": "ISBN"},
"isni": {"label": _("ISNI"), "validator": idutils.is_isni, "datacite": "ISNI"},
"issn": {"label": _("ISSN"), "validator": idutils.is_issn, "datacite": "ISSN"},
"istc": {"label": _("ISTC"), "validator": idutils.is_istc, "datacite": "ISTC"},
"lissn": {"label": _("LISSN"), "validator": idutils.is_issn, "datacite": "LISSN"},
Expand All @@ -83,16 +90,10 @@ def always_valid(identifier):
"url": {"label": _("URL"), "validator": idutils.is_url, "datacite": "URL"},
"urn": {"label": _("URN"), "validator": idutils.is_urn, "datacite": "URN"},
"w3id": {"label": _("W3ID"), "validator": always_valid, "datacite": "w3id"},
"other": {"label": _("Other"), "validator": always_valid, "datacite": "Other"},
}
"""These are used for main, alternate and related identifiers."""
"""These are used for references, main, alternate and related identifiers."""


RDM_RECORDS_REFERENCES_SCHEMES = {
"isni": {"label": _("ISNI"), "validator": idutils.is_isni},
"grid": {"label": _("GRID"), "validator": always_valid},
"crossreffunderid": {"label": _("Crossref Funder ID"), "validator": always_valid},
"other": {"label": _("Other"), "validator": always_valid},
}
RDM_RECORDS_LOCATION_SCHEMES = {
"wikidata": {"label": _("Wikidata"), "validator": always_valid},
"geonames": {"label": _("GeoNames"), "validator": always_valid},
Expand Down
8 changes: 1 addition & 7 deletions invenio_rdm_records/services/schemas/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@
lambda: current_app.config["RDM_RECORDS_IDENTIFIERS_SCHEMES"]
)


record_references_schemes = LocalProxy(
lambda: current_app.config["RDM_RECORDS_REFERENCES_SCHEMES"]
)


record_location_schemes = LocalProxy(
lambda: current_app.config["RDM_RECORDS_LOCATION_SCHEMES"]
)
Expand Down Expand Up @@ -275,7 +269,7 @@ class ReferenceSchema(IdentifierSchema):
def __init__(self, **kwargs):
"""Constructor."""
super().__init__(
allowed_schemes=record_references_schemes,
allowed_schemes=record_identifiers_schemes,
identifier_required=False,
**kwargs
)
Expand Down

0 comments on commit f9280c1

Please sign in to comment.