Skip to content

Commit

Permalink
Merge pull request #157 from IQSS/feature/125-integration-dataset-sum…
Browse files Browse the repository at this point in the history
…mary-continued

125 - Integration dataset summary continued
  • Loading branch information
kcondon authored Sep 12, 2023
2 parents dca9519 + ded688c commit 0ad3728
Show file tree
Hide file tree
Showing 23 changed files with 656 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
run: ./run-env.sh "$E2E_DATAVERSE_IMAGE_TAG"

- name: Wait for containers to be ready
run: timeout 300s sh -c 'while ! docker logs dev_dataverse_bootstrap 2>&1 | grep -q "your instance has been configured"; do sleep 2; done'
run: timeout 360s sh -c 'while ! docker logs dev_dataverse_bootstrap 2>&1 | grep -q "your instance has been configured"; do sleep 2; done'

- name: Run e2e tests
run: npm run test:e2e
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"@faker-js/faker": "7.6.0",
"@iqss/dataverse-client-javascript": "2.0.0-pr67.5dfc70a",
"@iqss/dataverse-client-javascript": "2.0.0-pr80.378cc1e",
"@iqss/dataverse-design-system": "*",
"@istanbuljs/nyc-config-typescript": "1.0.2",
"@tanstack/react-table": "8.9.2",
Expand Down
9 changes: 7 additions & 2 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ export class JSDatasetMapper {
citation,
JSDatasetMapper.toSummaryFields(jsDataset.metadataBlocks, summaryFieldsNames),
jsDataset.license,
JSDatasetMapper.toMetadataBlocks(jsDataset.metadataBlocks) // TODO Add alternativePersistentId, publicationDate, citationDate
JSDatasetMapper.toMetadataBlocks(
jsDataset.metadataBlocks,
jsDataset.alternativePersistentId,
jsDataset.publicationDate,
jsDataset.citationDate
)
).build()
}

Expand Down Expand Up @@ -143,7 +148,7 @@ export class JSDatasetMapper {
extraFields.publicationDate = publicationDate
}

