Skip to content

Commit

Permalink
Merge branch '1301-missing-daten-when-requesting-a-doi-for-a-publishe…
Browse files Browse the repository at this point in the history
…d-comparison' into 'master'

fix(Comparison): Missing data when requesting a DOI for a published comparison

Closes #1301

See merge request TIBHannover/orkg/orkg-frontend!1038
  • Loading branch information
aoelen committed Mar 9, 2023
2 parents e9483dd + 804b3a2 commit 9d92e38
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 96 deletions.
179 changes: 92 additions & 87 deletions src/components/Comparison/Publish/Publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function Publish(props) {
title,
description,
comparisonCreators,
subject,
researchField,
inputValue,
conference,
references,
Expand All @@ -79,7 +79,7 @@ function Publish(props) {
isOpenResearchFieldModal,
setTitle,
setDescription,
setSubject,
setResearchField,
setInputValue,
setIsOpenResearchFieldModal,
setAssignDOI,
Expand Down Expand Up @@ -198,7 +198,9 @@ function Publish(props) {
{id && (
<ShareCreatedContent
typeOfLink="comparison"
title={`An @orkg_org comparison on '${title}' in the area of ${subject?.label ? `%23${slugify(subject.label)}` : ''}`}
title={`An @orkg_org comparison on '${title}' in the area of ${
researchField?.label ? `%23${slugify(researchField.label)}` : ''
}`}
/>
)}
{!comparisonResource.doi && (!id || (id && assignDOI)) && (
Expand Down Expand Up @@ -240,12 +242,12 @@ function Publish(props) {
entityType={ENTITIES.RESOURCE}
optionsClass={CLASSES.RESEARCH_FIELD}
onItemSelected={i => {
setSubject({ ...i, label: i.value });
setResearchField({ ...i, label: i.value });
}}
placeholder="Search or choose a research field"
autoFocus
cacheOptions
value={subject || null}
value={researchField || null}
isClearable={false}
onBlur={() => setInputValue('')}
onChangeInputValue={e => setInputValue(e)}
Expand Down Expand Up @@ -289,91 +291,94 @@ function Publish(props) {
</AuthorTag>
))}
</FormGroup>
{!id &&
(!conference || conference.metadata.review_process !== CONFERENCE_REVIEW_MISC.DOUBLE_BLIND) && (
{!id && (!conference || conference.metadata.review_process !== CONFERENCE_REVIEW_MISC.DOUBLE_BLIND) && (
<FormGroup>
<div>
<Tooltip message="A DOI will be assigned to published comparison and it cannot be changed in future.">
<StyledCustomInput
onChange={e => {
setAssignDOI(e.target.checked);
}}
checked={assignDOI}
id="switchAssignDoi"
type="switch"
name="customSwitch"
label="Assign a DOI to the comparison"
/>{' '}
<Label for="switchAssignDoi" className="mb-0">
Assign a DOI to the comparison
</Label>
</Tooltip>
</div>
</FormGroup>
)}
{!id /* Hide those fields because they are not part of the DOI metadata */ && (
<>
<FormGroup>
<div>
<Tooltip message="A DOI will be assigned to published comparison and it cannot be changed in future.">
<StyledCustomInput
onChange={e => {
setAssignDOI(e.target.checked);
}}
checked={assignDOI}
id="switchAssignDoi"
type="switch"
name="customSwitch"
label="Assign a DOI to the comparison"
/>{' '}
<Label for="switchAssignDoi" className="mb-0">
Assign a DOI to the comparison
</Label>
<Label>
<Tooltip message="Enter a reference to the data sources from which the comparison is generated">
Reference (optional)
</Tooltip>
</div>
</FormGroup>
)}
<FormGroup>
<Label>
<Tooltip message="Enter a reference to the data sources from which the comparison is generated">
Reference (optional)
</Tooltip>
</Label>
{references &&
references.map((x, i) => (
<InputGroup className="mb-1" key={`ref${i}`}>
<Input
disabled={Boolean(id)}
type="text"
name="reference"
value={x}
onChange={e => handleReferenceChange(e, i)}
id="publish-reference"
/>
{!id && (
<>
{references.length !== 1 && (
<Button
color="light"
onClick={() => handleRemoveReferenceClick(i)}
className="ps-3 pe-3"
style={{ borderTopLeftRadius: 0, borderBottomLeftRadius: 0 }}
>
<Icon icon={faTrash} />
</Button>
</Label>
{references &&
references.map((reference, i) => (
<InputGroup className="mb-1" key={`ref${i}`}>
<Input
disabled={Boolean(id)}
type="text"
name="reference"
value={reference.label}
onChange={e => handleReferenceChange(e, i)}
id="publish-reference"
/>
{!id && (
<>
{references.length !== 1 && (
<Button
color="light"
onClick={() => handleRemoveReferenceClick(i)}
className="ps-3 pe-3"
style={{ borderTopLeftRadius: 0, borderBottomLeftRadius: 0 }}
>
<Icon icon={faTrash} />
</Button>
)}
{references.length - 1 === i && (
<Button
color="secondary"
onClick={() => setReferences([...references, ''])}
style={{ borderTopLeftRadius: 0, borderBottomLeftRadius: 0 }}
>
<Icon icon={faPlus} /> Add
</Button>
)}
</>
)}
{references.length - 1 === i && (
<Button
color="secondary"
onClick={() => setReferences([...references, ''])}
style={{ borderTopLeftRadius: 0, borderBottomLeftRadius: 0 }}
>
<Icon icon={faPlus} /> Add
</Button>
)}
</>
)}
</InputGroup>
))}
</FormGroup>
<FormGroup>
<Label for="conference">
<Tooltip message="Select a conference">
Conference <span className="text-muted fst-italic">(optional)</span>
</Tooltip>
</Label>
<Select
options={conferencesList}
onChange={e => {
setConference(e);
}}
getOptionValue={({ id }) => id}
isSearchable={true}
getOptionLabel={({ name }) => name}
isClearable={true}
classNamePrefix="react-select"
inputId="conference"
/>
<SelectGlobalStyle />
</FormGroup>
</InputGroup>
))}
</FormGroup>
<FormGroup>
<Label for="conference">
<Tooltip message="Select a conference">
Conference <span className="text-muted fst-italic">(optional)</span>
</Tooltip>
</Label>
<Select
options={conferencesList}
onChange={e => {
setConference(e);
}}
getOptionValue={({ id }) => id}
isSearchable={true}
getOptionLabel={({ name }) => name}
isClearable={true}
classNamePrefix="react-select"
inputId="conference"
/>
<SelectGlobalStyle />
</FormGroup>
</>
)}
</>
)}
</ModalBody>
Expand Down
20 changes: 11 additions & 9 deletions src/components/Comparison/hooks/usePublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ function usePublish() {
const [references, setReferences] = useState(
comparisonResource?.references && comparisonResource.references.length > 0 ? comparisonResource.references : [''],
);
const [subject, setSubject] = useState(comparisonResource && comparisonResource.subject ? comparisonResource.subject : undefined);
const [researchField, setResearchField] = useState(
comparisonResource && comparisonResource.researchField ? comparisonResource.researchField : undefined,
);
const [comparisonCreators, setComparisonCreators] = useState(comparisonResource?.authors ?? []);
const [conferencesList, setConferencesList] = useState([]);
const [conference, setConference] = useState(null);
Expand All @@ -55,7 +57,7 @@ function usePublish() {
setTitle(comparisonResource && comparisonResource.label ? comparisonResource.label : '');
setDescription(comparisonResource && comparisonResource.description ? comparisonResource.description : '');
setReferences(comparisonResource?.references && comparisonResource.references.length > 0 ? comparisonResource.references : ['']);
setSubject(comparisonResource && comparisonResource.subject ? comparisonResource.subject : undefined);
setResearchField(comparisonResource && comparisonResource.researchField ? comparisonResource.researchField : undefined);
setComparisonCreators(
comparisonResource.authors
? comparisonResource.authors
Expand Down Expand Up @@ -109,11 +111,11 @@ function usePublish() {
text: reference,
})),
}),
...(subject &&
subject.id && {
...(researchField &&
researchField.id && {
[PREDICATES.HAS_SUBJECT]: [
{
'@id': subject.id,
'@id': researchField.id,
},
],
}),
Expand Down Expand Up @@ -194,7 +196,7 @@ function usePublish() {
resource_type: 'Dataset',
resource_id: comparisonId,
title,
subject: subject ? subject.label : '',
subject: researchField ? researchField.label : '',
description,
related_resources: contributionsList,
authors: comparisonCreatorsORCID.map(c => ({ creator: c.label, orcid: c.orcid })),
Expand Down Expand Up @@ -237,7 +239,7 @@ function usePublish() {
};

const handleSelectField = ({ _id, label }) =>
setSubject({
setResearchField({
id: _id,
label,
});
Expand All @@ -250,7 +252,7 @@ function usePublish() {
title,
description,
comparisonCreators,
subject,
researchField,
inputValue,
conference,
references,
Expand All @@ -259,7 +261,7 @@ function usePublish() {
isOpenResearchFieldModal,
setTitle,
setDescription,
setSubject,
setResearchField,
setInputValue,
setIsOpenResearchFieldModal,
setAssignDOI,
Expand Down

0 comments on commit 9d92e38

Please sign in to comment.