Skip to content

Commit 09e4e11

Browse files
committed
Clean up and add table search by name
1 parent 2bdf15b commit 09e4e11

File tree

1 file changed

+10
-10
lines changed
  • packages/fhir-location-management/src/components/AllLocationListFlat

1 file changed

+10
-10
lines changed

packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React from 'react';
22
import { useSimpleTabularView } from '@opensrp/react-utils';
33
import { RouteComponentProps } from 'react-router';
44
import { ILocation } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/ILocation';
@@ -34,8 +34,12 @@ interface Props {
3434
LocationPageSize: number;
3535
}
3636

37-
const getSearchParams = () => {
38-
return { _include: 'Location:partof' };
37+
const getSearchParams = (search: string | null) => {
38+
const baseSearchParam = {"_include": "Location:partof"};
39+
if(search) {
40+
return {"name:contains": search, ...baseSearchParam}
41+
}
42+
return baseSearchParam;
3943
};
4044

4145
export type LocationListPropTypes = Props & RouteComponentProps<RouteParams>;
@@ -44,24 +48,20 @@ export const AllLocationListFlat: React.FC<LocationListPropTypes> = (props) => {
4448
const { fhirBaseURL } = props;
4549
const { t } = useTranslation();
4650
const history = useHistory();
47-
const [detailId, setDetailId] = useState<string>('');
4851
const { addParam, sParams } = useSearchParams();
4952
const userRole = useUserRole();
50-
const resourceId = sParams.get(viewDetailsQuery) ?? undefined;
5153

5254
const {
53-
queryValues: { data, isFetching, isLoading, error, refetch },
55+
queryValues: { data, isFetching, isLoading, error},
5456
tablePaginationProps,
5557
searchFormProps,
56-
} = useSimpleTabularView<ILocation>(fhirBaseURL, locationResourceType, getSearchParams());
58+
} = useSimpleTabularView<ILocation>(fhirBaseURL, locationResourceType, getSearchParams);
5759

5860
if (error && !data) {
5961
return <BrokenPage errorMessage={(error as Error).message} />;
6062
}
6163

62-
useEffect(() => {}, [data, isFetching, isLoading, error]);
63-
64-
const tableData: any[] = (data?.records ?? []).map((datum: Dictionary) => ({
64+
const tableData = (data?.records ?? []).map((datum: Dictionary) => ({
6565
key: datum.id,
6666
id: datum.id,
6767
name: datum.name,

0 commit comments

Comments
 (0)