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

fix: update keepRawFields to prevent markdown #588

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
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
3 changes: 2 additions & 1 deletion src/sections/dataset/DatasetFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function DatasetWithSearchParams() {
const privateUrlToken = searchParams.get('privateUrlToken')
const searchParamVersion = searchParams.get('version') ?? undefined
const version = searchParamVersionToDomainVersion(searchParamVersion)
const keepRawFields = true
const location = useLocation()
const state = location.state as
| { created: boolean; metadataUpdated: boolean; publishInProgress: boolean }
Expand Down Expand Up @@ -81,7 +82,7 @@ function DatasetWithSearchParams() {
return (
<DatasetProvider
repository={datasetRepository}
searchParams={{ persistentId: persistentId, version: version }}
searchParams={{ persistentId: persistentId, version: version, keepRawFields: keepRawFields }}
isPublishing={publishInProgress}>
<Dataset
collectionRepository={collectionRepository}
Expand Down
9 changes: 8 additions & 1 deletion src/sections/dataset/DatasetProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface DatasetProviderProps {
persistentId?: string
privateUrlToken?: string
version?: string
keepRawFields?: boolean
}
isPublishing?: boolean
}
Expand All @@ -25,7 +26,13 @@ export function DatasetProvider({

const getDataset = useCallback(() => {
if (searchParams.persistentId) {
return getDatasetByPersistentId(repository, searchParams.persistentId, searchParams.version)
return getDatasetByPersistentId(
repository,
searchParams.persistentId,
searchParams.version,
undefined,
searchParams.keepRawFields
ChengShi-1 marked this conversation as resolved.
Show resolved Hide resolved
)
}
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,11 @@ export function DatasetMetadataFieldValueFormatted({
t(`${metadataBlockName}.datasetField.${metadataFieldName}.name`)
)

if (metadataBlockDisplayFormatInfo.fields[metadataFieldName]?.type === 'TEXTBOX') {
const markdownValue = transformHtmlToMarkdown(valueFormattedWithNamesTranslated)
ChengShi-1 marked this conversation as resolved.
Show resolved Hide resolved
return <MarkdownComponent markdown={markdownValue} />
}

return <MarkdownComponent markdown={valueFormattedWithNamesTranslated} />
ChengShi-1 marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ function EditDatasetMetadataWithParams() {
const persistentId = searchParams.get('persistentId') ?? undefined
const searchParamVersion = searchParams.get('version') ?? undefined
const version = searchParamVersionToDomainVersion(searchParamVersion)
const keepRawFields = true

return (
<DatasetProvider
repository={datasetRepository}
searchParams={{ persistentId: persistentId, version: version }}>
searchParams={{ persistentId: persistentId, version: version, keepRawFields: keepRawFields }}>
<EditDatasetMetadata
datasetRepository={datasetRepository}
metadataBlockInfoRepository={metadataBlockInfoRepository}
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
1 change: 1 addition & 0 deletions tests/component/sections/dataset/Dataset.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ describe('Dataset', () => {
testDataset
)

cy.findByText('Dataset Title').should('exist')
cy.findByText('Dataset Title').should('exist').should('have.class', 'active')
cy.findByRole('link', { name: 'Root' }).should('exist')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('DatasetMetadata', () => {
)
cy.findByAltText(translatedAltText).should('exist')
cy.findByAltText(translatedAltText).should('have.attr', 'src', imageUrl)
cy.intercept(imageUrl).as('image')
})
}
} else {
Expand Down Expand Up @@ -323,5 +324,6 @@ describe('DatasetMetadata', () => {
)

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