Skip to content

Commit

Permalink
refactor: move citation to DatasetVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Dec 15, 2023
1 parent 9c3a455 commit 37180ad
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 127 deletions.
6 changes: 2 additions & 4 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,10 @@ export class DatasetVersion {
public readonly isLatest: boolean,
public readonly isInReview: boolean,
public readonly latestVersionStatus: DatasetPublishingStatus,
public readonly citation: string,
public readonly majorNumber?: number,
public readonly minorNumber?: number,
// requestedVersion will be set if the user requested a version that did not exist.
public readonly minorNumber?: number,
public readonly requestedVersion?: string
) {}

Expand Down Expand Up @@ -273,7 +274,6 @@ export class Dataset {
constructor(
public readonly persistentId: string,
public readonly version: DatasetVersion,
public readonly citation: string,
public readonly labels: DatasetLabel[],
public readonly alerts: Alert[],
public readonly summaryFields: DatasetMetadataBlock[],
Expand Down Expand Up @@ -361,7 +361,6 @@ export class Dataset {
constructor(
public readonly persistentId: string,
public readonly version: DatasetVersion,
public readonly citation: string,
public readonly summaryFields: DatasetMetadataBlock[],
public readonly license: DatasetLicense = defaultLicense,
public readonly metadataBlocks: DatasetMetadataBlocks,
Expand Down Expand Up @@ -470,7 +469,6 @@ export class Dataset {
return new Dataset(
this.persistentId,
this.version,
this.citation,
this.labels,
this.alerts,
this.summaryFields,
Expand Down
16 changes: 9 additions & 7 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import {
export class JSDatasetMapper {
static toDataset(
jsDataset: JSDataset,
citation: string,
summaryFieldsNames: string[],
jsDatasetCitation: string,
jsDatasetSummaryFieldsNames: string[],
jsDatasetPermissions: JSDatasetPermissions,
jsDatasetLocks: JSDatasetLock[],
requestedVersion?: string,
Expand All @@ -36,13 +36,13 @@ export class JSDatasetMapper {
const version = JSDatasetMapper.toVersion(
jsDataset.versionId,
jsDataset.versionInfo,
jsDatasetCitation,
requestedVersion
)
return new Dataset.Builder(
jsDataset.persistentId,
version,
citation,
JSDatasetMapper.toSummaryFields(jsDataset.metadataBlocks, summaryFieldsNames),
JSDatasetMapper.toSummaryFields(jsDataset.metadataBlocks, jsDatasetSummaryFieldsNames),
jsDataset.license,
JSDatasetMapper.toMetadataBlocks(
jsDataset.metadataBlocks,
Expand All @@ -66,14 +66,16 @@ export class JSDatasetMapper {
static toVersion(
jDatasetVersionId: number,
jsDatasetVersionInfo: JSDatasetVersionInfo,
jsDatasetCitation: string,
requestedVersion?: string
): DatasetVersion {
return new DatasetVersion(
jDatasetVersionId,
JSDatasetMapper.toStatus(jsDatasetVersionInfo.state),
true, // TODO Connect with dataset version isLatest
false, // TODO Connect with dataset version isInReview
JSDatasetMapper.toStatus(jsDatasetVersionInfo.state), // TODO Connect with dataset version latestVersionState
true,
false,
JSDatasetMapper.toStatus(jsDatasetVersionInfo.state),
jsDatasetCitation,
jsDatasetVersionInfo.majorNumber,
jsDatasetVersionInfo.minorNumber,
requestedVersion
Expand Down
1 change: 0 additions & 1 deletion src/sections/dataset/Dataset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export function Dataset({ fileRepository }: DatasetProps) {
<DatasetCitation
title={dataset.getTitle()}
thumbnail={dataset.thumbnail}
citation={dataset.citation}
version={dataset.version}
/>
</Col>
Expand Down
18 changes: 13 additions & 5 deletions src/sections/dataset/dataset-citation/DatasetCitation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import { CitationThumbnail } from './CitationThumbnail'
interface DatasetCitationProps {
thumbnail?: string
title: string
citation: string
version: DatasetVersion
}

export function DatasetCitation({ thumbnail, title, citation, version }: DatasetCitationProps) {
export function DatasetCitation({ thumbnail, title, version }: DatasetCitationProps) {
const { t } = useTranslation('dataset')
return (
<>
Expand All @@ -32,7 +31,10 @@ export function DatasetCitation({ thumbnail, title, citation, version }: Dataset
</Col>
<Col>
<Row>
<CitationDescription citation={citation} version={version} />
<CitationDescription
citation={version.citation}
publishingStatus={version.publishingStatus}
/>
</Row>
<Row>
<div>
Expand All @@ -53,13 +55,19 @@ export function DatasetCitation({ thumbnail, title, citation, version }: Dataset
)
}

function CitationDescription({ citation, version }: { citation: string; version: DatasetVersion }) {
function CitationDescription({
citation,
publishingStatus
}: {
citation: string
publishingStatus: DatasetPublishingStatus
}) {
const citationAsReactElement = parse(citation)

return (
<span className={styles.citation}>
{citationAsReactElement}
<CitationTooltip status={version.publishingStatus} />
<CitationTooltip status={publishingStatus} />
</span>
)
}
Expand Down
7 changes: 6 additions & 1 deletion src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export const DraftVersion: Story = {
DatasetPublishingStatus.DRAFT,
true,
false,
DatasetPublishingStatus.DRAFT
DatasetPublishingStatus.DRAFT,
''
),
permissions: DatasetPermissionsMother.createWithPublishingDatasetAllowed()
})
Expand All @@ -83,6 +84,7 @@ export const VersionNotFound: Story = {
true,
false,
DatasetPublishingStatus.RELEASED,
'',
1,
0,
'3.0'
Expand All @@ -105,6 +107,7 @@ export const VersionNotFoundShowDraft: Story = {
true,
false,
DatasetPublishingStatus.DRAFT,
'',
1,
0,
'3.0'
Expand All @@ -127,6 +130,7 @@ export const SharePrivateUrl: Story = {
true,
false,
DatasetPublishingStatus.DRAFT,
'',
1,
0
),
Expand All @@ -153,6 +157,7 @@ export const UsePrivateUrl: Story = {
true,
false,
DatasetPublishingStatus.DRAFT,
'',
1,
0
),
Expand Down
58 changes: 11 additions & 47 deletions src/stories/dataset/dataset-citation/DatasetCitation.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { Meta, StoryObj } from '@storybook/react'
import { WithI18next } from '../../WithI18next'
import { DatasetCitation } from '../../../sections/dataset/dataset-citation/DatasetCitation'
import { DatasetPublishingStatus, DatasetVersion } from '../../../dataset/domain/models/Dataset'
import { faker } from '@faker-js/faker'
import { DatasetMother } from '../../../../tests/component/dataset/domain/models/DatasetMother'
import {
DatasetMother,
DatasetVersionMother
} from '../../../../tests/component/dataset/domain/models/DatasetMother'

const meta: Meta<typeof DatasetCitation> = {
title: 'Sections/Dataset Page/DatasetCitation',
Expand All @@ -21,11 +23,7 @@ export const Default: Story = {
<div>
<br></br>
<br></br>
<DatasetCitation
title={dataset.getTitle()}
citation={dataset.citation}
version={dataset.version}
/>
<DatasetCitation title={dataset.getTitle()} version={dataset.version} />
</div>
)
}
Expand All @@ -41,7 +39,6 @@ export const WithThumbnail: Story = {
<DatasetCitation
title={dataset.getTitle()}
thumbnail={dataset.thumbnail}
citation={dataset.citation}
version={dataset.version}
/>
</div>
Expand All @@ -52,15 +49,7 @@ export const WithThumbnail: Story = {
export const DraftVersion: Story = {
render: () => {
const dataset = DatasetMother.createRealistic({
citation:
'Admin, Dataverse, 2023, "Dataset Title", <a href="https://doi.org/10.5072/FK2/BUDNRV" target="_blank">https://doi.org/10.5072/FK2/BUDNRV</a>, Root, DRAFT VERSION',
version: new DatasetVersion(
1,
DatasetPublishingStatus.DRAFT,
true,
false,
DatasetPublishingStatus.DRAFT
)
version: DatasetVersionMother.createDraft()
})

/*
Expand All @@ -70,11 +59,7 @@ export const DraftVersion: Story = {
<div>
<br></br>
<br></br>
<DatasetCitation
title={dataset.getTitle()}
citation={dataset.citation}
version={dataset.version}
/>
<DatasetCitation title={dataset.getTitle()} version={dataset.version} />
</div>
)
}
Expand All @@ -83,17 +68,7 @@ export const DraftVersion: Story = {
export const Deaccessioned: Story = {
render: () => {
const dataset = DatasetMother.createRealistic({
citation:
'Admin, Dataverse, 2023, "Dataset Title", <a href="https://doi.org/10.5072/FK2/BUDNRV" target="_blank">https://doi.org/10.5072/FK2/BUDNRV</a>, Root, V1 DEACCESSIONED VERSION',
version: new DatasetVersion(
1,
DatasetPublishingStatus.DEACCESSIONED,
true,
false,
DatasetPublishingStatus.DEACCESSIONED,
1,
0
)
version: DatasetVersionMother.createDeaccessioned()
})

/*
Expand All @@ -103,22 +78,15 @@ export const Deaccessioned: Story = {
<div>
<br></br>
<br></br>
<DatasetCitation
title={dataset.getTitle()}
citation={dataset.citation}
version={dataset.version}
/>
<DatasetCitation title={dataset.getTitle()} version={dataset.version} />
</div>
)
}
}

export const Anonymized: Story = {
render: () => {
const dataset = DatasetMother.createRealistic({
citation:
'Author name(s) withheld, 2023, "Dataset Title", <a href="https://doi.org/10.5072/FK2/BUDNRV" target="_blank">https://doi.org/10.5072/FK2/BUDNRV</a>, Root, V1'
})
const dataset = DatasetMother.createRealisticAnonymized()

/*
Includes extra breaks, so you can see the DRAFT tooltip message
Expand All @@ -127,11 +95,7 @@ export const Anonymized: Story = {
<div>
<br></br>
<br></br>
<DatasetCitation
title={dataset.getTitle()}
citation={dataset.citation}
version={dataset.version}
/>
<DatasetCitation title={dataset.getTitle()} version={dataset.version} />
</div>
)
}
Expand Down
Loading

0 comments on commit 37180ad

Please sign in to comment.