Skip to content

Commit 5c53570

Browse files
committed
feat(DatasetActionButtons): add ChangeCurationStatusMenu component
1 parent a9b1df2 commit 5c53570

9 files changed

Lines changed: 121 additions & 11 deletions

File tree

src/dataset/domain/models/Dataset.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import exp from 'constants'
2-
31
export enum DatasetLabelSemanticMeaning {
42
DATASET = 'dataset',
53
FILE = 'file',

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
Dataset,
32
DatasetPermissions,
43
DatasetStatus,
54
DatasetVersion
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import {
2+
DropdownButton,
3+
DropdownButtonItem,
4+
DropdownSeparator
5+
} from '@iqss/dataverse-design-system'
6+
import { useSettings } from '../../settings/SettingsContext'
7+
import { useEffect, useState } from 'react'
8+
import { SettingName } from '../../../settings/domain/models/Setting'
9+
import { AllowedExternalStatuses } from '../../../settings/domain/models/AllowedExternalStatuses'
10+
11+
export function ChangeCurationStatusMenu() {
12+
const { getSettingByName } = useSettings()
13+
const [allowedExternalStatuses, setAllowedExternalStatuses] = useState<string[]>([])
14+
useEffect(() => {
15+
getSettingByName<AllowedExternalStatuses>(SettingName.ALLOWED_EXTERNAL_STATUSES)
16+
.then((allowedExternalStatuses) => {
17+
setAllowedExternalStatuses(allowedExternalStatuses.value)
18+
})
19+
.catch((error) => {
20+
console.error(error)
21+
})
22+
}, [getSettingByName])
23+
24+
if (allowedExternalStatuses.length === 0) {
25+
return <></>
26+
}
27+
28+
return (
29+
<DropdownButton
30+
id={`change-curation-status-menu`}
31+
title="Change Curation Status"
32+
asButtonGroup
33+
variant="secondary">
34+
{allowedExternalStatuses.map((status) => (
35+
<DropdownButtonItem key={status}>{status}</DropdownButtonItem>
36+
))}
37+
<DropdownSeparator />
38+
<DropdownButtonItem>Remove Current Status</DropdownButtonItem>
39+
</DropdownButton>
40+
)
41+
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import {
2-
Dataset,
3-
DatasetPermissions,
4-
DatasetStatus,
5-
DatasetVersion
6-
} from '../../../dataset/domain/models/Dataset'
1+
import { Dataset, DatasetStatus } from '../../../dataset/domain/models/Dataset'
72
import { DropdownButton, DropdownButtonItem } from '@iqss/dataverse-design-system'
3+
import { ChangeCurationStatusMenu } from './ChangeCurationStatusMenu'
84

95
interface PublishDatasetMenuProps {
106
dataset: Dataset
@@ -27,6 +23,7 @@ export function PublishDatasetMenu({ dataset }: PublishDatasetMenuProps) {
2723
variant="secondary"
2824
disabled={dataset.isLockedFromPublishing}>
2925
<DropdownButtonItem>Publish</DropdownButtonItem>
26+
<ChangeCurationStatusMenu />
3027
</DropdownButton>
3128
)
3229
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type AllowedExternalStatuses = string[]

src/settings/domain/models/Setting.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export enum SettingName {
2-
ZIP_DOWNLOAD_LIMIT = 'ZIP_DOWNLOAD_LIMIT'
2+
ZIP_DOWNLOAD_LIMIT = 'ZIP_DOWNLOAD_LIMIT',
3+
ALLOWED_EXTERNAL_STATUSES = 'ALLOWED_EXTERNAL_STATUSES'
34
}
45

56
export interface Setting<T> {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { ChangeCurationStatusMenu } from '../../../../../src/sections/dataset/dataset-action-buttons/ChangeCurationStatusMenu'
2+
3+
import { SettingMother } from '../../../settings/domain/models/SettingMother'
4+
import { SettingsProvider } from '../../../../../src/sections/settings/SettingsProvider'
5+
import { SettingRepository } from '../../../../../src/settings/domain/repositories/SettingRepository'
6+
7+
describe('ChangeCurationStatusMenu', () => {
8+
it('renders the ChangeCurationStatusMenu if external statuses are allowed and the user has update dataset permissions', () => {
9+
const settingRepository = {} as SettingRepository
10+
settingRepository.getByName = cy
11+
.stub()
12+
.resolves(SettingMother.createExternalStatusesAllowed(['Author Contacted', 'Privacy Review']))
13+
14+
cy.customMount(
15+
<SettingsProvider repository={settingRepository}>
16+
<ChangeCurationStatusMenu />
17+
</SettingsProvider>
18+
)
19+
20+
cy.findByRole('button', { name: 'Change Curation Status' })
21+
.should('exist')
22+
.should('be.enabled')
23+
.click()
24+
25+
cy.findByRole('button', { name: 'Author Contacted' }).should('exist')
26+
cy.findByRole('button', { name: 'Privacy Review' }).should('exist')
27+
cy.findByRole('button', { name: 'Remove Current Status' }).should('exist')
28+
})
29+
30+
it('does not render the ChangeCurationStatusMenu if external statuses are not allowed', () => {
31+
cy.customMount(<ChangeCurationStatusMenu />)
32+
33+
cy.findByRole('button', { name: 'Change Curation Status' }).should('not.exist')
34+
})
35+
})

tests/component/sections/dataset/dataset-action-buttons/PublishDatasetMenu.spec.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {
55
DatasetVersionMother
66
} from '../../../dataset/domain/models/DatasetMother'
77
import { DatasetLockReason } from '../../../../../src/dataset/domain/models/Dataset'
8+
import { SettingRepository } from '../../../../../src/settings/domain/repositories/SettingRepository'
9+
import { SettingMother } from '../../../settings/domain/models/SettingMother'
10+
import { SettingsProvider } from '../../../../../src/sections/settings/SettingsProvider'
811

912
describe('PublishDatasetMenu', () => {
1013
it('renders the PublishDatasetMenu if is dataset latest version and it is a draft and publishing is allowed', () => {
@@ -16,7 +19,35 @@ describe('PublishDatasetMenu', () => {
1619

1720
cy.customMount(<PublishDatasetMenu dataset={dataset} />)
1821

19-
cy.findByRole('button', { name: 'Publish Dataset' }).should('exist').should('be.enabled')
22+
cy.findByRole('button', { name: 'Publish Dataset' })
23+
.should('exist')
24+
.should('be.enabled')
25+
.click()
26+
27+
cy.findByRole('button', { name: 'Publish' }).should('exist')
28+
})
29+
30+
it('renders the PublishDatasetMenu with the Change Curation Status sub menu', () => {
31+
const dataset = DatasetMother.create({
32+
version: DatasetVersionMother.createDraftAsLatestVersion(),
33+
permissions: DatasetPermissionsMother.createWithPublishingDatasetAllowed(),
34+
locks: []
35+
})
36+
37+
const settingRepository = {} as SettingRepository
38+
settingRepository.getByName = cy
39+
.stub()
40+
.resolves(SettingMother.createExternalStatusesAllowed(['Author Contacted', 'Privacy Review']))
41+
42+
cy.customMount(
43+
<SettingsProvider repository={settingRepository}>
44+
<PublishDatasetMenu dataset={dataset} />
45+
</SettingsProvider>
46+
)
47+
48+
cy.findByRole('button', { name: 'Publish Dataset' }).click()
49+
50+
cy.findByRole('button', { name: 'Change Curation Status' }).should('exist')
2051
})
2152

2253
it('does not render the PublishDatasetMenu if publishing is not allowed', () => {

tests/component/settings/domain/models/SettingMother.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ export class SettingMother {
1515
)
1616
}
1717
}
18+
19+
static createExternalStatusesAllowed(value?: string[]): Setting<string[]> {
20+
return {
21+
name: SettingName.ALLOWED_EXTERNAL_STATUSES,
22+
value: value ? value : [faker.datatype.string(), faker.datatype.string()]
23+
}
24+
}
1825
}

0 commit comments

Comments
 (0)