-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from IQSS/feature/187-files-table-download-bu…
…tton 187 - Files table download button
- Loading branch information
Showing
18 changed files
with
440 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,4 +179,8 @@ export class File { | |
} | ||
return false | ||
} | ||
|
||
get isTabularData(): boolean { | ||
return this.tabularData !== undefined | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.container { | ||
display: flex; | ||
justify-content: end; | ||
text-align: right; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...set/dataset-files/files-table/file-actions/download-files/DownloadFilesButton.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.icon { | ||
margin-right: 0.3rem; | ||
margin-bottom: 0.2rem; | ||
} |
75 changes: 75 additions & 0 deletions
75
...ons/dataset/dataset-files/files-table/file-actions/download-files/DownloadFilesButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { File } from '../../../../../../files/domain/models/File' | ||
import { useDataset } from '../../../../DatasetContext' | ||
import { Button, DropdownButton, DropdownButtonItem } from '@iqss/dataverse-design-system' | ||
import { Download } from 'react-bootstrap-icons' | ||
import styles from './DownloadFilesButton.module.scss' | ||
import { useTranslation } from 'react-i18next' | ||
import { FileSelection } from '../../row-selection/useFileSelection' | ||
import { NoSelectedFilesModal } from '../no-selected-files-modal/NoSelectedFilesModal' | ||
import { useState } from 'react' | ||
|
||
interface DownloadFilesButtonProps { | ||
files: File[] | ||
fileSelection: FileSelection | ||
} | ||
|
||
const MINIMUM_FILES_COUNT_TO_SHOW_DOWNLOAD_FILES_BUTTON = 1 | ||
const SELECTED_FILES_EMPTY = 0 | ||
export function DownloadFilesButton({ files, fileSelection }: DownloadFilesButtonProps) { | ||
const { t } = useTranslation('files') | ||
const { dataset } = useDataset() | ||
const [showNoFilesSelectedModal, setShowNoFilesSelectedModal] = useState(false) | ||
|
||
if ( | ||
files.length < MINIMUM_FILES_COUNT_TO_SHOW_DOWNLOAD_FILES_BUTTON || | ||
!dataset?.permissions.canDownloadFiles | ||
) { | ||
return <></> | ||
} | ||
|
||
const onClick = () => { | ||
if (Object.keys(fileSelection).length === SELECTED_FILES_EMPTY) { | ||
setShowNoFilesSelectedModal(true) | ||
} | ||
} | ||
|
||
if (files.some((file) => file.isTabularData)) { | ||
return ( | ||
<> | ||
<DropdownButton | ||
id="download-files" | ||
icon={<Download className={styles.icon} />} | ||
title={t('actions.downloadFiles.title')} | ||
variant="secondary" | ||
withSpacing> | ||
<DropdownButtonItem onClick={onClick}> | ||
{t('actions.downloadFiles.options.original')} | ||
</DropdownButtonItem> | ||
<DropdownButtonItem onClick={onClick}> | ||
{t('actions.downloadFiles.options.archival')} | ||
</DropdownButtonItem> | ||
</DropdownButton> | ||
<NoSelectedFilesModal | ||
show={showNoFilesSelectedModal} | ||
handleClose={() => setShowNoFilesSelectedModal(false)} | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
return ( | ||
<> | ||
<Button | ||
variant="secondary" | ||
icon={<Download className={styles.icon} />} | ||
withSpacing | ||
onClick={onClick}> | ||
{t('actions.downloadFiles.title')} | ||
</Button> | ||
<NoSelectedFilesModal | ||
show={showNoFilesSelectedModal} | ||
handleClose={() => setShowNoFilesSelectedModal(false)} | ||
/> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 38 additions & 8 deletions
46
...tions/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,62 @@ | ||
import { DropdownButtonItem } from '@iqss/dataverse-design-system' | ||
import { File } from '../../../../../../files/domain/models/File' | ||
import { useTranslation } from 'react-i18next' | ||
import { useState } from 'react' | ||
import { FileSelection } from '../../row-selection/useFileSelection' | ||
import { NoSelectedFilesModal } from '../no-selected-files-modal/NoSelectedFilesModal' | ||
|
||
interface EditFileOptionsProps { | ||
files: File[] | ||
fileSelection: FileSelection | ||
} | ||
export function EditFilesOptions({ files }: EditFileOptionsProps) { | ||
const SELECTED_FILES_EMPTY = 0 | ||
export function EditFilesOptions({ files, fileSelection }: EditFileOptionsProps) { | ||
const { t } = useTranslation('files') | ||
const [showNoFilesSelectedModal, setShowNoFilesSelectedModal] = useState(false) | ||
const settingsEmbargoAllowed = false // TODO - Ask Guillermo if this is included in the settings endpoint | ||
const provenanceEnabledByConfig = false // TODO - Ask Guillermo if this is included in the MVP and from which endpoint is coming from | ||
|
||
const onClick = () => { | ||
if (Object.keys(fileSelection).length === SELECTED_FILES_EMPTY) { | ||
setShowNoFilesSelectedModal(true) | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<DropdownButtonItem>{t('actions.editFilesMenu.options.metadata')}</DropdownButtonItem> | ||
<DropdownButtonItem onClick={onClick}> | ||
{t('actions.editFilesMenu.options.metadata')} | ||
</DropdownButtonItem> | ||
{files.some((file) => file.access.restricted) && ( | ||
<DropdownButtonItem>{t('actions.editFilesMenu.options.unrestrict')}</DropdownButtonItem> | ||
<DropdownButtonItem onClick={onClick}> | ||
{t('actions.editFilesMenu.options.unrestrict')} | ||
</DropdownButtonItem> | ||
)} | ||
{files.some((file) => !file.access.restricted) && ( | ||
<DropdownButtonItem>{t('actions.editFilesMenu.options.restrict')}</DropdownButtonItem> | ||
<DropdownButtonItem onClick={onClick}> | ||
{t('actions.editFilesMenu.options.restrict')} | ||
</DropdownButtonItem> | ||
)} | ||
<DropdownButtonItem>{t('actions.editFilesMenu.options.replace')}</DropdownButtonItem> | ||
<DropdownButtonItem onClick={onClick}> | ||
{t('actions.editFilesMenu.options.replace')} | ||
</DropdownButtonItem> | ||
{settingsEmbargoAllowed && ( | ||
<DropdownButtonItem>{t('actions.editFilesMenu.options.embargo')}</DropdownButtonItem> | ||
<DropdownButtonItem onClick={onClick}> | ||
{t('actions.editFilesMenu.options.embargo')} | ||
</DropdownButtonItem> | ||
)} | ||
{provenanceEnabledByConfig && ( | ||
<DropdownButtonItem>{t('actions.editFilesMenu.options.provenance')}</DropdownButtonItem> | ||
<DropdownButtonItem onClick={onClick}> | ||
{t('actions.editFilesMenu.options.provenance')} | ||
</DropdownButtonItem> | ||
)} | ||
<DropdownButtonItem>{t('actions.editFilesMenu.options.delete')}</DropdownButtonItem> | ||
<DropdownButtonItem onClick={onClick}> | ||
{t('actions.editFilesMenu.options.delete')} | ||
</DropdownButtonItem> | ||
<NoSelectedFilesModal | ||
show={showNoFilesSelectedModal} | ||
handleClose={() => setShowNoFilesSelectedModal(false)} | ||
/> | ||
</> | ||
) | ||
} |
30 changes: 30 additions & 0 deletions
30
...t/dataset-files/files-table/file-actions/no-selected-files-modal/NoSelectedFilesModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useTranslation } from 'react-i18next' | ||
import { Button, Modal } from '@iqss/dataverse-design-system' | ||
import styles from '../file-actions-cell/file-action-buttons/file-options-menu/FileAlreadyDeletedModal.module.scss' | ||
import { ExclamationCircleFill } from 'react-bootstrap-icons' | ||
|
||
interface NoSelectedFilesModalProps { | ||
show: boolean | ||
handleClose: () => void | ||
} | ||
|
||
export function NoSelectedFilesModal({ show, handleClose }: NoSelectedFilesModalProps) { | ||
const { t } = useTranslation('files') | ||
return ( | ||
<Modal show={show} onHide={handleClose} size="lg"> | ||
<Modal.Header> | ||
<Modal.Title>{t('actions.noSelectedFilesAlert.title')}</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<p className={styles.paragraph}> | ||
<ExclamationCircleFill /> {t('actions.noSelectedFilesAlert.message')} | ||
</p> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button variant="secondary" onClick={handleClose}> | ||
{t('actions.noSelectedFilesAlert.close')} | ||
</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...set/dataset-files/files-table/file-actions/download-files/DownloadFilesButton.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Meta, StoryObj } from '@storybook/react' | ||
import { EditFilesMenu } from '../../../../../../sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu' | ||
import { WithI18next } from '../../../../../WithI18next' | ||
import { WithSettings } from '../../../../../WithSettings' | ||
import { WithLoggedInUser } from '../../../../../WithLoggedInUser' | ||
import { WithDatasetAllPermissionsGranted } from '../../../../WithDatasetAllPermissionsGranted' | ||
import { FileMother } from '../../../../../../../tests/component/files/domain/models/FileMother' | ||
import { DownloadFilesButton } from '../../../../../../sections/dataset/dataset-files/files-table/file-actions/download-files/DownloadFilesButton' | ||
|
||
const meta: Meta<typeof EditFilesMenu> = { | ||
title: 'Sections/Dataset Page/DatasetFiles/FilesTable/DownloadFilesButton', | ||
component: EditFilesMenu, | ||
decorators: [WithI18next, WithSettings, WithLoggedInUser, WithDatasetAllPermissionsGranted] | ||
} | ||
|
||
export default meta | ||
type Story = StoryObj<typeof EditFilesMenu> | ||
|
||
export const NonTabularFiles: Story = { | ||
render: () => ( | ||
<DownloadFilesButton | ||
files={FileMother.createMany(2, { tabularData: undefined })} | ||
fileSelection={{}} | ||
/> | ||
) | ||
} | ||
|
||
export const TabularFiles: Story = { | ||
render: () => ( | ||
<DownloadFilesButton | ||
files={FileMother.createMany(2, { | ||
tabularData: { | ||
variablesCount: 2, | ||
observationsCount: 3, | ||
unf: 'some-unf' | ||
} | ||
})} | ||
fileSelection={{}} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.