Skip to content

Commit ce15802

Browse files
committed
feat: add missing feature and hide version note
1 parent ba207f2 commit ce15802

10 files changed

Lines changed: 197 additions & 28 deletions

File tree

public/locales/en/dataset.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,16 @@
232232
"files": "Files",
233233
"citationMetadata": "Citation Metadata",
234234
"additionalCitationMetadata": "Additional Citation Metadata",
235+
"termsAccess": "Terms of Use and Access",
235236
"fileID": "File ID",
236237
"MD5": "MD5",
237238
"name": "Name",
238239
"type": "Type",
239240
"description": "Description",
240241
"access": "Access",
241242
"needTwoVersions": "Please select two versions to view the differences.",
242-
"viewDetails": "View Details"
243+
"viewDetails": "View Details",
244+
"replace": "File Replace"
243245
},
244246
"getDatasetVersionDiffError": "Error Fetching Dataset Version Differences",
245247
"datasetVersionSummary": {
@@ -263,6 +265,6 @@
263265
"fileMetadataChanged": "File Metadata Changed: {{count}}",
264266
"variableMetadataChanged": "Variable Metadata Changed: {{count}}"
265267
},
266-
"termsAccessChanged": "Terms Access: Changed"
268+
"termsAccessChanged": "Changed"
267269
}
268270
}

src/dataset/domain/models/DatasetVersionDiff.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export interface DatasetVersionDiff {
66
filesRemoved?: FileSummary[]
77
fileChanges?: FileDiff[]
88
filesReplaced?: FileReplacement[]
9-
termsOfAccess?: FieldDiff[]
9+
termsOfAccess?: {
10+
changed: FieldDiff[]
11+
}
1012
}
1113

1214
export interface FileSummary {
@@ -33,6 +35,7 @@ export interface MetadataBlockDiff {
3335
export interface FileDiff {
3436
fileName: string
3537
md5: string
38+
MD5?: string
3639
fileId: number
3740
changed: FieldDiff[]
3841
}

src/sections/dataset/dataset-versions/DatasetVersions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function DatasetVersions({ datasetRepository, datasetId }: DatasetVersion
8383
)}
8484
<th>{t('versions.datasetVersions')}</th>
8585
<th>{t('versions.summary')}</th>
86-
<th>{t('versions.versionNote')}</th>
86+
{/* <th>{t('versions.versionNote')}</th> */}
8787
<th>{t('versions.contributors')}</th>
8888
<th>{t('versions.publishedOn')}</th>
8989
</tr>
@@ -126,7 +126,7 @@ export function DatasetVersions({ datasetRepository, datasetId }: DatasetVersion
126126
)}
127127
</p>
128128
</td>
129-
<td>{/* TODO: version note API is missing */}</td>
129+
{/* <td>{ TODO: version note API is missing }</td> */}
130130
<td>{dataset.contributors}</td>
131131
<td>{dataset.publishedOn}</td>
132132
</tr>

src/sections/dataset/dataset-versions/useDatasetVersionSummaryDescription.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ export const useDatasetVersionSummaryDescription = (
106106
}
107107

108108
case 'termsAccessChanged':
109-
if (value) description[key] = t('datasetVersionSummary.termsAccessChanged')
109+
if (value)
110+
description['Terms of Use/Access'] = t('datasetVersionSummary.termsAccessChanged')
110111
break
111112
}
112113
})

src/sections/dataset/dataset-versions/view-difference/DatasetVersionsDifferenceTable.tsx

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,24 @@ import { Table } from '@iqss/dataverse-design-system'
44
import { DateHelper } from '@/shared/helpers/DateHelper'
55
import styles from './DatasetVersionsDifferenceTable.module.scss'
66

