1+ import { useState } from 'react'
12import { DropdownButton , DropdownButtonItem , DropdownHeader } from '@iqss/dataverse-design-system'
23import { Download as DownloadIcon } from 'react-bootstrap-icons'
34import { useTranslation } from 'react-i18next'
45import {
6+ CustomTerms ,
57 DatasetDownloadUrls ,
8+ DatasetLicense ,
69 DatasetPermissions ,
710 DatasetPublishingStatus ,
811 DatasetVersion
912} from '../../../../dataset/domain/models/Dataset'
1013import { FileDownloadSize , FileDownloadMode } from '../../../../files/domain/models/FileMetadata'
1114import { 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
2532export 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
77103interface DatasetDownloadOptionsProps {
78104 hasOneTabularFileAtLeast : boolean
79105 fileDownloadSizes : FileDownloadSize [ ]
80106 downloadUrls : DatasetDownloadUrls
107+ hasGuestbook : boolean
108+ onDownloadWithGuestbook : ( event : React . MouseEvent < HTMLElement > ) => void
81109}
82110
83111const 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 >
0 commit comments