diff --git a/package-lock.json b/package-lock.json index 1d975f33c..c485f7295 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.0", "dependencies": { "@faker-js/faker": "7.6.0", - "@iqss/dataverse-client-javascript": "2.0.0-alpha.2", + "@iqss/dataverse-client-javascript": "npm:@IQSS/dataverse-client-javascript@^2.0.0-pr207.d14dc1c", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", @@ -3674,9 +3674,9 @@ }, "node_modules/@iqss/dataverse-client-javascript": { "name": "@IQSS/dataverse-client-javascript", - "version": "2.0.0-alpha.2", - "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-alpha.2/6f926581c976bbf8649053323e1c82a729d56706", - "integrity": "sha512-bJgGirBFr4gL+pVFz0zNAlMovxWHJMi9RCN9v6lnpkLU+fKHUTeMkEgQdGxoA0lI3V8cvA+e2xcpoi7/24vRKg==", + "version": "2.0.0-pr207.d14dc1c", + "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-pr207.d14dc1c/e1aad714bbd5a7e15904e1da1188823b4f41bcac", + "integrity": "sha512-1dXVQ5xdPeQUkePlZH2G5uHi7Jas3zaexM0Tx3UYzDTFihuBLoEfMqMYSRZIDlfRMP4omxsr8yKoccrEEqo0qQ==", "dependencies": { "@types/node": "^18.15.11", "@types/turndown": "^5.0.1", diff --git a/package.json b/package.json index fe43d59f1..f2f231e11 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "@faker-js/faker": "7.6.0", - "@iqss/dataverse-client-javascript": "2.0.0-alpha.2", + "@iqss/dataverse-client-javascript": "npm:@IQSS/dataverse-client-javascript@^2.0.0-pr207.d14dc1c", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", diff --git a/src/collection/domain/models/Collection.ts b/src/collection/domain/models/Collection.ts index de1235f8c..885c0a13a 100644 --- a/src/collection/domain/models/Collection.ts +++ b/src/collection/domain/models/Collection.ts @@ -15,5 +15,3 @@ export interface CollectionInputLevel { include: boolean required: boolean } - -export const ROOT_COLLECTION_ALIAS = ':root' diff --git a/src/collection/domain/repositories/CollectionRepository.ts b/src/collection/domain/repositories/CollectionRepository.ts index 75c77005c..d4a8567a4 100644 --- a/src/collection/domain/repositories/CollectionRepository.ts +++ b/src/collection/domain/repositories/CollectionRepository.ts @@ -7,10 +7,10 @@ import { CollectionUserPermissions } from '../models/CollectionUserPermissions' import { CollectionDTO } from '../useCases/DTOs/CollectionDTO' export interface CollectionRepository { - getById: (id: string) => Promise + getById: (id?: string) => Promise create(collection: CollectionDTO, hostCollection?: string): Promise - getFacets(collectionIdOrAlias: number | string): Promise - getUserPermissions(collectionIdOrAlias: number | string): Promise + getFacets(collectionIdOrAlias?: number | string): Promise + getUserPermissions(collectionIdOrAlias?: number | string): Promise publish(collectionIdOrAlias: number | string): Promise getItems( collectionId: string, diff --git a/src/collection/domain/useCases/createCollection.ts b/src/collection/domain/useCases/createCollection.ts index 68af8ba32..67da6fef5 100644 --- a/src/collection/domain/useCases/createCollection.ts +++ b/src/collection/domain/useCases/createCollection.ts @@ -5,7 +5,7 @@ import { CollectionDTO } from './DTOs/CollectionDTO' export function createCollection( collectionRepository: CollectionRepository, collection: CollectionDTO, - hostCollection?: string + hostCollection: string ): Promise { return collectionRepository.create(collection, hostCollection).catch((error: WriteError) => { throw error diff --git a/src/collection/domain/useCases/getCollectionById.ts b/src/collection/domain/useCases/getCollectionById.ts index 7fc9a9a40..c2da48d87 100644 --- a/src/collection/domain/useCases/getCollectionById.ts +++ b/src/collection/domain/useCases/getCollectionById.ts @@ -3,7 +3,7 @@ import { CollectionRepository } from '../repositories/CollectionRepository' export async function getCollectionById( collectionRepository: CollectionRepository, - id: string + id?: string ): Promise { return collectionRepository.getById(id).catch((error: Error) => { throw new Error(error.message) diff --git a/src/collection/domain/useCases/getCollectionUserPermissions.ts b/src/collection/domain/useCases/getCollectionUserPermissions.ts index fb5d10a6d..1c51b23f3 100644 --- a/src/collection/domain/useCases/getCollectionUserPermissions.ts +++ b/src/collection/domain/useCases/getCollectionUserPermissions.ts @@ -3,7 +3,7 @@ import { CollectionUserPermissions } from '../models/CollectionUserPermissions' export function getCollectionUserPermissions( collectionRepository: CollectionRepository, - collectionIdOrAlias: number | string + collectionIdOrAlias?: number | string ): Promise { return collectionRepository.getUserPermissions(collectionIdOrAlias).catch((error: Error) => { throw new Error(error.message) diff --git a/src/collection/infrastructure/repositories/CollectionJSDataverseRepository.ts b/src/collection/infrastructure/repositories/CollectionJSDataverseRepository.ts index 3f745a569..4a04c1545 100644 --- a/src/collection/infrastructure/repositories/CollectionJSDataverseRepository.ts +++ b/src/collection/infrastructure/repositories/CollectionJSDataverseRepository.ts @@ -18,7 +18,8 @@ import { CollectionSearchCriteria } from '../../domain/models/CollectionSearchCr import { JSCollectionItemsMapper } from '../mappers/JSCollectionItemsMapper' export class CollectionJSDataverseRepository implements CollectionRepository { - getById(id: string): Promise { + getById(id?: string): Promise { + console.log('calling getCollection.execute with id:', id) return getCollection .execute(id) .then((jsCollection) => JSCollectionMapper.toCollection(jsCollection)) @@ -30,11 +31,11 @@ export class CollectionJSDataverseRepository implements CollectionRepository { .then((newCollectionIdentifier) => newCollectionIdentifier) } - getFacets(collectionIdOrAlias: number | string): Promise { + getFacets(collectionIdOrAlias?: number | string): Promise { return getCollectionFacets.execute(collectionIdOrAlias).then((facets) => facets) } - getUserPermissions(collectionIdOrAlias: number | string): Promise { + getUserPermissions(collectionIdOrAlias?: number | string): Promise { return getCollectionUserPermissions .execute(collectionIdOrAlias) .then((jsCollectionUserPermissions) => jsCollectionUserPermissions) diff --git a/src/dataset/domain/repositories/DatasetRepository.ts b/src/dataset/domain/repositories/DatasetRepository.ts index d829934dc..0e708786b 100644 --- a/src/dataset/domain/repositories/DatasetRepository.ts +++ b/src/dataset/domain/repositories/DatasetRepository.ts @@ -8,7 +8,7 @@ export interface DatasetRepository { getByPersistentId: (persistentId: string, version?: string) => Promise getLocks(persistentId: string): Promise getByPrivateUrlToken: (privateUrlToken: string) => Promise - create: (dataset: DatasetDTO, collectionId?: string) => Promise<{ persistentId: string }> + create: (dataset: DatasetDTO, collectionId: string) => Promise<{ persistentId: string }> updateMetadata: (datasetId: string | number, datasetDTO: DatasetDTO) => Promise getAllWithCount: ( collectionId: string, diff --git a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts index cb352631a..84c4d93e2 100644 --- a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts +++ b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts @@ -32,7 +32,6 @@ import { DatasetDTO } from '../../domain/useCases/DTOs/DatasetDTO' import { DatasetDTOMapper } from '../mappers/DatasetDTOMapper' import { DatasetsWithCount } from '../../domain/models/DatasetsWithCount' import { VersionUpdateType } from '../../domain/models/VersionUpdateType' -import { ROOT_COLLECTION_ALIAS } from '../../../collection/domain/models/Collection' const includeDeaccessioned = true type DatasetDetails = [JSDataset, string[], string, JSDatasetPermissions, JSDatasetLock[]] @@ -223,10 +222,7 @@ export class DatasetJSDataverseRepository implements DatasetRepository { }) } - create( - dataset: DatasetDTO, - collectionId = ROOT_COLLECTION_ALIAS - ): Promise<{ persistentId: string }> { + create(dataset: DatasetDTO, collectionId: string): Promise<{ persistentId: string }> { return createDataset .execute(DatasetDTOMapper.toJSDatasetDTO(dataset), collectionId) .then((jsDatasetIdentifiers: JSDatasetIdentifiers) => ({ diff --git a/src/sections/account/Account.tsx b/src/sections/account/Account.tsx index 06d5a9fbb..8a9977f9d 100644 --- a/src/sections/account/Account.tsx +++ b/src/sections/account/Account.tsx @@ -1,37 +1,44 @@ -import { useEffect } from 'react' import { useTranslation } from 'react-i18next' import { Tabs } from '@iqss/dataverse-design-system' -import { useLoading } from '../loading/LoadingContext' import { AccountHelper, AccountPanelTabKey } from './AccountHelper' import { ApiTokenSection } from './api-token-section/ApiTokenSection' import { BreadcrumbsGenerator } from '../shared/hierarchy/BreadcrumbsGenerator' +import { useCollection } from '@/sections/collection/useCollection' +import { useLoading } from '../loading/LoadingContext' +import { CollectionRepository } from '@/collection/domain/repositories/CollectionRepository' import styles from './Account.module.scss' import { DvObjectType, UpwardHierarchyNode } from '../../shared/hierarchy/domain/models/UpwardHierarchyNode' -import { ROOT_COLLECTION_ALIAS } from '../../collection/domain/models/Collection' + +import { useEffect } from 'react' +import { BreadcrumbsSkeleton } from '@/sections/shared/hierarchy/BreadcrumbsSkeleton' const tabsKeys = AccountHelper.ACCOUNT_PANEL_TABS_KEYS interface AccountProps { defaultActiveTabKey: AccountPanelTabKey + collectionRepository: CollectionRepository } -export const Account = ({ defaultActiveTabKey }: AccountProps) => { +export const Account = ({ defaultActiveTabKey, collectionRepository }: AccountProps) => { const { t } = useTranslation('account') + const { collection, isLoading: collectionIsLoading } = useCollection(collectionRepository) const { setIsLoading } = useLoading() + useEffect(() => { + setIsLoading(collectionIsLoading) + }, [collectionIsLoading, setIsLoading]) + + if (collectionIsLoading || !collection) { + return + } const rootHierarchy = new UpwardHierarchyNode( - 'Root', + collection.name, DvObjectType.COLLECTION, - ROOT_COLLECTION_ALIAS + collection.id ) - - useEffect(() => { - setIsLoading(false) - }, [setIsLoading]) - return (
diff --git a/src/sections/account/AccountFactory.tsx b/src/sections/account/AccountFactory.tsx index 0ecbab6b5..218d44c55 100644 --- a/src/sections/account/AccountFactory.tsx +++ b/src/sections/account/AccountFactory.tsx @@ -2,6 +2,9 @@ import { ReactElement } from 'react' import { useSearchParams } from 'react-router-dom' import { AccountHelper } from './AccountHelper' import { Account } from './Account' +import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' + +const collectionRepository = new CollectionJSDataverseRepository() export class AccountFactory { static create(): ReactElement { @@ -13,5 +16,10 @@ function AccountWithSearchParams() { const [searchParams] = useSearchParams() const defaultActiveTabKey = AccountHelper.defineSelectedTabKey(searchParams) - return + return ( + + ) } diff --git a/src/sections/collection/Collection.tsx b/src/sections/collection/Collection.tsx index e8e2c3bcc..f90964f0b 100644 --- a/src/sections/collection/Collection.tsx +++ b/src/sections/collection/Collection.tsx @@ -18,7 +18,7 @@ import styles from './Collection.module.scss' interface CollectionProps { collectionRepository: CollectionRepository - collectionId: string + collectionIdFromParams: string | undefined created: boolean published: boolean collectionQueryParams: UseCollectionQueryParamsReturnType @@ -26,7 +26,7 @@ interface CollectionProps { } export function Collection({ - collectionId, + collectionIdFromParams, collectionRepository, created, published, @@ -35,9 +35,13 @@ export function Collection({ useTranslation('collection') useScrollTop() const { user } = useSession() - const { collection, isLoading } = useCollection(collectionRepository, collectionId, published) + const { collection, isLoading } = useCollection( + collectionRepository, + collectionIdFromParams, + published + ) const { collectionUserPermissions } = useGetCollectionUserPermissions({ - collectionIdOrAlias: collectionId, + collectionIdOrAlias: collectionIdFromParams, collectionRepository }) @@ -77,8 +81,8 @@ export function Collection({ )} () + const { collectionId } = useParams<{ collectionId: string }>() const location = useLocation() const state = location.state as { published: boolean; created: boolean } | undefined const created = state?.created ?? false @@ -24,7 +23,7 @@ function CollectionWithSearchParams() { return ( (
  • {collectionItem?.type === CollectionItemType.COLLECTION && ( - + )} {collectionItem?.type === CollectionItemType.DATASET && ( diff --git a/src/sections/collection/collection-items-panel/items-list/collection-card/CollectionCard.tsx b/src/sections/collection/collection-items-panel/items-list/collection-card/CollectionCard.tsx index 768d77d10..abeb31e39 100644 --- a/src/sections/collection/collection-items-panel/items-list/collection-card/CollectionCard.tsx +++ b/src/sections/collection/collection-items-panel/items-list/collection-card/CollectionCard.tsx @@ -6,15 +6,19 @@ import styles from './CollectionCard.module.scss' interface CollectionCardProps { collectionPreview: CollectionItemTypePreview + parentCollectionAlias: string } -export function CollectionCard({ collectionPreview }: CollectionCardProps) { +export function CollectionCard({ collectionPreview, parentCollectionAlias }: CollectionCardProps) { return (
    - +
    ) diff --git a/src/sections/collection/collection-items-panel/items-list/collection-card/CollectionCardInfo.tsx b/src/sections/collection/collection-items-panel/items-list/collection-card/CollectionCardInfo.tsx index 5c182b285..7fcaf07d6 100644 --- a/src/sections/collection/collection-items-panel/items-list/collection-card/CollectionCardInfo.tsx +++ b/src/sections/collection/collection-items-panel/items-list/collection-card/CollectionCardInfo.tsx @@ -1,6 +1,4 @@ -import { useParams } from 'react-router-dom' import { Stack } from '@iqss/dataverse-design-system' -import { ROOT_COLLECTION_ALIAS } from '@/collection/domain/models/Collection' import { CollectionItemTypePreview } from '@/collection/domain/models/CollectionItemTypePreview' import { DvObjectType } from '@/shared/hierarchy/domain/models/UpwardHierarchyNode' import { DateHelper } from '@/shared/helpers/DateHelper' @@ -10,11 +8,15 @@ import styles from './CollectionCard.module.scss' interface CollectionCardInfoProps { collectionPreview: CollectionItemTypePreview + parentCollectionAlias: string } -export function CollectionCardInfo({ collectionPreview }: CollectionCardInfoProps) { - const { collectionId = ROOT_COLLECTION_ALIAS } = useParams<{ collectionId: string }>() - const isStandingOnParentCollectionPage = collectionPreview.parentCollectionAlias === collectionId +export function CollectionCardInfo({ + collectionPreview, + parentCollectionAlias +}: CollectionCardInfoProps) { + const isStandingOnParentCollectionPage = + collectionPreview.parentCollectionAlias === parentCollectionAlias return (
    diff --git a/src/sections/collection/useCollection.tsx b/src/sections/collection/useCollection.tsx index 74c99159f..48a8742a2 100644 --- a/src/sections/collection/useCollection.tsx +++ b/src/sections/collection/useCollection.tsx @@ -5,7 +5,7 @@ import { getCollectionById } from '../../collection/domain/useCases/getCollectio export function useCollection( collectionRepository: CollectionRepository, - collectionId: string, + collectionId?: string | undefined, published?: boolean ) { const [isLoading, setIsLoading] = useState(true) @@ -15,7 +15,8 @@ export function useCollection( setIsLoading(true) setCollection(undefined) getCollectionById(collectionRepository, collectionId) - .then((collection: Collection | undefined) => { + .then((collection: Collection) => { + console.log('useCollection: returning collection', collection) setCollection(collection) }) .catch((error) => { diff --git a/src/sections/create-collection/CreateCollectionFactory.tsx b/src/sections/create-collection/CreateCollectionFactory.tsx index 1e65d3b9b..bce567238 100644 --- a/src/sections/create-collection/CreateCollectionFactory.tsx +++ b/src/sections/create-collection/CreateCollectionFactory.tsx @@ -2,7 +2,6 @@ import { ReactElement } from 'react' import { useParams } from 'react-router-dom' import { CollectionJSDataverseRepository } from '../../collection/infrastructure/repositories/CollectionJSDataverseRepository' import { CreateCollection } from './CreateCollection' -import { ROOT_COLLECTION_ALIAS } from '../../collection/domain/models/Collection' import { MetadataBlockInfoJSDataverseRepository } from '../../metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository' const collectionRepository = new CollectionJSDataverseRepository() @@ -15,8 +14,10 @@ export class CreateCollectionFactory { } function CreateCollectionWithParams() { - const { ownerCollectionId = ROOT_COLLECTION_ALIAS } = useParams<{ ownerCollectionId: string }>() - + const { ownerCollectionId } = useParams<{ ownerCollectionId: string }>() + if (!ownerCollectionId) { + throw new Error('ownerCollectionId is required') + } return ( = { title: 'Pages/Create Collection', component: CreateCollection, diff --git a/src/stories/shared/add-data-actions/AddDataActionsButton.stories.tsx b/src/stories/shared/add-data-actions/AddDataActionsButton.stories.tsx index 1da6ce4f7..069fcdb2a 100644 --- a/src/stories/shared/add-data-actions/AddDataActionsButton.stories.tsx +++ b/src/stories/shared/add-data-actions/AddDataActionsButton.stories.tsx @@ -1,7 +1,8 @@ import { Meta, StoryObj } from '@storybook/react' import { WithI18next } from '../../WithI18next' import AddDataActionsButton from '../../../sections/shared/add-data-actions/AddDataActionsButton' -import { ROOT_COLLECTION_ALIAS } from '../../../collection/domain/models/Collection' + +import { ROOT_COLLECTION_ALIAS } from '@tests/e2e-integration/shared/collection/CollectionHelper' const meta: Meta = { title: 'Sections/Shared/AddDataActions/AddDataActionsButton', diff --git a/tests/component/sections/collection/collection-items-panel/CollectionItemsPanel.spec.tsx b/tests/component/sections/collection/collection-items-panel/CollectionItemsPanel.spec.tsx index 4ea332bfa..871f3f272 100644 --- a/tests/component/sections/collection/collection-items-panel/CollectionItemsPanel.spec.tsx +++ b/tests/component/sections/collection/collection-items-panel/CollectionItemsPanel.spec.tsx @@ -1,5 +1,4 @@ import { CollectionItemsPanel } from '@/sections/collection/collection-items-panel/CollectionItemsPanel' -import { ROOT_COLLECTION_ALIAS } from '@/collection/domain/models/Collection' import { CollectionItem, CollectionItemSubset @@ -8,6 +7,8 @@ import { CollectionRepository } from '@/collection/domain/repositories/Collectio import { CollectionItemsMother } from '@tests/component/collection/domain/models/CollectionItemsMother' import { CollectionItemType } from '@/collection/domain/models/CollectionItemType' +import { ROOT_COLLECTION_ALIAS } from '@tests/e2e-integration/shared/collection/CollectionHelper' + const collectionRepository: CollectionRepository = {} as CollectionRepository const totalItemCount = 200 diff --git a/tests/component/sections/create-collection/useGetCollectionFacets.spec.tsx b/tests/component/sections/create-collection/useGetCollectionFacets.spec.tsx index 55b9962a9..2ba1780ee 100644 --- a/tests/component/sections/create-collection/useGetCollectionFacets.spec.tsx +++ b/tests/component/sections/create-collection/useGetCollectionFacets.spec.tsx @@ -2,7 +2,8 @@ import { act, renderHook } from '@testing-library/react' import { useGetCollectionFacets } from '../../../../src/sections/create-collection/useGetCollectionFacets' import { CollectionRepository } from '../../../../src/collection/domain/repositories/CollectionRepository' import { CollectionFacetMother } from '../../collection/domain/models/CollectionFacetMother' -import { ROOT_COLLECTION_ALIAS } from '../../../../src/collection/domain/models/Collection' + +import { ROOT_COLLECTION_ALIAS } from '@tests/e2e-integration/shared/collection/CollectionHelper' const collectionRepository: CollectionRepository = {} as CollectionRepository const collectionFacetsMock = CollectionFacetMother.createFacets() diff --git a/tests/e2e-integration/shared/collection/CollectionHelper.ts b/tests/e2e-integration/shared/collection/CollectionHelper.ts index 5fab95465..30a2bd12a 100644 --- a/tests/e2e-integration/shared/collection/CollectionHelper.ts +++ b/tests/e2e-integration/shared/collection/CollectionHelper.ts @@ -50,3 +50,5 @@ export class CollectionHelper extends DataverseApiHelper { return collectionResponse } } + +export const ROOT_COLLECTION_ALIAS = 'root' diff --git a/tests/e2e-integration/shared/datasets/DatasetHelper.ts b/tests/e2e-integration/shared/datasets/DatasetHelper.ts index faba4c5e1..5b1f91acf 100644 --- a/tests/e2e-integration/shared/datasets/DatasetHelper.ts +++ b/tests/e2e-integration/shared/datasets/DatasetHelper.ts @@ -3,7 +3,8 @@ import { DataverseApiHelper } from '../DataverseApiHelper' import { FileData } from '../files/FileHelper' import { DatasetLockReason } from '../../../../src/dataset/domain/models/Dataset' import { TestsUtils } from '../TestsUtils' -import { ROOT_COLLECTION_ALIAS } from '../../../../src/collection/domain/models/Collection' + +import { ROOT_COLLECTION_ALIAS } from '@tests/e2e-integration/shared/collection/CollectionHelper' export interface DatasetResponse { persistentId: string