ItemLayout.tsx 22.6 KB
Newer Older
Stefan Probst's avatar
Stefan Probst committed
1
2
3
import { Menu } from '@headlessui/react'
import cx from 'clsx'
import dynamic from 'next/dynamic'
Stefan Probst's avatar
Stefan Probst committed
4
import Link from 'next/link'
Stefan Probst's avatar
Stefan Probst committed
5
import type { PropsWithChildren } from 'react'
Stefan Probst's avatar
Stefan Probst committed
6
import { Fragment, useState } from 'react'
Stefan Probst's avatar
Stefan Probst committed
7

Stefan Probst's avatar
Stefan Probst committed
8
import type { ActorDto, PropertyDto } from '@/api/sshoc'
Stefan Probst's avatar
Stefan Probst committed
9
import { useGetItemCategories } from '@/api/sshoc'
Stefan Probst's avatar
Stefan Probst committed
10
import { getMediaFileUrl, getMediaThumbnailUrl } from '@/api/sshoc/client'
Stefan Probst's avatar
Stefan Probst committed
11
import type {
Stefan Probst's avatar
Stefan Probst committed
12
  Item as GenericItem,
Stefan Probst's avatar
Stefan Probst committed
13
14
15
  ItemCategory as ItemCategoryWithStep,
  ItemSearchQuery,
} from '@/api/sshoc/types'
Stefan Probst's avatar
Stefan Probst committed
16
import DocumentIcon from '@/elements/icons/small/document.svg'
Stefan Probst's avatar
Stefan Probst committed
17
import ProtectedView from '@/modules/auth/ProtectedView'
Stefan Probst's avatar
Stefan Probst committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import RelatedItems from '@/modules/item/RelatedItems'
import GridLayout from '@/modules/layout/GridLayout'
import HStack from '@/modules/layout/HStack'
import VStack from '@/modules/layout/VStack'
import Metadata from '@/modules/metadata/Metadata'
import { Anchor } from '@/modules/ui/Anchor'
import Breadcrumbs from '@/modules/ui/Breadcrumbs'
import Header from '@/modules/ui/Header'
import { ItemCategoryIcon } from '@/modules/ui/ItemCategoryIcon'
import Triangle from '@/modules/ui/Triangle'
import { SectionTitle } from '@/modules/ui/typography/SectionTitle'
import { Title } from '@/modules/ui/typography/Title'
import styles from '@/screens/item/ItemLayout.module.css'
import { formatDate } from '@/utils/formatDate'
import { getSingularItemCategoryLabel } from '@/utils/getSingularItemCategoryLabel'
import type { RequiredFields } from '@/utils/ts/object'
import { Svg as UrlIcon } from '@@/assets/icons/url.svg'
35
import OrcidIcon from '@@/public/assets/images/orcid.svg'
Stefan Probst's avatar
Stefan Probst committed
36
37
38
39
40
41
42

/** lazy load markdown processor */
const Markdown = dynamic(() => import('@/modules/markdown/Markdown'))

type ItemCategory = Exclude<ItemCategoryWithStep, 'step'>
type ItemProperties = Exclude<Item['properties'], undefined>
type ItemProperty = ItemProperties[number]
43
type ItemContributors = Exclude<Item['contributors'], undefined>
Stefan Probst's avatar
Stefan Probst committed
44
type RelatedItems = Exclude<Item['relatedItems'], undefined>
45
type Item = GenericItem & { dateCreated?: string; dateLastUpdated?: string }
Stefan Probst's avatar
Stefan Probst committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

/**
 * Shared item details screen.
 */
export default function ItemLayout({
  item: _item,
  children,
}: PropsWithChildren<{
  item: Item
}>): JSX.Element {
  const { data: itemCategories = {} } = useGetItemCategories()
  /** we can assume these fields to be present */
  const item = _item as RequiredFields<
    typeof _item,
    'id' | 'label' | 'category' | 'accessibleAt'
  >
  const query: ItemSearchQuery = {
    categories: [item.category],
    order: ['label'],
  }

Stefan Probst's avatar
Stefan Probst committed
67
  const relatedItems = item.relatedItems as RelatedItems
68

Stefan Probst's avatar
Stefan Probst committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  return (
    <Fragment>
      <Metadata
        title={item.label}
        description={item.description}
        openGraph={{ title: item.label, description: item.description }}
      />
      <GridLayout>
        <Header image={'/assets/images/browse-item/clouds@2x.png'}>
          <Breadcrumbs
            links={[
              { pathname: '/', label: 'Home' },
              {
                pathname: '/search',
                query,
                label: itemCategories[item.category],
              },
              {
87
                pathname: `/${item.category}/${item.persistentId}`,
Stefan Probst's avatar
Stefan Probst committed
88
89
90
91
92
93
                label: item.label,
              },
            ]}
          />
        </Header>
        <VStack className={cx('space-y-12 px-6 py-6', styles.mainColumn)}>
Stefan Probst's avatar
Stefan Probst committed
94
95
96
97
          <HStack className="items-start justify-between space-x-4">
            <div className="flex items-center justify-between space-x-4">
              <ItemThumbnail
                category={item.category as ItemCategory}
Stefan Probst's avatar
Stefan Probst committed
98
                thumbnail={item.thumbnail}
Stefan Probst's avatar
Stefan Probst committed
99
100
101
102
              />
              <Title>{item.label}</Title>
            </div>
            <ProtectedView>
103
              <div className="flex flex-col space-y-2 xl:flex-row xl:space-y-0 xl:space-x-4">
104
105
106
107
108
109
110
111
112
113
114
                {item.status === 'approved' ? (
                  <Link
                    href={{
                      pathname: `/${item.category}/${item.persistentId}/edit`,
                    }}
                  >
                    <a className="w-32 px-6 py-3 text-lg text-center text-white transition rounded lg:text-xl lg:w-48 lg:px-10 lg:py-4 bg-primary-750 hover:bg-secondary-600">
                      Edit
                    </a>
                  </Link>
                ) : null}
115
116
117
118
119
120
121
122
123
124
                <Link
                  href={{
                    pathname: `/${item.category}/${item.persistentId}/history`,
                  }}
                >
                  <a className="w-32 px-6 py-3 text-lg text-center text-white transition rounded lg:text-xl lg:w-48 lg:px-10 lg:py-4 bg-primary-750 hover:bg-secondary-600">
                    History
                  </a>
                </Link>
              </div>
Stefan Probst's avatar
Stefan Probst committed
125
            </ProtectedView>
Stefan Probst's avatar
Stefan Probst committed
126
127
128
129
          </HStack>
          <ItemDescription description={item.description} />
        </VStack>
        <div className={cx(styles.mainColumn, 'px-6 py-6')}>
Stefan Probst's avatar
Stefan Probst committed
130
          <ItemMedia media={item.media} />
Stefan Probst's avatar
Stefan Probst committed
131
132
133
        </div>
        {children}
        <div className={cx(styles.mainColumn, 'px-6 py-6')}>
134
          <RelatedItems items={relatedItems} />
Stefan Probst's avatar
Stefan Probst committed
135
136
137
138
139
140
141
142
143
        </div>
        <SideColumn>
          <VStack className="px-6 pt-6 pb-12 space-y-16">
            <AccessibleAtLinks
              accessibleAt={item.accessibleAt}
              category={item.category as ItemCategory}
            />
            <ItemPropertiesList
              properties={item.properties as ItemProperties}
144
              contributors={item.contributors as ItemContributors}
145
              source={item.source}
Stefan Probst's avatar
Stefan Probst committed
146
              sourceItemId={item.sourceItemId}
147
148
              dateCreated={item.dateCreated}
              dateLastUpdated={item.dateLastUpdated}
Stefan Probst's avatar
Stefan Probst committed
149
              externalIds={item.externalIds}
Stefan Probst's avatar
Stefan Probst committed
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
            />
          </VStack>
        </SideColumn>
      </GridLayout>
    </Fragment>
  )
}

function SideColumn({ children }: PropsWithChildren<unknown>) {
  return <section className={styles.sideColumn}>{children}</section>
}

/**
 * Thumbail or category icon
 */