7-
interface atasetVersionsDifferenceTableProps {
7+
interface datasetVersionsDifferenceTableProps {
88
differences: DatasetVersionDiff
99
}
1010

1111
export const DatasetVersionsDifferenceTable = ({
1212
differences
13-
}: atasetVersionsDifferenceTableProps) => {
13+
}: datasetVersionsDifferenceTableProps) => {
1414
const { t } = useTranslation('dataset')
15-
const { oldVersion, newVersion, metadataChanges, filesAdded, filesRemoved } = differences
15+
const {
16+
oldVersion,
17+
newVersion,
18+
metadataChanges,
19+
filesAdded,
20+
filesRemoved,
21+
fileChanges,
22+
termsOfAccess,
23+
filesReplaced
24+
} = differences
1625

1726
const citationMetadata = metadataChanges?.find((m) => m.blockName === 'Citation Metadata')
1827

@@ -57,7 +66,7 @@ export const DatasetVersionsDifferenceTable = ({
5766
</Table>
5867
)}
5968

60-
{(filesAdded || filesRemoved) && (
69+
{(filesAdded || filesRemoved || fileChanges || filesRemoved) && (
6170
<Table bordered>
6271
<thead>
6372
<tr>
@@ -103,6 +112,74 @@ export const DatasetVersionsDifferenceTable = ({
103112
</td>
104113
</tr>
105114
))}
115+
{fileChanges &&
116+
fileChanges.map((file) => (
117+
<tr key={`changed-${file.fileId}`}>
118+
<td>
119+
{t('versions.fileID')} {file.fileId}
120+
<br />
121+
{t('versions.MD5')} {file.MD5}
122+
</td>
123+
<td>
124+
{file.changed.map((change) => (
125+
<div key={change.fieldName}>
126+
{change.fieldName}: {change.oldValue || ''}
127+
</div>
128+
))}
129+
</td>
130+
<td>
131+
{file.changed.map((change) => (
132+
<div key={change.fieldName}>
133+
{change.fieldName}: {change.newValue || ''}
134+
</div>
135+
))}
136+
</td>
137+
</tr>
138+
))}
139+
</tbody>
140+
</Table>
141+
)}
142+
143+
{filesReplaced && (
144+
<Table bordered>
145+
<tbody>
146+
{filesReplaced.map(({ oldFile, newFile }) => (
147+
<tr key={`replaced-${oldFile.fileId}-${newFile.fileId}`}>
148+
<td>{t('versions.replace')}</td>
149+
<td>
150+
{t('versions.name')}: {oldFile.fileName}
151+
<br />
152+
{t('versions.type')}: {oldFile.type || ''}
153+
<br />
154+
{t('versions.description')}: {oldFile.description || ''}
155+
<br />
156+
</td>
157+
<td>
158+
{t('versions.fileID')} {newFile.fileId}
159+
<br />
160+
{t('versions.MD5')} {newFile.MD5} <br />
161+
{t('versions.name')}: {newFile.fileName}
162+
</td>
163+
</tr>
164+
))}
165+
</tbody>
166+
</Table>
167+
)}
168+
{termsOfAccess && (
169+
<Table bordered>
170+
<thead>
171+
<tr>
172+
<th>{t('versions.termsAccess')}</th>
173+
</tr>
174+
</thead>
175+
<tbody>
176+
{termsOfAccess.changed.map((term) => (
177+
<tr key={term.fieldName}>
178+
<td>{term.fieldName}</td>
179+
<td>{term.oldValue || ''}</td>
180+
<td>{term.newValue || ''}</td>
181+
</tr>
182+
))}
106183
</tbody>
107184
</Table>
108185
)}

tests/component/dataset/domain/models/DatasetVersionDiffMother.ts

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class DatasetVersionDiffMother {
6161
],
6262
filesRemoved: [
6363
{
64-
fileName: 'file1',
64+
fileName: 'file10',
6565
MD5: faker.datatype.uuid(),
6666
type: '',
6767
fileId: faker.datatype.number(),
@@ -71,7 +71,56 @@ export class DatasetVersionDiffMother {
7171
tags: [],
7272
categories: []
7373
}
74-
]
74+
],
75+
filesChanges: [
76+
{
77+
fileName: 'file4',
78+
md5: faker.datatype.uuid(),
79+
fileId: faker.datatype.number(),
80+
changed: [
81+
{
82+
fieldName: 'isRestricted',
83+
oldValue: 'old title',
84+
newValue: 'new title'
85+
}
86+
]
87+
}
88+
],
89+
fileReplaced: [
90+
{
91+
oldFile: {
92+
fileName: 'file5',
93+
MD5: faker.datatype.uuid(),
94+
type: '',
95+
fileId: faker.datatype.number(),
96+
description: 'file5 description',
97+
isRestricted: faker.datatype.boolean(),
98+
filePath: '',
99+
tags: [],
100+
categories: []
101+
},
102+
newFile: {
103+
fileName: 'file6',
104+
MD5: faker.datatype.uuid(),
105+
type: '',
106+
fileId: faker.datatype.number(),
107+
description: 'file6 description',
108+
isRestricted: faker.datatype.boolean(),
109+
filePath: '',
110+
tags: [],
111+
categories: []
112+
}
113+
}
114+
],
115+
termsOfAccess: {
116+
changed: [
117+
{
118+
fieldName: 'Terms of Access for Restricted Files',
119+
oldValue: 'old value',
120+
newValue: 'new value'
121+
}
122+
]
123+
}
75124
}
76125
return datasetVersionDiff
77126
}

