Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ This changelog follows the principles of [Keep a Changelog](https://keepachangel

- Add word-break to items text to prevent layout issues when long descriptions without spaces are entered. (#839)
- Show toast notification when API token is copied to clipboard.
- Dataset versions: (1) file changes should be `Access: Restricted` instead of `isResticted: true/false`; (2) logic of View Detail button. (#879)
- File versions: (1) logic of linking to a file version; (2)If file not included, show text information "File not included in this version.". (#879)

### Removed

Expand Down
5 changes: 3 additions & 2 deletions public/locales/en/dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@
"type": "Type",
"description": "Description",
"access": "Access",
"needTwoVersions": "Please select two versions to view the differences.",
"viewDetails": "View Details",
"fileReplaced": "File Replaced",
"termsOfUseandAccess": "Terms of Use/Access",
Expand All @@ -270,6 +269,8 @@
"firstDraft": "This is a draft version.",
"versionDeaccessioned": "Deaccessioned Reason: The research article has been retracted.",
"previousVersionDeaccessioned": "Due to the previous version being deaccessioned, there are no difference notes available for this published version.",
"thisIsADraftVersion": "This is a draft version.",
"noVersionDifferences": "There are no differences between version {{oldVersion}} and version {{newVersion}}.",
"citationMetadata": {
"changed": "Changed",
"added": "{{count}} Added"
Expand All @@ -283,7 +284,7 @@
"added": "Added: {{count}}",
"removed": "Removed: {{count}}",
"replaced": "Replaced: {{count}}",
"fileMetadataChanged": "File Metadata Changed: {{count}}",
"fileMetadataChanged": "Metadata Changed: {{count}}",
"variableMetadataChanged": "Variable Metadata Changed: {{count}}"
},
"termsAccessChanged": "Changed"
Expand Down
2 changes: 1 addition & 1 deletion public/locales/en/file.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"summary": "Summary",
"contributors": "Contributors",
"noChange": "No changes associated with this version.",
"noVersions": "File not included in this version.",
"file": "file",
"fileChanged": "[File {{name}}]",
"access": "File Access",
Expand All @@ -28,7 +29,6 @@
},
"error": "Error on loading file versions"
},
"fileNotChange": "No changes associated with this version",
"subtext": "This file is part of \"{{datasetTitle}}\".",
"datasetCitationTitle": "Dataset Citation",
"fileCitationTitle": "File Citation",
Expand Down
4 changes: 2 additions & 2 deletions src/files/domain/models/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FileAccess } from './FileAccess'
import { FilePermissions } from './FilePermissions'
import { FileIngest } from './FileIngest'
import { UpwardHierarchyNode } from '../../../shared/hierarchy/domain/models/UpwardHierarchyNode'
import { FileVersionSummaryInfo } from './FileVersionSummaryInfo'
import { FileVersionSummarySubset } from './FileVersionSummaryInfo'

export interface File {
id: number
Expand All @@ -17,5 +17,5 @@ export interface File {
permissions: FilePermissions
metadata: FileMetadata
ingest: FileIngest
fileVersionSummaries?: FileVersionSummaryInfo[]
fileVersionSummaries?: FileVersionSummarySubset
}
1 change: 1 addition & 0 deletions src/files/domain/models/FileVersionSummaryInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface FileVersionSummaryInfo {
}

export type FileDifferenceSummary = {
datafileId?: number
file?: FileChangeType
fileAccess?: 'Restricted' | 'Unrestricted'
fileMetadata?: FileMetadataChange[]
Expand Down
66 changes: 35 additions & 31 deletions src/sections/dataset/dataset-versions/DatasetVersions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ interface DatasetVersionsProps {
isCurrentVersionDeaccessioned?: boolean
}

const isVersionDeaccessioned = (version: DatasetVersionSummaryInfo) =>
typeof version.summary === 'object' &&
version.summary !== null &&
'deaccessioned' in version.summary

export function DatasetVersions({
datasetRepository,
datasetId,
Expand Down Expand Up @@ -61,12 +66,7 @@ export function DatasetVersions({

const selectableVersions =
datasetVersionSummaries &&
datasetVersionSummaries.filter((version) => {
const summary = version.summary
const isDeaccessioned =
typeof summary === 'object' && summary !== null && 'deaccessioned' in summary
return !isDeaccessioned
})
datasetVersionSummaries.filter((version) => !isVersionDeaccessioned(version))
const isCheckBoxValid = (selectableVersions?.length ?? 0) > 2

useEffect(() => {
Expand Down Expand Up @@ -111,36 +111,27 @@ export function DatasetVersions({
</thead>
<tbody>
{datasetVersionSummaries?.map((dataset, index) => {
const previousVersion =
index < datasetVersionSummaries.length - 1
? datasetVersionSummaries[index + 1]
: null

const isPreviousVersionDeaccessioned =
previousVersion &&
typeof previousVersion.summary === 'object' &&
previousVersion.summary !== null &&
'deaccessioned' in previousVersion.summary
const findLastNonDeaccessionedPreviousVersion = () => {
for (let i = index + 1; i < datasetVersionSummaries.length; i++) {
const version = datasetVersionSummaries[i]
if (!isVersionDeaccessioned(version)) {
return version
}
}
return null
}

const previousVersion = findLastNonDeaccessionedPreviousVersion()
const isCurrentVersion = dataset.versionNumber === currentVersionNumber

const isCurrentVersionDeaccessioned =
typeof dataset.summary === 'object' &&
dataset.summary !== null &&
'deaccessioned' in dataset.summary
const isCurrentVersionDeaccessioned = isVersionDeaccessioned(dataset)

const isLinkable =
(dataset.versionNumber !== DatasetVersionState.DRAFT &&
!isCurrentVersionDeaccessioned) ||
((dataset.versionNumber === DatasetVersionState.DRAFT ||
isCurrentVersionDeaccessioned) &&
canUpdateDataset)

const showViewDetails =
previousVersion &&
typeof dataset.summary !== 'string' &&
!isCurrentVersionDeaccessioned &&
!isPreviousVersionDeaccessioned
const showViewDetails = !isCurrentVersionDeaccessioned && previousVersion

return (
<tr key={dataset.id}>
Expand Down Expand Up @@ -172,7 +163,10 @@ export function DatasetVersions({
</td>
<td>
<p style={{ display: 'flex', flexWrap: 'wrap', margin: 0, textAlign: 'left' }}>
<SummaryDescription summary={dataset.summary} />
<SummaryDescription
summary={dataset.summary}
versionNumber={dataset.versionNumber}
/>
{showViewDetails && (
<DatasetViewDetailButton
datasetRepository={datasetRepository}
Expand Down Expand Up @@ -244,20 +238,30 @@ export const DatasetVersionsLoadingSkeleton = () => {
}

export const SummaryDescription = ({
summary
summary,
versionNumber
}: {
summary?: DatasetVersionSummary | DatasetVersionSummaryStringValues
versionNumber?: string
}) => {
const summaryText: Record<string, string> = useDatasetVersionSummaryDescription(summary)
const { t } = useTranslation('dataset')
const summaryText: Record<string, string> = useDatasetVersionSummaryDescription(
summary,
versionNumber
)

return (
<>
{Object.entries(summaryText).map(([key, value]) =>
typeof summary === 'string' ? (
<span key={key}>{value}</span>
) : key === t('versions.deaccessionedReason') ? (
<span key={key}>
{key}: {value}
</span>
) : (
<span key={key}>
<strong>{key}</strong>: {key == 'Files' ? <strong>{value}</strong> : value};&nbsp;
<strong>{key}</strong>: {key === 'Files' ? <strong>{value}</strong> : value};&nbsp;
</span>
)
)}
Expand Down
11 changes: 11 additions & 0 deletions src/sections/dataset/dataset-versions/DatasetViewDetailButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ export function DatasetViewDetailButton({
newVersion: newVersionNumber
})

if (!differences) {
return (
<span>
{t('datasetVersionSummary.noVersionDifferences', {
oldVersion: oldVersionNumber,
newVersion: newVersionNumber
})}
</span>
)
}

return (
<>
<Button variant="link" onClick={() => setShowModal(true)} style={{ padding: 0 }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@ import {
SummaryUpdates,
Deaccessioned
} from '@/dataset/domain/models/DatasetVersionSummaryInfo'
import { DatasetVersionState } from '@/dataset/domain/models/Dataset'

export const useDatasetVersionSummaryDescription = (
summary?: DatasetVersionSummary | DatasetVersionSummaryStringValues
summary?: DatasetVersionSummary | DatasetVersionSummaryStringValues,
versionState?: string
): Record<string, string> => {
const { t } = useTranslation('dataset')

if (!summary) return {}

if (typeof summary === 'string') {
const stringSummaryMap: Record<DatasetVersionSummaryStringValues, string> = {
const stringSummaryMap: Record<string, string> = {
[DatasetVersionSummaryStringValues.firstPublished]: t('datasetVersionSummary.firstPublished'),
[DatasetVersionSummaryStringValues.firstDraft]: t('datasetVersionSummary.firstDraft'),
[DatasetVersionSummaryStringValues.versionDeaccessioned]: t(
'datasetVersionSummary.versionDeaccessioned'
),
[DatasetVersionSummaryStringValues.previousVersionDeaccessioned]: t(
'datasetVersionSummary.previousVersionDeaccessioned'
)
[DatasetVersionSummaryStringValues.previousVersionDeaccessioned]:
versionState === DatasetVersionState.DRAFT
? t('datasetVersionSummary.thisIsADraftVersion')
: t('datasetVersionSummary.previousVersionDeaccessioned')
}
return { [summary]: stringSummaryMap[summary] }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const DatasetVersionsDifferenceTable = ({
differences
}: datasetVersionsDifferenceTableProps) => {
const { t } = useTranslation('dataset')
const { t: tFile } = useTranslation('file')
const {
oldVersion,
newVersion,
Expand Down Expand Up @@ -129,14 +130,26 @@ export const DatasetVersionsDifferenceTable = ({
<td>
{file.changed.map((change) => (
<div key={change.fieldName}>
{change.fieldName}: {change.oldValue || ''}
{change.fieldName === 'isRestricted'
? `${t('versions.access')}: ${
change.oldValue === 'true'
? tFile('fileAccess.restricted.name')
: tFile('fileAccess.public.name')
}`
: `${change.fieldName}: ${change.oldValue || ''}`}
</div>
))}
</td>
<td>
{file.changed.map((change) => (
<div key={change.fieldName}>
{change.fieldName}: {change.newValue || ''}
{change.fieldName === 'isRestricted'
? `${t('versions.access')}: ${
change.newValue === 'true'
? tFile('fileAccess.restricted.name')
: tFile('fileAccess.public.name')
}`
: `${change.fieldName}: ${change.newValue || ''}`}
</div>
))}
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const useGetDatasetVersionDiff = ({
oldVersion,
newVersion
}: getDatasetVersionDiffProps): UseGetDatasetVersionDiff => {
const [differences, setDifferences] = useState<DatasetVersionDiff>()
const [differences, setDifferences] = useState<DatasetVersionDiff | undefined>()
const [isLoading, setIsLoading] = useState<boolean>(true)
const [error, setError] = useState<string | null>(null)

Expand All @@ -43,7 +43,20 @@ export const useGetDatasetVersionDiff = ({
: newVersion,
true
)
setDifferences(response)

if (response) {
const hasAnyChanges =
response.metadataChanges !== undefined ||
response.filesAdded !== undefined ||
response.filesRemoved !== undefined ||
response.fileChanges !== undefined ||
response.filesReplaced !== undefined ||
response.termsOfAccess !== undefined

setDifferences(hasAnyChanges ? response : undefined)
} else {
setDifferences(undefined)
}
setError(null)
} catch (err) {
const errorMessage =
Expand Down
7 changes: 7 additions & 0 deletions src/sections/file/file-version/FileVersion.module.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import 'node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module';

.file-versions-table {
width: 100%;
margin: auto;
Expand All @@ -16,3 +18,8 @@
vertical-align: top;
}
}

.no-summary-text {
font-style: italic;
color: $dv-subtext-color;
}
Loading