From b21977be7016e6a77355df97d53f2b579baee853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Mon, 11 Nov 2024 09:00:56 -0300 Subject: [PATCH] refactor: change general info for just edit collection --- ...lectionGeneralInfo.json => editCollection.json} | 0 .../domain/repositories/CollectionRepository.ts | 2 +- ...tCollectionGeneralInfo.ts => editCollection.ts} | 10 ++++------ .../CollectionJSDataverseRepository.ts | 2 +- src/router/routes.tsx | 14 ++++++-------- src/sections/Route.enum.ts | 5 ++--- .../EditCollectionDropdown.tsx | 2 +- .../EditCollection.tsx} | 9 ++++----- .../EditCollectionFactory.tsx} | 11 ++++++----- .../EditCollectionSkeleton.tsx | 0 .../collection/CollectionLoadingMockRepository.ts | 2 +- src/stories/collection/CollectionMockRepository.ts | 2 +- 12 files changed, 27 insertions(+), 32 deletions(-) rename public/locales/en/{editCollectionGeneralInfo.json => editCollection.json} (100%) rename src/collection/domain/useCases/{editCollectionGeneralInfo.ts => editCollection.ts} (62%) rename src/sections/{edit-collection-general-info/EditCollectionGeneralInfo.tsx => edit-collection/EditCollection.tsx} (93%) rename src/sections/{edit-collection-general-info/EditCollectionGeneralInfoFactory.tsx => edit-collection/EditCollectionFactory.tsx} (76%) rename src/sections/{edit-collection-general-info => edit-collection}/EditCollectionSkeleton.tsx (100%) diff --git a/public/locales/en/editCollectionGeneralInfo.json b/public/locales/en/editCollection.json similarity index 100% rename from public/locales/en/editCollectionGeneralInfo.json rename to public/locales/en/editCollection.json diff --git a/src/collection/domain/repositories/CollectionRepository.ts b/src/collection/domain/repositories/CollectionRepository.ts index 3e2cb35b8..a710c61a8 100644 --- a/src/collection/domain/repositories/CollectionRepository.ts +++ b/src/collection/domain/repositories/CollectionRepository.ts @@ -17,5 +17,5 @@ export interface CollectionRepository { paginationInfo: CollectionItemsPaginationInfo, searchCriteria?: CollectionSearchCriteria ): Promise - editGeneralInfo(collectionIdOrAlias: string, updatedCollection: CollectionDTO): Promise + edit(collectionIdOrAlias: string, updatedCollection: CollectionDTO): Promise } diff --git a/src/collection/domain/useCases/editCollectionGeneralInfo.ts b/src/collection/domain/useCases/editCollection.ts similarity index 62% rename from src/collection/domain/useCases/editCollectionGeneralInfo.ts rename to src/collection/domain/useCases/editCollection.ts index a3228657d..d09856102 100644 --- a/src/collection/domain/useCases/editCollectionGeneralInfo.ts +++ b/src/collection/domain/useCases/editCollection.ts @@ -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 { - return collectionRepository - .editGeneralInfo(collectionId, updatedCollection) - .catch((error: WriteError) => { - throw error - }) + return collectionRepository.edit(collectionId, updatedCollection).catch((error: WriteError) => { + throw error + }) } diff --git a/src/collection/infrastructure/repositories/CollectionJSDataverseRepository.ts b/src/collection/infrastructure/repositories/CollectionJSDataverseRepository.ts index b5b27ae9e..c7851292f 100644 --- a/src/collection/infrastructure/repositories/CollectionJSDataverseRepository.ts +++ b/src/collection/infrastructure/repositories/CollectionJSDataverseRepository.ts @@ -63,7 +63,7 @@ export class CollectionJSDataverseRepository implements CollectionRepository { return publishCollection.execute(collectionIdOrAlias) } - editGeneralInfo(collectionIdOrAlias: string, updatedCollection: CollectionDTO): Promise { + edit(collectionIdOrAlias: string, updatedCollection: CollectionDTO): Promise { return updateCollection.execute(collectionIdOrAlias, updatedCollection) } } diff --git a/src/router/routes.tsx b/src/router/routes.tsx index dc8eeebd1..50fe2b5ad 100644 --- a/src/router/routes.tsx +++ b/src/router/routes.tsx @@ -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(() => @@ -139,10 +137,10 @@ export const routes: RouteObject[] = [ errorElement: }, { - path: Route.EDIT_COLLECTION_GENERAL_INFO, + path: Route.EDIT_COLLECTION, element: ( }> - + ) }, diff --git a/src/sections/Route.enum.ts b/src/sections/Route.enum.ts index c21e27085..742fd12f9 100644 --- a/src/sections/Route.enum.ts +++ b/src/sections/Route.enum.ts @@ -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' } @@ -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 { diff --git a/src/sections/collection/edit-collection-dropdown/EditCollectionDropdown.tsx b/src/sections/collection/edit-collection-dropdown/EditCollectionDropdown.tsx index 50048dab7..414918c34 100644 --- a/src/sections/collection/edit-collection-dropdown/EditCollectionDropdown.tsx +++ b/src/sections/collection/edit-collection-dropdown/EditCollectionDropdown.tsx @@ -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 ( diff --git a/src/sections/edit-collection-general-info/EditCollectionGeneralInfo.tsx b/src/sections/edit-collection/EditCollection.tsx similarity index 93% rename from src/sections/edit-collection-general-info/EditCollectionGeneralInfo.tsx rename to src/sections/edit-collection/EditCollection.tsx index d0e917d6e..ba861cd79 100644 --- a/src/sections/edit-collection-general-info/EditCollectionGeneralInfo.tsx +++ b/src/sections/edit-collection/EditCollection.tsx @@ -15,7 +15,7 @@ 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 @@ -23,14 +23,13 @@ interface EditCollectionGeneralInfoProps { // 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() diff --git a/src/sections/edit-collection-general-info/EditCollectionGeneralInfoFactory.tsx b/src/sections/edit-collection/EditCollectionFactory.tsx similarity index 76% rename from src/sections/edit-collection-general-info/EditCollectionGeneralInfoFactory.tsx rename to src/sections/edit-collection/EditCollectionFactory.tsx index 3a7851e64..21dc9dc52 100644 --- a/src/sections/edit-collection-general-info/EditCollectionGeneralInfoFactory.tsx +++ b/src/sections/edit-collection/EditCollectionFactory.tsx @@ -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 + return } } -function EditCollectionGeneralInfoWithParams() { +function EditCollectionWithParams() { const { collectionId } = useParams<{ collectionId: string }>() as { collectionId: string } + return ( - {}) } - editGeneralInfo(_collectionIdOrAlias: string, _updatedCollection: CollectionDTO): Promise { + edit(_collectionIdOrAlias: string, _updatedCollection: CollectionDTO): Promise { return new Promise(() => {}) } } diff --git a/src/stories/collection/CollectionMockRepository.ts b/src/stories/collection/CollectionMockRepository.ts index 435252959..1b45235e3 100644 --- a/src/stories/collection/CollectionMockRepository.ts +++ b/src/stories/collection/CollectionMockRepository.ts @@ -85,7 +85,7 @@ export class CollectionMockRepository implements CollectionRepository { }) } - editGeneralInfo(_collectionIdOrAlias: string, _updatedCollection: CollectionDTO): Promise { + edit(_collectionIdOrAlias: string, _updatedCollection: CollectionDTO): Promise { return new Promise((resolve) => { setTimeout(() => { resolve()