-
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.
feat(DatasetActionButtons): add EditDatasetMenu component
- Loading branch information
Showing
22 changed files
with
518 additions
and
27 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
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
18 changes: 18 additions & 0 deletions
18
src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.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,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> | ||
</> | ||
) | ||
} |
25 changes: 25 additions & 0 deletions
25
src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDatasetButton.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,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> | ||
</> | ||
) | ||
} |
38 changes: 38 additions & 0 deletions
38
src/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.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,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> | ||
) | ||
} |
46 changes: 46 additions & 0 deletions
46
src/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetPermissionsMenu.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,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> | ||
) | ||
} |
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 @@ | ||
export type HasPublicStore = boolean |
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
1 change: 0 additions & 1 deletion
1
src/stories/dataset/dataset-action-buttons/DatasetActionButtons.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
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.