if (publicationDate && citationDate !== publicationDate) {
if (citationDate && citationDate !== publicationDate) {
extraFields.citationDate = citationDate
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DatasetRepository } from '../../domain/repositories/DatasetRepository'
import { Dataset } from '../../domain/models/Dataset'
import {
getDatasetByPersistentId,
getDataset,
getDatasetCitation,
getDatasetSummaryFieldNames,
WriteError,
Expand All @@ -13,7 +13,7 @@ import { JSDatasetMapper } from '../mappers/JSDatasetMapper'

export class DatasetJSDataverseRepository implements DatasetRepository {
getByPersistentId(persistentId: string, version?: string): Promise<Dataset | undefined> {
return getDatasetByPersistentId
return getDataset
.execute(persistentId, this.versionToVersionId(version))
.then((jsDataset) =>
Promise.all([
Expand Down
5 changes: 4 additions & 1 deletion src/metadata-block-info/domain/models/MetadataBlockInfo.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
export interface MetadataBlockInfo {
name: string
fields: Record<string, MetadataFieldInfo>
fields: MetadataBlockInfoFields
}

export type MetadataBlockInfoFields = Record<string, MetadataFieldInfo>

export interface MetadataFieldInfo {
displayFormat: string
}

export const METADATA_FIELD_DISPLAY_FORMAT_PLACEHOLDER = '#VALUE'
export const METADATA_FIELD_DISPLAY_FORMAT_NAME_PLACEHOLDER = '#NAME'

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {
MetadataBlock as JSMetadataBlockInfo,
MetadataFieldInfo as JSMetadataFieldInfo
} from '@iqss/dataverse-client-javascript'
import { MetadataBlockInfo, MetadataBlockInfoFields } from '../../domain/models/MetadataBlockInfo'

export class JSMetadataBlockInfoMapper {
static toMetadataBlockInfo(jsMetadataBlockInfo: JSMetadataBlockInfo): MetadataBlockInfo {
return {
name: jsMetadataBlockInfo.name,
fields: this.toFields(jsMetadataBlockInfo.metadataFields)
}
}

static toFields(
jsMetadataBlockInfoFields: Record<string, JSMetadataFieldInfo>
): MetadataBlockInfoFields {
return Object.entries(jsMetadataBlockInfoFields).reduce(
(fields: MetadataBlockInfoFields, [key, value]) => {
fields[key] = { displayFormat: this.toDisplayFormat(value.displayFormat) }
return fields
},
{}
)
}

static toDisplayFormat(jsDisplayFormat: string): string {
const link = 'href="#VALUE"'
if (jsDisplayFormat.includes(link)) {
return '[#VALUE](#VALUE)'
}

const linkWithUrl = /<a\s+href='([^']*)\/#VALUE'[^>]*>#VALUE<\/a>/
const match = jsDisplayFormat.match(linkWithUrl)
if (match) {
return `[#VALUE](${match[1]}/#VALUE)`
}

const emailFormat = '#EMAIL'
if (jsDisplayFormat === emailFormat) {
return '[#VALUE](mailto:#VALUE)'
}

const imageFormat = '<img src="#VALUE" alt="#NAME" class="metadata-logo"/><br/>'
if (jsDisplayFormat === imageFormat) {
return '![#NAME](#VALUE)'
}

return jsDisplayFormat
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MetadataBlockInfoRepository } from '../../domain/repositories/MetadataBlockInfoRepository'
import { MetadataBlockInfo } from '../../domain/models/MetadataBlockInfo'
import {
getMetadataBlockByName,
MetadataBlock as JSMetadataBlockInfo
} from '@iqss/dataverse-client-javascript'
import { JSMetadataBlockInfoMapper } from '../mappers/JSMetadataBlockInfoMapper'

export class MetadataBlockInfoJSDataverseRepository implements MetadataBlockInfoRepository {
getByName(name: string): Promise<MetadataBlockInfo | undefined> {
return getMetadataBlockByName
.execute(name)
.then((jsMetadataBlockInfo: JSMetadataBlockInfo) =>
JSMetadataBlockInfoMapper.toMetadataBlockInfo(jsMetadataBlockInfo)
)
}
}
4 changes: 2 additions & 2 deletions src/sections/dataset/DatasetFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { useAnonymized } from './anonymized/AnonymizedContext'
import { AnonymizedProvider } from './anonymized/AnonymizedProvider'
import { FileJSDataverseRepository } from '../../files/infrastructure/FileJSDataverseRepository'
import { MetadataBlockInfoProvider } from './metadata-block-info/MetadataBlockProvider'
import { MetadataBlockInfoJSDataverseRepository } from '../../metadata-block-info/infrastructure/MetadataBlockInfoJSDataverseRepository'
import { SettingsProvider } from '../settings/SettingsProvider'
import { MetadataBlockInfoJSDataverseRepository } from '../../metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository'
import { SettingJSDataverseRepository } from '../../settings/infrastructure/SettingJSDataverseRepository'
import { SettingsProvider } from '../settings/SettingsProvider'

const datasetRepository = new DatasetJSDataverseRepository()
const fileRepository = new FileJSDataverseRepository()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function DatasetMetadataField({
metadataFieldName={metadataFieldName}
/>
<DatasetMetadataFieldValue
metadataBlockName={metadataBlockName}
metadataFieldName={metadataFieldName}
metadataFieldValue={metadataFieldValue}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
import {
ANONYMIZED_FIELD_VALUE,
DatasetMetadataFieldValue as DatasetMetadataFieldValueModel,
DatasetMetadataSubField
MetadataBlockName
} from '../../../../dataset/domain/models/Dataset'
import { MarkdownComponent } from '../../markdown/MarkdownComponent'
import { useAnonymized } from '../../anonymized/AnonymizedContext'
import { useTranslation } from 'react-i18next'
import { useMetadataBlockInfo } from '../../metadata-block-info/MetadataBlockInfoContext'
import {
METADATA_FIELD_DISPLAY_FORMAT_PLACEHOLDER,
MetadataBlockInfo
} from '../../../../metadata-block-info/domain/models/MetadataBlockInfo'
import { DatasetMetadataFieldValueFormatted } from './DatasetMetadataFieldValueFormatted'

interface DatasetMetadataFieldValueProps {
metadataBlockName: MetadataBlockName
metadataFieldName: string
metadataFieldValue: DatasetMetadataFieldValueModel
}

export function DatasetMetadataFieldValue({
metadataBlockName,
metadataFieldName,
metadataFieldValue
}: DatasetMetadataFieldValueProps) {
const { anonymizedView } = useAnonymized()
const isAnonymizedField = anonymizedView && metadataFieldValue == ANONYMIZED_FIELD_VALUE
const { metadataBlockInfo } = useMetadataBlockInfo()

if (isAnonymizedField) {
return <AnonymizedFieldValue />
}

return (
<MarkdownComponent
markdown={metadataFieldValueToString(
metadataFieldName,
metadataFieldValue,
metadataBlockInfo
)}
<DatasetMetadataFieldValueFormatted
metadataBlockName={metadataBlockName}
metadataFieldName={metadataFieldName}
metadataFieldValue={metadataFieldValue}
/>
)
}
Expand All @@ -44,65 +37,3 @@ const AnonymizedFieldValue = () => {
const { t } = useTranslation('dataset')
return <p>{t('anonymizedFieldValue')}</p>
}

export function metadataFieldValueToString(
metadataFieldName: string,
metadataFieldValue: DatasetMetadataFieldValueModel,
metadataBlockInfo?: MetadataBlockInfo
): string {
const separator = metadataBlockInfo?.fields[metadataFieldName]?.displayFormat ?? ''

if (isArrayOfObjects(metadataFieldValue)) {
return metadataFieldValue
.map((metadataSubField) => joinSubFields(metadataSubField, metadataBlockInfo))
.join(' \n \n')
}

if (Array.isArray(metadataFieldValue)) {
return metadataFieldValue.join(`${separator} `)
}

if (isAnObject(metadataFieldValue)) {
return Object.values(metadataFieldValue).join(`${separator} `)
}

return metadataFieldValue
}

export function isArrayOfObjects(variable: unknown): variable is object[] {
if (!Array.isArray(variable)) {
return false
}

return variable.every((item) => isAnObject(item))
}

function isAnObject(variable: unknown): variable is object {
return typeof variable === 'object' && variable !== null
}

function joinSubFields(
metadataSubField: DatasetMetadataSubField,
metadataBlockInfo?: MetadataBlockInfo
) {
return Object.entries(metadataSubField)
.map(([subFieldName, subFieldValue]) =>
formatSubFieldValue(subFieldValue, metadataBlockInfo?.fields[subFieldName]?.displayFormat)
)
.join(' ')
}

function formatSubFieldValue(
subFieldValue: string | undefined,
displayFormat: string | undefined
): string {
if (subFieldValue === undefined) {
return ''
}

if (displayFormat === undefined) {
return subFieldValue
}

return displayFormat.replaceAll(METADATA_FIELD_DISPLAY_FORMAT_PLACEHOLDER, subFieldValue)
}
Loading

0 comments on commit 0ad3728

Please sign in to comment.