Skip to content

Commit 9bf054e

Browse files
committed
fix: increase test coverage, and disable edit names and email in guestbook
1 parent 18691cb commit 9bf054e

32 files changed

Lines changed: 888 additions & 167 deletions

File tree

public/locales/en/dataset.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@
368368
},
369369
"guestbook": {
370370
"title": "Guestbook",
371-
"description": "Select a guestbook to have a user provide additional information when downloading a file. To learn more about guestbooks, visit the Dataset Guestbook section of the User Guide.",
371+
"description": "Select a guestbook to have a user provide additional information when downloading a file. To learn more about guestbooks, visit the <anchor>Dataset Guestbook</anchor> section of the User Guide.",
372+
"noGuestbooksEnabled": "There are no guestbooks enabled in {{collectionName}}. To create a guestbook, return to {{collectionName}}, click the \"Edit\" button and select the \"Dataset Guestbooks\" option.",
372373
"previewButton": "Preview Guestbook"
373374
},
374375
"unsavedChangesModal": {

src/access/domain/repositories/AccessRepository.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
export type GuestbookResponseAnswer = { id: number | string; value: string | string[] }
22

33
export interface AccessRepository {
4+
submitGuestbookForDatasetDownload: (
5+
datasetId: number | string,
6+
answers: GuestbookResponseAnswer[]
7+
) => Promise<string>
48
submitGuestbookForDatafileDownload: (
59
fileId: number | string,
610
answers: GuestbookResponseAnswer[]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { AccessRepository, GuestbookResponseAnswer } from '../repositories/AccessRepository'
2+
3+
export function submitGuestbookForDatasetDownload(
4+
accessRepository: AccessRepository,
5+
datasetId: number | string,
6+
answers: GuestbookResponseAnswer[]
7+
): Promise<string> {
8+
return accessRepository.submitGuestbookForDatasetDownload(datasetId, answers)
9+
}

src/access/infrastructure/repositories/AccessJSDataverseRepository.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
submitGuestbookForDatasetDownload as submitGuestbookForDatasetDownloadJSDv,
23
submitGuestbookForDatafileDownload as submitGuestbookForDatafileDownloadJSDv,
34
submitGuestbookForDatafilesDownload as submitGuestbookForDatafilesDownloadJSDv
45
} from '@iqss/dataverse-client-javascript'
@@ -8,6 +9,15 @@ import {
89
} from '@/access/domain/repositories/AccessRepository'
910

1011
export class AccessJSDataverseRepository implements AccessRepository {
12+
submitGuestbookForDatasetDownload(
13+
datasetId: number | string,
14+
answers: GuestbookResponseAnswer[]
15+
): Promise<string> {
16+
return submitGuestbookForDatasetDownloadJSDv.execute(datasetId, {
17+
guestbookResponse: { answers }
18+
})
19+
}
20+
1121
submitGuestbookForDatafileDownload(
1222
fileId: number | string,
1323
answers: GuestbookResponseAnswer[]

src/dataset/domain/useCases/updateTermsOfAccess.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ export function updateTermsOfAccess(
66
datasetId: string | number,
77
termsOfAccess: TermsOfAccess
88
): Promise<void> {
9-
return datasetRepository.updateTermsOfAccess(datasetId, termsOfAccess).catch((error: Error) => {
10-
throw new Error(error.message)
11-
})
9+
return datasetRepository.updateTermsOfAccess(datasetId, termsOfAccess)
1210
}

src/files/domain/models/File.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DatasetVersion } from '../../../dataset/domain/models/Dataset'
1+
import { CustomTerms, DatasetLicense, DatasetVersion } from '../../../dataset/domain/models/Dataset'
22
import { FileMetadata } from './FileMetadata'
33
import { FileAccess } from './FileAccess'
44
import { FilePermissions } from './FilePermissions'
@@ -10,6 +10,8 @@ export interface File {
1010
id: number
1111
datasetPersistentId: string
1212
guestbookId?: number
13+
datasetLicense?: DatasetLicense
14+
datasetCustomTerms?: CustomTerms
1315
name: string
1416
access: FileAccess
1517
datasetVersion: DatasetVersion

src/files/infrastructure/mappers/JSFileMapper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export class JSFileMapper {
6363
id: this.toFileId(jsFile.id),
6464
datasetPersistentId: jsDataset.persistentId,
6565
guestbookId: jsDataset.guestbookId,
66+
datasetLicense: jsDataset.license,
67+
datasetCustomTerms: jsDataset.termsOfUse?.customTerms,
6668
name: this.toFileName(jsFile.name),
6769
access: JSFileAccessMapper.toFileAccess(jsFile.restricted, jsFile.fileAccessRequest || false),
6870
datasetVersion: datasetVersion,

src/sections/dataset/dataset-action-buttons/DatasetActionButtons.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ export function DatasetActionButtons({
4141
downloadUrls={dataset.downloadUrls}
4242
fileStore={dataset.fileStore}
4343
persistentId={dataset.persistentId}
44+
guestbookId={dataset.guestbookId}
45+
license={dataset.license}
46+
customTerms={dataset.termsOfUse.customTerms}
4447
/>
4548
<PublishDatasetMenu
4649
dataset={dataset}

src/sections/dataset/dataset-action-buttons/access-dataset-menu/AccessDatasetMenu.tsx

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
import { useState } from 'react'
12
import { DropdownButton, DropdownButtonItem, DropdownHeader } from '@iqss/dataverse-design-system'
23
import { Download as DownloadIcon } from 'react-bootstrap-icons'
34
import { useTranslation } from 'react-i18next'
45
import {
6+
CustomTerms,
57
DatasetDownloadUrls,
8+
DatasetLicense,
69
DatasetPermissions,
710
DatasetPublishingStatus,
811
DatasetVersion
912
} from '../../../../dataset/domain/models/Dataset'
1013
import { FileDownloadSize, FileDownloadMode } from '../../../../files/domain/models/FileMetadata'
1114
import { DatasetExploreOptions } from '../DatasetToolsOptions'
15+
import { DownloadWithGuestbookModal } from '@/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/DownloadWithGuestbookModal'
1216

1317
// TODO: add compute feature
1418

@@ -20,6 +24,9 @@ interface AccessDatasetMenuProps {
2024
downloadUrls: DatasetDownloadUrls
2125
fileStore: string | undefined
2226
persistentId: string
27+
guestbookId?: number
28+
license?: DatasetLicense
29+
customTerms?: CustomTerms
2330
}
2431

2532
export function AccessDatasetMenu({
@@ -29,9 +36,14 @@ export function AccessDatasetMenu({
2936
fileDownloadSizes,
3037
downloadUrls,
3138
fileStore,
32-
persistentId
39+
persistentId,
40+
guestbookId,
41+
license,
42+
customTerms
3343
}: AccessDatasetMenuProps) {
3444
const { t } = useTranslation('dataset')
45+
const [showDownloadWithGuestbookModal, setShowDownloadWithGuestbookModal] = useState(false)
46+
const hasGuestbook = guestbookId !== undefined
3547

3648
const flesToDownloadSizeIsZero =
3749
fileDownloadSizes.map(({ value }) => value).reduce((acc, curr) => acc + curr, 0) === 0
@@ -50,40 +62,58 @@ export function AccessDatasetMenu({
5062
return <></>
5163
}
5264

53-
// TODO: remove this when access datafile supports bearer tokens
54-
if (version.publishingStatus === DatasetPublishingStatus.DRAFT) {
55-
return <></>
65+
const handleDownloadWithGuestbook = (event: React.MouseEvent<HTMLElement>) => {
66+
event.preventDefault()
67+
setShowDownloadWithGuestbookModal(true)
5668
}
5769

5870
return (
59-
<DropdownButton
60-
id={`access-dataset-menu`}
61-
title={t('datasetActionButtons.accessDataset.title')}
62-
asButtonGroup
63-
variant="primary">
64-
<DropdownHeader className="d-flex align-items-center gap-1">
65-
{t('datasetActionButtons.accessDataset.downloadOptions.header')} <DownloadIcon />
66-
</DropdownHeader>
67-
<DatasetDownloadOptions
68-
hasOneTabularFileAtLeast={hasOneTabularFileAtLeast}
69-
fileDownloadSizes={fileDownloadSizes}
70-
downloadUrls={downloadUrls}
71-
/>
72-
<DatasetExploreOptions persistentId={persistentId} />
73-
</DropdownButton>
71+
<>
72+
<DropdownButton
73+
id={`access-dataset-menu`}
74+
title={t('datasetActionButtons.accessDataset.title')}
75+
asButtonGroup
76+
variant="primary">
77+
<DropdownHeader className="d-flex align-items-center gap-1">
78+
{t('datasetActionButtons.accessDataset.downloadOptions.header')} <DownloadIcon />
79+
</DropdownHeader>
80+
<DatasetDownloadOptions
81+
hasOneTabularFileAtLeast={hasOneTabularFileAtLeast}
82+
fileDownloadSizes={fileDownloadSizes}
83+
downloadUrls={downloadUrls}
84+
hasGuestbook={hasGuestbook}
85+
onDownloadWithGuestbook={handleDownloadWithGuestbook}
86+
/>
87+
<DatasetExploreOptions persistentId={persistentId} />
88+
</DropdownButton>
89+
{hasGuestbook && (
90+
<DownloadWithGuestbookModal
91+
show={showDownloadWithGuestbookModal}
92+
handleClose={() => setShowDownloadWithGuestbookModal(false)}
93+
guestbookId={guestbookId}
94+
datasetPersistentId={persistentId}
95+
datasetLicense={license}
96+
datasetCustomTerms={customTerms}
97+
/>
98+
)}
99+
</>
74100
)
75101
}
76102

77103
interface DatasetDownloadOptionsProps {
78104
hasOneTabularFileAtLeast: boolean
79105
fileDownloadSizes: FileDownloadSize[]
80106
downloadUrls: DatasetDownloadUrls
107+
hasGuestbook: boolean
108+
onDownloadWithGuestbook: (event: React.MouseEvent<HTMLElement>) => void
81109
}
82110

83111
const DatasetDownloadOptions = ({
84112
hasOneTabularFileAtLeast,
85113
fileDownloadSizes,
86-
downloadUrls
114+
downloadUrls,
115+
hasGuestbook,
116+
onDownloadWithGuestbook
87117
}: DatasetDownloadOptionsProps) => {
88118
const { t } = useTranslation('dataset')
89119
function getFormattedFileSize(mode: FileDownloadMode): string {
@@ -93,17 +123,23 @@ const DatasetDownloadOptions = ({
93123

94124
return hasOneTabularFileAtLeast ? (
95125
<>
96-
<DropdownButtonItem href={downloadUrls[FileDownloadMode.ORIGINAL]}>
126+
<DropdownButtonItem
127+
href={hasGuestbook ? undefined : downloadUrls[FileDownloadMode.ORIGINAL]}
128+
onClick={hasGuestbook ? onDownloadWithGuestbook : undefined}>
97129
{t('datasetActionButtons.accessDataset.downloadOptions.originalZip')} (
98130
{getFormattedFileSize(FileDownloadMode.ORIGINAL)})
99131
</DropdownButtonItem>
100-
<DropdownButtonItem href={downloadUrls[FileDownloadMode.ARCHIVAL]}>
132+
<DropdownButtonItem
133+
href={hasGuestbook ? undefined : downloadUrls[FileDownloadMode.ARCHIVAL]}
134+
onClick={hasGuestbook ? onDownloadWithGuestbook : undefined}>
101135
{t('datasetActionButtons.accessDataset.downloadOptions.archivalZip')} (
102136
{getFormattedFileSize(FileDownloadMode.ARCHIVAL)})
103137
</DropdownButtonItem>
104138
</>
105139
) : (
106-
<DropdownButtonItem href={downloadUrls[FileDownloadMode.ORIGINAL]}>
140+
<DropdownButtonItem
141+
href={hasGuestbook ? undefined : downloadUrls[FileDownloadMode.ORIGINAL]}
142+
onClick={hasGuestbook ? onDownloadWithGuestbook : undefined}>
107143
{t('datasetActionButtons.accessDataset.downloadOptions.zip')} (
108144
{getFormattedFileSize(FileDownloadMode.ORIGINAL)})
109145
</DropdownButtonItem>

src/sections/dataset/dataset-files/files-table/file-actions/download-files/DownloadFilesButton.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useMultipleFileDownload } from '../../../../../file/multiple-file-downl
1111
import { FilePreview } from '../../../../../../files/domain/models/FilePreview'
1212
import { useMediaQuery } from '../../../../../../shared/hooks/useMediaQuery'
1313
import { DatasetPublishingStatus } from '@/dataset/domain/models/Dataset'
14-
import { GuestbookAppliedModal } from '../file-actions-cell/file-action-buttons/file-options-menu/GuestbookAppliedModal'
14+
import { DownloadWithGuestbookModal } from '../file-actions-cell/file-action-buttons/file-options-menu/DownloadWithGuestbookModal'
1515

1616
interface DownloadFilesButtonProps {
1717
files: FilePreview[]
@@ -25,13 +25,15 @@ export function DownloadFilesButton({ files, fileSelection }: DownloadFilesButto
2525
const { t } = useTranslation('files')
2626
const { dataset } = useDataset()
2727
const [showNoFilesSelectedModal, setShowNoFilesSelectedModal] = useState(false)
28-
const [showGuestbookAppliedModal, setShowGuestbookAppliedModal] = useState(false)
28+
const [showDownloadWithGuestbookModal, setShowDownloadWithGuestbookModal] = useState(false)
2929
const { getMultipleFileDownloadUrl } = useMultipleFileDownload()
3030
const isBelow768px = useMediaQuery('(max-width: 768px)')
3131

3232
const fileSelectionCount = Object.keys(fileSelection).length
3333
const allFilesSelected = Object.values(fileSelection).some((file) => file === undefined)
3434
const selectedFileIds = getFileIdsFromSelection(fileSelection)
35+
const allSelectedFileIds = files.map((file) => file.id)
36+
const fileIdsForGuestbookSubmission = allFilesSelected ? allSelectedFileIds : selectedFileIds
3537
const hasGuestbook = dataset?.guestbookId !== undefined
3638
const onClick = (event: MouseEvent<HTMLElement>) => {
3739
if (fileSelectionCount === SELECTED_FILES_EMPTY) {
@@ -42,7 +44,7 @@ export function DownloadFilesButton({ files, fileSelection }: DownloadFilesButto
4244

4345
if (hasGuestbook) {
4446
event.preventDefault()
45-
setShowGuestbookAppliedModal(true)
47+
setShowDownloadWithGuestbookModal(true)
4648
}
4749
}
4850

@@ -100,11 +102,11 @@ export function DownloadFilesButton({ files, fileSelection }: DownloadFilesButto
100102
show={showNoFilesSelectedModal}
101103
handleClose={() => setShowNoFilesSelectedModal(false)}
102104
/>
103-
<GuestbookAppliedModal
104-
fileIds={!allFilesSelected ? selectedFileIds : undefined}
105+
<DownloadWithGuestbookModal
106+
fileIds={fileIdsForGuestbookSubmission}
105107
guestbookId={dataset?.guestbookId}
106-
show={showGuestbookAppliedModal}
107-
handleClose={() => setShowGuestbookAppliedModal(false)}
108+
show={showDownloadWithGuestbookModal}
109+
handleClose={() => setShowDownloadWithGuestbookModal(false)}
108110
/>
109111
</>
110112
)
@@ -126,11 +128,11 @@ export function DownloadFilesButton({ files, fileSelection }: DownloadFilesButto
126128
show={showNoFilesSelectedModal}
127129
handleClose={() => setShowNoFilesSelectedModal(false)}
128130
/>
129-
<GuestbookAppliedModal
130-
fileIds={!allFilesSelected ? selectedFileIds : undefined}
131+
<DownloadWithGuestbookModal
132+
fileIds={fileIdsForGuestbookSubmission}
131133
guestbookId={dataset?.guestbookId}
132-
show={showGuestbookAppliedModal}
133-
handleClose={() => setShowGuestbookAppliedModal(false)}
134+
show={showDownloadWithGuestbookModal}
135+
handleClose={() => setShowDownloadWithGuestbookModal(false)}
134136
/>
135137
</>
136138
)

0 commit comments

Comments
 (0)