Skip to content

Commit

Permalink
feat(DatasetCard): refactor component
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Dec 4, 2023
1 parent ad4f308 commit e910803
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 103 deletions.
50 changes: 0 additions & 50 deletions src/sections/home/datasets-list/DatasetCard.tsx

This file was deleted.

1 change: 1 addition & 0 deletions src/sections/home/datasets-list/DatasetsList.module.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module";

.container {
min-height: calc(100vh + 100px);
padding:15px;
border: 1px solid #ddd;
border-radius: 4px;
Expand Down
2 changes: 1 addition & 1 deletion src/sections/home/datasets-list/DatasetsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DatasetPaginationInfo } from '../../../dataset/domain/models/DatasetPag
import { useLoading } from '../../loading/LoadingContext'
import { DatasetsListSkeleton } from './DatasetsListSkeleton'
import { NoDatasetsMessage } from './NoDatasetsMessage'
import { DatasetCard } from './DatasetCard'
import { DatasetCard } from './dataset-card/DatasetCard'

interface DatasetsListProps {
datasetRepository: DatasetRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
@use 'sass:color';
@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";

.container {
margin: 6px 0;
border: 1px solid $dv-info-border-color;
padding: 4px 10px;
border: 1px solid $dv-info-border-color;
}

.header {
display: flex;

> * {
margin-right: .5em;
}
Expand All @@ -31,8 +33,8 @@
.description {
display: flex;
flex-direction: column;
font-size: $dv-font-size-sm;
width: 100%;
font-size: $dv-font-size-sm;
}

.date {
Expand All @@ -41,15 +43,15 @@
}

.citation-box {
background-color: lighten($dv-primary-color, 51%) ;
padding: 4px;
margin-bottom: .5em;
margin-top: 4px;
margin-bottom: .5em;
padding: 4px;
background-color: color.adjust($dv-primary-color, $lightness: 51%) ;
}

.citation-box-deaccessioned {
background-color: $dv-danger-box-color;
padding: 4px;
margin-bottom: .5em;
margin-top: 4px;
margin-bottom: .5em;
padding: 4px;
background-color: $dv-danger-box-color;
}
21 changes: 21 additions & 0 deletions src/sections/home/datasets-list/dataset-card/DatasetCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { DatasetPreview } from '../../../../dataset/domain/models/DatasetPreview'
import styles from './DatasetCard.module.scss'
import { DatasetCardHeader } from './DatasetCardHeader'
import { DatasetCardThumbnail } from './DatasetCardThumbnail'
import { DatasetCardInfo } from './DatasetCardInfo'

interface DatasetCardProps {
dataset: DatasetPreview
}

export function DatasetCard({ dataset }: DatasetCardProps) {
return (
<article className={styles.container}>
<DatasetCardHeader dataset={dataset} />
<div className={styles.info}>
<DatasetCardThumbnail dataset={dataset} />
<DatasetCardInfo dataset={dataset} />
</div>
</article>
)
}
19 changes: 19 additions & 0 deletions src/sections/home/datasets-list/dataset-card/DatasetCardHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import styles from './DatasetCard.module.scss'
import { LinkToPage } from '../../../shared/link-to-page/LinkToPage'
import { Route } from '../../../Route.enum'
import { DatasetLabels } from '../../../dataset/dataset-labels/DatasetLabels'
import { DatasetPreview } from '../../../../dataset/domain/models/DatasetPreview'

interface DatasetCardHeaderProps {
dataset: DatasetPreview
}
export function DatasetCardHeader({ dataset }: DatasetCardHeaderProps) {
return (
<div className={styles.header}>
<LinkToPage page={Route.DATASETS} searchParams={{ persistentId: dataset.persistentId }}>
{dataset.title}
</LinkToPage>
<DatasetLabels labels={dataset.labels} />
</div>
)
}
23 changes: 23 additions & 0 deletions src/sections/home/datasets-list/dataset-card/DatasetCardInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import styles from './DatasetCard.module.scss'
import { DateHelper } from '../../../../shared/domain/helpers/DateHelper'
import { CitationDescription } from '../../../dataset/dataset-citation/DatasetCitation'
import { DatasetPreview } from '../../../../dataset/domain/models/DatasetPreview'

interface DatasetCardInfoProps {
dataset: DatasetPreview
}

export function DatasetCardInfo({ dataset }: DatasetCardInfoProps) {
return (
<div className={styles.description}>
<span className={styles.date}>{DateHelper.toDisplayFormat(dataset.releaseOrCreateDate)}</span>
<span
className={
dataset.isDeaccessioned ? styles['citation-box-deaccessioned'] : styles['citation-box']
}>
<CitationDescription citation={dataset.citation} version={dataset.version} />
</span>
<span>{dataset.abbreviatedDescription}</span>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import styles from './DatasetCard.module.scss'
import { DatasetPreview } from '../../../../dataset/domain/models/DatasetPreview'
import { LinkToPage } from '../../../shared/link-to-page/LinkToPage'
import { Route } from '../../../Route.enum'
import { DatasetThumbnail } from '../../../dataset/dataset-citation/DatasetThumbnail'

interface DatasetCardThumbnailProps {
dataset: DatasetPreview
}

export function DatasetCardThumbnail({ dataset }: DatasetCardThumbnailProps) {
return (
<div className={styles.thumbnail}>
<LinkToPage page={Route.DATASETS} searchParams={{ persistentId: dataset.persistentId }}>
<DatasetThumbnail
title={dataset.title}
thumbnail={dataset.thumbnail}
isDeaccessioned={dataset.isDeaccessioned}
/>
</LinkToPage>
</div>
)
}
6 changes: 5 additions & 1 deletion src/stories/home/datasets-list/DatasetCard.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta, StoryObj } from '@storybook/react'
import { WithI18next } from '../../WithI18next'
import { DatasetCard } from '../../../sections/home/datasets-list/DatasetCard'
import { DatasetCard } from '../../../sections/home/datasets-list/dataset-card/DatasetCard'
import { DatasetPreviewMother } from '../../../../tests/component/dataset/domain/models/DatasetPreviewMother'

const meta: Meta<typeof DatasetCard> = {
Expand All @@ -15,3 +15,7 @@ type Story = StoryObj<typeof DatasetCard>
export const Default: Story = {
render: () => <DatasetCard dataset={DatasetPreviewMother.create()} />
}

export const Deaccessioned: Story = {
render: () => <DatasetCard dataset={DatasetPreviewMother.createDeaccessioned()} />
}
19 changes: 19 additions & 0 deletions tests/component/dataset/domain/models/DatasetMother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,25 @@ export class DatasetLabelsMother {
{ value: DatasetLabelValue.DRAFT, semanticMeaning: DatasetLabelSemanticMeaning.DATASET }
]
}

static createDeaccessioned(): DatasetLabel[] {
return [
{
value: DatasetLabelValue.DEACCESSIONED,
semanticMeaning: DatasetLabelSemanticMeaning.DANGER
}
]
}
}

export class DatasetCitationMother {
static create(): string {
return 'Finch, Fiona, 2023, "Darwin\'s Finches", <a href="https://doi.org/10.5072/FK2/0YFWKL" target="_blank">https://doi.org/10.5072/FK2/0YFWKL</a>, Root, DRAFT VERSION'
}

static createDeaccessioned(): string {
return 'Finch, Fiona, 2023, "Darwin\'s Finches", <a href="https://doi.org/10.5072/FK2/0YFWKL" target="_blank">https://doi.org/10.5072/FK2/0YFWKL</a>, Root, V1, DEACCESSIONED VERSION'
}
}

export class DatasetMother {
Expand Down
15 changes: 11 additions & 4 deletions tests/component/dataset/domain/models/DatasetPreviewMother.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { faker } from '@faker-js/faker'
import { DatasetPreview } from '../../../../../src/dataset/domain/models/DatasetPreview'
import { DatasetLabelsMother, DatasetVersionMother } from './DatasetMother'
import { DatasetCitationMother, DatasetLabelsMother, DatasetVersionMother } from './DatasetMother'

export class DatasetPreviewMother {
static createMany(count: number): DatasetPreview[] {
Expand All @@ -16,8 +16,7 @@ export class DatasetPreviewMother {
thumbnail: faker.datatype.boolean() ? faker.image.imageUrl() : undefined,
releaseOrCreateDate: faker.date.past(),
version: DatasetVersionMother.create(),
citation:
'Finch, Fiona, 2023, "Darwin\'s Finches", <a href="https://doi.org/10.5072/FK2/0YFWKL" target="_blank">https://doi.org/10.5072/FK2/0YFWKL</a>, Root, DRAFT VERSION',
citation: DatasetCitationMother.create(),
description: faker.lorem.paragraph(),
...props
}
Expand All @@ -39,7 +38,15 @@ export class DatasetPreviewMother {
return this.create({ thumbnail: faker.image.imageUrl(), isDeaccessioned: false })
}

static createWithNoThumbnail(): DatasetPreview {
return this.create({ thumbnail: undefined, isDeaccessioned: false })
}

static createDeaccessioned(): DatasetPreview {
return this.create({ isDeaccessioned: true })
return this.create({
isDeaccessioned: true,
labels: DatasetLabelsMother.createDeaccessioned(),
citation: DatasetCitationMother.createDeaccessioned()
})
}
}
38 changes: 0 additions & 38 deletions tests/component/sections/home/datasets-list/DatasetCard.spec.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Datasets List', () => {

cy.findByText('1 to 10 of 200 Datasets').should('exist')
datasets.forEach((dataset) => {
cy.findByRole('link', { name: dataset.title })
cy.findByText(dataset.title)
.should('exist')
.should('have.attr', 'href', `/datasets?persistentId=${dataset.persistentId}`)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { DatasetPreviewMother } from '../../../../dataset/domain/models/DatasetPreviewMother'
import { DatasetCard } from '../../../../../../src/sections/home/datasets-list/dataset-card/DatasetCard'
import { DateHelper } from '../../../../../../src/shared/domain/helpers/DateHelper'
import styles from '../../../../../../src/sections/home/datasets-list/dataset-card/DatasetCard.module.scss'

describe('DatasetCard', () => {
it('should render the card', () => {
const dataset = DatasetPreviewMother.create()
cy.customMount(<DatasetCard dataset={dataset} />)

cy.findByText(dataset.title).should('exist')

cy.findByRole('img').should('exist')
cy.findByText(DateHelper.toDisplayFormat(dataset.releaseOrCreateDate)).should('exist')
cy.findByText(/Finch, Fiona, 2023, "Darwin's Finches"/)
.should('exist')
.parent()
.should('have.class', styles['citation-box'])
cy.findByText(dataset.abbreviatedDescription).should('exist')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { DatasetCardHeader } from '../../../../../../src/sections/home/datasets-list/dataset-card/DatasetCardHeader'
import { DatasetPreviewMother } from '../../../../dataset/domain/models/DatasetPreviewMother'

describe('DatasetCardHeader', () => {
it('should render the header', () => {
const dataset = DatasetPreviewMother.create()
cy.customMount(<DatasetCardHeader dataset={dataset} />)

cy.findByText(dataset.title)
.should('exist')
.should('have.attr', 'href', `/datasets?persistentId=${dataset.persistentId}`)
dataset.labels.forEach((label) => {
cy.findByText(label.value).should('exist')
})
})
})
Loading

0 comments on commit e910803

Please sign in to comment.