Skip to content

Commit

Permalink
refactor: change general info for just edit collection
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Nov 11, 2024
1 parent 9cd8bea commit b21977b
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 32 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/collection/domain/repositories/CollectionRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export interface CollectionRepository {
paginationInfo: CollectionItemsPaginationInfo,
searchCriteria?: CollectionSearchCriteria
): Promise<CollectionItemSubset>
editGeneralInfo(collectionIdOrAlias: string, updatedCollection: CollectionDTO): Promise<void>
edit(collectionIdOrAlias: string, updatedCollection: CollectionDTO): Promise<void>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import { WriteError } from '@iqss/dataverse-client-javascript'
import { CollectionRepository } from '../repositories/CollectionRepository'
import { CollectionDTO } from './DTOs/CollectionDTO'

export async function editCollectionGeneralInfo(
export async function editCollection(
collectionRepository: CollectionRepository,
collectionId: string,
updatedCollection: CollectionDTO
): Promise<void> {
return collectionRepository
.editGeneralInfo(collectionId, updatedCollection)
.catch((error: WriteError) => {
throw error
})
return collectionRepository.edit(collectionId, updatedCollection).catch((error: WriteError) => {
throw error
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class CollectionJSDataverseRepository implements CollectionRepository {
return publishCollection.execute(collectionIdOrAlias)
}

editGeneralInfo(collectionIdOrAlias: string, updatedCollection: CollectionDTO): Promise<void> {
edit(collectionIdOrAlias: string, updatedCollection: CollectionDTO): Promise<void> {
return updateCollection.execute(collectionIdOrAlias, updatedCollection)
}
}
14 changes: 6 additions & 8 deletions src/router/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ const CreateCollectionPage = lazy(() =>
)
)

const EditCollectionGeneralInfoPage = lazy(() =>
import('../sections/edit-collection-general-info/EditCollectionGeneralInfoFactory').then(
({ EditCollectionGeneralInfoFactory }) => ({
default: () => EditCollectionGeneralInfoFactory.create()
})
)
const EditCollectionPage = lazy(() =>
import('../sections/edit-collection/EditCollectionFactory').then(({ EditCollectionFactory }) => ({
default: () => EditCollectionFactory.create()
}))
)

const CreateDatasetPage = lazy(() =>
Expand Down Expand Up @@ -139,10 +137,10 @@ export const routes: RouteObject[] = [
errorElement: <ErrorPage />
},
{
path: Route.EDIT_COLLECTION_GENERAL_INFO,
path: Route.EDIT_COLLECTION,
element: (
<Suspense fallback={<AppLoader />}>
<EditCollectionGeneralInfoPage />
<EditCollectionPage />
</Suspense>
)
},
Expand Down
5 changes: 2 additions & 3 deletions src/sections/Route.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export enum Route {
COLLECTIONS_BASE = '/collections',
COLLECTIONS = '/collections/:collectionId',
CREATE_COLLECTION = '/collections/:parentCollectionId/create',
EDIT_COLLECTION_GENERAL_INFO = '/collections/:collectionId/edit-general-info',
EDIT_COLLECTION = '/collections/:collectionId/edit',
ACCOUNT = '/account'
}

Expand All @@ -20,8 +20,7 @@ export const RouteWithParams = {
collectionId ? `/collections/${collectionId}` : Route.COLLECTIONS_BASE,
CREATE_COLLECTION: (parentCollectionId: string) => `/collections/${parentCollectionId}/create`,
CREATE_DATASET: (collectionId: string) => `/datasets/${collectionId}/create`,
EDIT_COLLECTION_GENERAL_INFO: (collectionId: string) =>
`/collections/${collectionId}/edit-general-info`
EDIT_COLLECTION: (collectionId: string) => `/collections/${collectionId}/edit`
}

export enum QueryParamKey {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const EditCollectionDropdown = ({ collection }: EditCollectionDropdownPro
const navigate = useNavigate()

const onClickEditGeneralInformation = () => {
navigate(RouteWithParams.EDIT_COLLECTION_GENERAL_INFO(collection.id))
navigate(RouteWithParams.EDIT_COLLECTION(collection.id))
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ import { User } from '@/users/domain/models/User'
import { useEffect } from 'react'
import { EditCollectionSkeleton } from './EditCollectionSkeleton'

interface EditCollectionGeneralInfoProps {
interface EditCollectionProps {
collectionId: string
collectionRepository: CollectionRepository
metadataBlockInfoRepository: MetadataBlockInfoRepository
}

// TODO:ME - Move collection form to a shared component and make everything work again after, tests stories etc.
// TODO:ME - Integrated shared form here.
// TODO:ME Change name to EditCollection and use cases also

export const EditCollectionGeneralInfo = ({
export const EditCollection = ({
collectionId,
collectionRepository,
metadataBlockInfoRepository
}: EditCollectionGeneralInfoProps) => {
const { t } = useTranslation('editCollectionGeneralInfo')
}: EditCollectionProps) => {
const { t } = useTranslation('editCollection')
const { setIsLoading } = useLoading()
const { user } = useSession()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ import { ReactElement } from 'react'
import { useParams } from 'react-router-dom'
import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository'
import { MetadataBlockInfoJSDataverseRepository } from '@/metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository'
import { EditCollectionGeneralInfo } from './EditCollectionGeneralInfo'
import { EditCollection } from './EditCollection'

const collectionRepository = new CollectionJSDataverseRepository()
const metadataBlockInfoRepository = new MetadataBlockInfoJSDataverseRepository()

export class EditCollectionGeneralInfoFactory {
export class EditCollectionFactory {
static create(): ReactElement {
return <EditCollectionGeneralInfoWithParams />
return <EditCollectionWithParams />
}
}

function EditCollectionGeneralInfoWithParams() {
function EditCollectionWithParams() {
const { collectionId } = useParams<{ collectionId: string }>() as {
collectionId: string
}

return (
<EditCollectionGeneralInfo
<EditCollection
collectionId={collectionId}
collectionRepository={collectionRepository}
metadataBlockInfoRepository={metadataBlockInfoRepository}
Expand Down
2 changes: 1 addition & 1 deletion src/stories/collection/CollectionLoadingMockRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class CollectionLoadingMockRepository extends CollectionMockRepository {
return new Promise(() => {})
}

editGeneralInfo(_collectionIdOrAlias: string, _updatedCollection: CollectionDTO): Promise<void> {
edit(_collectionIdOrAlias: string, _updatedCollection: CollectionDTO): Promise<void> {
return new Promise(() => {})
}
}
2 changes: 1 addition & 1 deletion src/stories/collection/CollectionMockRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class CollectionMockRepository implements CollectionRepository {
})
}

editGeneralInfo(_collectionIdOrAlias: string, _updatedCollection: CollectionDTO): Promise<void> {
edit(_collectionIdOrAlias: string, _updatedCollection: CollectionDTO): Promise<void> {
return new Promise((resolve) => {
setTimeout(() => {
resolve()
Expand Down

0 comments on commit b21977b

Please sign in to comment.