Skip to content

Commit

Permalink
fix: remove tooltip from dataset card citation
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Dec 14, 2023
1 parent 6da0f0a commit efbe448
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 74 deletions.
6 changes: 5 additions & 1 deletion src/sections/dataset/dataset-citation/DatasetCitation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next'
import { DatasetPublishingStatus, DatasetVersion } from '../../../dataset/domain/models/Dataset'
import { DatasetThumbnail } from './DatasetThumbnail'
import { CitationDescription } from '../../shared/citation/CitationDescription'
import { DatasetCitationTooltip } from './DatasetCitationTooltip'

interface DatasetCitationProps {
thumbnail?: string
Expand Down Expand Up @@ -32,7 +33,10 @@ export function DatasetCitation({ thumbnail, title, citation, version }: Dataset
</Col>
<Col>
<Row>
<CitationDescription citation={citation} version={version} />
<span className={styles.citation}>
<CitationDescription citation={citation} />
<DatasetCitationTooltip status={version.publishingStatus} />
</span>
</Row>
<Row>
<div>
Expand Down
24 changes: 24 additions & 0 deletions src/sections/dataset/dataset-citation/DatasetCitationTooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { DatasetPublishingStatus } from '../../../dataset/domain/models/Dataset'
import { useTranslation } from 'react-i18next'
import { QuestionMarkTooltip } from '@iqss/dataverse-design-system'

interface DatasetCitationTooltipProps {
status: DatasetPublishingStatus
}

export function DatasetCitationTooltip({ status }: DatasetCitationTooltipProps) {
const { t } = useTranslation('dataset')

if (status !== DatasetPublishingStatus.RELEASED) {
return (
<>
{' '}
<QuestionMarkTooltip
placement={'top'}
message={t(`citation.status.${status}.description`)}
/>
</>
)
}
return <></>
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function DatasetCardInfo({ dataset }: DatasetCardInfoProps) {
className={
dataset.isDeaccessioned ? styles['citation-box-deaccessioned'] : styles['citation-box']
}>
<CitationDescription citation={dataset.citation} version={dataset.version} />
<CitationDescription citation={dataset.citation} />
</span>
<span>{dataset.abbreviatedDescription}</span>
</div>
Expand Down
35 changes: 2 additions & 33 deletions src/sections/shared/citation/CitationDescription.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,11 @@
import { DatasetPublishingStatus, DatasetVersion } from '../../../dataset/domain/models/Dataset'
import parse from 'html-react-parser'
import styles from '../../dataset/dataset-citation/DatasetCitation.module.scss'
import { useTranslation } from 'react-i18next'
import { QuestionMarkTooltip } from '@iqss/dataverse-design-system'

interface CitationDescriptionProps {
citation: string
version: DatasetVersion
}

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

return (
<span className={styles.citation}>
{citationAsReactElement}
<CitationTooltip status={version.publishingStatus} />
</span>
)
}

interface CitationTooltipProps {
status: DatasetPublishingStatus
}

function CitationTooltip({ status }: CitationTooltipProps) {
const { t } = useTranslation('dataset')

if (status !== DatasetPublishingStatus.RELEASED) {
return (
<>
{' '}
<QuestionMarkTooltip
placement={'top'}
message={t(`citation.status.${status}.description`)}
/>
</>
)
}
return <></>
return <span>{citationAsReactElement}</span>
}
Original file line number Diff line number Diff line change
@@ -1,46 +1,12 @@
import { CitationDescription } from '../../../../../src/sections/shared/citation/CitationDescription'
import { DatasetMother } from '../../../dataset/domain/models/DatasetMother'
import {
DatasetPublishingStatus,
DatasetVersion
} from '../../../../../src/dataset/domain/models/Dataset'

describe('CitationDescription', () => {
it('renders the citation', () => {
const citation = 'This is a citation'
cy.customMount(
<CitationDescription citation={citation} version={DatasetMother.create().version} />
)
const 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, V1'
cy.customMount(<CitationDescription citation={citation} />)

cy.findByText(citation).should('exist')
})

it('renders the citation with a tooltip when the version is not released', () => {
const citation = 'This is a citation'
const dataset = DatasetMother.create({
version: new DatasetVersion(
1,
DatasetPublishingStatus.DRAFT,
true,
false,
DatasetPublishingStatus.DRAFT
)
})
cy.customMount(<CitationDescription citation={citation} version={dataset.version} />)

cy.findByText(citation).should('exist')
cy.findByRole('img', { name: 'tooltip icon' }).should('exist').trigger('mouseover')
cy.findByText(
/DRAFT VERSION will be replaced in the citation with the selected version once the dataset has been published./
).should('exist')
})

it('does not render the tooltip when the version is released', () => {
const citation = 'This is a citation'
const dataset = DatasetMother.create()
cy.customMount(<CitationDescription citation={citation} version={dataset.version} />)

cy.findByText(citation).should('exist')
cy.findByRole('img', { name: 'tooltip icon' }).should('not.exist')
cy.findByText(/Finch, Fiona, 2023, "Darwin's Finches",/).should('exist')
cy.findByRole('link', { name: 'https://doi.org/10.5072/FK2/0YFWKL' }).should('exist')
})
})

0 comments on commit efbe448

Please sign in to comment.