Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: indent org unit with no child and refresh lists on updates #473

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/lib/form/useOnSubmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -24,6 +25,7 @@ export const useOnSubmitEdit = <TFormValues extends IdentifiableObject>({
section,
}: UseOnSubmitEditOptions) => {
const patchDirtyFields = usePatchModel(modelId, section.namePlural)
const queryClient = useQueryClient()
const saveAlert = useAlert(
({ message }) => message,
(options) => options
Expand Down Expand Up @@ -53,6 +55,9 @@ export const useOnSubmitEdit = <TFormValues extends IdentifiableObject>({
message: i18n.t('Saved successfully'),
success: true,
})
queryClient.invalidateQueries({
Copy link
Member

@Birkbjo Birkbjo Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes a lot of sense, however I'm not sure if we want to couple the sectionPath to the resource?
getSectionPath is for the router, and if we in the future would want to change those paths.

I think it's more correct to use section.namePlural if we want to do this.

Initially I was thinking to add refetchOnMount: true on the queries for the list. That should fix the problem in this case. But I do agree that invalidating the query makes a lot of sense as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, i'll chande it to namePlural and keep it as it is then (i do like being explicit about it)

queryKey: [{ resource: getSectionPath(section) }],
})
navigate(`/${getSectionPath(section)}`)
},
[patchDirtyFields, saveAlert, navigate, section]
Expand Down Expand Up @@ -81,6 +86,7 @@ export const useOnSubmitNew = <TFormValues extends ModelWithAttributeValues>({
section: ModelSection
}) => {
const createModel = useCreateModel(section.namePlural)
const queryClient = useQueryClient()
const saveAlert = useAlert(
({ message }) => message,
(options) => options
Expand All @@ -107,6 +113,9 @@ export const useOnSubmitNew = <TFormValues extends ModelWithAttributeValues>({
message: i18n.t('Created successfully'),
success: true,
})
queryClient.invalidateQueries({
queryKey: [{ resource: getSectionPath(section) }],
})
navigate(`/${getSectionPath(section)}`)
},
[createModel, saveAlert, navigate, section]
Expand Down
2 changes: 1 addition & 1 deletion src/pages/defaultFormTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {})
})
}

Expand Down
4 changes: 3 additions & 1 deletion src/pages/organisationUnits/list/OrganisationUnitRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ export const OrganisationUnitRow = ({
onClick={row.getToggleExpandedHandler()}
></Button>
</>
) : null}
) : (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we not decide to remove the expand all as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i can do that as well

<span style={{ width: 26 }} />
)}
<Checkbox
checked={row.getIsSelected()}
onChange={({ checked }) =>
Expand Down
Loading