Skip to content

Commit

Permalink
test: tests in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Nov 13, 2024
1 parent b1adff9 commit 1afcaa8
Show file tree
Hide file tree
Showing 7 changed files with 399 additions and 1,375 deletions.
3 changes: 1 addition & 2 deletions src/sections/create-collection/CreateCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ export function CreateCollection({
<EditCreateCollectionForm
mode="create"
user={user as User}
collection={collection}
parentCollection={{ id: collection.id, name: collection.name }}
parentCollection={collection}
collectionRepository={collectionRepository}
metadataBlockInfoRepository={metadataBlockInfoRepository}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class CollectionFormHelper {
public static defineShouldCheckUseFromParent(
onEditMode: boolean,
isEditingRootCollection: boolean,
isMetadataBlockOrFacetRoot: boolean
isMetadataBlockOrFacetRoot?: boolean
): boolean {
if (onEditMode) {
if (isEditingRootCollection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ type EditCreateCollectionFormProps =
| {
mode: 'create'
user: User
collection: Collection
parentCollection: ParentCollectionData
collection?: never
parentCollection: Collection
collectionRepository: CollectionRepository
metadataBlockInfoRepository: MetadataBlockInfoRepository
}
| {
mode: 'edit'
user: User
collection: Collection
parentCollection?: ParentCollectionData
parentCollection?: ParentCollectionDataInEdition
collectionRepository: CollectionRepository
metadataBlockInfoRepository: MetadataBlockInfoRepository
}

export type EditCreateCollectionFormMode = 'create' | 'edit'

interface ParentCollectionData {
interface ParentCollectionDataInEdition {
id: string
name: string
}
Expand Down Expand Up @@ -103,10 +103,13 @@ export const EditCreateCollectionForm = ({
return CollectionFormHelper.defineBaseInputLevels(allMetadataBlocksInfo)
}, [allMetadataBlocksInfo])

const collectionInputLevelsToFormat =
mode === 'edit' ? collection?.inputLevels : parentCollection?.inputLevels

const formattedCollectionInputLevels: FormattedCollectionInputLevelsWithoutParentBlockName =
useDeepCompareMemo(() => {
return CollectionFormHelper.formatCollectiontInputLevels(collection?.inputLevels)
}, [collection?.inputLevels])
return CollectionFormHelper.formatCollectiontInputLevels(collectionInputLevelsToFormat)
}, [collectionInputLevelsToFormat])

const mergedInputLevels = useDeepCompareMemo(() => {
return CollectionFormHelper.mergeBaseAndDefaultInputLevels(
Expand Down Expand Up @@ -189,19 +192,19 @@ export const EditCreateCollectionForm = ({
const useFieldsFromParentDefault = CollectionFormHelper.defineShouldCheckUseFromParent(
onEditMode,
isEditingRootCollection,
collection.isMetadataBlockRoot
mode === 'edit' ? collection.isMetadataBlockRoot : undefined
)

const useFacetsFromParentDefault = CollectionFormHelper.defineShouldCheckUseFromParent(
onEditMode,
isEditingRootCollection,
collection.isFacetRoot
mode === 'edit' ? collection.isMetadataBlockRoot : undefined
)

const formDefaultValues: CollectionFormData = {
hostCollection: isEditingRootCollection
? null
: (parentCollection as ParentCollectionData).name,
: (parentCollection as ParentCollectionDataInEdition).name,
name: defaultCollectionName,
alias: onEditMode ? collection.id : '',
type: onEditMode ? collection.type : '',
Expand Down
Loading

0 comments on commit 1afcaa8

Please sign in to comment.