-
Notifications
You must be signed in to change notification settings - Fork 143
/
RDMDepositForm.js
713 lines (683 loc) · 27.2 KB
/
RDMDepositForm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
// This file is part of InvenioRDM
// Copyright (C) 2020-2024 CERN.
// Copyright (C) 2020-2022 Northwestern University.
// Copyright (C) 2021-2022 Graz University of Technology.
// Copyright (C) 2022-2023 KTH Royal Institute of Technology.
//
// Invenio App RDM 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 { i18next } from "@translations/invenio_app_rdm/i18next";
import _get from "lodash/get";
import _isEmpty from "lodash/isEmpty";
import React, { Component, createRef, Fragment } from "react";
import { AccordionField, CustomFields } from "react-invenio-forms";
import {
AccessRightField,
DescriptionsField,
CreatibutorsField,
DatesField,
DeleteButton,
DepositStatusBox,
FileUploader,
FormFeedback,
IdentifiersField,
PIDField,
PreviewButton,
LanguagesField,
LicenseField,
PublicationDateField,
PublishButton,
PublisherField,
ReferencesField,
RelatedWorksField,
ResourceTypeField,
SubjectsField,
TitlesField,
VersionField,
DepositFormApp,
CommunityHeader,
SaveButton,
} from "@js/invenio_rdm_records";
import { FundingField } from "@js/invenio_vocabularies";
import { Card, Container, Grid, Ref, Sticky } from "semantic-ui-react";
import PropTypes from "prop-types";
import Overridable from "react-overridable";
import { ShareDraftButton } from "./ShareDraftButton";
export class RDMDepositForm extends Component {
constructor(props) {
super(props);
this.config = props.config || {};
const { files, record } = this.props;
// TODO: Make ALL vocabulary be generated by backend.
// Currently, some vocabulary is generated by backend and some is
// generated by frontend here. Iteration is faster and abstractions can be
// discovered by generating vocabulary here. Once happy with vocabularies,
// then we can generate it in the backend.
this.vocabularies = {
metadata: {
...this.config.vocabularies,
creators: {
...this.config.vocabularies.creators,
type: [
{ text: "Person", value: "personal" },
{ text: "Organization", value: "organizational" },
],
},
contributors: {
...this.config.vocabularies.contributors,
type: [
{ text: "Person", value: "personal" },
{ text: "Organization", value: "organizational" },
],
},
identifiers: {
...this.config.vocabularies.identifiers,
},
},
};
// check if files are present
this.noFiles = false;
if (
!Array.isArray(files.entries) ||
(!files.entries.length && record.is_published)
) {
this.noFiles = true;
}
// hide community header for branded communities
this.hide_community_selection = this.config.hide_community_selection || false;
}
formFeedbackRef = createRef();
sidebarRef = createRef();
render() {
const {
record,
files,
permissions,
preselectedCommunity,
filesLocked,
recordRestrictionGracePeriod,
allowRecordRestriction,
groupsEnabled,
} = this.props;
const customFieldsUI = this.config.custom_fields.ui;
return (
<DepositFormApp
config={this.config}
record={record}
preselectedCommunity={preselectedCommunity}
files={files}
permissions={permissions}
>
<Overridable
id="InvenioAppRdm.Deposit.FormFeedback.container"
labels={this.config.custom_fields.error_labels}
fieldPath="message"
>
<FormFeedback
fieldPath="message"
labels={this.config.custom_fields.error_labels}
/>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.CommunityHeader.container"
record={record}
>
{!this.hide_community_selection && (
<CommunityHeader
imagePlaceholderLink="/static/images/square-placeholder.png"
record={record}
/>
)}
</Overridable>
<Container id="rdm-deposit-form" className="rel-mt-1">
<Grid className="mt-25">
<Grid.Column mobile={16} tablet={16} computer={11}>
<Overridable
id="InvenioAppRdm.Deposit.AccordionFieldFiles.container"
record={record}
config={this.config}
noFiles={this.noFiles}
>
<AccordionField
includesPaths={["files.enabled"]}
active
label={i18next.t("Files")}
>
{this.noFiles && record.is_published && (
<div className="text-align-center pb-10">
<em>{i18next.t("The record has no files.")}</em>
</div>
)}
<Overridable
id="InvenioAppRdm.Deposit.FileUploader.container"
record={record}
config={this.config}
permissions={permissions}
filesLocked={filesLocked}
>
<FileUploader
isDraftRecord={!record.is_published}
quota={this.config.quota}
decimalSizeDisplay={this.config.decimal_size_display}
showMetadataOnlyToggle={permissions?.can_manage_files}
filesLocked={filesLocked}
/>
</Overridable>
</AccordionField>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.AccordionFieldBasicInformation.container"
config={this.config}
record={record}
vocabularies={this.vocabularies}
>
<AccordionField
includesPaths={[
"metadata.resource_type",
"metadata.title",
"metadata.additional_titles",
"metadata.publication_date",
"metadata.creators",
"metadata.description",
"metadata.additional_descriptions",
"metadata.rights",
]}
active
label={i18next.t("Basic information")}
>
<Overridable
id="InvenioAppRdm.Deposit.PIDField.container"
config={this.config}
record={record}
>
<Fragment>
{this.config.pids.map((pid) => (
<Fragment key={pid.scheme}>
<PIDField
btnLabelDiscardPID={pid.btn_label_discard_pid}
btnLabelGetPID={pid.btn_label_get_pid}
canBeManaged={pid.can_be_managed}
canBeUnmanaged={pid.can_be_unmanaged}
fieldPath={`pids.${pid.scheme}`}
fieldLabel={pid.field_label}
isEditingPublishedRecord={
record.is_published === true // is_published is `null` at first upload
}
managedHelpText={pid.managed_help_text}
pidLabel={pid.pid_label}
pidPlaceholder={pid.pid_placeholder}
pidType={pid.scheme}
unmanagedHelpText={pid.unmanaged_help_text}
required
record={record}
/>
</Fragment>
))}
</Fragment>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.ResourceTypeField.container"
vocabularies={this.vocabularies}
fieldPath="metadata.resource_type"
>
<ResourceTypeField
options={this.vocabularies.metadata.resource_type}
fieldPath="metadata.resource_type"
required
/>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.TitlesField.container"
vocabularies={this.vocabularies}
fieldPath="metadata.title"
record={record}
>
<TitlesField
options={this.vocabularies.metadata.titles}
fieldPath="metadata.title"
recordUI={record.ui}
required
/>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.PublicationDateField.container"
fieldPath="metadata.publication_date"
>
<PublicationDateField
required
fieldPath="metadata.publication_date"
/>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.CreatorsField.container"
vocabularies={this.vocabularies}
config={this.config}
fieldPath="metadata.creators"
>
<CreatibutorsField
label={i18next.t("Creators")}
labelIcon="user"
fieldPath="metadata.creators"
roleOptions={this.vocabularies.metadata.creators.role}
schema="creators"
autocompleteNames={this.config.autocomplete_names}
required
/>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.DescriptionsField.container"
record={record}
vocabularies={this.vocabularies}
fieldPath="metadata.description"
>
<DescriptionsField
fieldPath="metadata.description"
options={this.vocabularies.metadata.descriptions}
recordUI={_get(record, "ui", null)}
/>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.LicenseField.container"
fieldPath="metadata.rights"
>
<LicenseField
fieldPath="metadata.rights"
searchConfig={{
searchApi: {
axios: {
headers: {
Accept: "application/vnd.inveniordm.v1+json",
},
url: "/api/vocabularies/licenses",
withCredentials: false,
},
},
initialQueryState: {
filters: [["tags", "recommended"]],
},
}}
serializeLicenses={(result) => ({
title: result.title_l10n,
description: result.description_l10n,
id: result.id,
link: result.props.url,
})}
/>
</Overridable>
</AccordionField>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.AccordionFieldRecommendedInformation.container"
vocabularies={this.vocabularies}
config={this.config}
record={record}
>
<AccordionField
includesPaths={[
"metadata.contributors",
"metadata.subjects",
"metadata.languages",
"metadata.dates",
"metadata.version",
"metadata.publisher",
]}
active
label={i18next.t("Recommended information")}
>
<Overridable
id="InvenioAppRdm.Deposit.ContributorsField.container"
fieldPath="metadata.contributors"
vocabularies={this.vocabularies}
config={this.config}
>
<CreatibutorsField
addButtonLabel={i18next.t("Add contributor")}
label={i18next.t("Contributors")}
labelIcon="user plus"
fieldPath="metadata.contributors"
roleOptions={this.vocabularies.metadata.contributors.role}
schema="contributors"
autocompleteNames={this.config.autocomplete_names}
modal={{
addLabel: "Add contributor",
editLabel: "Edit contributor",
}}
/>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.SubjectsField.container"
vocabularies={this.vocabularies}
fieldPath="metadata.subjects"
record={record}
>
<SubjectsField
fieldPath="metadata.subjects"
initialOptions={_get(record, "ui.subjects", null)}
limitToOptions={this.vocabularies.metadata.subjects.limit_to}
searchOnFocus
/>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.LanguagesField.container"
fieldPath="metadata.languages"
record={record}
>
<LanguagesField
fieldPath="metadata.languages"
initialOptions={_get(record, "ui.languages", []).filter(
(lang) => lang !== null
)} // needed because dumped empty record from backend gives [null]
serializeSuggestions={(suggestions) =>
suggestions.map((item) => ({
text: item.title_l10n,
value: item.id,
key: item.id,
}))
}
/>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.DateField.container"
vocabularies={this.vocabularies}
fieldPath="metadata.dates"
>
<DatesField
fieldPath="metadata.dates"
options={this.vocabularies.metadata.dates}
showEmptyValue
/>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.VersionField.container"
fieldPath="metadata.version"
>
<VersionField fieldPath="metadata.version" />
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.PublisherField.container"
fieldPath="metadata.publisher"
>
<PublisherField fieldPath="metadata.publisher" />
</Overridable>
</AccordionField>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.AccordionFieldFunding.container"
ui={this.accordionStyle}
>
<AccordionField
includesPaths={["metadata.funding"]}
active
label="Funding"
ui={this.accordionStyle}
>
<Overridable
id="InvenioAppRdm.Deposit.FundingField.container"
fieldPath="metadata.funding"
>
<FundingField
fieldPath="metadata.funding"
searchConfig={{
searchApi: {
axios: {
headers: {
Accept: "application/vnd.inveniordm.v1+json",
},
url: "/api/awards",
withCredentials: false,
},
},
initialQueryState: {
sortBy: "bestmatch",
sortOrder: "asc",
layout: "list",
page: 1,
size: 5,
},
}}
label="Awards/Grants"
labelIcon="money bill alternate outline"
deserializeAward={(award) => {
return {
title: award.title_l10n,
number: award.number,
funder: award.funder ?? "",
id: award.id,
...(award.identifiers && {
identifiers: award.identifiers,
}),
...(award.acronym && { acronym: award.acronym }),
};
}}
deserializeFunder={(funder) => {
return {
id: funder.id,
name: funder.name,
...(funder.title_l10n && { title: funder.title_l10n }),
...(funder.pid && { pid: funder.pid }),
...(funder.country && { country: funder.country }),
...(funder.country_name && {
country_name: funder.country_name,
}),
...(funder.identifiers && {
identifiers: funder.identifiers,
}),
};
}}
computeFundingContents={(funding) => {
let headerContent,
descriptionContent,
awardOrFunder = "";
if (funding.funder) {
const funderName =
funding.funder?.name ??
funding.funder?.title ??
funding.funder?.id ??
"";
awardOrFunder = "funder";
headerContent = funderName;
descriptionContent = "";
// there cannot be an award without a funder
if (funding.award) {
const { acronym, title } = funding.award;
awardOrFunder = "award";
descriptionContent = funderName;
headerContent = acronym ? `${acronym} — ${title}` : title;
}
}
return { headerContent, descriptionContent, awardOrFunder };
}}
/>
</Overridable>
</AccordionField>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.AccordionFieldAlternateIdentifiers.container"
vocabularies={this.vocabularies}
>
<AccordionField
includesPaths={["metadata.identifiers"]}
active
label={i18next.t("Alternate identifiers")}
>
<Overridable
id="InvenioAppRdm.Deposit.IdentifiersField.container"
vocabularies={this.vocabularies}
fieldPath="metadata.identifiers"
>
<IdentifiersField
fieldPath="metadata.identifiers"
label={i18next.t("Alternate identifiers")}
labelIcon="barcode"
schemeOptions={this.vocabularies.metadata.identifiers.scheme}
showEmptyValue
/>
</Overridable>
</AccordionField>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.AccordionFieldRelatedWorks.container"
vocabularies={this.vocabularies}
>
<AccordionField
includesPaths={["metadata.related_identifiers"]}
active
label={i18next.t("Related works")}
>
<Overridable
id="InvenioAppRdm.Deposit.RelatedWorksField.container"
fieldPath="metadata.related_identifiers"
vocabularies={this.vocabularies}
>
<RelatedWorksField
fieldPath="metadata.related_identifiers"
options={this.vocabularies.metadata.identifiers}
showEmptyValue
/>
</Overridable>
</AccordionField>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.AccordionFieldReferences.container"
vocabularies={this.vocabularies}
>
<AccordionField
includesPaths={["metadata.references"]}
active
label={i18next.t("References")}
>
<Overridable
id="InvenioAppRdm.Deposit.ReferencesField.container"
fieldPath="metadata.references"
vocabularies={this.vocabularies}
>
<ReferencesField fieldPath="metadata.references" showEmptyValue />
</Overridable>
</AccordionField>
</Overridable>
{!_isEmpty(customFieldsUI) && (
<Overridable
id="InvenioAppRdm.Deposit.CustomFields.container"
record={record}
customFieldsUI={customFieldsUI}
>
<CustomFields
config={customFieldsUI}
record={record}
templateLoaders={[
(widget) => import(`@templates/custom_fields/${widget}.js`),
(widget) =>
import(`@js/invenio_rdm_records/src/deposit/customFields`),
(widget) => import(`react-invenio-forms`),
]}
fieldPathPrefix="custom_fields"
/>
</Overridable>
)}
</Grid.Column>
<Ref innerRef={this.sidebarRef}>
<Grid.Column
mobile={16}
tablet={16}
computer={5}
className="deposit-sidebar"
>
<Sticky context={this.sidebarRef} offset={20}>
<Overridable
id="InvenioAppRdm.Deposit.CardDepositStatusBox.container"
record={record}
permissions={permissions}
groupsEnabled={groupsEnabled}
>
<Card>
<Card.Content>
<DepositStatusBox />
</Card.Content>
<Card.Content>
<Grid relaxed>
<Grid.Column
computer={8}
mobile={16}
className="pb-0 left-btn-col"
>
<SaveButton fluid />
</Grid.Column>
<Grid.Column
computer={8}
mobile={16}
className="pb-0 right-btn-col"
>
<PreviewButton fluid />
</Grid.Column>
<Grid.Column width={16} className="pt-10">
<PublishButton fluid record={record} />
</Grid.Column>
<Grid.Column width={16} className="pt-0">
{(record.is_draft === null || permissions.can_manage) && (
<ShareDraftButton
record={record}
permissions={permissions}
groupsEnabled={groupsEnabled}
/>
)}
</Grid.Column>
</Grid>
</Card.Content>
</Card>
</Overridable>
<Overridable
id="InvenioAppRdm.Deposit.AccessRightField.container"
fieldPath="access"
record={record}
permissions={permissions}
recordRestrictionGracePeriod={recordRestrictionGracePeriod}
allowRecordRestriction={allowRecordRestriction}
>
<AccessRightField
label={i18next.t("Visibility")}
record={record}
labelIcon="shield"
fieldPath="access"
showMetadataAccess={permissions?.can_manage_record_access}
recordRestrictionGracePeriod={recordRestrictionGracePeriod}
allowRecordRestriction={allowRecordRestriction}
/>
</Overridable>
{permissions?.can_delete_draft && (
<Overridable
id="InvenioAppRdm.Deposit.CardDeleteButton.container"
record={record}
>
<Card>
<Card.Content>
<DeleteButton fluid />
</Card.Content>
</Card>
</Overridable>
)}
</Sticky>
</Grid.Column>
</Ref>
</Grid>
</Container>
</DepositFormApp>
);
}
}
RDMDepositForm.propTypes = {
groupsEnabled: PropTypes.bool.isRequired,
config: PropTypes.object.isRequired,
recordRestrictionGracePeriod: PropTypes.object.isRequired,
allowRecordRestriction: PropTypes.bool.isRequired,
record: PropTypes.object.isRequired,
preselectedCommunity: PropTypes.object,
files: PropTypes.object,
permissions: PropTypes.object,
filesLocked: PropTypes.bool,
};
RDMDepositForm.defaultProps = {
preselectedCommunity: undefined,
permissions: null,
files: null,
filesLocked: false,
};