Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataset Page: apply markdown transforming only to TEXTBOX type fields #588

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"react-toastify": "11.0.2",
"react-topbar-progress-indicator": "4.1.1",
"sass": "1.58.1",
"turndown": "7.2.0",
"typescript": "5.7.2",
"use-deep-compare": "1.2.1",
"vite-plugin-istanbul": "4.0.1",
Expand Down
7 changes: 6 additions & 1 deletion src/dataset/domain/repositories/DatasetRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { DatasetsWithCount } from '../models/DatasetsWithCount'
import { VersionUpdateType } from '../models/VersionUpdateType'

export interface DatasetRepository {
getByPersistentId: (persistentId: string, version?: string) => Promise<Dataset | undefined>
getByPersistentId: (
persistentId: string,
version?: string,
requestedVersion?: string,
keepRawFields?: boolean
) => Promise<Dataset | undefined>
getLocks(persistentId: string): Promise<DatasetLock[]>
getByPrivateUrlToken: (privateUrlToken: string) => Promise<Dataset | undefined>
getVersionDiff: (
Expand Down
12 changes: 8 additions & 4 deletions src/dataset/domain/useCases/getDatasetByPersistentId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import { Dataset } from '../models/Dataset'
export async function getDatasetByPersistentId(
datasetRepository: DatasetRepository,
persistentId: string,
version?: string
version?: string,
requestedVersion?: string,
keepRawFields?: boolean
): Promise<Dataset | undefined> {
return datasetRepository.getByPersistentId(persistentId, version).catch((error: Error) => {
throw new Error(error.message)
})
return datasetRepository
.getByPersistentId(persistentId, version, requestedVersion, keepRawFields)
.catch((error: Error) => {
throw new Error(error.message)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
getByPersistentId(
persistentId: string,
version: string = DatasetNonNumericVersion.LATEST_PUBLISHED,
requestedVersion?: string
requestedVersion?: string,
keepRawFields?: boolean
): Promise<Dataset | undefined> {
return getDataset
.execute(persistentId, version, includeDeaccessioned)
.execute(persistentId, version, includeDeaccessioned, keepRawFields)
.then((jsDataset) => this.fetchDatasetDetails(jsDataset, version))
.then((datasetDetails) => {
return this.fetchDownloadSizes(persistentId, version).then((downloadSizes) => {
Expand Down Expand Up @@ -223,7 +224,8 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
return this.getByPersistentId(
persistentId,
DatasetNonNumericVersion.LATEST_PUBLISHED,
(requestedVersion = version)
(requestedVersion = version),
keepRawFields
)
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/metadata-block-info/domain/models/MetadataBlockInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export interface MetadataBlockInfoDisplayFormat {

export type MetadataBlockInfoDisplayFormatFields = Record<string, MetadataFieldInfo>

export type MetadataFieldInfo = Pick<MetadataField, 'displayFormat'>
export type MetadataFieldInfo = Pick<MetadataField, 'displayFormat' | 'type'>

export const METADATA_FIELD_DISPLAY_FORMAT_PLACEHOLDER = '#VALUE'
export const METADATA_FIELD_DISPLAY_FORMAT_NAME_PLACEHOLDER = '#NAME'
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class JSMetadataBlockInfoMapper {
const fields: MetadataBlockInfoDisplayFormatFields = {}

Object.entries(jsMetadataBlockInfoFields).forEach(([key, value]) => {
fields[key] = { displayFormat: this.toDisplayFormat(value.displayFormat) }
fields[key] = { displayFormat: this.toDisplayFormat(value.displayFormat), type: value.type }

if (value.typeClass === 'compound' && value.childMetadataFields) {
this.processCompoundFields(value.childMetadataFields, fields)
Expand All @@ -38,7 +38,7 @@ export class JSMetadataBlockInfoMapper {
result: MetadataBlockInfoDisplayFormatFields
): void {
Object.entries(jsFields).forEach(([key, value]) => {
result[key] = { displayFormat: this.toDisplayFormat(value.displayFormat) }
result[key] = { displayFormat: this.toDisplayFormat(value.displayFormat), type: value.type }
})
}

Expand Down
8 changes: 7 additions & 1 deletion src/sections/dataset/DatasetProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ export function DatasetProvider({

const getDataset = useDeepCompareCallback(() => {
if (searchParams.persistentId) {
return getDatasetByPersistentId(repository, searchParams.persistentId, searchParams.version)
return getDatasetByPersistentId(
repository,
searchParams.persistentId,
searchParams.version,
undefined,
true
)
}
if (searchParams.privateUrlToken) {
return getDatasetByPrivateUrlToken(repository, searchParams.privateUrlToken)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import TurndownService from 'turndown'
import {
METADATA_FIELD_DISPLAY_FORMAT_NAME_PLACEHOLDER,
METADATA_FIELD_DISPLAY_FORMAT_PLACEHOLDER,
Expand All @@ -17,6 +18,13 @@ interface DatasetMetadataFieldValueFormattedProps {
metadataFieldValue: DatasetMetadataFieldValueModel
metadataBlockDisplayFormatInfo: MetadataBlockInfoDisplayFormat
}

const turndownService = new TurndownService()

function transformHtmlToMarkdown(source: string): string {
return turndownService.turndown(source)
}

export function DatasetMetadataFieldValueFormatted({
metadataBlockName,
metadataFieldName,
Expand All @@ -36,6 +44,12 @@ export function DatasetMetadataFieldValueFormatted({
t(`${metadataBlockName}.datasetField.${metadataFieldName}.name`)
)

if (metadataBlockDisplayFormatInfo.fields[metadataFieldName]?.type === 'TEXTBOX') {
const markdownValue = transformHtmlToMarkdown(valueFormattedWithNamesTranslated)

return <MarkdownComponent markdown={markdownValue} />
}

return <MarkdownComponent markdown={valueFormattedWithNamesTranslated} />
}

Expand Down Expand Up @@ -80,9 +94,18 @@ function joinSubFields(
metadataBlockInfo?: MetadataBlockInfoDisplayFormat
): string {
return Object.entries(metadataSubField)
.map(([subFieldName, subFieldValue]) =>
formatSubFieldValue(subFieldValue, metadataBlockInfo?.fields[subFieldName]?.displayFormat)
)
.map(([subFieldName, subFieldValue]) => {
let formattedSubFieldValue = formatSubFieldValue(
subFieldValue,
metadataBlockInfo?.fields[subFieldName]?.displayFormat
)
const subFieldType = metadataBlockInfo?.fields[subFieldName]?.type as string | undefined

if (subFieldType === 'TEXTBOX')
formattedSubFieldValue = transformHtmlToMarkdown(formattedSubFieldValue)

return formattedSubFieldValue
})
.join(' ')
}

Expand Down
5 changes: 4 additions & 1 deletion src/sections/shared/hierarchy/BreadcrumbsGenerator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export function BreadcrumbsGenerator({
<Breadcrumb.Item
key={index}
linkAs={LinkToPage}
linkProps={{ page: Route.COLLECTIONS_BASE, children: <>{item.name}</> }}>
linkProps={{
page: Route.COLLECTIONS_BASE,
children: <>{item.name}</>
}}>
{item.name}
</Breadcrumb.Item>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ export class MetadataBlockInfoMother {
return {
name: MetadataBlockName.CITATION,
fields: {
alternativePersistentId: { displayFormat: '' },
publicationDate: { displayFormat: '' },
citationDate: { displayFormat: '' },
title: { displayFormat: '' },
subject: { displayFormat: ';' },
author: { displayFormat: '' },
authorName: { displayFormat: '#VALUE' },
authorAffiliation: { displayFormat: '(#VALUE)' },
authorIdentifierScheme: { displayFormat: '- #VALUE:' },
authorIdentifier: { displayFormat: '[#VALUE](https://orcid.org/#VALUE)' },
datasetContact: { displayFormat: '#VALUE' },
datasetContactName: { displayFormat: '#VALUE' },
datasetContactAffiliation: { displayFormat: '(#VALUE)' },
datasetContactEmail: { displayFormat: '[#VALUE](mailto:#VALUE)' },
dsDescription: { displayFormat: '' },
dsDescriptionValue: { displayFormat: '#VALUE' },
producerURL: { displayFormat: '[#VALUE](#VALUE)' },
producerLogoURL: { displayFormat: '![#NAME](#VALUE)' },
dateOfCollectionStart: { displayFormat: '#NAME: #VALUE ' }
alternativePersistentId: { displayFormat: '', type: 'TEXT' },
publicationDate: { displayFormat: '', type: 'DATE' },
citationDate: { displayFormat: '', type: 'DATE' },
title: { displayFormat: '', type: 'TEXT' },
subject: { displayFormat: ';', type: 'TEXT' },
author: { displayFormat: '', type: 'NONE' },
authorName: { displayFormat: '#VALUE', type: 'TEXT' },
authorAffiliation: { displayFormat: '(#VALUE)', type: 'TEXT' },
authorIdentifierScheme: { displayFormat: '- #VALUE:', type: 'TEXT' },
authorIdentifier: { displayFormat: '[#VALUE](https://orcid.org/#VALUE)', type: 'TEXT' },
datasetContact: { displayFormat: '#VALUE', type: 'NONE' },
datasetContactName: { displayFormat: '#VALUE', type: 'TEXT' },
datasetContactAffiliation: { displayFormat: '(#VALUE)', type: 'TEXT' },
datasetContactEmail: { displayFormat: '[#VALUE](mailto:#VALUE)', type: 'EMAIL' },
dsDescription: { displayFormat: '', type: 'NONE' },
dsDescriptionValue: { displayFormat: '#VALUE', type: 'TEXTBOX' },
producerURL: { displayFormat: '[#VALUE](#VALUE)', type: 'NONE' },
producerLogoURL: { displayFormat: '![#NAME](#VALUE)', type: 'URL' },
dateOfCollectionStart: { displayFormat: '#NAME: #VALUE ', type: 'NONE' }
},
...props
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,5 +323,6 @@ describe('DatasetMetadata', () => {
)

cy.findAllByTestId('ds-metadata-block-display-format-error').should('exist')
cy.contains('Error getting metadata block display info').should('not.exist')
})
})