Skip to content

Commit

Permalink
Merge pull request #269 from IQSS/feature/261-file-citation-ui
Browse files Browse the repository at this point in the history
261 - Add File Citation to File Page
  • Loading branch information
ekraffmiller authored Jan 21, 2024
2 parents 4dba60a + 30ae03e commit c0516c5
Show file tree
Hide file tree
Showing 41 changed files with 305 additions and 82 deletions.
1 change: 1 addition & 0 deletions public/locales/en/citationBlock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "learnAbout": "Learn About", "standards": "Data Citation Standards" }
4 changes: 1 addition & 3 deletions public/locales/en/dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"deaccessioned": {
"description": "DEACCESSIONED VERSION has been added to the citation for this version since it is no longer available."
}
},
"learnAbout": "Learn About",
"standards": "Data Citation Standards"
}
},
"datasetActionButtons": {
"title": "Dataset Action Buttons",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/en/file.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"metadata": "Metadata"
},
"subtext": "This file is part of \"{{datasetTitle}}\".",
"datasetCitationTitle": "Dataset Citation",
"fileCitationTitle": "File Citation",
"fileAccess": {
"title": "File Access",
"restricted": {
Expand Down
1 change: 1 addition & 0 deletions src/files/domain/models/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface FilePermissions {
export interface File {
name: string
datasetVersion: DatasetVersion
citation: string
restricted: boolean
permissions: FilePermissions
}
2 changes: 1 addition & 1 deletion src/sections/dataset/Dataset.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}

.summary-container {
margin:1em 0;
margin-bottom: 1em;
}

.tab-container {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
@import "node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module";

.container {
min-height: 150px;
margin: 0.5rem 0;
padding: 10px;
margin: 0 0 20px;
padding: 10px 0;
border: 1px solid $dv-info-border-color;
}

.citation {
margin-bottom: 1em;
}

.deaccessioned {
margin: 0.5rem 0;
padding: 10px;
Expand Down
67 changes: 26 additions & 41 deletions src/sections/dataset/dataset-citation/DatasetCitation.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,41 @@
import { Col, Row } from '@iqss/dataverse-design-system'
import styles from './DatasetCitation.module.scss'
import { useTranslation } from 'react-i18next'
import { DatasetPublishingStatus, DatasetVersion } from '../../../dataset/domain/models/Dataset'
import { DatasetThumbnail } from '../dataset-thumbnail/DatasetThumbnail'
import { CitationDescription } from '../../shared/citation/CitationDescription'
import { DatasetCitationTooltip } from './DatasetCitationTooltip'
import { CitationLearnAbout } from '../../shared/citation/CitationLearnAbout'

interface DatasetCitationProps {
thumbnail?: string
version: DatasetVersion
withoutThumbnail?: boolean
}

export function DatasetCitation({ thumbnail, version }: DatasetCitationProps) {
const { t } = useTranslation('dataset')
export function DatasetCitation({ thumbnail, version, withoutThumbnail }: DatasetCitationProps) {
return (
<>
<Row
className={
version.publishingStatus === DatasetPublishingStatus.DEACCESSIONED
? styles.deaccessioned
: styles.container
}>
<Row className={styles.row}>
<Col sm={2} className={styles.thumbnail}>
<DatasetThumbnail
thumbnail={thumbnail}
title={version.title}
isDeaccessioned={version.publishingStatus === DatasetPublishingStatus.DEACCESSIONED}
/>
</Col>
<Col>
<Row>
<span className={styles.citation}>
<CitationDescription citation={version.citation} />
<DatasetCitationTooltip status={version.publishingStatus} />
</span>
</Row>
<Row>
<div>
{t('citation.learnAbout')}{' '}
<a
className={styles.link}
href="https://dataverse.org/best-practices/data-citation"
target="_blank"
rel="noopener noreferrer">
{t('citation.standards')}.
</a>
</div>
</Row>
</Col>
</Row>
</Row>
</>
<Row
className={
version.publishingStatus === DatasetPublishingStatus.DEACCESSIONED
? styles.deaccessioned
: styles.container
}>
{!withoutThumbnail && (
<Col sm={2} className={styles.thumbnail}>
<DatasetThumbnail
thumbnail={thumbnail}
title={version.title}
isDeaccessioned={version.publishingStatus === DatasetPublishingStatus.DEACCESSIONED}
/>
</Col>
)}
<Col sm={withoutThumbnail ? 12 : 10}>
<CitationDescription
citation={version.citation}
tooltip={<DatasetCitationTooltip status={version.publishingStatus} />}
/>
<CitationLearnAbout />
</Col>
</Row>
)
}
17 changes: 6 additions & 11 deletions src/sections/dataset/dataset-citation/DatasetCitationTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@ interface DatasetCitationTooltipProps {
export function DatasetCitationTooltip({ status }: DatasetCitationTooltipProps) {
const { t } = useTranslation('dataset')

if (status !== DatasetPublishingStatus.RELEASED) {
return (
<>
{' '}
<QuestionMarkTooltip
placement={'top'}
message={t(`citation.status.${status}.description`)}
/>
</>
)
if (status === DatasetPublishingStatus.RELEASED) {
return <></>
}
return <></>

return (
<QuestionMarkTooltip placement={'top'} message={t(`citation.status.${status}.description`)} />
)
}
7 changes: 6 additions & 1 deletion src/sections/file/File.module.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
@import "node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module";
@import "node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/typography.module";

.header {
margin: 0.5em 0;
}

.subtext {
margin-bottom: 10px;
color: $dv-subtext-color;
color: $dv-subtext-color;
}

.container {
Expand All @@ -18,6 +19,10 @@
border-bottom: 1px solid #dee2e6;
}

.citation-title {
font-weight: $dv-font-weight-bold;
}

.labels {
display: flex;
align-items: center;
Expand Down
12 changes: 11 additions & 1 deletion src/sections/file/File.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { useTranslation } from 'react-i18next'
import { PageNotFound } from '../page-not-found/PageNotFound'
import styles from './File.module.scss'
import { Tabs } from '@iqss/dataverse-design-system'
import { Col, Row, Tabs } from '@iqss/dataverse-design-system'
import { FileRepository } from '../../files/domain/repositories/FileRepository'
import { useFile } from './useFile'
import { useEffect } from 'react'
import { useLoading } from '../loading/LoadingContext'
import { FileSkeleton } from './FileSkeleton'
import { DatasetCitation } from '../dataset/dataset-citation/DatasetCitation'
import { FileCitation } from './file-citation/FileCitation'
import { DatasetLabels } from '../dataset/dataset-labels/DatasetLabels'
import { FileAccessRestrictedIcon } from './file-access/FileAccessRestrictedIcon'

Expand Down Expand Up @@ -51,6 +53,14 @@ export function File({ repository, id }: FileProps) {
</div>
</header>
<div className={styles.container}>
<Row>
<Col sm={9}>
<span className={styles['citation-title']}>{t('fileCitationTitle')}</span>
<FileCitation citation={file.citation} datasetVersion={file.datasetVersion} />
<span className={styles['citation-title']}>{t('datasetCitationTitle')}</span>
<DatasetCitation version={file.datasetVersion} withoutThumbnail />
</Col>
</Row>
<Tabs defaultActiveKey="metadata">
<Tabs.Tab eventKey="metadata" title={t('tabs.metadata')}>
<span></span>
Expand Down
15 changes: 13 additions & 2 deletions src/sections/file/FileSkeleton.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import styles from './File.module.scss'
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'
import { Tabs } from '@iqss/dataverse-design-system'
import { Col, Row, Tabs } from '@iqss/dataverse-design-system'
import { useTranslation } from 'react-i18next'

export function FileSkeleton() {
const { t } = useTranslation('file')
return (
<SkeletonTheme>
<article data-testid="file-skeleton">
Expand All @@ -16,11 +18,20 @@ export function FileSkeleton() {
<Skeleton width="10%" />
</header>
<div className={styles.container}>
<Row>
<Col sm={9}>
<span className={styles['citation-title']}>{t('fileCitationTitle')}</span>
<Skeleton height="80px" style={{ marginBottom: 20 }} />
<span className={styles['citation-title']}>{t('datasetCitationTitle')}</span>
<Skeleton height="80px" style={{ marginBottom: 20 }} />
</Col>
</Row>
<Tabs defaultActiveKey="metadata">
<Tabs.Tab eventKey="metadata" title="Metadata">
<Skeleton height="1000px" style={{ marginTop: 20 }} />
<></>
</Tabs.Tab>
</Tabs>
<div className={styles['separation-line']}></div>
</div>
</article>
</SkeletonTheme>
Expand Down
13 changes: 13 additions & 0 deletions src/sections/file/file-citation/FileCitation.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@import "node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module";

.container {
margin: 0 0 20px;
padding: 10px 0;
border: 1px solid $dv-secondary-color;
}

.deaccessioned {
margin: 0.5rem 0;
padding: 10px;
border: 1px solid $dv-danger-color;
}
29 changes: 29 additions & 0 deletions src/sections/file/file-citation/FileCitation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { DatasetPublishingStatus, DatasetVersion } from '../../../dataset/domain/models/Dataset'
import styles from './FileCitation.module.scss'
import { CitationDescription } from '../../shared/citation/CitationDescription'
import { DatasetCitationTooltip } from '../../dataset/dataset-citation/DatasetCitationTooltip'
import { CitationLearnAbout } from '../../shared/citation/CitationLearnAbout'
import { Col, Row } from '@iqss/dataverse-design-system'

interface FileCitationProps {
citation: string
datasetVersion: DatasetVersion
}
export function FileCitation({ citation, datasetVersion }: FileCitationProps) {
return (
<Row
className={
datasetVersion.publishingStatus === DatasetPublishingStatus.DEACCESSIONED
? styles.deaccessioned
: styles.container
}>
<Col>
<CitationDescription
citation={citation}
tooltip={<DatasetCitationTooltip status={datasetVersion.publishingStatus} />}
/>
<CitationLearnAbout />
</Col>
</Row>
)
}
9 changes: 9 additions & 0 deletions src/sections/shared/citation/Citation.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@import "node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module";

.description {
margin-bottom: 1em;
}

.text {
color: $dv-subtext-color
}
13 changes: 11 additions & 2 deletions src/sections/shared/citation/CitationDescription.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import parse from 'html-react-parser'
import styles from './Citation.module.scss'
import { ReactNode } from 'react'

interface CitationDescriptionProps {
citation: string
tooltip?: ReactNode
}

export function CitationDescription({ citation }: CitationDescriptionProps) {
export function CitationDescription({ citation, tooltip }: CitationDescriptionProps) {
const citationAsReactElement = parse(citation)

return <span>{citationAsReactElement}</span>
return (
<div className={styles.description}>
<span>
{citationAsReactElement} {tooltip}
</span>
</div>
)
}
17 changes: 17 additions & 0 deletions src/sections/shared/citation/CitationLearnAbout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useTranslation } from 'react-i18next'
import styles from './Citation.module.scss'

export function CitationLearnAbout() {
const { t } = useTranslation('citationBlock')
return (
<div>
<span className={styles.text}>{t('learnAbout')}</span>{' '}
<a
href="https://dataverse.org/best-practices/data-citation"
target="_blank"
rel="noopener noreferrer">
{t('standards')}.
</a>
</div>
)
}
8 changes: 4 additions & 4 deletions src/stories/dataset/Dataset.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { WithLayout } from '../WithLayout'
import { Dataset } from '../../sections/dataset/Dataset'
import { WithAnonymizedView } from './WithAnonymizedView'
import { WithDatasetPrivateUrl } from './WithDatasetPrivateUrl'
import { FileMockRepository } from '../files/FileMockRepository'
import { FileMockRepository } from '../file/FileMockRepository'
import { WithCitationMetadataBlockInfo } from './WithCitationMetadataBlockInfo'
import { FileMockNoDataRepository } from '../files/FileMockNoDataRepository'
import { FileMockNoDataRepository } from '../file/FileMockNoDataRepository'
import { WithSettings } from '../WithSettings'
import { WithFilePermissionsDenied } from '../files/file-permission/WithFilePermissionsDenied'
import { WithFilePermissionsGranted } from '../files/file-permission/WithFilePermissionsGranted'
import { WithFilePermissionsDenied } from '../file/file-permission/WithFilePermissionsDenied'
import { WithFilePermissionsGranted } from '../file/file-permission/WithFilePermissionsGranted'
import { WithDataset } from './WithDataset'
import { WithDatasetDraftAsOwner } from './WithDatasetDraftAsOwner'
import { WithDatasetNotFound } from './WithDatasetNotFound'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const Default: Story = {
}
}

export const WithThumbnail: Story = {
export const WithThumbnailImage: Story = {
render: () => {
const dataset = DatasetMother.createRealistic({ thumbnail: faker.image.imageUrl() })
return (
Expand Down Expand Up @@ -91,3 +91,10 @@ export const Anonymized: Story = {
)
}
}

export const WithoutThumbnail: Story = {
render: () => {
const dataset = DatasetMother.createRealistic()
return <DatasetCitation withoutThumbnail version={dataset.version} />
}
}
Loading

0 comments on commit c0516c5

Please sign in to comment.