Skip to content

Commit

Permalink
feat(DatasetActionButtons): add EditDatasetMenu component
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Sep 12, 2023
1 parent c295c7b commit 1c4ab2d
Show file tree
Hide file tree
Showing 22 changed files with 518 additions and 27 deletions.
31 changes: 22 additions & 9 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ export class DatasetVersion {
public readonly minorNumber: number,
public readonly status: DatasetStatus,
public readonly isLatest: boolean,
public readonly isInReview: boolean
public readonly isInReview: boolean,
public readonly latestVersionStatus: DatasetStatus
) {}

toString(): string {
Expand All @@ -222,6 +223,9 @@ export interface DatasetPermissions {
canDownloadFiles: boolean
canUpdateDataset: boolean
canPublishDataset: boolean
canManageDatasetPermissions: boolean
canManageFilesPermissions: boolean
canDeleteDataset: boolean
}

export interface DatasetLock {
Expand Down Expand Up @@ -251,19 +255,16 @@ export class Dataset {
public readonly license: DatasetLicense,
public readonly metadataBlocks: DatasetMetadataBlocks,
public readonly permissions: DatasetPermissions,
public readonly locks: DatasetLock[]
public readonly locks: DatasetLock[],
public readonly hasValidTermsOfAccess: boolean
) {}

public getTitle(): string {
return this.metadataBlocks[0].fields.title
}

public get isLockedFromPublishing(): boolean {
const lockedReasonIsInReview = this.locks.some(
(lock) => lock.reason === DatasetLockReason.IN_REVIEW
)

return this.isLocked && !(lockedReasonIsInReview && this.permissions.canPublishDataset)
return this.isLockedFromEdits
}

public get isLocked(): boolean {
Expand All @@ -274,6 +275,16 @@ export class Dataset {
return this.locks.some((lock) => lock.reason === DatasetLockReason.WORKFLOW)
}

public get isLockedFromEdits(): boolean {
const lockedReasonIsInReview = this.locks.some(
(lock) => lock.reason === DatasetLockReason.IN_REVIEW
)
// If the lock reason is workflow and the workflow userId is the same as the current user, then the user can edit
// TODO - Ask how we want to manage pending workflows

return this.isLocked && !(lockedReasonIsInReview && this.permissions.canPublishDataset)
}

static Builder = class {
public readonly labels: DatasetLabel[] = []

Expand All @@ -285,7 +296,8 @@ export class Dataset {
public readonly license: DatasetLicense = defaultLicense,
public readonly metadataBlocks: DatasetMetadataBlocks,
public readonly permissions: DatasetPermissions,
public readonly locks: DatasetLock[]
public readonly locks: DatasetLock[],
public readonly hasValidTermsOfAccess: boolean
) {
this.withLabels()
}
Expand Down Expand Up @@ -345,7 +357,8 @@ export class Dataset {
this.license,
this.metadataBlocks,
this.permissions,
this.locks
this.locks,
this.hasValidTermsOfAccess
)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class JSDatasetMapper {
jsDatasetVersionInfo.minorNumber,
JSDatasetMapper.toStatus(jsDatasetVersionInfo.state),
false,
false,
false
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AccessDatasetMenu } from './access-dataset-menu/AccessDatasetMenu'
import { PublishDatasetMenu } from './publish-dataset-menu/PublishDatasetMenu'
import styles from './DatasetActionButtons.module.scss'
import { SubmitForReviewButton } from './submit-for-review-button/SubmitForReviewButton'
import { EditDatasetMenu } from './edit-dataset-menu/EditDatasetMenu'

interface DatasetActionButtonsProps {
dataset: Dataset
Expand All @@ -15,6 +16,7 @@ export function DatasetActionButtons({ dataset }: DatasetActionButtonsProps) {
<AccessDatasetMenu version={dataset.version} permissions={dataset.permissions} />
<PublishDatasetMenu dataset={dataset} />
<SubmitForReviewButton dataset={dataset} />
<EditDatasetMenu dataset={dataset} />
</ButtonGroup>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Dataset, DatasetStatus } from '../../../../dataset/domain/models/Dataset'
import { DropdownButtonItem, DropdownSeparator } from '@iqss/dataverse-design-system'

interface DeaccessionDatasetButtonProps {
dataset: Dataset
}
export function DeaccessionDatasetButton({ dataset }: DeaccessionDatasetButtonProps) {
if (dataset.version.status !== DatasetStatus.RELEASED || !dataset.permissions.canPublishDataset) {
return <></>
}

return (
<>
<DropdownSeparator />
<DropdownButtonItem>Deaccession Dataset</DropdownButtonItem>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Dataset, DatasetStatus } from '../../../../dataset/domain/models/Dataset'
import { DropdownButtonItem, DropdownSeparator } from '@iqss/dataverse-design-system'

interface DeleteDatasetButtonProps {
dataset: Dataset
}
export function DeleteDatasetButton({ dataset }: DeleteDatasetButtonProps) {
if (
!dataset.permissions.canDeleteDataset ||
dataset.version.latestVersionStatus !== DatasetStatus.DRAFT
) {
return <></>
}

return (
<>
<DropdownSeparator />
<DropdownButtonItem>
{dataset.version.status === DatasetStatus.RELEASED
? 'Delete Draft Version'
: 'Delete Dataset'}
</DropdownButtonItem>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Dataset } from '../../../../dataset/domain/models/Dataset'
import { DropdownButton, DropdownButtonItem } from '@iqss/dataverse-design-system'
import { EditDatasetPermissionsMenu } from './EditDatasetPermissionsMenu'
import { DeleteDatasetButton } from './DeleteDatasetButton'
import { DeaccessionDatasetButton } from './DeaccessionDatasetButton'

interface EditDatasetMenuProps {
dataset: Dataset
}

export function EditDatasetMenu({ dataset }: EditDatasetMenuProps) {
if (!dataset.permissions.canUpdateDataset) {
return <></>
}

return (
<DropdownButton
id={`edit-dataset-menu`}
title="Edit Dataset"
asButtonGroup
variant="secondary"
disabled={dataset.isLockedFromEdits}>
<DropdownButtonItem disabled={!dataset.hasValidTermsOfAccess}>
Files (Upload)
</DropdownButtonItem>
<DropdownButtonItem disabled={!dataset.hasValidTermsOfAccess}>Metadata</DropdownButtonItem>
<DropdownButtonItem>Terms</DropdownButtonItem>
<EditDatasetPermissionsMenu dataset={dataset} />
{(dataset.permissions.canManageDatasetPermissions ||
dataset.permissions.canManageFilesPermissions) && (
<DropdownButtonItem>Private URL</DropdownButtonItem>
)}
<DropdownButtonItem>Thumbnails + Widgets</DropdownButtonItem>
<DeleteDatasetButton dataset={dataset} />
<DeaccessionDatasetButton dataset={dataset} />
</DropdownButton>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Dataset } from '../../../../dataset/domain/models/Dataset'
import { DropdownButton, DropdownButtonItem } from '@iqss/dataverse-design-system'
import { useSettings } from '../../../settings/SettingsContext'
import { useEffect, useState } from 'react'
import { SettingName } from '../../../../settings/domain/models/Setting'
import { HasPublicStore } from '../../../../settings/domain/models/HasPublicStore'

interface EditDatasetPermissionsMenuProps {
dataset: Dataset
}
export function EditDatasetPermissionsMenu({ dataset }: EditDatasetPermissionsMenuProps) {
if (
!dataset.permissions.canManageDatasetPermissions &&
!dataset.permissions.canManageFilesPermissions
) {
return <></>
}

const { getSettingByName } = useSettings()
const [hasPublicStore, setHasPublicStore] = useState<HasPublicStore>(false)

useEffect(() => {
getSettingByName<HasPublicStore>(SettingName.HAS_PUBLIC_STORE)
.then((hasPublicStoreSetting) => {
setHasPublicStore(hasPublicStoreSetting.value)
})
.catch((error) => {
console.error(error)
})
}, [getSettingByName])

if (hasPublicStore) {
return <DropdownButtonItem>Permissions</DropdownButtonItem>
}

return (
<DropdownButton id={`edit-permissions-menu`} title="Permissions" variant="secondary">
{dataset.permissions.canManageDatasetPermissions && (
<DropdownButtonItem>Dataset</DropdownButtonItem>
)}
{dataset.permissions.canManageFilesPermissions && (
<DropdownButtonItem>File</DropdownButtonItem>
)}
</DropdownButton>
)
}
1 change: 1 addition & 0 deletions src/settings/domain/models/HasPublicStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type HasPublicStore = boolean
4 changes: 3 additions & 1 deletion src/settings/domain/models/Setting.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export enum SettingName {
ZIP_DOWNLOAD_LIMIT = 'ZIP_DOWNLOAD_LIMIT',
ALLOWED_EXTERNAL_STATUSES = 'ALLOWED_EXTERNAL_STATUSES'
ALLOWED_EXTERNAL_STATUSES = 'ALLOWED_EXTERNAL_STATUSES',

HAS_PUBLIC_STORE = 'HAS_PUBLIC_STORE'
}

export interface Setting<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/stories/dataset/DatasetMockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const DatasetMockData = (props?: Partial<Dataset>, anonymized = false): D
citation: `${
anonymized ? 'Author name(s) withheld' : 'Bennet, Elizabeth; Darcy, Fitzwilliam'
}, 2023, "Dataset Title", <a href="https://doi.org/10.5072/FK2/BUDNRV" target="_blank">https://doi.org/10.5072/FK2/BUDNRV</a>, Root, V1`,
version: new DatasetVersion(1, 0, DatasetStatus.RELEASED, false, false),
version: new DatasetVersion(1, 0, DatasetStatus.RELEASED, false, false, false),
labels: [
{ value: 'Version 1.0', semanticMeaning: DatasetLabelSemanticMeaning.FILE },
{ value: DatasetLabelValue.DRAFT, semanticMeaning: DatasetLabelSemanticMeaning.DATASET }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Meta, StoryObj } from '@storybook/react'
import { WithI18next } from '../../WithI18next'
import { WithSettings } from '../../WithSettings'
import { WithLayout } from '../../WithLayout'
import { DatasetActionButtons } from '../../../sections/dataset/dataset-action-buttons/DatasetActionButtons'
import {
DatasetMother,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const DraftVersion: Story = {
const dataset = DatasetMockData({
citation:
'Admin, Dataverse, 2023, "Dataset Title", <a href="https://doi.org/10.5072/FK2/BUDNRV" target="_blank">https://doi.org/10.5072/FK2/BUDNRV</a>, Root, DRAFT VERSION',
version: new DatasetVersion(1, 0, DatasetStatus.DRAFT, false, false)
version: new DatasetVersion(1, 0, DatasetStatus.DRAFT, false, false, false)
})

/*
Expand All @@ -52,7 +52,7 @@ export const Deaccessioned: Story = {
const dataset = DatasetMockData({
citation:
'Admin, Dataverse, 2023, "Dataset Title", <a href="https://doi.org/10.5072/FK2/BUDNRV" target="_blank">https://doi.org/10.5072/FK2/BUDNRV</a>, Root, V1 DEACCESSIONED VERSION',
version: new DatasetVersion(1, 0, DatasetStatus.DEACCESSIONED, false, false)
version: new DatasetVersion(1, 0, DatasetStatus.DEACCESSIONED, false, false, false)
})

/*
Expand Down
Loading

0 comments on commit 1c4ab2d

Please sign in to comment.