Skip to content

Commit

Permalink
feat(FilePage): add dataset citation
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Dec 19, 2023
1 parent be47437 commit 9913c27
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 12 deletions.
3 changes: 2 additions & 1 deletion public/locales/en/file.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"tabs": {
"metadata": "Metadata"
},
"subtext": "This file is part of \"{{datasetTitle}}\"."
"subtext": "This file is part of \"{{datasetTitle}}\".",
"datasetCitation": "Dataset Citation"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@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;
border: 1px solid $dv-info-border-color;
Expand Down
19 changes: 11 additions & 8 deletions src/sections/dataset/dataset-citation/DatasetCitation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { CitationThumbnail } from './CitationThumbnail'
interface DatasetCitationProps {
thumbnail?: string
version: DatasetVersion
withoutThumbnail?: boolean
}

export function DatasetCitation({ thumbnail, version }: DatasetCitationProps) {
export function DatasetCitation({ thumbnail, version, withoutThumbnail }: DatasetCitationProps) {
const { t } = useTranslation('dataset')
return (
<>
Expand All @@ -21,13 +22,15 @@ export function DatasetCitation({ thumbnail, version }: DatasetCitationProps) {
: styles.container
}>
<Row className={styles.row}>
<Col sm={2}>
<CitationThumbnail
thumbnail={thumbnail}
title={version.title}
publishingStatus={version.publishingStatus}
/>
</Col>
{!withoutThumbnail && (
<Col sm={2}>
<CitationThumbnail
thumbnail={thumbnail}
title={version.title}
publishingStatus={version.publishingStatus}
/>
</Col>
)}
<Col>
<Row>
<CitationDescription
Expand Down
5 changes: 5 additions & 0 deletions src/sections/file/File.module.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@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;
Expand All @@ -15,4 +16,8 @@
.separation-line {
margin: 1em 0;
border-bottom: 1px solid #dee2e6;
}

.citation-title {
font-weight: $dv-font-weight-bold;
}
9 changes: 8 additions & 1 deletion src/sections/file/File.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
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'

interface FileProps {
repository: FileRepository
Expand Down Expand Up @@ -38,6 +39,12 @@ export function File({ repository, id }: FileProps) {
</span>
</header>
<div className={styles.container}>
<Row>
<Col sm={9}>
<span className={styles['citation-title']}>{t('datasetCitation')}</span>
<DatasetCitation version={file.datasetVersion} withoutThumbnail />
</Col>
</Row>
<Tabs defaultActiveKey="metadata">
<Tabs.Tab eventKey="metadata" title={t('tabs.metadata')}>
<span></span>
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} />
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('DatasetCitation', () => {
cy.findByText(/RELEASED/).should('not.exist')
cy.findByText(/V1/).should('exist')
cy.findByLabelText('icon-dataset').should('exist')
cy.findByLabelText('icon-dataset').should('exist')
})

it('shows the draft tooltip when version is draft', () => {
Expand All @@ -38,4 +39,11 @@ describe('DatasetCitation', () => {
/DEACCESSIONED VERSION has been added to the citation for this version since it is no longer available./
).should('exist')
})

it('does not render the thumbnail when withoutThumbnail prop is true', () => {
const version = DatasetVersionMother.createRealistic()
cy.customMount(<DatasetCitation version={version} withoutThumbnail={true} />)

cy.findByLabelText('icon-dataset').should('not.exist')
})
})
2 changes: 2 additions & 0 deletions tests/component/sections/file/File.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ describe('File', () => {

cy.findAllByText(testFile.name).should('exist')
cy.findByText(`This file is part of "${testFile.datasetVersion.title}".`).should('exist')
cy.findByText('Dataset Citation').should('exist')
cy.findByText(/Bennet, Elizabeth; Darcy, Fitzwilliam, 2023, "Dataset Title",/).should('exist')
})

it('renders skeleton while loading', () => {
Expand Down

0 comments on commit 9913c27

Please sign in to comment.