Skip to content

Commit

Permalink
Merge branch 'develop' into 564-collection-page-add-file-tags-into-th…
Browse files Browse the repository at this point in the history
…e-item-card-information-and-add-numbers-tabular-tags-for-tabular-file
  • Loading branch information
ChengShi-1 committed Jan 16, 2025
2 parents b9c0780 + f758ee6 commit 59056b0
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 37 deletions.
2 changes: 2 additions & 0 deletions src/files/domain/models/FileItemTypePreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export interface FileItemTypePreview {
variables?: number
observations?: number
tags?: FileLabel[]
restricted: boolean
canDownloadFile: boolean
}

export interface FilePreviewChecksum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export class JSFileItemTypePreviewMapper {
releaseOrCreateDate: jsFilePreview.releaseOrCreateDate,
tags: [...categoriesAsLabels, ...tabularTagsAsLabels] as FileLabel[],
variables: jsFilePreview.variables,
observations: jsFilePreview.observations
observations: jsFilePreview.observations,
restricted: jsFilePreview.restricted,
canDownloadFile: jsFilePreview.canDownloadFile
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,7 @@
color: black;
}
}

.restricted-icon {
margin: -5px -5px 0 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Route } from '@/sections/Route.enum'
import { LinkToPage } from '@/sections/shared/link-to-page/LinkToPage'
import { DatasetLabels } from '@/sections/dataset/dataset-labels/DatasetLabels'
import { FileCardHelper } from './FileCardHelper'
import { FileAccessRestrictedIcon } from '../../../../file/file-access/FileAccessRestrictedIcon'
import styles from './FileCard.module.scss'

