From 49683369f7d4d35fe5c1df3d4c07fec3ab54c2ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Thu, 31 Oct 2024 16:21:42 -0300 Subject: [PATCH 1/4] chore: update js-dataverse version --- package-lock.json | 9 +++++---- package.json | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0bbb5c74c..42ddaf1e7 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": "2.0.0-alpha.4", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", @@ -3674,9 +3674,10 @@ }, "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-alpha.4", + "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-alpha.4/10ab7e0ed2a31a09b1b32d27521b96f84ef50f4f", + "integrity": "sha512-SJdkBIks+yjJxEVw8G7sf4YY2Bujl+8vOD+fZqt2qhIGmyPSlj9ld0APnYyoVX6lI8lGsREHZzYYjzeAmYfxhw==", + "license": "MIT", "dependencies": { "@types/node": "^18.15.11", "@types/turndown": "^5.0.1", diff --git a/package.json b/package.json index fe43d59f1..db411a652 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": "2.0.0-alpha.4", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", From f9bda330dbff9db8f6c8dcc913f79b3b7b4563b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Thu, 31 Oct 2024 16:42:15 -0300 Subject: [PATCH 2/4] feat: reset checked metadata blocks without hardcoded array --- .../FieldsFromParentCheckbox.tsx | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/sections/create-collection/collection-form/metadata-fields-section/fields-from-parent-checkbox/FieldsFromParentCheckbox.tsx b/src/sections/create-collection/collection-form/metadata-fields-section/fields-from-parent-checkbox/FieldsFromParentCheckbox.tsx index 30c93442d..e04c1ea71 100644 --- a/src/sections/create-collection/collection-form/metadata-fields-section/fields-from-parent-checkbox/FieldsFromParentCheckbox.tsx +++ b/src/sections/create-collection/collection-form/metadata-fields-section/fields-from-parent-checkbox/FieldsFromParentCheckbox.tsx @@ -2,7 +2,6 @@ import { ChangeEvent, useId, useState } from 'react' import { useTranslation } from 'react-i18next' import { Controller, UseControllerProps, useFormContext, useWatch } from 'react-hook-form' import { Form } from '@iqss/dataverse-design-system' -import { MetadataBlockName } from '../../../../../metadata-block-info/domain/models/MetadataBlockInfo' import { ConfirmResetModificationsModal } from './ConfirmResetModificationsModal' import { CollectionFormData, @@ -11,15 +10,6 @@ import { USE_FIELDS_FROM_PARENT } from '../../CollectionForm' -const ALL_INPUT_LEVEL_FIELDS = [ - MetadataBlockName.CITATION, - MetadataBlockName.GEOSPATIAL, - MetadataBlockName.SOCIAL_SCIENCE, - MetadataBlockName.ASTROPHYSICS, - MetadataBlockName.BIOMEDICAL, - MetadataBlockName.JOURNAL -] - interface FieldsFromParentCheckboxProps { defaultValues: CollectionFormData } @@ -34,12 +24,11 @@ export const FieldsFromParentCheckbox = ({ defaultValues }: FieldsFromParentChec const handleContinueWithReset = () => { setValue(USE_FIELDS_FROM_PARENT, true) - // Reset metadata block names checboxes to the inital value - ALL_INPUT_LEVEL_FIELDS.forEach((blockName) => { - setValue( - `${METADATA_BLOCKS_NAMES_GROUPER}.${blockName}`, - defaultValues[METADATA_BLOCKS_NAMES_GROUPER][blockName] - ) + const metadataBlockDefaultValues = Object.entries(defaultValues[METADATA_BLOCKS_NAMES_GROUPER]) + + // Reset metadata block names checkboxes to the inital value + metadataBlockDefaultValues.forEach(([blockName, blockInitialValue]) => { + setValue(`${METADATA_BLOCKS_NAMES_GROUPER}.${blockName}`, blockInitialValue) }) // Reset input levels to the initial value From c379d5027a54a71519b7cbf34a66081c35c2c92b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Fri, 1 Nov 2024 08:56:11 -0300 Subject: [PATCH 3/4] fix: dont send block names and input levels if use fields from parent is checked --- .../collection-form/useSubmitCollection.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/sections/create-collection/collection-form/useSubmitCollection.ts b/src/sections/create-collection/collection-form/useSubmitCollection.ts index e3a724877..7a8fff79c 100644 --- a/src/sections/create-collection/collection-form/useSubmitCollection.ts +++ b/src/sections/create-collection/collection-form/useSubmitCollection.ts @@ -8,7 +8,8 @@ import { CollectionFormData, CollectionFormValuesOnSubmit, INPUT_LEVELS_GROUPER, - METADATA_BLOCKS_NAMES_GROUPER + METADATA_BLOCKS_NAMES_GROUPER, + USE_FIELDS_FROM_PARENT } from './CollectionForm' import { RouteWithParams } from '../../Route.enum' import { JSDataverseWriteErrorHandler } from '../../../shared/helpers/JSDataverseWriteErrorHandler' @@ -65,6 +66,8 @@ export function useSubmitCollection( const facetIdsDTO = formData.facetIds.map((facet) => facet.value) + const useFieldsFromParentChecked = formData[USE_FIELDS_FROM_PARENT] + const newCollection: CollectionDTO = { name: formData.name, alias: formData.alias, @@ -72,8 +75,8 @@ export function useSubmitCollection( affiliation: formData.affiliation, description: formData.description, contacts: contactsDTO, - metadataBlockNames: metadataBlockNamesDTO, - inputLevels: inputLevelsDTO, + metadataBlockNames: useFieldsFromParentChecked ? undefined : metadataBlockNamesDTO, + inputLevels: useFieldsFromParentChecked ? undefined : inputLevelsDTO, facetIds: facetIdsDTO } From 11f8e9cc6c8faf0c2e41ab18093be344c574d9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Fri, 1 Nov 2024 11:07:46 -0300 Subject: [PATCH 4/4] test: add cases to assert sended properties --- .../create-collection/CollectionForm.spec.tsx | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tests/component/sections/create-collection/CollectionForm.spec.tsx b/tests/component/sections/create-collection/CollectionForm.spec.tsx index b7442e989..0dd7f9f78 100644 --- a/tests/component/sections/create-collection/CollectionForm.spec.tsx +++ b/tests/component/sections/create-collection/CollectionForm.spec.tsx @@ -18,6 +18,7 @@ import { MetadataBlockInfoMother } from '../../metadata-block-info/domain/models import { CollectionFormHelper } from '../../../../src/sections/create-collection/collection-form/CollectionFormHelper' import { MetadataBlockName } from '../../../../src/metadata-block-info/domain/models/MetadataBlockInfo' import { CollectionFacetMother } from '../../collection/domain/models/CollectionFacetMother' +import { CollectionDTO } from '@/collection/domain/useCases/DTOs/CollectionDTO' const collectionRepository: CollectionRepository = {} as CollectionRepository @@ -547,6 +548,75 @@ describe('CollectionForm', () => { cy.findByLabelText('Subtitle').should('be.checked') }) + + it('should send metadataBlockNames and inputLevels as undefined if use fields from parent is checked', () => { + const collectionRepository = {} as CollectionRepository + collectionRepository.create = cy.stub().as('createCollection').resolves() + + cy.customMount( + + ) + // Accept suggestion + cy.findByRole('button', { name: 'Apply suggestion' }).click() + // Select a Category option + cy.findByLabelText(/^Category/i).select(1) + + cy.findByRole('button', { name: 'Create Collection' }).click() + + cy.get('@createCollection').should((spy) => { + const createCollectionSpy = spy as unknown as Cypress.Agent + const collectionDTO = createCollectionSpy.getCall(0).args[0] as CollectionDTO + + const inputLevels = collectionDTO.inputLevels + const metadataBlockNames = collectionDTO.metadataBlockNames + + expect(inputLevels).to.be.undefined + expect(metadataBlockNames).to.be.undefined + }) + }) + + it('should not send metadataBlockNames and inputLevels as undefined if use fields from parent is unchecked', () => { + const collectionRepository = {} as CollectionRepository + collectionRepository.create = cy.stub().as('createCollection').resolves() + + cy.customMount( + + ) + + cy.get('@useFieldsFromParentCheckbox').uncheck({ force: true }) + + // Accept suggestion + cy.findByRole('button', { name: 'Apply suggestion' }).click() + // Select a Category option + cy.findByLabelText(/^Category/i).select(1) + + cy.findByRole('button', { name: 'Create Collection' }).click() + + cy.get('@createCollection').should((spy) => { + const createCollectionSpy = spy as unknown as Cypress.Agent + const collectionDTO = createCollectionSpy.getCall(0).args[0] as CollectionDTO + + const inputLevels = collectionDTO.inputLevels + const metadataBlockNames = collectionDTO.metadataBlockNames + + expect(inputLevels).to.not.be.undefined + expect(metadataBlockNames).to.not.be.undefined + }) + }) }) describe('InputLevelFieldRow', () => {