Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

134 - Files table UI [1/2] - Integration display data #169

Merged
merged 41 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
dff245e
feat(FilesIntegration): create files for integration tests
MellyGray Aug 24, 2023
47cf74a
feat(FilesIntegration): add first integration test for the FileJSData…
MellyGray Aug 24, 2023
cc4e02a
fix: change fileId from string to number
MellyGray Aug 25, 2023
451a95a
feat(FilesVersion): refactor files version
MellyGray Aug 25, 2023
626ef64
feat(FilesTabIntegration): add mapper function to get the file version
MellyGray Aug 25, 2023
0eddceb
fix(Dataset): refactor DatasetVersion and use cases requiring this data
MellyGray Aug 25, 2023
2759453
feat(FilesIntegration): add deaccessioned to DatasetHelper for the in…
MellyGray Aug 25, 2023
db9f168
feat(FilesIntegration): add FileAccess to mapper
MellyGray Aug 28, 2023
ab4fcc8
feat(FilesIntegration): add FileType to mapper
MellyGray Aug 28, 2023
688011a
feat(FilesIntegration): add FileSize to mapper
MellyGray Aug 28, 2023
d690796
feat(FilesIntegration): add FileDate to mapper
MellyGray Aug 28, 2023
ae8c476
feat(FilesIntegration): add downloadCount to mapper
MellyGray Aug 28, 2023
5be48de
feat(FilesIntegration): add FileLabels to mapper
MellyGray Aug 28, 2023
cfd9685
feat(FilesIntegration): add FileChecksum to mapper
MellyGray Aug 28, 2023
6d427f5
feat(FilesIntegration): add directory to mapper
MellyGray Aug 28, 2023
1ea6e61
feat(FilesIntegration): add embargo to mapper
MellyGray Aug 28, 2023
6e1ed38
feat(FilesIntegration): add tabularData to mapper
MellyGray Aug 29, 2023
afd8d78
feat(FilesIntegration): add description to mapper
MellyGray Aug 29, 2023
b2b33ec
feat(FilesTable): fix responsive
MellyGray Aug 29, 2023
2e9cdcf
fix(FilesTable): some fixes for the integration
MellyGray Aug 29, 2023
f3f1edf
feat(FileUserPermissions): connect to js-dataverse implementation
MellyGray Aug 29, 2023
e0d46c1
feat(FilesIntegration): add sortBy test
MellyGray Aug 29, 2023
6298401
feat(FilesIntegration): add pagnationInfo test
MellyGray Aug 29, 2023
ce0da7d
feat(FilesIntegration): add tabularTags test
MellyGray Aug 29, 2023
8193a7e
fix: use DataverseApiHelper in the e2e tests
MellyGray Aug 30, 2023
4898310
feat(FilesIntegration): add e2e tests
MellyGray Aug 30, 2023
769b8b2
fix: integration tests for the tabular tags
MellyGray Aug 30, 2023
cfdbd29
fix: useFiles to prevent unnecessary calls to the use case
MellyGray Aug 30, 2023
5048552
fix(e2e action): change dataverse image tag
MellyGray Aug 30, 2023
d1ff31a
fix(e2e action): restore unstable dataverse image tag
MellyGray Aug 30, 2023
e909312
Fixed: dev.Dockerfile to avoid package installation issues
GPortas Sep 15, 2023
0be7171
fix: remove debugging log
MellyGray Sep 18, 2023
8cdf2bc
fix: remove debugging error log
MellyGray Sep 18, 2023
d989455
fix: remove outdated TODO
MellyGray Sep 18, 2023
7eb7638
fix(FileDate): replicate jsf date format
MellyGray Sep 18, 2023
ec26f1c
fix(FileChecksum): correctly display the truncated checksum
MellyGray Sep 18, 2023
b0cbf6e
fix(FileSize): should return only 1 decimal place
MellyGray Sep 18, 2023
4f89035
fix(SortByButton): bold selected option
MellyGray Sep 18, 2023
cb5cc72
fix: embargo e2e test
MellyGray Sep 19, 2023
0363f22
Merge branch 'feature/159-manage-user-permissions-files' of https://g…
MellyGray Sep 20, 2023
ec7e914
fix(Checksum): add spacing to the button
MellyGray Sep 20, 2023
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
Prev Previous commit
Next Next commit
feat(FilesVersion): refactor files version
  • Loading branch information