interface FileCardHeaderProps {
Expand All @@ -21,6 +22,12 @@ export function FileCardHeader({ filePreview }: FileCardHeaderProps) {
return (
<header className={styles['card-header-container']}>
<div className={styles['left-side-content']}>
<div className={styles['restricted-icon']} data-testid="file-access-restricted-icon">
<FileAccessRestrictedIcon
restricted={filePreview.restricted}
canDownloadFile={filePreview.canDownloadFile}
/>
</div>
<LinkToPage
page={Route.FILES}
type={DvObjectType.FILE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export function UploadedFiles({
<div>
<Form.Group.Checkbox
label={t('restricted')}
data-testid={'restricted_checkbox_' + file.fileName}
id={'restricted-' + file.key}
checked={file.restricted}
onChange={(event: FormEvent<HTMLInputElement>) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function FilesHeader({
label={''}
aria-label={t('filesHeader.selectAll')}
id={'select-all'}
data-testid="select-all-files-checkbox"
checked={selectAllChecked}
onChange={all}
/>
Expand All @@ -96,16 +97,26 @@ export function FilesHeader({
icon={<PencilFill className={styles.icon_pencil} />}
id={'edit-files'}
title={t('filesHeader.editFiles')}>
<DropdownButtonItem onClick={showAddTagsModal} title={t('filesHeader.addTagsToSelected')}>
<DropdownButtonItem
data-testid="add-tags-selected"
onClick={showAddTagsModal}
title={t('filesHeader.addTagsToSelected')}>
{t('filesHeader.addTags')}
</DropdownButtonItem>
<DropdownButtonItem onClick={() => updateRestriction(true)}>
<DropdownButtonItem
data-testid="restrict-selected"
onClick={() => updateRestriction(true)}>
{t('filesHeader.restrict')}
</DropdownButtonItem>
<DropdownButtonItem onClick={() => updateRestriction(false)}>
<DropdownButtonItem
data-testid="unrestrict-selected"
onClick={() => updateRestriction(false)}>
{t('filesHeader.unrestrict')}
</DropdownButtonItem>
<DropdownButtonItem onClick={deleteSelected} title={t('filesHeader.deleteSelected')}>
<DropdownButtonItem
data-testid="delete-selected"
onClick={deleteSelected}
title={t('filesHeader.deleteSelected')}>
{t('delete')}
</DropdownButtonItem>
</DropdownButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function RestrictionModal({
update({ saved: saved, terms: terms, requestAccess: requestAccess })

return (
<Modal show={show} onHide={() => handleClose(false)} size="lg">
<Modal data-testid="restrictionModal" show={show} onHide={() => handleClose(false)} size="lg">
<Modal.Header>
<Modal.Title>{t('restriction.restrictAccess')}</Modal.Title>
</Modal.Header>
Expand All @@ -47,6 +47,7 @@ export function RestrictionModal({
<Col sm={9}>
<Form.Group.Checkbox
label={t('restriction.enableAccessRequest')}
data-testid="enable-access-request-checkbox"
id={'requestAccessCB'}
checked={requestAccess}
onChange={(event: FormEvent<HTMLInputElement>) =>
Expand All @@ -61,6 +62,7 @@ export function RestrictionModal({
</Form.Group.Label>
<Col sm={9}>
<Form.Group.TextArea
data-testid="terms-of-access-textarea"
defaultValue={defaultTerms}
onChange={(event: FormEvent<HTMLInputElement>) =>
setTerms(event.currentTarget.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export class FileItemTypePreviewMother {
],
observations: faker.datatype.number(),
variables: faker.datatype.number(),
restricted: faker.datatype.boolean(),
canDownloadFile: faker.datatype.boolean(),
...props
}
}
Expand Down Expand Up @@ -68,6 +70,8 @@ export class FileItemTypePreviewMother {
datasetCitation: 'test citation',
publicationStatuses: [PublicationStatus.Published],
releaseOrCreateDate: new Date('2023-05-15T08:21:01Z'),
restricted: false,
canDownloadFile: true,
...props
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ describe('FileCard', () => {
const filePreview = FileItemTypePreviewMother.create()
cy.customMount(<FileCard filePreview={filePreview} />)

filePreview.restricted
? cy.findByTestId('file-access-restricted-icon').should('exist')
: cy.findByTestId('file-access-restricted-icon').should('not.exist')
cy.contains(DateHelper.toDisplayFormat(filePreview.releaseOrCreateDate)).should('exist')
cy.contains(filePreview.fileType).should('exist')
filePreview.checksum?.type && cy.contains(filePreview.checksum?.type).should('exist')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ describe('UploadDatasetFiles', () => {
cy.get('input[value="users1.json"]').should('not.exist')
cy.get('input[value="users2.json"]').should('exist')
})

it('restrict uploaded file', () => {
it(`restrict uploaded file`, () => {
const testDataset = DatasetMother.create()

mountWithDataset(<UploadDatasetFiles fileRepository={new FileMockRepository()} />, testDataset)
Expand All @@ -353,38 +352,60 @@ describe('UploadDatasetFiles', () => {
{ action: 'drag-drop' }
)
// wait for upload to finish
// Set users2.json to restricted
cy.findByText('2 files uploaded').should('exist')
cy.get('[type="checkbox"]').last().click()
cy.findByText('Save Changes').first().click()
cy.get('[type="checkbox"]').last().should('be.checked')
cy.get('[type="checkbox"]').last().click()
cy.get('[type="checkbox"]').last().should('not.be.checked')
cy.get('[type="checkbox"]').first().click()
cy.findByText('Edit files').first().click()
cy.findByText('Restrict').first().click()
cy.findByText('Save Changes').first().click()
cy.get('[type="checkbox"]').last().should('be.checked')
cy.findByText('Edit files').first().click()
cy.findByText('Unrestrict').first().click()
cy.get('[type="checkbox"]').last().should('not.be.checked')
cy.findByText('Edit files').first().click()
cy.findByText('Restrict').first().click()
cy.findByTestId('restricted_checkbox_users2.json').click()
cy.findByText('Save Changes').click()
cy.findByTestId('restrctionModal').should('not.exist')

// Set users2.json to unrestricted
cy.findByTestId('restricted_checkbox_users2.json').should('be.checked')
cy.findByTestId('restricted_checkbox_users2.json').click()
cy.findByTestId('restricted_checkbox_users2.json').should('not.be.checked')

// Set both files to restricted
cy.findByTestId('select-all-files-checkbox').click()
cy.findByRole('button', { name: 'Edit files' }).click()
cy.findByTestId('restrict-selected').click()
cy.findByText('Save Changes').click()
cy.findByTestId('restrctionModal').should('not.exist')
cy.findByTestId('restricted_checkbox_users1.json').should('be.checked')
cy.findByTestId('restricted_checkbox_users2.json').should('be.checked')

// Set both files to unrestricted
cy.findByRole('button', { name: 'Edit files' }).click()
cy.findByTestId('unrestrict-selected').click()
cy.findByTestId('restricted_checkbox_users1.json').should('not.be.checked')
cy.findByTestId('restricted_checkbox_users2.json').should('not.be.checked')

// Select Restrict, but don't save changes in the Modal.
// The changes should not be applied.
cy.findByRole('button', { name: 'Edit files' }).click()
cy.findByTestId('restrict-selected').click()
cy.findByLabelText('Close').click()
cy.get('[type="checkbox"]').last().should('not.be.checked')
cy.findByText('Edit files').first().click()
cy.findByText('Restrict').first().click()
cy.get('[type="checkbox"]').last().click()
cy.get('textarea').last().type('Hello, World!')
cy.findByText('Save Changes').first().click()
cy.get('[type="checkbox"]').last().should('be.checked')
cy.findByText('Edit files').first().click()
cy.findByText('Restrict').first().click()
cy.findByTestId('restricted_checkbox_users1.json').should('not.be.checked')
cy.findByTestId('restricted_checkbox_users2.json').should('not.be.checked')

// Select Restrict, and add a reason,then save changes in the Modal.
cy.findByRole('button', { name: 'Edit files' }).click()
cy.findByTestId('restrict-selected').click()
cy.findByTestId('enable-access-request-checkbox').click()
cy.findByTestId('terms-of-access-textarea').type('Hello, World!')
cy.findByText('Save Changes').click()
cy.findByTestId('restricted_checkbox_users1.json').should('be.checked')
cy.findByTestId('restricted_checkbox_users2.json').should('be.checked')

// Select Restrict, cancel changes in the Modal. The changes should not be applied.
cy.findByRole('button', { name: 'Edit files' }).click()
cy.findByTestId('restrict-selected').click()
cy.findByTitle('Cancel Changes').click()
cy.get('[type="checkbox"]').last().should('be.checked')
cy.get('[type="checkbox"]').first().click()
cy.get('[type="checkbox"]').first().click()
cy.findByText('Edit files').first().click()
cy.findByTitle('Delete selected').click()
cy.findByTestId('restricted_checkbox_users1.json').should('be.checked')
cy.findByTestId('restricted_checkbox_users2.json').should('be.checked')

cy.get('input[value="users1.json"]').should('exist')
cy.get('input[value="users2.json"]').should('exist')
cy.findByRole('button', { name: 'Edit files' }).click()
cy.findByTestId('delete-selected').click()
cy.get('input[value="users1.json"]').should('not.exist')
cy.get('input[value="users2.json"]').should('not.exist')
})
Expand Down

0 comments on commit 59056b0

Please sign in to comment.