-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove tooltip from dataset card citation
- Loading branch information
Showing
5 changed files
with
37 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/sections/dataset/dataset-citation/DatasetCitationTooltip.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <></> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
44 changes: 5 additions & 39 deletions
44
tests/component/sections/shared/citation/CitationDescription.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |