Skip to content

Commit

Permalink
fix: some adjustments, remove contactFactory & isCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengShi-1 committed Feb 25, 2025
1 parent a916132 commit fd58aea
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 40 deletions.
3 changes: 1 addition & 2 deletions packages/design-system/src/lib/components/alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ interface AlertProps {
dismissible?: boolean
customHeading?: string
children?: ReactNode
onClose?: () => void
}

function Alert({ variant, dismissible = true, customHeading, children, onClose }: AlertProps) {
function Alert({ variant, dismissible = true, customHeading, children }: AlertProps) {
interface AlertHeadings {
[key: string]: string
}
Expand Down
9 changes: 5 additions & 4 deletions src/sections/collection/Collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ContactButton } from '@/sections/shared/contact/ContactButton'
import { EditCollectionDropdown } from './edit-collection-dropdown/EditCollectionDropdown'
import { FeaturedItems } from './featured-items/FeaturedItems'
import styles from './Collection.module.scss'
import { ContactRepositoryFactory } from '@/sections/shared/contact/ContactFactory'
import { ContactRepository } from '@/contact/domain/repositories/ContactRepository'

interface CollectionProps {
collectionRepository: CollectionRepository
Expand All @@ -28,6 +28,7 @@ interface CollectionProps {
edited?: boolean
collectionQueryParams: UseCollectionQueryParamsReturnType
infiniteScrollEnabled?: boolean
contactRepository: ContactRepository
}

export function Collection({
Expand All @@ -36,11 +37,11 @@ export function Collection({
created,
published,
edited,
collectionQueryParams
collectionQueryParams,
contactRepository
}: CollectionProps) {
useScrollTop()
const { t } = useTranslation('collection')
const contactRepository = ContactRepositoryFactory.create()
const { collection, isLoading: isLoadingCollection } = useCollection(
collectionRepository,
collectionIdFromParams,
Expand Down Expand Up @@ -98,7 +99,7 @@ export function Collection({
<div className={styles['right-content']}>
<ContactButton
toContactName={collection.name}
isCollection={true}
contactObjectType={'collection'}
id={collection.id}
contactRepository={contactRepository}
/>
Expand Down
3 changes: 3 additions & 0 deletions src/sections/collection/CollectionFactory.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { ReactElement } from 'react'
import { useLocation, useParams } from 'react-router-dom'
import { CollectionJSDataverseRepository } from '../../collection/infrastructure/repositories/CollectionJSDataverseRepository'
import { ContactJSDataverseRepository } from '@/contact/infrastructure/ContactJSDataverseRepository'
import { Collection } from './Collection'
import { INFINITE_SCROLL_ENABLED } from './config'
import { useGetCollectionQueryParams } from './useGetCollectionQueryParams'

const collectionRepository = new CollectionJSDataverseRepository()
const contactRepository = new ContactJSDataverseRepository()
export class CollectionFactory {
static create(): ReactElement {
return <CollectionWithSearchParams />
Expand All @@ -32,6 +34,7 @@ function CollectionWithSearchParams() {
published={published}
edited={edited}
infiniteScrollEnabled={INFINITE_SCROLL_ENABLED}
contactRepository={contactRepository}
/>
)
}
4 changes: 4 additions & 0 deletions src/sections/dataset/Dataset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ import { QueryParamKey, Route } from '../Route.enum'
import { MetadataBlockInfoRepository } from '../../metadata-block-info/domain/repositories/MetadataBlockInfoRepository'
import { CollectionRepository } from '../../collection/domain/repositories/CollectionRepository'
import { DatasetTerms } from '@/sections/dataset/dataset-terms/DatasetTerms'
import { ContactRepository } from '@/contact/domain/repositories/ContactRepository'

interface DatasetProps {
datasetRepository: DatasetRepository
fileRepository: FileRepository
metadataBlockInfoRepository: MetadataBlockInfoRepository
collectionRepository: CollectionRepository
contactRepository: ContactRepository
created?: boolean
metadataUpdated?: boolean
filesTabInfiniteScrollEnabled?: boolean
Expand All @@ -45,6 +47,7 @@ export function Dataset({
fileRepository,
metadataBlockInfoRepository,
collectionRepository,
contactRepository,
created,
metadataUpdated,
filesTabInfiniteScrollEnabled,
Expand Down Expand Up @@ -129,6 +132,7 @@ export function Dataset({
datasetRepository={datasetRepository}
collectionRepository={collectionRepository}
dataset={dataset}
contactRepository={contactRepository}
/>
</Col>
</Row>
Expand Down
5 changes: 4 additions & 1 deletion src/sections/dataset/DatasetFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import { AlertProvider } from '../alerts/AlertProvider'
import { searchParamVersionToDomainVersion } from '../../router'
import { FILES_TAB_INFINITE_SCROLL_ENABLED } from './config'
import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository'
import { ContactJSDataverseRepository } from '@/contact/infrastructure/ContactJSDataverseRepository'

const collectionRepository = new CollectionJSDataverseRepository()
const datasetRepository = new DatasetJSDataverseRepository()
const fileRepository = new FileJSDataverseRepository()
const metadataBlockInfoRepository = new MetadataBlockInfoJSDataverseRepository()

const contactRepository = new ContactJSDataverseRepository()
const settingRepository = new SettingJSDataverseRepository()

export class DatasetFactory {
Expand Down Expand Up @@ -73,6 +74,7 @@ function DatasetWithSearchParams() {
datasetRepository={datasetRepository}
fileRepository={fileRepository}
metadataBlockInfoRepository={metadataBlockInfoRepository}
contactRepository={contactRepository}
filesTabInfiniteScrollEnabled={FILES_TAB_INFINITE_SCROLL_ENABLED}
tab={tab}
/>
Expand All @@ -90,6 +92,7 @@ function DatasetWithSearchParams() {
datasetRepository={datasetRepository}
fileRepository={fileRepository}
metadataBlockInfoRepository={metadataBlockInfoRepository}
contactRepository={contactRepository}
created={created}
publishInProgress={publishInProgress}
metadataUpdated={metadataUpdated}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ import { LinkDatasetButton } from './link-dataset-button/LinkDatasetButton'
import { ShareDatasetButton } from './share-dataset-button/ShareDatasetButton'
import styles from './DatasetActionButtons.module.scss'
import { ContactButton } from '@/sections/shared/contact/ContactButton'
import { ContactRepositoryFactory } from '@/sections/shared/contact/ContactFactory'
import { ContactRepository } from '@/contact/domain/repositories/ContactRepository'

interface DatasetActionButtonsProps {
dataset: Dataset
datasetRepository: DatasetRepository
collectionRepository: CollectionRepository
contactRepository: ContactRepository
}

export function DatasetActionButtons({
dataset,
datasetRepository,
collectionRepository
collectionRepository,
contactRepository
}: DatasetActionButtonsProps) {
const { t } = useTranslation('dataset')
const contactRepository = ContactRepositoryFactory.create()

return (
<ButtonGroup aria-label={t('datasetActionButtons.title')} vertical className={styles.group}>
Expand All @@ -46,8 +47,8 @@ export function DatasetActionButtons({
<LinkDatasetButton dataset={dataset} />
<ButtonGroup className={styles['contact-owner-and-share-group']}>
<ContactButton
isCollection={false}
toContactName={dataset.metadataBlocks[0].fields.title}
contactObjectType="dataset"
id={dataset.persistentId}
contactRepository={contactRepository}
/>
Expand Down
15 changes: 8 additions & 7 deletions src/sections/shared/contact/ContactButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import { ContactRepository } from '@/contact/domain/repositories/ContactReposito

interface ContactButtonProps {
toContactName: string
isCollection: boolean
contactObjectType: ContactObjectType
id: string | number
contactRepository: ContactRepository
}

type ContactObjectType = 'collection' | 'dataset'

export const ContactButton = ({
toContactName,
isCollection,
contactObjectType,
id,
contactRepository
}: ContactButtonProps) => {
Expand All @@ -25,11 +27,9 @@ export const ContactButton = ({

return (
<>
{isCollection ? (
{contactObjectType == 'collection' && (
<>
<Tooltip
overlay={isCollection ? t('contact.contactCollection') : t('contact.contactDataset')}
placement="top">
<Tooltip overlay={t('contact.contactCollection')} placement="top">
<Button
variant="link"
onClick={openContactModal}
Expand All @@ -47,7 +47,8 @@ export const ContactButton = ({
contactRepository={contactRepository}
/>
</>
) : (
)}
{contactObjectType == 'dataset' && (
<>
<Button variant="secondary" onClick={openContactModal} size="sm">
{t('contact.title.dataset')}
Expand Down
8 changes: 0 additions & 8 deletions src/sections/shared/contact/ContactFactory.tsx

This file was deleted.

9 changes: 9 additions & 0 deletions src/stories/collection/Collection.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CollectionLoadingMockRepository } from './CollectionLoadingMockReposito
import { UnpublishedCollectionMockRepository } from '@/stories/collection/UnpublishedCollectionMockRepository'
import { CollectionFeaturedItemMother } from '@tests/component/collection/domain/models/CollectionFeaturedItemMother'
import { FakerHelper } from '@tests/component/shared/FakerHelper'
import { ContactMockRepository } from '../shared/contact/ContactMockRepository'

const meta: Meta<typeof Collection> = {
title: 'Pages/Collection',
Expand All @@ -26,6 +27,7 @@ export const Default: Story = {
render: () => (
<Collection
collectionRepository={new CollectionMockRepository()}
contactRepository={new ContactMockRepository()}
collectionIdFromParams="collection"
created={false}
published={false}
Expand All @@ -43,6 +45,7 @@ export const Loading: Story = {
<Collection
collectionIdFromParams="collection"
collectionRepository={new CollectionLoadingMockRepository()}
contactRepository={new ContactMockRepository()}
created={false}
published={false}
collectionQueryParams={{ pageQuery: 1, searchQuery: undefined, typesQuery: undefined }}
Expand All @@ -56,6 +59,7 @@ export const LoggedIn: Story = {
<Collection
collectionIdFromParams="collection"
collectionRepository={new CollectionMockRepository()}
contactRepository={new ContactMockRepository()}
created={false}
published={false}
collectionQueryParams={{ pageQuery: 1, searchQuery: undefined, typesQuery: undefined }}
Expand All @@ -68,6 +72,7 @@ export const Unpublished: Story = {
<Collection
collectionIdFromParams="collection"
collectionRepository={new UnpublishedCollectionMockRepository()}
contactRepository={new ContactMockRepository()}
created={false}
published={false}
collectionQueryParams={{ pageQuery: 1, searchQuery: undefined, typesQuery: undefined }}
Expand All @@ -80,6 +85,7 @@ export const Created: Story = {
render: () => (
<Collection
collectionRepository={new CollectionMockRepository()}
contactRepository={new ContactMockRepository()}
collectionIdFromParams="collection"
created={true}
published={false}
Expand All @@ -92,6 +98,7 @@ export const Published: Story = {
render: () => (
<Collection
collectionRepository={new CollectionMockRepository()}
contactRepository={new ContactMockRepository()}
collectionIdFromParams="collection"
created={false}
published={true}
Expand All @@ -105,6 +112,7 @@ export const Edited: Story = {
render: () => (
<Collection
collectionRepository={new CollectionMockRepository()}
contactRepository={new ContactMockRepository()}
collectionIdFromParams="collection"
created={false}
published={false}
Expand All @@ -128,6 +136,7 @@ export const WithFeaturedItems: Story = {
render: () => (
<Collection
collectionRepository={collectionRepositoryWithFeaturedItems}
contactRepository={new ContactMockRepository()}
collectionIdFromParams="collection"
created={false}
published={false}
Expand Down
12 changes: 12 additions & 0 deletions src/stories/dataset/Dataset.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { WithNotImplementedModal } from '../WithNotImplementedModal'
import { MetadataBlockInfoMockRepository } from '../shared-mock-repositories/metadata-block-info/MetadataBlockInfoMockRepository'
import { DatasetMockRepository } from './DatasetMockRepository'
import { CollectionMockRepository } from '@/stories/collection/CollectionMockRepository'
import { ContactMockRepository } from '../shared/contact/ContactMockRepository'

const meta: Meta<typeof Dataset> = {
title: 'Pages/Dataset',
Expand All @@ -40,6 +41,7 @@ export const Default: Story = {
datasetRepository={new DatasetMockRepository()}
fileRepository={new FileMockRepository()}
metadataBlockInfoRepository={new MetadataBlockInfoMockRepository()}
contactRepository={new ContactMockRepository()}
filesTabInfiniteScrollEnabled
/>
)
Expand All @@ -52,6 +54,7 @@ export const WithNormalPagination: Story = {
datasetRepository={new DatasetMockRepository()}
fileRepository={new FileMockRepository()}
metadataBlockInfoRepository={new MetadataBlockInfoMockRepository()}
contactRepository={new ContactMockRepository()}
/>
)
}
Expand All @@ -64,6 +67,7 @@ export const Created: Story = {
datasetRepository={new DatasetMockRepository()}
fileRepository={new FileMockRepository()}
metadataBlockInfoRepository={new MetadataBlockInfoMockRepository()}
contactRepository={new ContactMockRepository()}
created={true}
filesTabInfiniteScrollEnabled
/>
Expand All @@ -78,6 +82,7 @@ export const MetadataUpdated: Story = {
datasetRepository={new DatasetMockRepository()}
fileRepository={new FileMockRepository()}
metadataBlockInfoRepository={new MetadataBlockInfoMockRepository()}
contactRepository={new ContactMockRepository()}
metadataUpdated={true}
/>
)
Expand All @@ -90,6 +95,7 @@ export const DraftWithAllDatasetPermissions: Story = {
datasetRepository={new DatasetMockRepository()}
fileRepository={new FileMockRepository()}
metadataBlockInfoRepository={new MetadataBlockInfoMockRepository()}
contactRepository={new ContactMockRepository()}
filesTabInfiniteScrollEnabled
/>
)
Expand All @@ -102,6 +108,7 @@ export const Deaccessioned: Story = {
datasetRepository={new DatasetMockRepository()}
fileRepository={new FileMockRepository()}
metadataBlockInfoRepository={new MetadataBlockInfoMockRepository()}
contactRepository={new ContactMockRepository()}
filesTabInfiniteScrollEnabled
/>
)
Expand All @@ -114,6 +121,7 @@ export const LoggedInAsOwner: Story = {
datasetRepository={new DatasetMockRepository()}
fileRepository={new FileMockRepository()}
metadataBlockInfoRepository={new MetadataBlockInfoMockRepository()}
contactRepository={new ContactMockRepository()}
filesTabInfiniteScrollEnabled
/>
)
Expand All @@ -127,6 +135,7 @@ export const Loading: Story = {
datasetRepository={new DatasetMockRepository()}
fileRepository={new FileMockRepository()}
metadataBlockInfoRepository={new MetadataBlockInfoMockRepository()}
contactRepository={new ContactMockRepository()}
filesTabInfiniteScrollEnabled
/>
)
Expand All @@ -140,6 +149,7 @@ export const DatasetNotFound: Story = {
datasetRepository={new DatasetMockRepository()}
fileRepository={new FileMockRepository()}
metadataBlockInfoRepository={new MetadataBlockInfoMockRepository()}
contactRepository={new ContactMockRepository()}
filesTabInfiniteScrollEnabled
/>
)
Expand All @@ -153,6 +163,7 @@ export const DatasetAnonymizedView: Story = {
datasetRepository={new DatasetMockRepository()}
fileRepository={new FileMockRepository()}
metadataBlockInfoRepository={new MetadataBlockInfoMockRepository()}
contactRepository={new ContactMockRepository()}
filesTabInfiniteScrollEnabled
/>
)
Expand All @@ -166,6 +177,7 @@ export const DatasetWithNoFiles: Story = {
datasetRepository={new DatasetMockRepository()}
fileRepository={new FileMockNoDataRepository()}
metadataBlockInfoRepository={new MetadataBlockInfoMockRepository()}
contactRepository={new ContactMockRepository()}
filesTabInfiniteScrollEnabled
/>
)
Expand Down
Loading

0 comments on commit fd58aea

Please sign in to comment.