Skip to content

Commit

Permalink
Merge pull request #493 from IQSS/485-create-dataset-url
Browse files Browse the repository at this point in the history
485 create dataset url
  • Loading branch information
ekraffmiller authored Sep 18, 2024
2 parents e405c09 + c9a36cd commit c6c5144
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ describe('Create Dataset', () => {
})
it('navigates to the new dataset after submitting a valid form', () => {
cy.visit('/spa/datasets/create')
cy.visit('/spa/datasets/root/create')
cy.findByLabelText(/Title/i).type('Test Dataset Title')
cy.findByLabelText(/Author Name/i).type('Test author name', { force: true })
Expand Down
6 changes: 4 additions & 2 deletions src/sections/Route.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export enum Route {
LOG_IN = '/loginpage.xhtml?redirectPage=%2Fdataverse.xhtml',
LOG_OUT = '/',
DATASETS = '/datasets',
CREATE_DATASET = '/datasets/create',
CREATE_DATASET = '/datasets/:collectionId/create',
UPLOAD_DATASET_FILES = '/datasets/upload-files',
EDIT_DATASET_METADATA = '/datasets/edit-metadata',
FILES = '/files',
Expand All @@ -19,7 +19,9 @@ export enum Route {
export const RouteWithParams = {
COLLECTIONS: (collectionId?: string) => `/collections/${collectionId ?? 'root'}`,
CREATE_COLLECTION: (ownerCollectionId?: string) =>
`/collections/${ownerCollectionId ?? ROOT_COLLECTION_ALIAS}/create`
`/collections/${ownerCollectionId ?? ROOT_COLLECTION_ALIAS}/create`,
CREATE_DATASET: (collectionId?: string) =>
`/datasets/${collectionId ?? ROOT_COLLECTION_ALIAS}/create`
}

export enum QueryParamKey {
Expand Down
5 changes: 2 additions & 3 deletions src/sections/create-dataset/CreateDatasetFactory.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReactElement } from 'react'
import { useSearchParams } from 'react-router-dom'
import { useParams } from 'react-router-dom'
import { CreateDataset } from './CreateDataset'
import { DatasetJSDataverseRepository } from '../../dataset/infrastructure/repositories/DatasetJSDataverseRepository'
import { MetadataBlockInfoJSDataverseRepository } from '../../metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository'
Expand All @@ -21,8 +21,7 @@ export class CreateDatasetFactory {
}

function CreateDatasetWithSearchParams() {
const [searchParams] = useSearchParams()
const collectionId = searchParams.get('collectionId') ?? undefined
const { collectionId } = useParams<{ collectionId: string }>()

return (
<CreateDataset
Expand Down
8 changes: 3 additions & 5 deletions src/sections/layout/header/LoggedInHeaderActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Link, useNavigate } from 'react-router-dom'
import { Navbar } from '@iqss/dataverse-design-system'
import { useGetCollectionUserPermissions } from '../../../shared/hooks/useGetCollectionUserPermissions'
import { useSession } from '../../session/SessionContext'
import { Route, RouteWithParams } from '../../Route.enum'
import { RouteWithParams } from '../../Route.enum'
import { User } from '../../../users/domain/models/User'
import { CollectionRepository } from '../../../collection/domain/repositories/CollectionRepository'
import { ROOT_COLLECTION_ALIAS } from '../../../collection/domain/models/Collection'
Expand Down Expand Up @@ -36,6 +36,7 @@ export const LoggedInHeaderActions = ({
}

const createCollectionRoute = RouteWithParams.CREATE_COLLECTION()
const createDatasetRoute = RouteWithParams.CREATE_DATASET()

const canUserAddCollectionToRoot = Boolean(collectionUserPermissions?.canAddCollection)
const canUserAddDatasetToRoot = Boolean(collectionUserPermissions?.canAddDataset)
Expand All @@ -49,10 +50,7 @@ export const LoggedInHeaderActions = ({
disabled={!canUserAddCollectionToRoot}>
{t('navigation.newCollection')}
</Navbar.Dropdown.Item>
<Navbar.Dropdown.Item
as={Link}
to={Route.CREATE_DATASET}
disabled={!canUserAddDatasetToRoot}>
<Navbar.Dropdown.Item as={Link} to={createDatasetRoute} disabled={!canUserAddDatasetToRoot}>
{t('navigation.newDataset')}
</Navbar.Dropdown.Item>
</Navbar.Dropdown>
Expand Down
7 changes: 2 additions & 5 deletions src/sections/shared/add-data-actions/AddDataActionsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Dropdown } from 'react-bootstrap'
import { Link } from 'react-router-dom'
import { DropdownButton } from '@iqss/dataverse-design-system'
import { PlusLg } from 'react-bootstrap-icons'
import { Route, RouteWithParams } from '../../Route.enum'
import { RouteWithParams } from '../../Route.enum'
import styles from './AddDataActionsButton.module.scss'

interface AddDataActionsButtonProps {
Expand All @@ -19,11 +19,8 @@ export default function AddDataActionsButton({
}: AddDataActionsButtonProps) {
const { t } = useTranslation('header')

const createDatasetRoute = collectionId
? `${Route.CREATE_DATASET}?collectionId=${collectionId}`
: Route.CREATE_DATASET

const createCollectionRoute = RouteWithParams.CREATE_COLLECTION(collectionId)
const createDatasetRoute = RouteWithParams.CREATE_DATASET(collectionId)

return (
<DropdownButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('AddDataActionsButton', () => {
cy.findByRole('button', { name: /Add Data/i }).click()
cy.findByText('New Dataset')
.should('be.visible')
.should('have.attr', 'href', '/datasets/create')
.should('have.attr', 'href', '/datasets/root/create')
})

it('renders the new dataset button with the correct generated link for specified collectionId', () => {
Expand All @@ -32,7 +32,7 @@ describe('AddDataActionsButton', () => {
cy.findByRole('button', { name: /Add Data/i }).click()
cy.findByText('New Dataset')
.should('be.visible')
.should('have.attr', 'href', `/datasets/create?collectionId=${collectionId}`)
.should('have.attr', 'href', `/datasets/${collectionId}/create`)
})

it('shows New Collection button enabled if user has permissions to create collection', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ describe('Create Dataset', () => {
})

it('visits the Create Dataset Page as a logged in user', () => {
cy.visit('/spa/datasets/create')
cy.visit('/spa/datasets/root/create')

cy.findByRole('heading', { name: 'Create Dataset' }).should('exist')
})

it('navigates to the new dataset after submitting a valid form', () => {
cy.visit('/spa/datasets/create')
cy.visit('/spa/datasets/root/create')

cy.findByLabelText(/^Title/i).type('Test Dataset Title', { force: true })

Expand All @@ -44,7 +44,7 @@ describe('Create Dataset', () => {
})

it('navigates to the home if the user cancels the form', () => {
cy.visit('/spa/datasets/create')
cy.visit('/spa/datasets/root/create')

cy.findByText(/Cancel/i).click()

Expand Down

0 comments on commit c6c5144

Please sign in to comment.