function ItemThumbnail({
  category,
Stefan Probst's avatar
Stefan Probst committed
167
  thumbnail,
Stefan Probst's avatar
Stefan Probst committed
168
169
}: {
  category: ItemCategory
Stefan Probst's avatar
Stefan Probst committed
170
  thumbnail: Item['thumbnail']
Stefan Probst's avatar
Stefan Probst committed
171
}) {
Stefan Probst's avatar
Stefan Probst committed
172
  if (thumbnail != null && thumbnail.mediaId !== undefined) {
Stefan Probst's avatar
Stefan Probst committed
173
    return (
Stefan Probst's avatar
Stefan Probst committed
174
175
176
177
178
      <img
        src={getMediaFileUrl({ mediaId: thumbnail.mediaId })}
        alt=""
        className="object-contain w-24 h-24"
      />
Stefan Probst's avatar
Stefan Probst committed
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
    )
  }
  return (
    <ItemCategoryIcon
      category={category}
      width="6em"
      className="flex-shrink-0"
    />
  )
}

/**
 * Description
 */
function ItemDescription({
  description,
}: {
  description: Item['description']
}) {
  if (description === undefined) return null
  return (
    <div className="leading-8">
      <Markdown text={description} />
    </div>
  )
}

/**
 * Upstream link(s) to item.
 */
function AccessibleAtLinks({
  accessibleAt,
  category,
}: {
  accessibleAt: Array<string>
  category: ItemCategory
}) {
  if (accessibleAt === undefined || accessibleAt.length === 0) return null
  /** we only get plural labels from the backend in GET items-categories */
  const label = getSingularItemCategoryLabel(category)
  const buttonClassNames =
    'w-full text-xl rounded py-4 px-4 bg-primary-800 text-white hover:bg-primary-700 transition-colors duration-150 inline-flex items-center'

  /** when more than one upstream link is provided render a menu button */
  if (accessibleAt.length > 1) {
    return (
      <Menu>
        {({ open }) => (
          <div className="relative inline-block w-full">
            <Menu.Button
              className={cx(buttonClassNames, 'inline-flex justify-between')}
            >
Stefan Probst's avatar
Stefan Probst committed
231
              <span className="px-4 text-left">Go to {label}</span>
Stefan Probst's avatar
Stefan Probst committed
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
              <span className="pl-3 pr-1 border-l border-primary-500">
                <Triangle />
              </span>
            </Menu.Button>
            <Menu.Items className="absolute z-10 w-full mt-1 overflow-hidden bg-white border rounded shadow-md">
              {accessibleAt.map((href) => (
                <Menu.Item key={href} as={Fragment}>
                  <a
                    href={href}
                    target="_blank"
                    rel="noopener noreferrer"
                    className="block px-8 py-6 truncate transition-colors duration-150 text-primary-500 hover:bg-gray-50"
                  >
                    {href}
                  </a>
                </Menu.Item>
              ))}
            </Menu.Items>
          </div>
        )}
      </Menu>
    )
  }

  return (
    <a
      className={buttonClassNames}
      href={accessibleAt[0]}
      rel="noopener noreferrer"
      target="_blank"
    >
      <span className="inline-flex items-start justify-center w-full px-4 space-x-2">
        <span>Go to {label}</span> <UrlIcon width="0.75em" className="pt-1" />
      </span>
    </a>
  )
}

/**
 * Item media.
 */
