forked from uncch-rdmc/dataverse-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request IQSS#352 from IQSS/feature-344-display-real-collec…
…tion-data 344 - Display real collection data in the Collection Page
- Loading branch information
Showing
35 changed files
with
578 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
VITE_DATAVERSE_BACKEND_URL=http://localhost:8000 | ||
VITE_DATAVERSE_BACKEND_URL=http://localhost:8000 | ||
STORYBOOK_CHROMATIC_BUILD=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { UpwardHierarchyNode } from '../../../shared/hierarchy/domain/models/UpwardHierarchyNode' | ||
|
||
export interface Collection { | ||
id: string | ||
name: string | ||
hierarchy: UpwardHierarchyNode | ||
description?: string | ||
affiliation?: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Collection } from '../models/Collection' | ||
|
||
export interface CollectionRepository { | ||
getById: (id: string) => Promise<Collection> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Collection } from '../models/Collection' | ||
import { CollectionRepository } from '../repositories/CollectionRepository' | ||
|
||
export async function getCollectionById( | ||
collectionRepository: CollectionRepository, | ||
id: string | ||
): Promise<Collection | undefined> { | ||
return collectionRepository.getById(id).catch((error: Error) => { | ||
throw new Error(error.message) | ||
}) | ||
} |
41 changes: 41 additions & 0 deletions
41
src/collection/infrastructure/mappers/JSCollectionMapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
Collection as JSCollection, | ||
DvObjectOwnerNode as JSUpwardHierarchyNode | ||
} from '@iqss/dataverse-client-javascript' | ||
import { Collection } from '../../domain/models/Collection' | ||
import { | ||
DvObjectType, | ||
UpwardHierarchyNode | ||
} from '../../../shared/hierarchy/domain/models/UpwardHierarchyNode' | ||
import { JSUpwardHierarchyNodeMapper } from '../../../shared/hierarchy/infrastructure/mappers/JSUpwardHierarchyNodeMapper' | ||
|
||
export class JSCollectionMapper { | ||
static toCollection(jsCollection: JSCollection): Collection { | ||
return { | ||
id: jsCollection.alias, | ||
name: jsCollection.name, | ||
description: jsCollection.description, | ||
affiliation: jsCollection.affiliation, | ||
hierarchy: JSCollectionMapper.toHierarchy( | ||
jsCollection.name, | ||
jsCollection.alias, | ||
jsCollection.isPartOf | ||
) | ||
} | ||
} | ||
|
||
static toHierarchy( | ||
name: string, | ||
id: string, | ||
jsUpwardHierarchyNode: JSUpwardHierarchyNode | ||
): UpwardHierarchyNode { | ||
return new UpwardHierarchyNode( | ||
name, | ||
DvObjectType.COLLECTION, | ||
id, | ||
undefined, | ||
undefined, | ||
JSUpwardHierarchyNodeMapper.toUpwardHierarchyNode(jsUpwardHierarchyNode) | ||
) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/collection/infrastructure/repositories/CollectionJSDataverseRepository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { CollectionRepository } from '../../domain/repositories/CollectionRepository' | ||
import { Collection } from '../../domain/models/Collection' | ||
import { getCollection } from '@iqss/dataverse-client-javascript' | ||
import { JSCollectionMapper } from '../mappers/JSCollectionMapper' | ||
|
||
export class CollectionJSDataverseRepository implements CollectionRepository { | ||
getById(id: string): Promise<Collection> { | ||
return getCollection | ||
.execute(id) | ||
.then((jsCollection) => JSCollectionMapper.toCollection(jsCollection)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
@import 'node_modules/bootstrap/scss/functions'; | ||
@import 'node_modules/bootstrap/scss/variables'; | ||
@import "node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module"; | ||
|
||
.container { | ||
display: flex; | ||
justify-content: flex-end; | ||
margin-bottom: $spacer; | ||
} | ||
|
||
.header { | ||
margin-bottom: $spacer; | ||
} | ||
|
||
.subtext { | ||
color: $dv-subtext-color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,62 @@ | ||
import { Row } from '@iqss/dataverse-design-system' | ||
import { Col, Row } from '@iqss/dataverse-design-system' | ||
import { DatasetRepository } from '../../dataset/domain/repositories/DatasetRepository' | ||
import { DatasetsList } from './datasets-list/DatasetsList' | ||
import { DatasetsListWithInfiniteScroll } from './datasets-list/DatasetsListWithInfiniteScroll' | ||
import { BreadcrumbsGenerator } from '../shared/hierarchy/BreadcrumbsGenerator' | ||
import { | ||
DvObjectType, | ||
UpwardHierarchyNode | ||
} from '../../shared/hierarchy/domain/models/UpwardHierarchyNode' | ||
|
||
import styles from './Collection.module.scss' | ||
import AddDataActionsButton from '../shared/add-data-actions/AddDataActionsButton' | ||
import { useSession } from '../session/SessionContext' | ||
import { useCollection } from './useCollection' | ||
import { CollectionRepository } from '../../collection/domain/repositories/CollectionRepository' | ||
import { PageNotFound } from '../page-not-found/PageNotFound' | ||
import { CollectionSkeleton } from './CollectionSkeleton' | ||
import { CollectionInfo } from './CollectionInfo' | ||
|
||
interface CollectionProps { | ||
repository: CollectionRepository | ||
datasetRepository: DatasetRepository | ||
id: string | ||
page?: number | ||
infiniteScrollEnabled?: boolean | ||
} | ||
const rootNode = new UpwardHierarchyNode( | ||
'Root', | ||
DvObjectType.COLLECTION, | ||
'root', | ||
undefined, | ||
undefined, | ||
undefined | ||
) | ||
|
||
export function Collection({ | ||
datasetRepository, | ||
repository, | ||
id, | ||
datasetRepository, | ||
page, | ||
infiniteScrollEnabled = false | ||
}: CollectionProps) { | ||
const { user } = useSession() | ||
const { collection, isLoading } = useCollection(repository, id) | ||
|
||
if (!isLoading && !collection) { | ||
return <PageNotFound /> | ||
} | ||
|
||
return ( | ||
<Row> | ||
<BreadcrumbsGenerator | ||
hierarchy={ | ||
new UpwardHierarchyNode( | ||
capitalizeFirstLetter(id), | ||
DvObjectType.COLLECTION, | ||
id, | ||
undefined, | ||
undefined, | ||
id !== rootNode.id ? rootNode : undefined | ||
) | ||
} | ||
/> | ||
<header> | ||
<h1>{capitalizeFirstLetter(id)}</h1> | ||
</header> | ||
{user && ( | ||
<div className={styles.container}> | ||
<AddDataActionsButton /> | ||
</div> | ||
)} | ||
{infiniteScrollEnabled ? ( | ||
<DatasetsListWithInfiniteScroll datasetRepository={datasetRepository} collectionId={id} /> | ||
) : ( | ||
<DatasetsList datasetRepository={datasetRepository} page={page} collectionId={id} /> | ||
)} | ||
<Col> | ||
{!collection ? ( | ||
<CollectionSkeleton /> | ||
) : ( | ||
<> | ||
<BreadcrumbsGenerator hierarchy={collection.hierarchy} /> | ||
<CollectionInfo collection={collection} /> | ||
{user && ( | ||
<div className={styles.container}> | ||
<AddDataActionsButton /> | ||
</div> | ||
)} | ||
</> | ||
)} | ||
{infiniteScrollEnabled ? ( | ||
<DatasetsListWithInfiniteScroll datasetRepository={datasetRepository} collectionId={id} /> | ||
) : ( | ||
<DatasetsList datasetRepository={datasetRepository} page={page} collectionId={id} /> | ||
)} | ||
</Col> | ||
</Row> | ||
) | ||
} | ||
|
||
function capitalizeFirstLetter(text: string): string { | ||
return text.charAt(0).toUpperCase() + text.slice(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.