MellyGray committed Aug 25, 2023
commit 451a95a06e528ac5e90ebada6fea708b5074b8ae
17 changes: 5 additions & 12 deletions src/files/domain/models/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,15 @@ export interface FileAccess {
requested: boolean
}

export enum FileStatus {
export enum FilePublishingStatus {
DRAFT = 'draft',
RELEASED = 'released',
DEACCESSIONED = 'deaccessioned'
}

export class FileVersion {
constructor(
public readonly majorNumber: number,
public readonly minorNumber: number,
public readonly status: FileStatus
) {}

toString(): string {
return `${this.majorNumber}.${this.minorNumber}`
}
export interface FileVersion {
number: number
publishingStatus: FilePublishingStatus
}

export enum FileDateType {
Expand Down Expand Up @@ -125,7 +118,7 @@ export class File {
) {}

getLink(): string {
return `/file?id=${this.id}&version=${this.version.toString()}`
return `/file?id=${this.id}&version=${this.version.number}`
}

get isActivelyEmbargoed(): boolean {
Expand Down
4 changes: 2 additions & 2 deletions src/files/domain/useCases/checkFileDownloadPermission.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { FileRepository } from '../repositories/FileRepository'
import { File, FileStatus } from '../models/File'
import { File, FilePublishingStatus } from '../models/File'

export async function checkFileDownloadPermission(
fileRepository: FileRepository,
file: File
): Promise<boolean> {
if (file.version.status === FileStatus.DEACCESSIONED) {
if (file.version.publishingStatus === FilePublishingStatus.DEACCESSIONED) {
return fileRepository.getFileUserPermissionsById(file.id).then((permissions) => {
return permissions.canEditDataset
})
Expand Down
7 changes: 3 additions & 4 deletions src/files/infrastructure/mappers/JSFileMapper.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import {
File,
FileDateType,
FilePublishingStatus,
FileSize,
FileSizeUnit,
FileStatus,
FileType,
FileVersion
FileType
} from '../../domain/models/File'
import { File as JSFile } from '@iqss/dataverse-client-javascript'

export class JSFileMapper {
static toFile(jsFile: JSFile): File {
return new File(
jsFile.id,
new FileVersion(1, 0, FileStatus.RELEASED),
{ number: jsFile.version, publishingStatus: FilePublishingStatus.DRAFT },
jsFile.name,
{
restricted: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DropdownButtonItem } from '@iqss/dataverse-design-system'
import styles from './AccessFileMenu.module.scss'
import { RequestAccessModal } from './RequestAccessModal'
import { File, FileStatus } from '../../../../../../../../files/domain/models/File'
import { File, FilePublishingStatus } from '../../../../../../../../files/domain/models/File'
import { useTranslation } from 'react-i18next'
import { useFileDownloadPermission } from '../../../../../../../file/file-permissions/useFileDownloadPermission'

Expand All @@ -12,7 +12,10 @@ export function RequestAccessOption({ file }: RequestAccessButtonProps) {
const { t } = useTranslation('files')
const { sessionUserHasFileDownloadPermission } = useFileDownloadPermission(file)

if (file.version.status === FileStatus.DEACCESSIONED || sessionUserHasFileDownloadPermission) {
if (
file.version.publishingStatus === FilePublishingStatus.DEACCESSIONED ||
sessionUserHasFileDownloadPermission
) {
return <></>
}
if (file.isActivelyEmbargoed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ export function FileInfoCell({ file }: { file: File }) {
<FileDirectory directory={file.directory} />
<FileType type={file.type} size={file.size} />
<FileDate date={file.date} />
<FileEmbargoDate embargo={file.embargo} status={file.version.status} />
<FileDownloads downloads={file.downloads} status={file.version.status} />
<FileEmbargoDate
embargo={file.embargo}
publishingStatus={file.version.publishingStatus}
/>
<FileDownloads
downloads={file.downloads}
publishingStatus={file.version.publishingStatus}
/>
<FileChecksum checksum={file.checksum} />
<FileTabularData tabularData={file.tabularData} />
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { FileStatus } from '../../../../../../../files/domain/models/File'
import { FilePublishingStatus } from '../../../../../../../files/domain/models/File'
import { useTranslation } from 'react-i18next'

interface FileDownloadsProps {
downloads: number
status: FileStatus
publishingStatus: FilePublishingStatus
}
export function FileDownloads({ downloads, status }: FileDownloadsProps) {
export function FileDownloads({ downloads, publishingStatus }: FileDownloadsProps) {
const { t } = useTranslation('files')
if (status !== FileStatus.RELEASED) {
if (publishingStatus !== FilePublishingStatus.RELEASED) {
return <></>
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { FileEmbargo, FileStatus } from '../../../../../../../files/domain/models/File'
import { FileEmbargo, FilePublishingStatus } from '../../../../../../../files/domain/models/File'
import { useTranslation } from 'react-i18next'

interface FileEmbargoDateProps {
embargo: FileEmbargo | undefined
status: FileStatus
publishingStatus: FilePublishingStatus
}

export function FileEmbargoDate({ embargo, status }: FileEmbargoDateProps) {
export function FileEmbargoDate({ embargo, publishingStatus }: FileEmbargoDateProps) {
const { t } = useTranslation('files')

if (!embargo) {
Expand All @@ -16,14 +16,15 @@ export function FileEmbargoDate({ embargo, status }: FileEmbargoDateProps) {
return (
<div>
<span>
{t(embargoTypeOfDate(embargo.isActive, status))} {embargo.dateAvailable.toDateString()}
{t(embargoTypeOfDate(embargo.isActive, publishingStatus))}{' '}
{embargo.dateAvailable.toDateString()}
</span>
</div>
)
}

const embargoTypeOfDate = (embargoIsActive: boolean, status: FileStatus) => {
if (status === FileStatus.RELEASED) {
const embargoTypeOfDate = (embargoIsActive: boolean, publishingStatus: FilePublishingStatus) => {
if (publishingStatus === FilePublishingStatus.RELEASED) {
return embargoIsActive
? 'table.embargoDate.embargoedUntil'
: 'table.embargoDate.embargoedWasThrough'
Expand Down
26 changes: 9 additions & 17 deletions tests/component/files/domain/models/FileMother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import {
FileLabelType,
FileSize,
FileSizeUnit,
FileStatus,
FileType,
FileVersion
FilePublishingStatus,
FileType
} from '../../../../../src/files/domain/models/File'

const valueOrUndefined: <T>(value: T) => T | undefined = (value) => {
Expand Down Expand Up @@ -49,9 +48,8 @@ export class FileMother {
requested: faker.datatype.boolean()
},
version: {
majorNumber: faker.datatype.number(),
minorNumber: faker.datatype.number(),
status: faker.helpers.arrayElement(Object.values(FileStatus))
number: faker.datatype.number(),
publishingStatus: faker.helpers.arrayElement(Object.values(FilePublishingStatus))
},
type: new FileType(thumbnail ? 'image' : fileType),
size: {
Expand Down Expand Up @@ -89,11 +87,7 @@ export class FileMother {

return new File(
fileMockedData.id,
new FileVersion(
fileMockedData.version.majorNumber,
fileMockedData.version.minorNumber,
fileMockedData.version.status
),
fileMockedData.version,
fileMockedData.name,
fileMockedData.access,
fileMockedData.type,
Expand All @@ -118,9 +112,8 @@ export class FileMother {
const defaultFile = {
type: new FileType('file'),
version: {
majorNumber: 1,
minorNumber: 0,
status: FileStatus.RELEASED
number: 1,
publishingStatus: FilePublishingStatus.RELEASED
},
access: {
restricted: false,
Expand Down Expand Up @@ -304,9 +297,8 @@ export class FileMother {
static createDeaccessioned(): File {
return this.createDefault({
version: {
majorNumber: 1,
minorNumber: 0,
status: FileStatus.DEACCESSIONED
number: 1,
publishingStatus: FilePublishingStatus.DEACCESSIONED
}
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { FileStatus } from '../../../../../../../../../src/files/domain/models/File'
import { FilePublishingStatus } from '../../../../../../../../../src/files/domain/models/File'
import { FileDownloads } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileDownloads'

describe('FileDownloads', () => {
it('renders the number of downloads when file is RELEASED', () => {
const downloads = 10
const status = FileStatus.RELEASED
cy.customMount(<FileDownloads downloads={downloads} status={status} />)
const status = FilePublishingStatus.RELEASED
cy.customMount(<FileDownloads downloads={downloads} publishingStatus={status} />)

cy.findByText('10 Downloads').should('exist')
})

it('renders an empty fragment when file is not RELEASED', () => {
const downloads = 10
const status = FileStatus.DRAFT
cy.customMount(<FileDownloads downloads={downloads} status={status} />)
const status = FilePublishingStatus.DRAFT
cy.customMount(<FileDownloads downloads={downloads} publishingStatus={status} />)

cy.findByText('10 Downloads').should('not.exist')
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { FileEmbargoDate } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileEmbargoDate'
import { FileStatus } from '../../../../../../../../../src/files/domain/models/File'
import { FilePublishingStatus } from '../../../../../../../../../src/files/domain/models/File'
import { FileEmbargoMother } from '../../../../../../../files/domain/models/FileMother'

describe('FileEmbargoDate', () => {
it('renders the embargo date when embargo exists', () => {
const embargo = FileEmbargoMother.create()
const status = FileStatus.RELEASED
cy.customMount(<FileEmbargoDate embargo={embargo} status={status} />)
const status = FilePublishingStatus.RELEASED
cy.customMount(<FileEmbargoDate embargo={embargo} publishingStatus={status} />)

cy.findByText(`Embargoed until ${embargo.dateAvailable.toDateString()}`).should('exist')
})

it('renders the until embargo date when embargo is not active and the file is not released', () => {
const embargo = FileEmbargoMother.createNotActive()
const status = FileStatus.RELEASED
const status = FilePublishingStatus.RELEASED

cy.customMount(<FileEmbargoDate embargo={embargo} status={status} />)
cy.customMount(<FileEmbargoDate embargo={embargo} publishingStatus={status} />)

cy.findByText(`Was embargoed until ${embargo.dateAvailable.toDateString()}`).should('exist')
})

it('renders the draft until embargo date when embargo is active and the file is not released', () => {
const embargo = FileEmbargoMother.create()
const status = FileStatus.DRAFT
const status = FilePublishingStatus.DRAFT

cy.customMount(<FileEmbargoDate embargo={embargo} status={status} />)
cy.customMount(<FileEmbargoDate embargo={embargo} publishingStatus={status} />)

cy.findByText(`Draft: will be embargoed until ${embargo.dateAvailable.toDateString()}`).should(
'exist'
Expand All @@ -33,9 +33,9 @@ describe('FileEmbargoDate', () => {

it('renders an empty fragment when embargo is undefined', () => {
const embargo = undefined
const status = FileStatus.RELEASED
const status = FilePublishingStatus.RELEASED

cy.customMount(<FileEmbargoDate embargo={embargo} status={status} />)
cy.customMount(<FileEmbargoDate embargo={embargo} publishingStatus={status} />)

cy.findByText(/Draft: will be embargoed until/).should('not.exist')
cy.findByText(/Embargoed until/).should('not.exist')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FileMother } from '../../../../../../../files/domain/models/FileMother'
import { FileTitle } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-info/file-info-cell/file-info-data/FileTitle'
import { FileStatus } from '../../../../../../../../../src/files/domain/models/File'
import { FilePublishingStatus } from '../../../../../../../../../src/files/domain/models/File'

describe('FileTitle', () => {
it('renders the link and name correctly', () => {
Expand All @@ -9,7 +9,7 @@ describe('FileTitle', () => {
const name = 'file-name.txt'
const file = FileMother.create({
id: id,
version: { majorNumber: 1, minorNumber: 0, status: FileStatus.RELEASED },
version: { majorNumber: 1, minorNumber: 0, status: FilePublishingStatus.RELEASED },
name: name
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import {
FileDateType,
FileSize,
FileSizeUnit,
FileStatus,
FileType,
FileVersion
FilePublishingStatus,
FileType
} from '../../../../src/files/domain/models/File'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
Expand All @@ -19,7 +18,7 @@ const expect = chai.expect
const fileRepository = new FileJSDataverseRepository()
const expectedFile = new File(
1,
new FileVersion(1, 0, FileStatus.RELEASED),
{ number: 1, publishingStatus: FilePublishingStatus.DRAFT },
'blob',
{
restricted: false,
Expand Down