From 3d689122dce9c11bba84cf2900a81a0f979166b0 Mon Sep 17 00:00:00 2001 From: Flaminia Cavallo Date: Wed, 18 Dec 2024 10:48:33 +0100 Subject: [PATCH 1/2] fix: indent org unit with no childs and refresh lists on update or new item --- src/lib/form/useOnSubmit.ts | 9 +++++++++ src/pages/defaultFormTests.tsx | 2 +- src/pages/organisationUnits/list/OrganisationUnitRow.tsx | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib/form/useOnSubmit.ts b/src/lib/form/useOnSubmit.ts index 84e861dc..fc97a6d1 100644 --- a/src/lib/form/useOnSubmit.ts +++ b/src/lib/form/useOnSubmit.ts @@ -2,6 +2,7 @@ import { useAlert } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import { useMemo } from 'react' import { FormProps } from 'react-final-form' +import { useQueryClient } from 'react-query' import { ModelSection } from '../../types' import { IdentifiableObject } from '../../types/generated' import { getSectionPath, useNavigateWithSearchState } from '../routeUtils' @@ -24,6 +25,7 @@ export const useOnSubmitEdit = ({ section, }: UseOnSubmitEditOptions) => { const patchDirtyFields = usePatchModel(modelId, section.namePlural) + const queryClient = useQueryClient() const saveAlert = useAlert( ({ message }) => message, (options) => options @@ -53,6 +55,9 @@ export const useOnSubmitEdit = ({ message: i18n.t('Saved successfully'), success: true, }) + queryClient.invalidateQueries({ + queryKey: [{ resource: getSectionPath(section) }], + }) navigate(`/${getSectionPath(section)}`) }, [patchDirtyFields, saveAlert, navigate, section] @@ -81,6 +86,7 @@ export const useOnSubmitNew = ({ section: ModelSection }) => { const createModel = useCreateModel(section.namePlural) + const queryClient = useQueryClient() const saveAlert = useAlert( ({ message }) => message, (options) => options @@ -107,6 +113,9 @@ export const useOnSubmitNew = ({ message: i18n.t('Created successfully'), success: true, }) + queryClient.invalidateQueries({ + queryKey: [{ resource: getSectionPath(section) }], + }) navigate(`/${getSectionPath(section)}`) }, [createModel, saveAlert, navigate, section] diff --git a/src/pages/defaultFormTests.tsx b/src/pages/defaultFormTests.tsx index 0f40106a..6649d796 100644 --- a/src/pages/defaultFormTests.tsx +++ b/src/pages/defaultFormTests.tsx @@ -5,7 +5,7 @@ export const generateDefaultAddFormTests = ({ }) => { xdescribe(`${componentName} default add form tests`, () => { it('should should return to the list view when cancelling', () => {}) - it('should show a loader while the form is being submitted ', () => {}) + it('should show a loader while the form is being submitted', () => {}) }) } diff --git a/src/pages/organisationUnits/list/OrganisationUnitRow.tsx b/src/pages/organisationUnits/list/OrganisationUnitRow.tsx index 49b740bc..c68ad9dc 100644 --- a/src/pages/organisationUnits/list/OrganisationUnitRow.tsx +++ b/src/pages/organisationUnits/list/OrganisationUnitRow.tsx @@ -87,7 +87,9 @@ export const OrganisationUnitRow = ({ onClick={row.getToggleExpandedHandler()} > - ) : null} + ) : ( + + )} From e3e0e51894b64bab13a1a9bfc5c5117ad57cc92e Mon Sep 17 00:00:00 2001 From: Flaminia Cavallo Date: Wed, 18 Dec 2024 13:39:35 +0100 Subject: [PATCH 2/2] fix: remove show all button and small changes to invalidate --- src/lib/form/useOnSubmit.ts | 4 ++-- .../list/OrganisationUnitList.tsx | 13 ---------- .../list/OrganisationUnitRow.tsx | 24 ------------------- 3 files changed, 2 insertions(+), 39 deletions(-) diff --git a/src/lib/form/useOnSubmit.ts b/src/lib/form/useOnSubmit.ts index fc97a6d1..7e21b022 100644 --- a/src/lib/form/useOnSubmit.ts +++ b/src/lib/form/useOnSubmit.ts @@ -56,7 +56,7 @@ export const useOnSubmitEdit = ({ success: true, }) queryClient.invalidateQueries({ - queryKey: [{ resource: getSectionPath(section) }], + queryKey: [{ resource: section.namePlural }], }) navigate(`/${getSectionPath(section)}`) }, @@ -114,7 +114,7 @@ export const useOnSubmitNew = ({ success: true, }) queryClient.invalidateQueries({ - queryKey: [{ resource: getSectionPath(section) }], + queryKey: [{ resource: section.namePlural }], }) navigate(`/${getSectionPath(section)}`) }, diff --git a/src/pages/organisationUnits/list/OrganisationUnitList.tsx b/src/pages/organisationUnits/list/OrganisationUnitList.tsx index 58954413..b35f83d0 100644 --- a/src/pages/organisationUnits/list/OrganisationUnitList.tsx +++ b/src/pages/organisationUnits/list/OrganisationUnitList.tsx @@ -250,19 +250,6 @@ export const OrganisationUnitList = () => { - setParentIdsToLoad((prev) => { - const { [id]: wasShown, ...withoutId } = - prev - if (wasShown) { - return withoutId - } - return { ...prev, [id]: true } - }) - } - showAllActive={ - parentIdsToLoad[row.original.id] === true - } onShowDetailsClick={handleDetailsClick} isFiltering={isFiltering} hasErrored={hasErrored} diff --git a/src/pages/organisationUnits/list/OrganisationUnitRow.tsx b/src/pages/organisationUnits/list/OrganisationUnitRow.tsx index c68ad9dc..cb42a8c3 100644 --- a/src/pages/organisationUnits/list/OrganisationUnitRow.tsx +++ b/src/pages/organisationUnits/list/OrganisationUnitRow.tsx @@ -18,16 +18,12 @@ import { OrganisationUnitListActions } from './OrganisationUnitListActions' export const OrganisationUnitRow = ({ row, - toggleShowAll, - showAllActive, isFiltering, fetchNextPage, onShowDetailsClick, hasErrored, }: { row: Row - toggleShowAll: (id: string) => void - showAllActive: boolean isFiltering: boolean fetchNextPage: (id: string) => void onShowDetailsClick: (model: BaseListModel) => void @@ -47,26 +43,6 @@ export const OrganisationUnitRow = ({ > {row.getCanExpand() ? ( <> - {isFiltering && - (showAllActive || - row.original.childCount !== - row.subRows.length) && ( - - )}