Stefan Probst's avatar
Stefan Probst committed
273
function ItemMedia({ media }: { media: Item['media'] }) {
Stefan Probst's avatar
Stefan Probst committed
274
275
276
277
278
  const [index, setIndex] = useState(0)

  if (media === undefined || media.length === 0) return null

  const current = media[index]
Stefan Probst's avatar
Stefan Probst committed
279
280
281
282
283
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  const mediaId = current.metadata!.mediaId!
  const currentMediaUrl =
    current.metadata!.location?.sourceUrl ?? getMediaFileUrl({ mediaId })
  const currentMediaCategory = current.metadata!.category
Stefan Probst's avatar
Stefan Probst committed
284
285
286
287
288
289

  return (
    <section>
      <SectionTitle className="sr-only">Media</SectionTitle>
      <div className="relative w-full h-64 border border-b-0 border-gray-200">
        <div className="absolute inset-0 flex flex-col items-center justify-center">
Stefan Probst's avatar
Stefan Probst committed
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
          {currentMediaCategory === 'image' ? (
            <img
              src={currentMediaUrl}
              alt=""
              loading="lazy"
              className="object-contain w-full h-full"
            />
          ) : currentMediaCategory === 'video' ? (
            // eslint-disable-next-line jsx-a11y/media-has-caption
            <video
              src={currentMediaUrl}
              className="object-contain w-full h-full"
            />
          ) : (
            <div className="grid place-items-center">
305
              <a href={currentMediaUrl} download rel="noopener noreferrer">
Stefan Probst's avatar
Stefan Probst committed
306
307
308
309
310
311
312
                Download{' '}
                {current.metadata?.filename ??
                  current.metadata?.location?.sourceUrl ??
                  'document'}
              </a>
            </div>
          )}
Stefan Probst's avatar
Stefan Probst committed
313
314
315
316
        </div>
      </div>
      <div className="flex justify-center border border-gray-200">
        <button
317
          aria-label="Previous image"
Stefan Probst's avatar
Stefan Probst committed
318
319
320
          className={cx(
            'inline-flex items-center justify-center px-6',
            media.length === 1
Stefan Probst's avatar
Stefan Probst committed
321
              ? 'text-gray-550 pointer-events-none'
Stefan Probst's avatar
Stefan Probst committed
322
323
324
325
326
327
328
              : 'text-primary-800',
          )}
          disabled={media.length === 1}
          onClick={() => {
            setIndex((index) => (index > 0 ? index - 1 : media.length - 1))
          }}
        >
329
330
331
332
333
334
          <svg
            aria-hidden
            viewBox="0 0 7.599 14.043"
            fill={'currentColor'}
            height="0.8em"
          >
Stefan Probst's avatar
Stefan Probst committed
335
336
337
338
339
340
341
342
343
344
            <g transform="translate(7.599) rotate(90)">
              <path
                className="a"
                d="M14.043,0H0L6.931,7.6Z"
                transform="translate(0 0)"
              />
            </g>
          </svg>
        </button>
        <ul className="flex justify-center flex-1 px-6 space-x-1 border-l border-r border-gray-200">
Stefan Probst's avatar
Stefan Probst committed
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
          {media.map((m, index) => {
            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
            const mediaId = m.metadata!.mediaId!
            const hasThumbnail = m.metadata!.hasThumbnail
            return (
              <li key={m.metadata?.mediaId}>
                <button onClick={() => setIndex(index)}>
                  {hasThumbnail === true ? (
                    <img
                      src={getMediaThumbnailUrl({ mediaId })}
                      alt=""
                      className="h-24 py-2"
                    />
                  ) : (
                    <div className="grid w-16 h-24 py-2 place-items-center">
                      <img src={DocumentIcon} alt="" className="w-6 h-6" />
                    </div>
                  )}
                </button>
              </li>
            )
          })}
Stefan Probst's avatar
Stefan Probst committed
367
368
        </ul>
        <button
369
          aria-label="Next image"
Stefan Probst's avatar
Stefan Probst committed
370
371
372
          className={cx(
            'inline-flex items-center justify-center px-6',
            media.length === 1
Stefan Probst's avatar
Stefan Probst committed
373
              ? 'text-gray-550 pointer-events-none'
Stefan Probst's avatar
Stefan Probst committed
374
375
376
377
378
379
380
              : 'text-primary-800',
          )}
          disabled={media.length === 1}
          onClick={() => {
            setIndex((index) => (index >= media.length - 1 ? 0 : index + 1))
          }}
        >
381
382
383
384
385
386
          <svg
            aria-hidden
            viewBox="0 0 7.599 14.043"
            fill={'currentColor'}
            height="0.8em"
          >
Stefan Probst's avatar
Stefan Probst committed
387
388
389
390
391
392
393
394
395
396
397
            <g transform="translate(0 14.043) rotate(-90)">
              <path d="M14.043,0H0L6.931,7.6Z" transform="translate(0 0)" />
            </g>
          </svg>
        </button>
      </div>
    </section>
  )
}

