-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathedit-document-modal.tsx
More file actions
915 lines (817 loc) · 28.4 KB
/
edit-document-modal.tsx
File metadata and controls
915 lines (817 loc) · 28.4 KB
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
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
import { plugins } from "@citation-js/core"
import type React from "react"
import { useEffect, useMemo, useState } from "react"
import DatePicker from "react-date-picker"
import { FiInfo } from "react-icons/fi/index"
import TextareaAutosize from "react-textarea-autosize"
import { v4 as uuidv4 } from "uuid"
import { InfoTooltip } from "src/components/info-tooltip"
import { form } from "src/edit-word-feature.css"
import * as Dailp from "src/graphql/dailp"
import { UserRole, useUserRole } from "../../auth"
import { useTagSelector } from "../../hooks/use-tag-selector"
import { buildCitationMetadata } from "../../utils/build-citation-metadata"
import Cite from "../../utils/citation-config"
import { Dropdown } from "./dropdown"
import * as styles from "./edit-document-modal.css"
import { EditingProvider, useEditing } from "./editing-context"
import { TagSelector } from "./tag-selector"
export type EditDocumentModalProps = {
isOpen: boolean
onClose: () => void
onSubmit: (data: any) => void
documentMetadata: Dailp.AnnotatedDoc
initialCiteFormat?: string
}
export interface FormContributor extends Dailp.Contributor {
details: Dailp.ContributorDetails | null
isNew: boolean
isVisible: boolean | false
}
// year month day as string
function getDateString(date: Date | null): string | undefined {
if (!date) return undefined
const year = date.getFullYear()
const month = (date.getMonth() + 1).toString().padStart(2, "0")
const day = date.getDate().toString().padStart(2, "0")
return `${year}/${month}/${day}`
}
// Citation formats for dropdown (mapped from display name to name Cite expects)
export const formatMap: Record<string, string> = {
APA: "apa",
Vancouver: "vancouver",
Harvard: "harvard1",
}
// Get citation format display name
function getDisplayName(code: string) {
return Object.keys(formatMap).find((key) => formatMap[key] === code) ?? code
}
// Tool tips for metadata types
const TOOLTIP_TEXT = {
date: "Date that the physical resource we are translated here was created.",
docType:
"Distinguishes resources by describing the nature of this resource's content. Please use format and genre for more information.",
format: "File type for this digital version of the resource.",
contributors:
"People who work to create the resources on the site, labelled by the types of contributions they made.",
keywords:
"Main words that represent this resource’s content. This helps to improve searching on our site, but can also be a good place to gain context for the resource.",
subjectHeadings:
"Topic or main concept of this resource’s content, including Indigenous knowledge practices.",
spatialCoverage:
"Locations, dates, and/or time periods that appear throughout this resource.",
}
// Reusable approved tags lists
const approvedKeywords = [
"Colonialism",
"Government",
"Politics",
"History",
"Culture",
"Law",
"Constitution",
"Indigenous Rights",
"Treaty",
"Land Rights",
"Self-Determination",
"Tribal Governance",
]
const approvedSubjectHeadings = [
"Cherokee Political Structure",
"Sacred Relationships to Land",
"Indigenous Self-Determination",
"Ecological Stewardship",
"Colonial Disruption and Resilience",
"Ceremony and Sacred Practice",
"Indigenous Governance Models",
]
const approvedLanguages = [
"Mandarin Chinese",
"English",
"Cherokee",
"Hindi",
"Spanish",
"French",
"Arabic",
"Bengali",
"Portuguese",
"Navajo",
"Cree",
"Sioux",
"Chippewa",
]
const approvedSpatialCoverages = [
"New Echota, GA",
"Tennessee, USA",
"Boston, MA",
"New York City, NY",
"Los Angeles, CA",
"Tokyo, Japan",
"Beijing, China",
"Paris, France",
"Dubai, UAE",
]
export const EditDocumentModal: React.FC<EditDocumentModalProps> = ({
isOpen,
onClose,
onSubmit,
documentMetadata,
initialCiteFormat = "apa",
}: EditDocumentModalProps) => {
const { isEditing, setIsEditing } = useEditing()
// Only render the modal when isOpen is true
if (!isOpen) return null
const handleDateChange = (e: any) => {
const selectedDateValue = e as Date
if (selectedDateValue) {
setDate(selectedDateValue)
const selectedDay = selectedDateValue.getDate()
const selectedMonth = selectedDateValue.getMonth() + 1
const selectedYear = selectedDateValue.getFullYear()
setDay(selectedDay)
setMonth(selectedMonth)
setYear(selectedYear)
}
}
const userRole = useUserRole()
const isContributor = userRole === UserRole.Contributor
// Memoize extracted names from metadata so they update when documentMetadata changes
const keywordStrings = useMemo(
() => (documentMetadata.keywords ?? []).map((k) => k.name),
[documentMetadata.keywords]
)
const languageStrings = useMemo(
() => (documentMetadata.languages ?? []).map((l) => l.name),
[documentMetadata.languages]
)
const subjectHeadingStrings = useMemo(
() => (documentMetadata.subjectHeadings ?? []).map((sh) => sh.name),
[documentMetadata.subjectHeadings]
)
const spatialCoverageStrings = useMemo(
() => (documentMetadata.spatialCoverage ?? []).map((sc) => sc.name),
[documentMetadata.spatialCoverage]
)
const [title, setTitle] = useState(documentMetadata.title ?? "")
const [date, setDate] = useState<Date | null>(null)
const [day, setDay] = useState<Number>()
const [month, setMonth] = useState<Number>()
const [year, setYear] = useState<Number>()
const [creator, setCreator] = useState(documentMetadata.creators ?? [])
const [keywords, setKeywords] = useState(documentMetadata.keywords ?? [])
const [languages, setLanguages] = useState(documentMetadata.languages ?? [])
const [spatialCoverage, setSpatialCoverage] = useState(
documentMetadata.spatialCoverage ?? []
)
const [subjectHeadings, setSubjectHeadings] = useState(
documentMetadata.subjectHeadings ?? []
)
const [contributors, setContributors] = useState<FormContributor[]>(() =>
(documentMetadata.contributors ?? []).map((c) => ({
...c,
isNew: false,
isVisible: c.details?.isVisible ?? false,
details: c.details ? { ...c.details } : null,
}))
)
// const [description, setDescription] = useState(documentMetadata.description ?? "")
const [genre, setGenre] = useState(documentMetadata.genre?.name ?? "")
const [format, setFormat] = useState(documentMetadata.format?.name ?? "")
// const [pages, setPages] = useState(documentMetadata.pages ?? "")
// const [source, setSource] = useState(documentMetadata.source ?? "")
// const [doi, setDOI] = useState(documentMetadata.doi ?? "")
// For initializing new contributors who may not have a role yet
type MaybeContributorRole = Dailp.ContributorRole | null
const [newContributors, setNewContributors] = useState<Set<string>>(new Set())
const [tempName, setTempName] = useState("")
const [tempRole, setTempRole] = useState<MaybeContributorRole>(null)
const [tempVisible, setTempVisible] = useState(false)
const contributorRoles = Object.values(Dailp.ContributorRole)
const [creatorInput, setCreatorInput] = useState(
documentMetadata.creators?.map((c) => c.name).join(", ") ?? ""
)
const [citation, setCitation] = useState("")
// Initialize citation format from localStorage or default to "apa"
const [citeFormat, setCiteFormat] = useState(() => {
if (typeof window !== "undefined") {
return localStorage.getItem("preferredCitationFormat") || "apa"
}
return "apa"
})
// Generate citation from document metadata and selected format (APA by default)
useEffect(() => {
const hasTemplate = !!plugins?.config
?.get?.("csl")
?.templates?.has?.(citeFormat)
console.log("Using template:", citeFormat, "exists?", hasTemplate)
try {
// Create text citation using selected format
const docCitation = new Cite(docMetadata).format("bibliography", {
format: "text",
template: citeFormat || "apa",
lang: "en-US",
})
console.log("Using citeFormat:", citeFormat)
console.log("Generated citation:", docCitation)
setCitation(docCitation)
} catch (err) {
console.error("Citation formatting failed:", err)
setCitation("Error generating citation")
}
}, [citeFormat, documentMetadata]) // Re-run everytime format or metadata changes
// useEffect(() => {
// if (!isOpen) return
// const dm = documentMetadata
// setTitle(dm.title ?? "")
// setDate(dm.date ?? "")
// setCreator(dm.creators ?? [])
// setKeywords(dm.keywords ?? [])
// setLanguages(dm.languages ?? [])
// setSubjectHeadings(dm.subjectHeadings ?? [])
// setSpatialCoverage(dm.spatialCoverage ?? [])
// setContributors(
// (dm.contributors ?? []).map((c) => ({
// ...c,
// isNew: false,
// isVisible: c.details?.isVisible ?? false,
// details: c.details ? { ...c.details } : null,
// }))
// )
// }, [isOpen, documentMetadata])
// Initialize tag selectors with memoized strings
const {
tags: selectedKeywords,
newTags: newKeywords,
addTag: addKeyword,
removeTag: removeKeyword,
} = useTagSelector(keywordStrings, approvedKeywords)
const {
tags: selectedSubjectHeadings,
newTags: newHeadings,
addTag: addHeading,
removeTag: removeHeading,
} = useTagSelector(subjectHeadingStrings, approvedSubjectHeadings)
const {
tags: selectedLanguages,
newTags: newLanguages,
addTag: addLanguage,
removeTag: removeLanguage,
} = useTagSelector(languageStrings, approvedLanguages)
const {
tags: selectedSpatialCoverages,
newTags: newCoverages,
addTag: addCoverage,
removeTag: removeCoverage,
} = useTagSelector(spatialCoverageStrings, approvedSpatialCoverages)
const [backupState, setBackupState] = useState<null | {
title: string
date: Date | null
// description: string
// type: string
format: Dailp.Format["name"]
genre: Dailp.Genre["name"]
// pages: string
creator: Dailp.Creator[]
// source: string
// doi: string
contributors: FormContributor[]
keywords: Dailp.Keyword[]
subjectHeadings: Dailp.SubjectHeading[]
languages: Dailp.Language[]
spatialCoverages: Dailp.SpatialCoverage[]
}>(null)
useEffect(() => {
if (isOpen) {
setBackupState({
title,
date,
//description,
format,
genre,
// pages,
creator: [...creator],
//source,
//doi,
contributors,
keywords: [...keywords],
subjectHeadings: [...subjectHeadings],
languages: [...languages],
spatialCoverages: [...spatialCoverage],
})
}
}, [isOpen])
// Reset state when modal opens or documentMetadata changes
useEffect(() => {
const dm = documentMetadata
// Convert documentMetadata date to Date object
let dateObj = null
if (dm.date) {
if (typeof dm.date === "object" && "year" in dm.date) {
const year = dm.date.year
const month = (dm.date.month || 1) - 1
const day = dm.date.day || 1
dateObj = new Date(year, month, day)
}
}
setDate(dateObj)
setTitle(dm.title ?? "")
setFormat(dm.format?.name ?? "")
setGenre(dm.genre?.name ?? "")
setCreator(dm.creators ?? [])
setCreatorInput(dm.creators?.map((c) => c.name).join(", ") ?? "")
setKeywords(dm.keywords ?? [])
setLanguages(dm.languages ?? [])
setSubjectHeadings(dm.subjectHeadings ?? [])
setSpatialCoverage(dm.spatialCoverage ?? [])
const formattedContributors = (dm.contributors ?? []).map((c) => ({
...c,
isNew: false,
isVisible: c.details?.isVisible ?? false,
details: c.details ? { ...c.details } : null,
}))
setContributors(formattedContributors)
setNewContributors(new Set())
// Reset temp form fields
setTempName("")
setTempRole(null)
setTempVisible(false)
setBackupState({
title: dm.title ?? "",
date: dateObj,
// description,
format: dm.format?.name ?? "",
genre: dm.genre?.name ?? "",
// pages,
creator: [...(dm.creators ?? [])],
// source,
// doi,
contributors: formattedContributors,
keywords: [...(dm.keywords ?? [])],
subjectHeadings: [...(dm.subjectHeadings ?? [])],
languages: [...(dm.languages ?? [])],
spatialCoverages: [...(dm.spatialCoverage ?? [])],
})
}, [documentMetadata])
const addContributor = (
name: string,
role: Dailp.ContributorRole,
isVisible: boolean
) => {
if (!name || !role) return
const newContributor: FormContributor = {
id: uuidv4(),
name,
role,
isVisible,
isNew: true,
details: null,
}
setContributors((prev) => [...prev, newContributor])
const label = `${name} (${role})`
setNewContributors((prev) => new Set(prev).add(label))
// Reset temp form fields
setTempName("")
setTempRole(null)
setTempVisible(false)
}
const removeContributor = (index: number) => {
const removedContributor = contributors[index]
if (!removedContributor) return
const label = `${removedContributor.name} (${removedContributor.role})`
setContributors((prev) => prev.filter((_, i) => i !== index))
setNewContributors((prev) => {
const copy = new Set(prev)
copy.delete(label)
return copy
})
}
const creatorStrings = useMemo(
() => (documentMetadata.creators ?? []).map((cr) => cr.name),
[documentMetadata.creators]
)
const docMetadata = useMemo(
() =>
buildCitationMetadata({
title,
creator: creatorStrings,
date: getDateString(date),
// source,
// pages,
type: format.toLowerCase() || "document",
// doi,
}),
[title, creator, date, format]
)
useEffect(() => {
try {
const docCitation = new Cite(docMetadata).format("bibliography", {
format: "text",
template: citeFormat.toLowerCase() || "apa",
lang: "en-US",
})
setCitation(docCitation)
} catch {
setCitation("Error generating citation")
}
}, [citeFormat, docMetadata])
const cancelEdits = () => {
if (!backupState) return
setTitle(backupState.title)
setDate(backupState.date)
//setDescription(backupState.description)
setGenre(backupState.genre)
setFormat(backupState.format)
//setPages(backupState.pages)
setCreator(backupState.creator)
setKeywords(backupState.keywords)
setLanguages(backupState.languages)
setSubjectHeadings(backupState.subjectHeadings)
setSpatialCoverage(backupState.spatialCoverages)
//setSource(backupState.source)
//setDOI(backupState.doi)
// Tags reset handled by reinitialization on modal open
setContributors(backupState.contributors)
// Reset new contributors tracking
setNewContributors(new Set())
// Reset temp form fields
setTempName("")
setTempRole(null)
setTempVisible(false)
setIsEditing(false)
}
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault()
// Format date for submission
let dateValue: { year: number; month: number; day: number } | null = null
if (date) {
dateValue = {
year: date.getFullYear(),
month: date.getMonth() + 1,
day: date.getDate(),
}
}
// Format genre for submission
const formatToSubmit = format ? { id: uuidv4(), name: format } : undefined
// Format genre for submission
const genreToSubmit = genre ? { id: uuidv4(), name: genre } : undefined
// Keywords to be submitted
const keywordsToSubmit = selectedKeywords.map((name) => {
// Find existing keyword by name to get id, otherwise generate new UUID
const existing = keywords.find((k) => k.name === name)
return {
id: existing?.id ?? uuidv4(),
name,
//status: existing?.status ?? Dailp.ApprovalStatus.Approved, // If part of the editing form, can assume that keywords are approved (for now)
}
})
// Subject Headings to be submitted
const subjectHeadingsToSubmit = selectedSubjectHeadings.map((name) => {
// Find existing subject headings by name to get id, otherwise generate new UUID
const existing = subjectHeadings.find((sh) => sh.name === name)
return {
id: existing?.id ?? uuidv4(),
name,
//status: existing?.status ?? Dailp.ApprovalStatus.Approved,
}
})
// Languages to be submitted
const languagesToSubmit = selectedLanguages.map((name) => {
// Find existing languages by name to get id, otherwise generate new UUID
const existing = languages.find((l) => l.name === name)
return {
id: existing?.id ?? uuidv4(),
name,
//status: existing?.status ?? Dailp.ApprovalStatus.Approved,
}
})
// Languages to be submitted
const spatialCoverageToSubmit = selectedSpatialCoverages.map((name) => {
// Find existing spatial coverages by name to get id, otherwise generate new UUID
const existing = spatialCoverage.find((sc) => sc.name === name)
return {
id: existing?.id ?? uuidv4(),
name,
//status: existing?.status ?? Dailp.ApprovalStatus.Approved,
}
})
// Update local state for metadata
// setKeywords(keywordsToSubmit)
// setSubjectHeadings(subjectHeadingsToSubmit)
// setLanguages(languagesToSubmit)
// setSpatialCoverage(spatialCoverageToSubmit)
// Build updated document metadata object
const updatedMetadata = {
title,
date: dateValue,
format: formatToSubmit,
genre: genreToSubmit,
creator,
contributors,
keywords: keywordsToSubmit,
subjectHeadings: subjectHeadingsToSubmit,
languages: languagesToSubmit,
spatialCoverage: spatialCoverageToSubmit,
citeFormat: citeFormat,
}
// Update backup state to new submitted state
// setBackupState({
// title,
// date,
// creator: [...creator],
// contributors: [...contributors],
// keywords: keywordsToSubmit,
// subjectHeadings: subjectHeadingsToSubmit,
// languages: languagesToSubmit,
// spatialCoverages: spatialCoverageToSubmit,
// })
// setIsEditing(false)
onSubmit(updatedMetadata)
// onClose()
}
// Pass UUID of the keyword
return (
<div className={styles.overlay}>
<div className={styles.modal} onClick={(e) => e.stopPropagation()}>
<h2 className={styles.title}>Editing Document Information</h2>
<p className={styles.subtitle}>* indicates a required field</p>
<form onSubmit={handleSubmit}>
<div className={styles.formGrid}>
<div className={styles.fieldGroup}>
<label className={styles.label}>Title*</label>
<input
type="text"
className={styles.input}
value={title}
onChange={(e) => setTitle(e.target.value)}
disabled={!isEditing}
/>
</div>
<div className={styles.fieldGroup}>
<label className={styles.label}>
Date Created <InfoTooltip content={TOOLTIP_TEXT.date} />
</label>
<DatePicker
onChange={(newDate: any) => setDate(newDate)}
value={date}
format="MM-dd-y"
disabled={!isEditing} // change to !(userRole == UserRole.Editor)
/>
</div>
</div>
{/*
<div className={styles.fullWidthGroup}>
<label className={styles.label}>Description</label>
<TextareaAutosize
className={styles.input}
value={description}
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) =>
setDescription(e.target.value)
}
minRows={1}
maxRows={10}
disabled={!isEditing}
/>
</div>
*/}
<div className={styles.formGrid}>
<div className={styles.fieldGroup}>
<label className={styles.label}>
Document Type <InfoTooltip content={TOOLTIP_TEXT.docType} />
</label>
<input
type="text"
className={styles.input}
value={genre}
onChange={(e) => setGenre(e.target.value)}
disabled={!isEditing}
/>
</div>
<div className={styles.fieldGroup}>
<label className={styles.label}>
Format <InfoTooltip content={TOOLTIP_TEXT.format} />
</label>
<input
type="text"
className={styles.input}
value={format}
onChange={(e) => setFormat(e.target.value)}
disabled={!isEditing}
/>
</div>
</div>
{/*
<div className={styles.fieldGroup}>
<label className={styles.label}>Pages (start page, end page)</label>
<input
type="text"
className={styles.input}
value={pages}
onChange={(e) => setPages(e.target.value)}
disabled={!isEditing}
/>
</div>
*/}
<div className={styles.fieldGroup}>
<label className={styles.label}>
Creator (separate by ',' if multiple)
</label>
<input
type="text"
className={styles.input}
value={creatorInput}
onChange={(e) => setCreatorInput(e.target.value)}
onBlur={(e) => {
// Parse and set creators when user leaves the field
setCreator(
e.target.value
.split(",")
.map((c) => c.trim())
.filter((c) => c.length > 0)
.map((name) => ({
id: uuidv4(),
name,
}))
)
}}
disabled={!isEditing}
/>
</div>
<TagSelector
label="Contributors"
selectedTags={contributors.map((c) => `${c.name} (${c.role})`)}
approvedTags={[]}
newTags={newContributors}
onAdd={() => {}}
onRemove={isEditing ? removeContributor : undefined}
addButtonLabel="Add Contributor"
customForm={
isEditing ? (
<div className={styles.fullWidthGroup}>
<input
type="text"
placeholder="Contributor name"
value={tempName}
onChange={(e) => setTempName(e.target.value)}
className={styles.input}
/>
<select
value={tempRole ?? ""}
onChange={(e) => {
const val = e.target.value
setTempRole(
val === "" ? null : (val as Dailp.ContributorRole)
)
}}
>
{/* Show display name for role */}
<option value="">Select role</option>
{contributorRoles.map((role) => (
<option key={role} value={role}>
{role}
</option>
))}
</select>
<label className={styles.label}>
<input
type="checkbox"
checked={tempVisible}
onChange={(e) => setTempVisible(e.target.checked)}
/>
Allow contributor profile to be publically visible?
</label>
<button
type="button"
className={styles.addTagButton}
onClick={() => {
if (!tempName || !tempRole) return
addContributor(tempName, tempRole, tempVisible)
setTempName("")
setTempRole(null)
setTempVisible(false)
}}
>
Submit
</button>
</div>
) : null
}
tooltipInfo={TOOLTIP_TEXT.contributors}
/>
{/* <div className={styles.fullWidthGroup}>
<label className={styles.label}>Source</label>
<input
type="text"
className={styles.input}
value={source}
onChange={(e) => setSource(e.target.value)}
disabled={!isEditing}
/>
</div>
<div className={styles.fullWidthGroup}>
<label className={styles.label}>DOI</label>
<input
type="text"
className={styles.input}
value={doi}
onChange={(e) => setDOI(e.target.value)}
disabled={!isEditing}
/>
</div>
*/}
<TagSelector
label="Keywords"
selectedTags={selectedKeywords}
approvedTags={approvedKeywords}
newTags={newKeywords}
onAdd={(tagName) => addKeyword(tagName)}
onRemove={removeKeyword}
addButtonLabel="Add Keyword"
tooltipInfo={TOOLTIP_TEXT.keywords}
/>
<TagSelector
label="Subject Headings"
selectedTags={selectedSubjectHeadings}
approvedTags={approvedSubjectHeadings}
newTags={newHeadings}
onAdd={isEditing ? addHeading : undefined}
onRemove={isEditing ? removeHeading : undefined}
addButtonLabel="Add Subject Heading"
tooltipInfo={TOOLTIP_TEXT.subjectHeadings}
/>
<TagSelector
label="Languages"
selectedTags={selectedLanguages}
approvedTags={approvedLanguages}
newTags={newLanguages}
onAdd={isEditing ? addLanguage : undefined}
onRemove={isEditing ? removeLanguage : undefined}
addButtonLabel="Add Language"
/>
<TagSelector
label="Spatial Coverages"
selectedTags={selectedSpatialCoverages}
approvedTags={approvedSpatialCoverages}
newTags={newCoverages}
onAdd={isEditing ? addCoverage : undefined}
onRemove={isEditing ? removeCoverage : undefined}
addButtonLabel="Add Spatial Coverage"
tooltipInfo={TOOLTIP_TEXT.spatialCoverage}
/>
{/* Might need to pull the creator(s) from creator or contributors w/ author role */}
<div className={styles.fullWidthGroup}>
<label className={styles.label}>Citation</label>
<TextareaAutosize
className={styles.input}
value={citation}
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) =>
setCitation(e.target.value)
}
minRows={1}
maxRows={10}
disabled={!isEditing}
/>
</div>
<div>{getDisplayName(citeFormat)}</div>
<Dropdown
options={Object.keys(formatMap)}
selected={
Object.entries(formatMap).find(
([_, v]) => v === citeFormat
)?.[0] || "apa"
}
setSelected={(displayName) => {
setCiteFormat(formatMap[displayName] ?? "apa")
}}
addButtonLabel="Change Format"
disabled={!isEditing}
/>
{/* Cancel and submit buttons */}
<div className={styles.buttonGroup}>
{isEditing ? (
<>
<button
type="button"
onClick={cancelEdits}
className={styles.modalCancelButton}
>
Cancel
</button>
<button type="submit" className={styles.submitButton}>
Submit
</button>
</>
) : (
<button
type="button"
onClick={onClose}
className={styles.modalCancelButton}
>
Close
</button>
)}
</div>
</form>
</div>
</div>
)
}