-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(fix) O3-3709 - ward app - handle pagination (#1292)
- Loading branch information
Showing
18 changed files
with
254 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
import { type Concept, openmrsFetch, restBaseUrl } from '@openmrs/esm-framework'; | ||
import useSWRImmutable from 'swr/immutable'; | ||
import { type Concept, restBaseUrl, useOpenmrsFetchAll } from '@openmrs/esm-framework'; | ||
|
||
export function useConcepts(uuids: string[], rep = 'default') { | ||
const apiUrl = `${restBaseUrl}/concept?references=${uuids.join()}&v=${rep}`; | ||
const { data, ...rest } = useSWRImmutable<{ data: { results: Array<Concept> } }, Error>(apiUrl, openmrsFetch); | ||
const { data, ...rest } = useOpenmrsFetchAll<Concept>(apiUrl, { immutable: true }); | ||
return { | ||
concepts: data?.data?.results, | ||
concepts: data, | ||
...rest, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,11 @@ | ||
import { type FetchResponse, fhirBaseUrl, openmrsFetch } from '@openmrs/esm-framework'; | ||
import { useEffect, useMemo, useState } from 'react'; | ||
import useSWRImmutable from 'swr/immutable'; | ||
import { fhirBaseUrl, useFhirPagination } from '@openmrs/esm-framework'; | ||
|
||
interface FhirLocation { | ||
fullUrl: string; | ||
resource: { | ||
resourceType: 'Location'; | ||
id: string; | ||
name: string; | ||
description: string; | ||
}; | ||
} | ||
|
||
interface FhirResponse { | ||
resourceType: 'Bundle'; | ||
id: '6a107c31-d760-4df0-bb70-89ad742225ca'; | ||
meta: { | ||
lastUpdated: '2024-08-08T06:28:01.495+00:00'; | ||
}; | ||
type: 'searchset'; | ||
total: number; | ||
link: Array<{ | ||
relation: 'self' | 'prev' | 'next'; | ||
url: string; | ||
}>; | ||
entry: Array<FhirLocation>; | ||
} | ||
|
||
export default function useLocations(filterCriteria: Array<Array<string>> = [], skip: boolean = false) { | ||
const [totalLocations, setTotalLocations] = useState(0); | ||
const [url, setUrl] = useState(`${fhirBaseUrl}/Location`); | ||
export default function useLocations( | ||
filterCriteria: Array<Array<string>> = [], | ||
pageSize: number, | ||
skip: boolean = false, | ||
) { | ||
const searchParams = new URLSearchParams(filterCriteria); | ||
const urlWithSearchParams = `${url}?${searchParams.toString()}`; | ||
const { data, ...rest } = useSWRImmutable<FetchResponse<FhirResponse>>( | ||
!skip ? urlWithSearchParams : null, | ||
openmrsFetch, | ||
); | ||
|
||
useEffect(() => { | ||
if (data?.data) { | ||
setTotalLocations(data.data.total); | ||
} | ||
}, [data]); | ||
|
||
const results = useMemo(() => { | ||
return { | ||
locations: data?.data?.entry?.map((entry) => entry.resource), | ||
totalLocations, | ||
...rest, | ||
}; | ||
}, [data, rest, totalLocations]); | ||
return results; | ||
const urlWithSearchParams = `${fhirBaseUrl}/Location?${searchParams.toString()}`; | ||
return useFhirPagination<fhir.Location>(skip ? null : urlWithSearchParams, pageSize, { immutable: true }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.