/**
Stefan Probst's avatar
Stefan Probst committed
398
399
400
 * Some properties are marked as `hidden` by the backend.
 * `thumbnail` and `media` are already shown, so we treat these as additional hidden properties
 * in the metadata sidepanel.
Stefan Probst's avatar
Stefan Probst committed
401
 */
Stefan Probst's avatar
Stefan Probst committed
402
403
404
const ADDITIONAL_HIDDEN_PROPERTIES = ['thumbnail', 'media']

interface ItemMetadata {
405
406
  properties: ItemProperties
  contributors: ItemContributors
407
  source?: Item['source']
Stefan Probst's avatar
Stefan Probst committed
408
  sourceItemId?: Item['sourceItemId']
409
410
  dateCreated?: string
  dateLastUpdated?: string
Stefan Probst's avatar
Stefan Probst committed
411
  externalIds?: Item['externalIds']
Stefan Probst's avatar
Stefan Probst committed
412
}
Stefan Probst's avatar
Stefan Probst committed
413

Stefan Probst's avatar
Stefan Probst committed
414
415
416
417
418
/**
 * Properties.
 */
function ItemPropertiesList(props: ItemMetadata) {
  const metadata = useItemMetadata(props)
419

Stefan Probst's avatar
Stefan Probst committed
420
  if (metadata == null) return null
Stefan Probst's avatar
Stefan Probst committed
421

Stefan Probst's avatar
Stefan Probst committed
422
423
424
  return (
    <aside className="">
      <h2 className="text-xl font-medium">Details</h2>
Stefan Probst's avatar
Stefan Probst committed
425
      <div className="text-sm divide-y">{Object.values(metadata)}</div>
Stefan Probst's avatar
Stefan Probst committed
426
427
428
    </aside>
  )
}
Stefan Probst's avatar
Stefan Probst committed
429

Stefan Probst's avatar
Stefan Probst committed
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
function ItemPropertyValue({ property }: { property: ItemProperty }) {
  switch (property.type?.type) {
    case 'concept':
      return (
        <Anchor href={property.concept?.uri}>{property.concept?.label}</Anchor>
      )
    case 'string':
      return <span>{property.value}</span>
    case 'url':
      return <Anchor href={property.value}>{property.value}</Anchor>
    case 'int':
    case 'float':
      return <span>{property.value}</span>
    case 'date':
      return property.value === undefined ? null : (
        <time dateTime={property.value}>{formatDate(property.value)}</time>
      )
    default:
      return null
449
  }
Stefan Probst's avatar
Stefan Probst committed
450
}
451

