Skip to content

Commit

Permalink
feat: dropdown ready
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Nov 7, 2024
1 parent 61f1d38 commit ada39ff
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { PropsWithChildren } from 'react'
import { Dropdown } from 'react-bootstrap'

export function DropdownHeader({ children }: PropsWithChildren) {
return <Dropdown.Header>{children}</Dropdown.Header>
interface DropdownHeaderProps {
className?: string
children: React.ReactNode
}

export function DropdownHeader({ className, children }: DropdownHeaderProps) {
return <Dropdown.Header className={className}>{children}</Dropdown.Header>
}
6 changes: 5 additions & 1 deletion public/locales/en/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@
"question": "Are you sure you want to publish your collection? Once you do so it must remain published.",
"error": "There was an error publishing your collection."
},
"publishedAlert": "Your collection is now public."
"publishedAlert": "Your collection is now public.",
"editCollection": {
"edit": "Edit",
"generalInfo": "General Information"
}
}
26 changes: 18 additions & 8 deletions src/sections/collection/Collection.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useTranslation } from 'react-i18next'
import { Alert, Col, Row } from '@iqss/dataverse-design-system'
import { Alert, ButtonGroup, Col, Row } from '@iqss/dataverse-design-system'

import { CollectionRepository } from '../../collection/domain/repositories/CollectionRepository'
import { useCollection } from './useCollection'
import { useScrollTop } from '../../shared/hooks/useScrollTop'
Expand All @@ -14,6 +15,7 @@ import { CollectionSkeleton } from './CollectionSkeleton'
import { PageNotFound } from '../page-not-found/PageNotFound'
import { CreatedAlert } from './CreatedAlert'
import { PublishCollectionButton } from './publish-collection/PublishCollectionButton'
import { EditCollectionDropdown } from './edit-collection-dropdown/EditCollectionDropdown'
import styles from './Collection.module.scss'

interface CollectionProps {
Expand All @@ -33,6 +35,7 @@ export function Collection({
collectionQueryParams
}: CollectionProps) {
useTranslation('collection')
const { t } = useTranslation('collection')
useScrollTop()
const { user } = useSession()
const { collection, isLoading } = useCollection(
Expand All @@ -46,11 +49,13 @@ export function Collection({
})

const canUserAddCollection = Boolean(collectionUserPermissions?.canAddCollection)
const canUserEditCollection = Boolean(collectionUserPermissions?.canEditCollection)
const canUserAddDataset = Boolean(collectionUserPermissions?.canAddDataset)
const canUserPublishCollection = user && Boolean(collectionUserPermissions?.canPublishCollection)
const canUserPublishCollection = Boolean(collectionUserPermissions?.canPublishCollection)

const showAddDataActions = Boolean(user && (canUserAddCollection || canUserAddDataset))
const { t } = useTranslation('collection')
const showPublishButton = user && !collection?.isReleased && canUserPublishCollection
const showEditButton = user && canUserEditCollection

if (!isLoading && !collection) {
return <PageNotFound />
Expand All @@ -71,12 +76,17 @@ export function Collection({
{t('publishedAlert')}
</Alert>
)}
{!collection.isReleased && canUserPublishCollection && (
{(showPublishButton || showEditButton) && (
<div className={styles['action-buttons']}>
<PublishCollectionButton
repository={collectionRepository}
collectionId={collection.id}
/>
<ButtonGroup>
{showPublishButton && (
<PublishCollectionButton
repository={collectionRepository}
collectionId={collection.id}
/>
)}
{showEditButton && <EditCollectionDropdown collection={collection} />}
</ButtonGroup>
</div>
)}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@import 'node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module';

.dropdown-icon {
margin-right: 0.3rem;
margin-bottom: 0.2rem;
}

.dropdown-header {
display: flex;
gap: 12px;
align-items: center;
color: unset;

.collection-alias,
.collection-name {
margin: 0;
}

.collection-name {
font-weight: 600;

span {
color: $dv-subtext-color;
font-weight: 400;
}
}

.collection-alias {
color: $dv-subtext-color;
}

.collection-icon {
height: fit-content;
color: $dv-collection-border-color;

> span {
margin-right: 0;
font-size: 40px;
line-height: 1;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import {
DropdownButton,
DropdownButtonItem,
DropdownHeader,
DropdownSeparator,
Icon,
IconName
} from '@iqss/dataverse-design-system'
import { PencilFill } from 'react-bootstrap-icons'
import { Collection } from '@/collection/domain/models/Collection'
import styles from './EditCollectionDropdown.module.scss'

interface EditCollectionDropdownProps {
collection: Collection
}

export const EditCollectionDropdown = ({ collection }: EditCollectionDropdownProps) => {
const { t } = useTranslation('collection')
const navigate = useNavigate()

const onClickEditGeneralInformation = () => {
navigate('edit-general-information')
}

console.log(collection)

return (
<DropdownButton
id="edit-collection-dropdown"
title={t('editCollection.edit')}
asButtonGroup
variant="secondary"
icon={<PencilFill className={styles['dropdown-icon']} />}>
<DropdownHeader className={styles['dropdown-header']}>
<div className={styles['collection-icon']}>
<Icon name={IconName.COLLECTION} />
</div>
<div>
<p className={styles['collection-name']}>
{collection.name}{' '}
{collection.affiliation ? <span>({collection.affiliation})</span> : null}
</p>
<p className={styles['collection-alias']}>{collection.id}</p>
</div>
</DropdownHeader>
<DropdownSeparator />
<DropdownButtonItem onClick={onClickEditGeneralInformation}>
{t('editCollection.generalInfo')}
</DropdownButtonItem>
</DropdownButton>
)
}

0 comments on commit ada39ff

Please sign in to comment.