Skip to content

Commit

Permalink
removed references to ROOT_COLLECTION_ALIAS from components (using de…
Browse files Browse the repository at this point in the history
…fault instead) Updated components that depend on collectionId.
  • Loading branch information
ekraffmiller committed Oct 29, 2024
1 parent 4c7f434 commit 21acc36
Show file tree
Hide file tree
Showing 28 changed files with 98 additions and 65 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions src/collection/domain/models/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ export interface CollectionInputLevel {
include: boolean
required: boolean
}

export const ROOT_COLLECTION_ALIAS = ':root'
6 changes: 3 additions & 3 deletions src/collection/domain/repositories/CollectionRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { CollectionUserPermissions } from '../models/CollectionUserPermissions'
import { CollectionDTO } from '../useCases/DTOs/CollectionDTO'

export interface CollectionRepository {
getById: (id: string) => Promise<Collection>
getById: (id?: string) => Promise<Collection>
create(collection: CollectionDTO, hostCollection?: string): Promise<number>
getFacets(collectionIdOrAlias: number | string): Promise<CollectionFacet[]>
getUserPermissions(collectionIdOrAlias: number | string): Promise<CollectionUserPermissions>
getFacets(collectionIdOrAlias?: number | string): Promise<CollectionFacet[]>
getUserPermissions(collectionIdOrAlias?: number | string): Promise<CollectionUserPermissions>
publish(collectionIdOrAlias: number | string): Promise<void>
getItems(
collectionId: string,
Expand Down
2 changes: 1 addition & 1 deletion src/collection/domain/useCases/createCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CollectionDTO } from './DTOs/CollectionDTO'
export function createCollection(
collectionRepository: CollectionRepository,
collection: CollectionDTO,
hostCollection?: string
hostCollection: string
): Promise<number> {
return collectionRepository.create(collection, hostCollection).catch((error: WriteError) => {
throw error
Expand Down
2 changes: 1 addition & 1 deletion src/collection/domain/useCases/getCollectionById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CollectionRepository } from '../repositories/CollectionRepository'

export async function getCollectionById(
collectionRepository: CollectionRepository,
id: string
id?: string
): Promise<Collection> {
return collectionRepository.getById(id).catch((error: Error) => {
throw new Error(error.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CollectionUserPermissions } from '../models/CollectionUserPermissions'

export function getCollectionUserPermissions(
collectionRepository: CollectionRepository,
collectionIdOrAlias: number | string
collectionIdOrAlias?: number | string
): Promise<CollectionUserPermissions> {
return collectionRepository.getUserPermissions(collectionIdOrAlias).catch((error: Error) => {
throw new Error(error.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { CollectionSearchCriteria } from '../../domain/models/CollectionSearchCr
import { JSCollectionItemsMapper } from '../mappers/JSCollectionItemsMapper'

export class CollectionJSDataverseRepository implements CollectionRepository {
getById(id: string): Promise<Collection> {
getById(id?: string): Promise<Collection> {
console.log('calling getCollection.execute with id:', id)
return getCollection
.execute(id)
.then((jsCollection) => JSCollectionMapper.toCollection(jsCollection))
Expand All @@ -30,11 +31,11 @@ export class CollectionJSDataverseRepository implements CollectionRepository {
.then((newCollectionIdentifier) => newCollectionIdentifier)
}

getFacets(collectionIdOrAlias: number | string): Promise<CollectionFacet[]> {
getFacets(collectionIdOrAlias?: number | string): Promise<CollectionFacet[]> {
return getCollectionFacets.execute(collectionIdOrAlias).then((facets) => facets)
}

getUserPermissions(collectionIdOrAlias: number | string): Promise<CollectionUserPermissions> {
getUserPermissions(collectionIdOrAlias?: number | string): Promise<CollectionUserPermissions> {
return getCollectionUserPermissions
.execute(collectionIdOrAlias)
.then((jsCollectionUserPermissions) => jsCollectionUserPermissions)
Expand Down
2 changes: 1 addition & 1 deletion src/dataset/domain/repositories/DatasetRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface DatasetRepository {
getByPersistentId: (persistentId: string, version?: string) => Promise<Dataset | undefined>
getLocks(persistentId: string): Promise<DatasetLock[]>
getByPrivateUrlToken: (privateUrlToken: string) => Promise<Dataset | undefined>
create: (dataset: DatasetDTO, collectionId?: string) => Promise<{ persistentId: string }>
create: (dataset: DatasetDTO, collectionId: string) => Promise<{ persistentId: string }>
updateMetadata: (datasetId: string | number, datasetDTO: DatasetDTO) => Promise<void>
getAllWithCount: (
collectionId: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]]
Expand Down Expand Up @@ -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) => ({
Expand Down
29 changes: 18 additions & 11 deletions src/sections/account/Account.tsx
Original file line number Diff line number Diff line change
@@ -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 <BreadcrumbsSkeleton />
}
const rootHierarchy = new UpwardHierarchyNode(
'Root',
collection.name,
DvObjectType.COLLECTION,
ROOT_COLLECTION_ALIAS
collection.id
)

useEffect(() => {
setIsLoading(false)
}, [setIsLoading])

return (
<section>
<BreadcrumbsGenerator hierarchy={rootHierarchy} withActionItem actionItemText="Account" />
Expand Down
10 changes: 9 additions & 1 deletion src/sections/account/AccountFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -13,5 +16,10 @@ function AccountWithSearchParams() {
const [searchParams] = useSearchParams()
const defaultActiveTabKey = AccountHelper.defineSelectedTabKey(searchParams)

return <Account defaultActiveTabKey={defaultActiveTabKey} />
return (
<Account
collectionRepository={collectionRepository}
defaultActiveTabKey={defaultActiveTabKey}
/>
)
}
16 changes: 10 additions & 6 deletions src/sections/collection/Collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import styles from './Collection.module.scss'

interface CollectionProps {
collectionRepository: CollectionRepository
collectionId: string
collectionIdFromParams: string | undefined
created: boolean
published: boolean
collectionQueryParams: UseCollectionQueryParamsReturnType
infiniteScrollEnabled?: boolean
}

export function Collection({
collectionId,
collectionIdFromParams,
collectionRepository,
created,
published,
Expand All @@ -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
})

Expand Down Expand Up @@ -77,8 +81,8 @@ export function Collection({
)}

<CollectionItemsPanel
key={collectionId}
collectionId={collectionId}
key={collection.id}
collectionId={collection.id}
collectionRepository={collectionRepository}
collectionQueryParams={collectionQueryParams}
addDataSlot={
Expand Down
5 changes: 2 additions & 3 deletions src/sections/collection/CollectionFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { CollectionJSDataverseRepository } from '../../collection/infrastructure
import { Collection } from './Collection'
import { INFINITE_SCROLL_ENABLED } from './config'
import { useGetCollectionQueryParams } from './useGetCollectionQueryParams'
import { ROOT_COLLECTION_ALIAS } from '@/collection/domain/models/Collection'

const collectionRepository = new CollectionJSDataverseRepository()
export class CollectionFactory {
Expand All @@ -15,7 +14,7 @@ export class CollectionFactory {

function CollectionWithSearchParams() {
const collectionQueryParams = useGetCollectionQueryParams()
const { collectionId = ROOT_COLLECTION_ALIAS } = useParams<{ collectionId: string }>()
const { collectionId } = useParams<{ collectionId: string }>()
const location = useLocation()
const state = location.state as { published: boolean; created: boolean } | undefined
const created = state?.created ?? false
Expand All @@ -24,7 +23,7 @@ function CollectionWithSearchParams() {
return (
<Collection
collectionRepository={collectionRepository}
collectionId={collectionId}
collectionIdFromParams={collectionId}
created={created}
collectionQueryParams={collectionQueryParams}
published={published}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export const CollectionItemsPanel = ({
/>

<ItemsList
parentCollectionAlias={collectionId}
items={accumulatedItems}
error={error}
accumulatedCount={accumulatedCount}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { FileCard } from './file-card/FileCard'
import styles from './ItemsList.module.scss'

interface ItemsListProps {
parentCollectionAlias: string
items: CollectionItem[]
error: string | null
accumulatedCount: number
Expand All @@ -32,6 +33,7 @@ interface ItemsListProps {
export const ItemsList = forwardRef(
(
{
parentCollectionAlias,
items,
error,
accumulatedCount,
Expand Down Expand Up @@ -94,7 +96,10 @@ export const ItemsList = forwardRef(
{items.map((collectionItem, index) => (
<li key={`${collectionItem.type}-${index}`}>
{collectionItem?.type === CollectionItemType.COLLECTION && (
<CollectionCard collectionPreview={collectionItem} />
<CollectionCard
parentCollectionAlias={parentCollectionAlias}
collectionPreview={collectionItem}
/>
)}
{collectionItem?.type === CollectionItemType.DATASET && (
<DatasetCard datasetPreview={collectionItem} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<article className={styles['card-main-container']} data-testid="collection-card">
<CollectionCardHeader collectionPreview={collectionPreview} />
<div className={styles['thumbnail-and-info-wrapper']}>
<CollectionCardThumbnail collectionPreview={collectionPreview} />
<CollectionCardInfo collectionPreview={collectionPreview} />
<CollectionCardInfo
parentCollectionAlias={parentCollectionAlias}
collectionPreview={collectionPreview}
/>
</div>
</article>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 (
<div className={styles['card-info-container']}>
Expand Down
5 changes: 3 additions & 2 deletions src/sections/collection/useCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) => {
Expand Down
Loading

0 comments on commit 21acc36

Please sign in to comment.