Stefan Probst's avatar
Stefan Probst committed
452
453
454
455
456
457
458
function useItemMetadata({
  properties,
  contributors,
  source,
  sourceItemId,
  dateCreated,
  dateLastUpdated,
Stefan Probst's avatar
Stefan Probst committed
459
  externalIds,
Stefan Probst's avatar
Stefan Probst committed
460
461
}: ItemMetadata) {
  const metadata: any = {}
462

Stefan Probst's avatar
Stefan Probst committed
463
464
465
466
467
468
469
470
471
472
473
474
  if (Array.isArray(properties) && properties.length > 0) {
    const grouped: Record<string, Record<string, Array<PropertyDto>>> = {}
    properties.forEach((property) => {
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
      const type = property.type!
      if (
        type.hidden === true ||
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
        ADDITIONAL_HIDDEN_PROPERTIES.includes(type.code!)
      ) {
        return
      }
475

Stefan Probst's avatar
Stefan Probst committed
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
      const groupName = property.type?.groupName ?? 'Other'
      // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
      grouped[groupName] = grouped[groupName] ?? {}
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
      const label = type.label!
      // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
      grouped[groupName][label] = grouped[groupName][label] ?? []
      grouped[groupName][label].push(property)
    })
    const sorted = Object.entries(grouped)
      .map(([key, values]) => {
        const sortedValues = Object.entries(values).sort(([, [a]], [, [b]]) =>
          // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
          a.type!.ord! > b.type!.ord! ? 1 : -1,
        )
        return [key, sortedValues] as [
          string,
          Array<[string, Array<PropertyDto>]>,
        ]
      })
      .sort(([a], [b]) => (a > b ? 1 : -1))
    metadata.properties = (
498
      <ul className="py-8 space-y-6" key="item-properties">
Stefan Probst's avatar
Stefan Probst committed
499
        {sorted.map(([groupName, entries]) => {
Stefan Probst's avatar
Stefan Probst committed
500
          return (
Stefan Probst's avatar
Stefan Probst committed
501
            <li key={groupName} className="flex flex-col space-y-2">
Stefan Probst's avatar
Stefan Probst committed
502
              <span className="font-bold tracking-wide text-gray-600 uppercase text-ui-sm whitespace-nowrap">
Stefan Probst's avatar
Stefan Probst committed
503
504
505
506
                {groupName}
              </span>
              <ul className="flex flex-col space-y-2">
                {entries.map(([label, properties]) => {
Stefan Probst's avatar
Stefan Probst committed
507
                  return (
Stefan Probst's avatar
Stefan Probst committed
508
                    <li key={label}>
Stefan Probst's avatar
Stefan Probst committed
509
                      <span className="mr-2 font-medium text-gray-550 whitespace-nowrap">
Stefan Probst's avatar
Stefan Probst committed
510
511
512
513
514
515
516
517
518
519
520
521
522
                        {label}:
                      </span>
                      <ul className="inline">
                        {properties.map((property, index) => {
                          return (
                            <li key={property.id} className="inline">
                              {index !== 0 ? ', ' : null}
                              <ItemPropertyValue property={property} />
                            </li>
                          )
                        })}
                      </ul>
                    </li>
Stefan Probst's avatar
Stefan Probst committed
523
524
                  )
                })}
Stefan Probst's avatar
Stefan Probst committed
525
526
              </ul>
            </li>
Stefan Probst's avatar
Stefan Probst committed
527
528
          )
        })}
Stefan Probst's avatar
Stefan Probst committed
529
530
531
      </ul>
    )
  }
532

Stefan Probst's avatar
Stefan Probst committed
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
  if (Array.isArray(contributors) && contributors.length > 0) {
    const grouped: Record<string, Array<ActorDto>> = {}
    contributors.forEach((contributor) => {
      const role = contributor.role?.label
      if (role != null && contributor.actor != null) {
        // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
        grouped[role] = grouped[role] ?? []
        grouped[role].push(contributor.actor)
      }
    })
    const sorted = Object.entries(grouped)
      .map(([key, value]) => {
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
        return [key, value.sort((a, b) => a.name!.localeCompare(b.name!))] as [
          string,
          Array<ActorDto>,
        ]
      })
      .sort(([a], [b]) => (a > b ? 1 : -1))
    metadata.contributors = (
553
      <ul className="py-8 space-y-6" key="item-actors">
Stefan Probst's avatar
Stefan Probst committed
554
555
556
        {sorted.map(([role, actors]) => {
          return (
            <li key={role} className="flex flex-col space-y-3">
Stefan Probst's avatar
Stefan Probst committed
557
              <span className="font-bold tracking-wide text-gray-600 uppercase text-ui-sm whitespace-nowrap">
Stefan Probst's avatar
Stefan Probst committed
558
559
560
561
                {role}
              </span>
              <ul className="flex flex-col space-y-2">
                {actors.map((actor) => {
562
563
564
                  const orcid = actor.externalIds?.find(
                    (a) => a.identifierService?.code === 'ORCID',
                  )
Stefan Probst's avatar
Stefan Probst committed
565
566
                  return (
                    <li key={actor.id} className="flex flex-col">
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
                      <span className="flex flex-wrap items-center">
                        <span className="mr-1.5">{actor.name}</span>
                        {orcid != null ? (
                          <a
                            href={`https://orcid.org/${orcid.identifier}`}
                            rel="noopener noreferrer"
                            target="_blank"
                            aria-label="ORCID"
                            className="flex-shrink-0 mr-1.5"
                          >
                            <img
                              src={OrcidIcon}
                              alt=""
                              aria-hidden
                              className="w-5 h-5"
                            />
                          </a>
                        ) : null}
                        {Array.isArray(actor.affiliations) &&
                        actor.affiliations.length > 0 ? (
                          <span className="mr-1.5 text-gray-550">
                            {actor.affiliations
                              .map((affiliation) => {
                                return affiliation.name
                              })
                              .join(', ')}
                          </span>
                        ) : null}
Stefan Probst's avatar
Stefan Probst committed
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
                      </span>
                      {actor.email != null ? (
                        <Anchor href={'mailto:' + actor.email}>
                          {actor.email}
                        </Anchor>
                      ) : null}
                      {actor.website != null ? (
                        <Anchor href={actor.website}>Website</Anchor>
                      ) : null}
                    </li>
                  )
                })}
              </ul>
            </li>
          )
        })}
      </ul>
    )
  }

  if (dateCreated != null || dateLastUpdated != null) {
    metadata.dates = (
617
      <dl className="py-8 space-y-2" key="item-dates">
Stefan Probst's avatar
Stefan Probst committed
618
        {dateCreated != null ? (
619
          <div className="flex">
Stefan Probst's avatar
Stefan Probst committed
620
            <dt>
Stefan Probst's avatar
Stefan Probst committed
621
              <span className="mr-2 font-medium text-gray-550 whitespace-nowrap">
Stefan Probst's avatar
Stefan Probst committed
622
623
624
625
626
                Created:
              </span>
            </dt>
            <dd>
              <time dateTime={dateCreated}>{formatDate(dateCreated)}</time>
627
628
629
            </dd>
          </div>
        ) : null}
Stefan Probst's avatar
Stefan Probst committed
630
        {dateLastUpdated != null ? (
631
          <div className="flex">
Stefan Probst's avatar
Stefan Probst committed
632
            <dt>
Stefan Probst's avatar
Stefan Probst committed
633
              <span className="mr-2 font-medium text-gray-550 whitespace-nowrap">
634
                Last updated:
Stefan Probst's avatar
Stefan Probst committed
635
636
637
638
639
640
              </span>
            </dt>
            <dd>
              <time dateTime={dateLastUpdated}>
                {formatDate(dateLastUpdated)}
              </time>
Stefan Probst's avatar
Stefan Probst committed
641
642
643
            </dd>
          </div>
        ) : null}
Stefan Probst's avatar
Stefan Probst committed
644
645
646
      </dl>
    )
  }
Stefan Probst's avatar
Stefan Probst committed
647

Stefan Probst's avatar
Stefan Probst committed
648
649
650
651
652
  if (source != null) {
    const label = source.label

    if (sourceItemId != null) {
      metadata.sourceItemId = (
653
        <div className="py-8" key="item-source">
Stefan Probst's avatar
Stefan Probst committed
654
          <span className="mr-2 font-medium text-gray-550 whitespace-nowrap">
Stefan Probst's avatar
Stefan Probst committed
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
            Source:
          </span>
          {source.urlTemplate != null ? (
            <Anchor
              href={source.urlTemplate.replace(
                '{source-item-id}',
                sourceItemId,
              )}
            >
              {label}
            </Anchor>
          ) : (
            <span>{label}</span>
          )}
        </div>
Stefan Probst's avatar
Stefan Probst committed
670
      )
Stefan Probst's avatar
Stefan Probst committed
671
    }
Stefan Probst's avatar
Stefan Probst committed
672
  }
Stefan Probst's avatar
Stefan Probst committed
673

Stefan Probst's avatar
Stefan Probst committed
674
675
  if (Array.isArray(externalIds) && externalIds.length > 0) {
    metadata.externalIds = (
676
      <ul className="py-8 space-y-6" key="item-externalids">
Stefan Probst's avatar
Stefan Probst committed
677
678
        {externalIds.map((id) => {
          return (
Stefan Probst's avatar
Stefan Probst committed
679
            <li key={id.identifier} className="flex">
Stefan Probst's avatar
Stefan Probst committed
680
              <span className="mr-2 font-medium text-gray-550 whitespace-nowrap">
Stefan Probst's avatar
Stefan Probst committed
681
682
683
                {id.identifierService?.label}:
              </span>
              <span>{id.identifier}</span>
Stefan Probst's avatar
Stefan Probst committed
684
685
686
687
688
689
690
            </li>
          )
        })}
      </ul>
    )
  }

Stefan Probst's avatar
Stefan Probst committed
691
  return metadata
Stefan Probst's avatar
Stefan Probst committed
692
}