tests/component/sections/dataset/Dataset.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ describe('Dataset', () => {
473473
versionsTab.should('exist').click()
474474
cy.findByText('Dataset Version').should('exist')
475475
cy.findByText('Summary').should('exist')
476-
cy.findByText('Version Note').should('exist')
476+
// cy.findByText('Version Note').should('exist')
477477
cy.findByText('Contributors').should('exist')
478478
cy.findByText('Published On').should('exist')
479479
})

tests/component/sections/dataset/dataset-versions/DatasetVersions.spec.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('DatasetVersions', () => {
4343

4444
cy.contains('th', 'Dataset Version').should('exist')
4545
cy.contains('th', 'Summary').should('exist')
46-
cy.contains('th', 'Version Note').should('exist')
46+
// cy.contains('th', 'Version Note').should('exist')
4747
cy.contains('th', 'Contributors').should('exist')
4848
cy.contains('th', 'Published On').should('exist')
4949
cy.findByRole('button', { name: 'View Differences' }).should('not.exist')
@@ -59,12 +59,12 @@ describe('DatasetVersions', () => {
5959
datasetsRepository.getVersionDiff = cy.stub().resolves(datasetVersionDiff)
6060
})
6161

62-
it.only('should render the dataset versions table with view differences button and checkbox', () => {
62+
it('should render the dataset versions table with view differences button and checkbox', () => {
6363
cy.findByTestId('dataset-versions-table').should('exist')
6464

6565
cy.contains('th', 'Dataset Version').should('exist')
6666
cy.contains('th', 'Summary').should('exist')
67-
cy.contains('th', 'Version Note').should('exist')
67+
// cy.contains('th', 'Version Note').should('exist')
6868
cy.contains('th', 'Contributors').should('exist')
6969
cy.contains('th', 'Published On').should('exist')
7070
cy.findAllByTestId('select-checkbox').first().should('exist').check().should('be.checked')
@@ -98,7 +98,7 @@ describe('DatasetVersions', () => {
9898
cy.findByTestId('dataset-versions-table').should('exist')
9999
cy.contains('th', 'Dataset Version').should('exist')
100100
cy.contains('th', 'Summary').should('exist')
101-
cy.contains('th', 'Version Note').should('exist')
101+
// cy.contains('th', 'Version Note').should('exist')
102102
cy.contains('th', 'Contributors').should('exist')
103103
cy.contains('th', 'Published On').should('exist')
104104
cy.findAllByTestId('select-checkbox').first().should('exist').check().should('be.checked')

tests/component/sections/dataset/dataset-versions/DatasetVersionsViewDifferencesModal.spec.tsx

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const datasetVersionDiff: DatasetVersionDiff | undefined = {
5656
fileName: 'blob (5)',
5757
MD5: '53d3d10e00812f7c55e0c9c3935f3769',
5858
type: '',
59-
fileId: 40,
59+
fileId: 41,
6060
description: '',
6161
isRestricted: true,
6262
filePath: '',
@@ -98,7 +98,30 @@ const datasetVersionDiff: DatasetVersionDiff | undefined = {
9898
tags: [],
9999
categories: []
100100
}
101-
]
101+
],
102+
fileChanges: [
103+
{
104+
fileName: 'blob (2)',
105+
md5: '53d3d10e00812f7c55e0c9c3935f3769',
106+
fileId: 40,
107+
changed: [
108+
{
109+
fieldName: 'Restricted',
110+
oldValue: 'false',
111+
newValue: 'true'
112+
}
113+
]
114+
}
115+
],
116+
termsOfAccess: {
117+
changed: [
118+
{
119+
fieldName: 'Terms of Access',
120+
oldValue: 'Public',
121+
newValue: 'Restricted'
122+
}
123+
]
124+
}
102125
}
103126

104127
describe('DatasetVersions', () => {
@@ -116,12 +139,25 @@ describe('DatasetVersions', () => {
116139

117140
cy.get('table').should('exist')
118141
cy.get('table').find('tbody').first().find('tr').should('have.length', 1) // for versions info
119-
const numOfTbody = (datasetVersionDiff?.metadataChanges?.length ?? 0) + 2 // add extra 2 for Versions info(header) and Files tables
142+
const numOfTermsOfAccess = datasetVersionDiff?.termsOfAccess ? 1 : 0
143+
const numOfTbody = (datasetVersionDiff?.metadataChanges?.length ?? 0) + numOfTermsOfAccess + 2 // add extra 2 for Versions info(header) and Files tables
120144
cy.get('table').find('tbody').should('have.length', numOfTbody)
145+
121146
const numOfFilesTr =
122-
(datasetVersionDiff?.filesRemoved?.length ?? 0) +
123-
(datasetVersionDiff?.filesAdded?.length ?? 0)
124-
cy.get('table').find('tbody').last().find('tr').should('have.length', numOfFilesTr)
147+
(datasetVersionDiff.filesRemoved?.length ?? 0) +
148+
(datasetVersionDiff.filesAdded?.length ?? 0) +
149+
(datasetVersionDiff.fileChanges?.length ?? 0) +
150+
(datasetVersionDiff.filesReplaced?.length ?? 0)
151+
152+
cy.get('table').find('tbody').eq(2).find('tr').should('have.length', numOfFilesTr)
153+
154+
if (datasetVersionDiff.termsOfAccess) {
155+
cy.get('table')
156+
.find('tbody')
157+
.last()
158+
.find('tr')
159+
.should('have.length', datasetVersionDiff.termsOfAccess?.changed.length)
160+
}
125161
})
126162

127163
it('should render a correct file info', () => {
@@ -142,7 +178,7 @@ describe('DatasetVersions', () => {
142178
const text = `File ID ${FileId}MD5 ${MD5}`
143179
cy.get('table')
144180
.find('tbody')
145-
.last()
181+
.eq(2)
146182
.find('tr')
147183
.first()
148184
.find('td')
@@ -160,14 +196,15 @@ describe('DatasetVersions', () => {
160196
datasetVersionDifferences={{
161197
...datasetVersionDiff,
162198
filesRemoved: [],
163-
filesAdded: []
199+
filesAdded: [],
200+
fileChanges: [],
201+
filesReplaced: []
164202
}}
165203
/>
166204
)
167205

168206
cy.get('table').should('exist')
169-
cy.get('table').find('tbody').should('have.length', 3)
170-
cy.get('table').find('tbody').last().find('tr').should('have.length', 0)
207+
cy.get('table').find('tbody').eq(2).find('tr').should('have.length', 0)
171208
})
172209

173210
it('should render a modal with the differences between two versions', () => {

0 commit comments

Comments
 (0)