From 62ff7b9b0218c6af78bd6d190abf4d6f3a337931 Mon Sep 17 00:00:00 2001 From: Nisarg Vadgama <31422051+ngunner15@users.noreply.github.com> Date: Tue, 24 Sep 2024 07:09:28 -0700 Subject: [PATCH] feat: 1594 adjustments for orchard screen (#1599) Co-authored-by: mgaseta <105936322+mgaseta@users.noreply.github.com> Co-authored-by: mgaseta Co-authored-by: Ricardo Campos --- .../a-class-seedlot-reg-form-orchard.cy.ts | 10 ++-- .../OrchardStep/OrchardWarnModal/index.tsx | 4 +- .../OrchardStep/index.tsx | 55 +++++++++++++------ 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/frontend/cypress/e2e/smoke-test/a-class-seedlot-reg-form-orchard.cy.ts b/frontend/cypress/e2e/smoke-test/a-class-seedlot-reg-form-orchard.cy.ts index 33887e85c..900968a12 100644 --- a/frontend/cypress/e2e/smoke-test/a-class-seedlot-reg-form-orchard.cy.ts +++ b/frontend/cypress/e2e/smoke-test/a-class-seedlot-reg-form-orchard.cy.ts @@ -57,24 +57,22 @@ describe('A Class Seedlot Registration form, Orchard', () => { .eq(0) .should('have.text', regFormData.orchard.subtitle); - cy.get('.seedlot-orchard-title-row') + cy.get('.seedlot-gamete-title-row') .find('h2') - .eq(1) .should('have.text', regFormData.orchard.gameteTitle); - cy.get('.seedlot-orchard-title-row') + cy.get('.seedlot-gamete-title-row') .find('.subtitle-section') - .eq(1) .should('have.text', regFormData.orchard.gameteSubtitle); cy.get('.seedlot-orchard-title-row') .find('h2') - .eq(2) + .eq(1) .should('have.text', regFormData.orchard.pollenTitle); cy.get('.seedlot-orchard-title-row') .find('.subtitle-section') - .eq(2) + .eq(1) .should('have.text', regFormData.orchard.pollenSubtitle); }); diff --git a/frontend/src/components/SeedlotRegistrationSteps/OrchardStep/OrchardWarnModal/index.tsx b/frontend/src/components/SeedlotRegistrationSteps/OrchardStep/OrchardWarnModal/index.tsx index 4bb313b02..6ab97550a 100644 --- a/frontend/src/components/SeedlotRegistrationSteps/OrchardStep/OrchardWarnModal/index.tsx +++ b/frontend/src/components/SeedlotRegistrationSteps/OrchardStep/OrchardWarnModal/index.tsx @@ -9,12 +9,13 @@ interface OrchardWarnModalProps { open: boolean; setOpen: Function; confirmEdit: Function; + cancelEdit: Function; modalType: keyof orchardModalOptions; } const OrchardWarnModal = ( { - open, setOpen, confirmEdit, modalType + open, setOpen, confirmEdit, modalType, cancelEdit }: OrchardWarnModalProps ) => ( { + cancelEdit(); setOpen(false); }} onRequestSubmit={() => { diff --git a/frontend/src/components/SeedlotRegistrationSteps/OrchardStep/index.tsx b/frontend/src/components/SeedlotRegistrationSteps/OrchardStep/index.tsx index d0860525a..fdb392faf 100644 --- a/frontend/src/components/SeedlotRegistrationSteps/OrchardStep/index.tsx +++ b/frontend/src/components/SeedlotRegistrationSteps/OrchardStep/index.tsx @@ -67,6 +67,8 @@ const OrchardStep = ({ const [modalType, setModalType] = useState('change'); // Store the orchard selection until the user has confirmed the warning modal const [stagedOrchard, setStagedOrchard] = useState(null); + const [forceUpdatePrimary, setForceUpdatePrimary] = useState(0); + const [forceUpdateSecondary, setForceUpdateSecondary] = useState(0); const gameticMethodologyQuery = useQuery({ queryKey: ['gametic-methodologies'], @@ -187,19 +189,22 @@ const OrchardStep = ({ orchards } ); + + if (isPrimary) { + setForceUpdatePrimary((prev) => prev + 1); + } else { + setForceUpdateSecondary((prev) => prev + 1); + } }; // Remove options that are already selected by a user - const removeSelectedOption = (data: MultiOptionsObj[]) => { - const filteredOptions: MultiOptionsObj[] = structuredClone(data); - const orchardId = state.orchards.primaryOrchard.value.code; - // The index of a matching orchard in filteredOptions - const orchardOptIndex = filteredOptions.findIndex((option) => option.code === orchardId); - if (orchardOptIndex > -1) { - // Remove found option - filteredOptions.splice(orchardOptIndex, 1); + const filterOrchardOpts = (codeToFilter: string) => { + if (orchardQuery.data) { + return orchardQuery.data.filter( + (orchards) => orchards.code !== codeToFilter + ); } - return filteredOptions; + return []; }; const isTableEmpty = Object.keys(tableRowData).length === 0; @@ -217,6 +222,18 @@ const OrchardStep = ({ } }; + const cancelEdit = () => { + if (modalType === 'change' && stagedOrchard) { + const value = stagedOrchard.id === state.orchards.primaryOrchard.id + ? state.orchards.primaryOrchard.value + : state.orchards.secondaryOrchard.value; + setOrchard( + stagedOrchard.id === state.orchards.primaryOrchard.id, + value + ); + } + }; + const renderOrchardButtons = () => { if (!isFormSubmitted && !isReview) { return state.orchards.secondaryOrchard.enabled @@ -301,13 +318,14 @@ const OrchardStep = ({ <> - + { gameticMethodologyQuery.isFetching ? @@ -469,13 +488,14 @@ const OrchardStep = ({ onChange={(e: ComboBoxEvent) => setGametic(e, true)} readOnly={isFormSubmitted && !isReview} selectedItem={state.femaleGametic.value} + initialSelectedItem={state.femaleGametic.value} /> ) } - + { gameticMethodologyQuery.isFetching ? @@ -495,6 +515,7 @@ const OrchardStep = ({ onChange={(e: ComboBoxEvent) => setGametic(e, false)} readOnly={isFormSubmitted && !isReview} selectedItem={state.maleGametic.value} + initialSelectedItem={state.maleGametic.value} /> ) } @@ -592,13 +613,14 @@ const OrchardStep = ({ ? ( <> - + );