Skip to content

Commit b758da1

Browse files
committed
fix: summaries version tab
1 parent e1957ab commit b758da1

File tree

12 files changed

+224
-45
lines changed

12 files changed

+224
-45
lines changed

public/locales/en/dataset.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@
283283
"added": "Added: {{count}}",
284284
"removed": "Removed: {{count}}",
285285
"replaced": "Replaced: {{count}}",
286-
"fileMetadataChanged": "File Metadata Changed: {{count}}",
286+
"fileMetadataChanged": "Metadata Changed: {{count}}",
287287
"variableMetadataChanged": "Variable Metadata Changed: {{count}}"
288288
},
289289
"termsAccessChanged": "Changed"

public/locales/en/file.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"summary": "Summary",
1313
"contributors": "Contributors",
1414
"noChange": "No changes associated with this version.",
15+
"noVersions": "File not included in this version.",
1516
"file": "file",
1617
"fileChanged": "[File {{name}}]",
1718
"access": "File Access",

src/files/domain/models/FileVersionSummaryInfo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface FileVersionSummaryInfo {
1212
}
1313

1414
export type FileDifferenceSummary = {
15+
datafileId?: number
1516
file?: FileChangeType
1617
fileAccess?: 'Restricted' | 'Unrestricted'
1718
fileMetadata?: FileMetadataChange[]

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

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -111,36 +111,34 @@ export function DatasetVersions({
111111
</thead>
112112
<tbody>
113113
{datasetVersionSummaries?.map((dataset, index) => {
114-
const previousVersion =
115-
index < datasetVersionSummaries.length - 1
116-
? datasetVersionSummaries[index + 1]
117-
: null
114+
// Helper function to check if a version is deaccessioned
115+
const isVersionDeaccessioned = (version: DatasetVersionSummaryInfo) =>
116+
typeof version.summary === 'object' &&
117+
version.summary !== null &&
118+
'deaccessioned' in version.summary
118119

119-
const isPreviousVersionDeaccessioned =
120-
previousVersion &&
121-
typeof previousVersion.summary === 'object' &&
122-
previousVersion.summary !== null &&
123-
'deaccessioned' in previousVersion.summary
120+
// Find the last non-deaccessioned previous version
121+
const findLastNonDeaccessionedPreviousVersion = () => {
122+
for (let i = index + 1; i < datasetVersionSummaries.length; i++) {
123+
const version = datasetVersionSummaries[i]
124+
if (!isVersionDeaccessioned(version)) {
125+
return version
126+
}
127+
}
128+
return null
129+
}
124130

131+
const previousVersion = findLastNonDeaccessionedPreviousVersion()
125132
const isCurrentVersion = dataset.versionNumber === currentVersionNumber
126-
127-
const isCurrentVersionDeaccessioned =
128-
typeof dataset.summary === 'object' &&
129-
dataset.summary !== null &&
130-
'deaccessioned' in dataset.summary
133+
const isCurrentVersionDeaccessioned = isVersionDeaccessioned(dataset)
131134

132135
const isLinkable =
133136
(dataset.versionNumber !== DatasetVersionState.DRAFT &&
134137
!isCurrentVersionDeaccessioned) ||
135138
((dataset.versionNumber === DatasetVersionState.DRAFT ||
136139
isCurrentVersionDeaccessioned) &&
137140
canUpdateDataset)
138-
139-
const showViewDetails =
140-
previousVersion &&
141-
typeof dataset.summary !== 'string' &&
142-
!isCurrentVersionDeaccessioned &&
143-
!isPreviousVersionDeaccessioned
141+
const showViewDetails = !isCurrentVersionDeaccessioned && previousVersion
144142

145143
return (
146144
<tr key={dataset.id}>
@@ -173,7 +171,7 @@ export function DatasetVersions({
173171
<td>
174172
<p style={{ display: 'flex', flexWrap: 'wrap', margin: 0, textAlign: 'left' }}>
175173
<SummaryDescription summary={dataset.summary} />
176-
{showViewDetails && (
174+
{showViewDetails && previousVersion && (
177175
<DatasetViewDetailButton
178176
datasetRepository={datasetRepository}
179177
oldVersionNumber={previousVersion.versionNumber}
@@ -248,13 +246,18 @@ export const SummaryDescription = ({
248246
}: {
249247
summary?: DatasetVersionSummary | DatasetVersionSummaryStringValues
250248
}) => {
249+
const { t } = useTranslation('dataset')
251250
const summaryText: Record<string, string> = useDatasetVersionSummaryDescription(summary)
252251

253252
return (
254253
<>
255254
{Object.entries(summaryText).map(([key, value]) =>
256255
typeof summary === 'string' ? (
257256
<span key={key}>{value}</span>
257+
) : key === t('versions.deaccessionedReason') ? (
258+
<span key={key}>
259+
{key}: {value}
260+
</span>
258261
) : (
259262
<span key={key}>
260263
<strong>{key}</strong>: {key == 'Files' ? <strong>{value}</strong> : value};&nbsp;

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const DatasetVersionsDifferenceTable = ({
1212
differences
1313
}: datasetVersionsDifferenceTableProps) => {
1414
const { t } = useTranslation('dataset')
15+
const { t: tFile } = useTranslation('file')
1516
const {
1617
oldVersion,
1718
newVersion,
@@ -129,14 +130,26 @@ export const DatasetVersionsDifferenceTable = ({
129130
<td>
130131
{file.changed.map((change) => (
131132
<div key={change.fieldName}>
132-
{change.fieldName}: {change.oldValue || ''}
133+
{change.fieldName === 'isRestricted'
134+
? `${t('versions.access')}: ${
135+
change.oldValue === 'true'
136+
? tFile('fileAccess.restricted.name')
137+
: tFile('fileAccess.public.name')
138+
}`
139+
: `${change.fieldName}: ${change.oldValue || ''}`}
133140
</div>
134141
))}
135142
</td>
136143
<td>
137144
{file.changed.map((change) => (
138145
<div key={change.fieldName}>
139-
{change.fieldName}: {change.newValue || ''}
146+
{change.fieldName === 'isRestricted'
147+
? `${t('versions.access')}: ${
148+
change.newValue === 'true'
149+
? tFile('fileAccess.restricted.name')
150+
: tFile('fileAccess.public.name')
151+
}`
152+
: `${change.fieldName}: ${change.newValue || ''}`}
140153
</div>
141154
))}
142155
</td>

src/sections/file/file-version/FileVersions.tsx

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,23 @@ export function FileVersions({
7575
<tbody>
7676
{fileVersionSummaries?.map((fileVersion) => {
7777
const isCurrentVersion = fileVersion.datasetVersion === displayVersion
78+
// Helper functions for readability
79+
const hasDataFile = fileVersion.datafileId
80+
const hasSummaryChanges =
81+
fileVersion.fileDifferenceSummary !== undefined &&
82+
Object.entries(fileVersion.fileDifferenceSummary).length > 0
83+
const isReleased = fileVersion.versionState === DatasetVersionState.RELEASED
84+
const isDeaccessionedWithAccess =
85+
fileVersion.versionState === DatasetVersionState.DEACCESSIONED && canEditOwnerDataset
86+
const isDraftWithAccess =
87+
fileVersion.versionState === DatasetVersionState.DRAFT && canEditOwnerDataset
88+
7889
const isLinkable =
79-
fileVersion.versionState === DatasetVersionState.RELEASED ||
80-
(fileVersion.versionState === DatasetVersionState.DEACCESSIONED &&
81-
canEditOwnerDataset) ||
82-
(fileVersion.versionState === DatasetVersionState.DRAFT && canEditOwnerDataset)
90+
hasDataFile &&
91+
hasSummaryChanges &&
92+
(isReleased || isDeaccessionedWithAccess || isDraftWithAccess)
93+
94+
console.log('fileVersion', fileVersion, isLinkable)
8395

8496
return (
8597
<tr key={fileVersion.datasetVersion}>
@@ -98,7 +110,10 @@ export function FileVersions({
98110
</td>
99111

100112
<td style={{ textAlign: 'left' }}>
101-
<SummaryDescription summary={fileVersion.fileDifferenceSummary} />
113+
<SummaryDescription
114+
summary={fileVersion.fileDifferenceSummary}
115+
isNoVersions={fileVersion.datafileId === undefined}
116+
/>
102117
</td>
103118
<td>{fileVersion.contributors}</td>
104119
{fileVersion.publishedDate &&
@@ -116,18 +131,32 @@ export function FileVersions({
116131
)
117132
}
118133

119-
export const SummaryDescription = ({ summary }: { summary?: FileDifferenceSummary }) => {
134+
export const SummaryDescription = ({
135+
summary,
136+
isNoVersions
137+
}: {
138+
summary?: FileDifferenceSummary
139+
isNoVersions?: boolean
140+
}) => {
120141
const summaryText: Record<string, string> | string = useFileVersionSummaryDescription(summary)
121142
const { t } = useTranslation('file')
122143

123144
if (typeof summaryText === 'string') {
124145
return <span style={{ fontStyle: 'italic' }}>{summaryText}</span>
125146
}
126147

148+
if (isNoVersions) {
149+
return <span style={{ fontStyle: 'italic' }}>{t('fileVersion.noVersions')}</span>
150+
}
151+
152+
if (!summary || !Object.entries(summary).length) {
153+
return <span style={{ fontStyle: 'italic' }}>{t('fileVersion.noChange')}</span>
154+
}
155+
127156
if (summaryText[t('fileVersion.deaccessionedReason')]) {
128157
return (
129158
<span>
130-
<strong>Deaccessioned Reason</strong>: {summaryText[t('fileVersion.deaccessionedReason')]}
159+
{t('fileVersion.deaccessionedReason')}: {summaryText[t('fileVersion.deaccessionedReason')]}
131160
</span>
132161
)
133162
}

src/sections/file/file-version/useFileVersionSummaryDescription.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ export const useFileVersionSummaryDescription = (
1010
): Record<string, string> | string => {
1111
const { t } = useTranslation('file')
1212

13-
if (!summary || !Object.entries(summary).length) return t('fileVersion.noChange')
14-
1513
const description: Record<string, string> = {}
1614

17-
Object.entries(summary).forEach(([key, value]) => {
15+
Object.entries(summary ?? {}).forEach(([key, value]) => {
1816
switch (key) {
1917
case 'file': {
2018
if ((value as FileChangeType) && typeof value === 'string') {

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const versionSummaryInfoDraft: DatasetVersionSummaryInfo[] = [
3535
publishedOn: ''
3636
}
3737
]
38+
const versionSummaryInfoDeaccessioned = DatasetVersionsSummariesMother.createDeaccessioned()
39+
3840
const datasetVersionDiff: DatasetVersionDiff = DatasetVersionDiffMother.create()
3941

4042
describe('DatasetVersions', () => {
@@ -54,6 +56,52 @@ describe('DatasetVersions', () => {
5456
cy.findByText('DRAFT').should('exist').and('have.attr', 'href')
5557
})
5658

59+
it('should not show view detail buttons if the version is deaccessioned', () => {
60+
cy.customMount(
61+
<DatasetVersions
62+
datasetId={'datasetId'}
63+
datasetRepository={datasetsRepository}
64+
currentVersionNumber={'1.0'}
65+
canUpdateDataset={true}
66+
isInView
67+
/>
68+
)
69+
datasetsRepository.getDatasetVersionsSummaries = cy
70+
.stub()
71+
.resolves(versionSummaryInfoDeaccessioned)
72+
73+
cy.findByTestId('dataset-versions-table').should('exist')
74+
cy.get('tr').eq(1).find('td').eq(2).findByText('View Details').should('not.exist')
75+
})
76+
77+
it('should show view detail buttons if previous version is deaccessioned', () => {
78+
cy.customMount(
79+
<DatasetVersions
80+
datasetId={'datasetId'}
81+
datasetRepository={datasetsRepository}
82+
currentVersionNumber={'1.0'}
83+
canUpdateDataset={true}
84+
isInView
85+
/>
86+
)
87+
const versionSummaryInfoNoPreviousVersion = [
88+
{
89+
id: 12,
90+
versionNumber: '5.0',
91+
summary: {},
92+
contributors: 'Test ',
93+
publishedOn: ''
94+
},
95+
...versionSummaryInfoDeaccessioned
96+
]
97+
datasetsRepository.getDatasetVersionsSummaries = cy
98+
.stub()
99+
.resolves(versionSummaryInfoNoPreviousVersion)
100+
101+
cy.findByTestId('dataset-versions-table').should('exist')
102+
cy.get('tr').eq(1).find('td').eq(2).findByText('View Details').should('exist')
103+
})
104+
57105
beforeEach(() => {
58106
cy.customMount(
59107
<DatasetVersions

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,4 +370,38 @@ describe('DatasetVersions', () => {
370370
cy.findByTestId(`file-replaced-row-${file.newFile.fileId}`).should('exist')
371371
})
372372
})
373+
374+
it('should show Access Granted for restricted files', () => {
375+
cy.customMount(
376+
<VersionDetailModal
377+
show={true}
378+
handleClose={() => {}}
379+
isLoading={false}
380+
errorHandling={''}
381+
datasetVersionDifferences={{
382+
...datasetVersionDiff,
383+
fileChanges: [
384+
{
385+
fileName: 'blob (2)',
386+
md5: '53d3d10e00812f7c55e0c9c3935f3769',
387+
fileId: 40,
388+
changed: [
389+
{
390+
fieldName: 'isRestricted',
391+
oldValue: 'false',
392+
newValue: 'true'
393+
}
394+
]
395+
}
396+
]
397+
}}
398+
/>
399+
)
400+
401+
cy.findByTestId(`file-changed-row-40`).find('td').eq(1).should('have.text', 'Access: Public')
402+
cy.findByTestId(`file-changed-row-40`)
403+
.find('td')
404+
.eq(2)
405+
.should('have.text', 'Access: Restricted')
406+
})
373407
})

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ describe('useDatasetVersionSummaryDescription', () => {
2929

3030
expect(result.current)
3131
.haveOwnProperty('Files')
32-
.equal(
33-
'Added: 2; Removed: 1; Replaced: 1; File Metadata Changed: 3; Variable Metadata Changed: 1'
34-
)
32+
.equal('Added: 2; Removed: 1; Replaced: 1; Metadata Changed: 3; Variable Metadata Changed: 1')
3533
expect(result.current)
3634
.haveOwnProperty('Citation Metadata')
3735
.equal('Description (Changed); Title (1 Added)')

0 commit comments

Comments
 (0)