From cdce6fadb4e30b5fc34d8b3ca69abbddaa821569 Mon Sep 17 00:00:00 2001 From: mahendar Date: Tue, 24 Dec 2024 15:38:15 +0530 Subject: [PATCH 1/7] clear all badge handled --- src/components/Resource/ResourceFilter.tsx | 74 ++++++++++------------ 1 file changed, 32 insertions(+), 42 deletions(-) diff --git a/src/components/Resource/ResourceFilter.tsx b/src/components/Resource/ResourceFilter.tsx index a000c81e1a4..51b8280cded 100644 --- a/src/components/Resource/ResourceFilter.tsx +++ b/src/components/Resource/ResourceFilter.tsx @@ -16,7 +16,7 @@ import { RESOURCE_FILTER_ORDER } from "@/common/constants"; import { RESOURCE_CHOICES } from "@/common/constants"; import routes from "@/Utils/request/api"; -import useTanStackQueryInstead from "@/Utils/request/useQuery"; +import useQuery from "@/Utils/request/useQuery"; import { dateQueryString } from "@/Utils/utils"; const getDate = (value: any) => @@ -31,7 +31,7 @@ export default function ListFilter(props: any) { approving_facility_ref: null, assigned_facility: filter.assigned_facility || "", assigned_facility_ref: null, - emergency: filter.emergency || "--", + emergency: filter.emergency || "", created_date_before: filter.created_date_before || null, created_date_after: filter.created_date_after || null, modified_date_before: filter.modified_date_before || null, @@ -40,51 +40,41 @@ export default function ListFilter(props: any) { status: filter.status || null, }); - const { loading: orginFacilityLoading } = useTanStackQueryInstead( - routes.getAnyFacility, - { - prefetch: filter.origin_facility !== undefined, - pathParams: { id: filter.origin_facility }, - onResponse: ({ res, data }) => { - if (res && data) { - setFilterState({ - origin_facility_ref: filter.origin_facility === "" ? "" : data, - }); - } - }, + const { loading: orginFacilityLoading } = useQuery(routes.getAnyFacility, { + prefetch: filter.origin_facility !== undefined, + pathParams: { id: filter.origin_facility }, + onResponse: ({ res, data }) => { + if (res && data) { + setFilterState({ + origin_facility_ref: filter.origin_facility === "" ? "" : data, + }); + } }, - ); + }); - const { loading: resourceFacilityLoading } = useTanStackQueryInstead( - routes.getAnyFacility, - { - prefetch: filter.approving_facility !== undefined, - pathParams: { id: filter.approving_facility }, - onResponse: ({ res, data }) => { - if (res && data) { - setFilterState({ - approving_facility_ref: - filter.approving_facility === "" ? "" : data, - }); - } - }, + const { loading: resourceFacilityLoading } = useQuery(routes.getAnyFacility, { + prefetch: filter.approving_facility !== undefined, + pathParams: { id: filter.approving_facility }, + onResponse: ({ res, data }) => { + if (res && data) { + setFilterState({ + approving_facility_ref: filter.approving_facility === "" ? "" : data, + }); + } }, - ); + }); - const { loading: assignedFacilityLoading } = useTanStackQueryInstead( - routes.getAnyFacility, - { - pathParams: { id: filter.assigned_facility }, - prefetch: filter.assigned_facility !== undefined, - onResponse: ({ res, data }) => { - if (res && data) { - setFilterState({ - assigned_facility_ref: filter.assigned_facility === "" ? "" : data, - }); - } - }, + const { loading: assignedFacilityLoading } = useQuery(routes.getAnyFacility, { + pathParams: { id: filter.assigned_facility }, + prefetch: filter.assigned_facility !== undefined, + onResponse: ({ res, data }) => { + if (res && data) { + setFilterState({ + assigned_facility_ref: filter.assigned_facility === "" ? "" : data, + }); + } }, - ); + }); const setFacility = (selected: any, name: string) => { setFilterState({ From 608bea500ee8e0599dc4234317d97ba52b8a6a46 Mon Sep 17 00:00:00 2001 From: mahendar Date: Tue, 24 Dec 2024 18:02:11 +0530 Subject: [PATCH 2/7] used useQuery tanstack --- src/components/Resource/ResourceFilter.tsx | 91 ++++++++++++++-------- 1 file changed, 57 insertions(+), 34 deletions(-) diff --git a/src/components/Resource/ResourceFilter.tsx b/src/components/Resource/ResourceFilter.tsx index 51b8280cded..49d61f1eb69 100644 --- a/src/components/Resource/ResourceFilter.tsx +++ b/src/components/Resource/ResourceFilter.tsx @@ -1,4 +1,6 @@ +import { useQuery } from "@tanstack/react-query"; import dayjs from "dayjs"; +import { useEffect } from "react"; import FiltersSlideover from "@/CAREUI/interactive/FiltersSlideover"; @@ -16,7 +18,7 @@ import { RESOURCE_FILTER_ORDER } from "@/common/constants"; import { RESOURCE_CHOICES } from "@/common/constants"; import routes from "@/Utils/request/api"; -import useQuery from "@/Utils/request/useQuery"; +import query from "@/Utils/request/query"; import { dateQueryString } from "@/Utils/utils"; const getDate = (value: any) => @@ -40,41 +42,62 @@ export default function ListFilter(props: any) { status: filter.status || null, }); - const { loading: orginFacilityLoading } = useQuery(routes.getAnyFacility, { - prefetch: filter.origin_facility !== undefined, - pathParams: { id: filter.origin_facility }, - onResponse: ({ res, data }) => { - if (res && data) { - setFilterState({ - origin_facility_ref: filter.origin_facility === "" ? "" : data, - }); - } - }, - }); + const { isLoading: orginFacilityLoading, data: originFacilityData } = + useQuery({ + queryKey: [routes.getAnyFacility.path, filter.origin_facility], + queryFn: () => + query(routes.getAnyFacility, { + pathParams: { id: filter.origin_facility }, + }), + enabled: filter.origin_facility !== undefined, + }); - const { loading: resourceFacilityLoading } = useQuery(routes.getAnyFacility, { - prefetch: filter.approving_facility !== undefined, - pathParams: { id: filter.approving_facility }, - onResponse: ({ res, data }) => { - if (res && data) { - setFilterState({ - approving_facility_ref: filter.approving_facility === "" ? "" : data, - }); - } - }, - }); + useEffect(() => { + if (originFacilityData) { + setFilterState({ + origin_facility_ref: + filter.origin_facility === "" ? "" : originFacilityData, + }); + } + }, [originFacilityData]); - const { loading: assignedFacilityLoading } = useQuery(routes.getAnyFacility, { - pathParams: { id: filter.assigned_facility }, - prefetch: filter.assigned_facility !== undefined, - onResponse: ({ res, data }) => { - if (res && data) { - setFilterState({ - assigned_facility_ref: filter.assigned_facility === "" ? "" : data, - }); - } - }, - }); + const { isLoading: resourceFacilityLoading, data: resourceFacilityData } = + useQuery({ + queryKey: [routes.getAnyFacility.path, filter.approving_facility], + queryFn: () => + query(routes.getAnyFacility, { + pathParams: { id: filter.approving_facility }, + }), + enabled: filter.approving_facility !== undefined, + }); + + useEffect(() => { + if (resourceFacilityData) { + setFilterState({ + approving_facility_ref: + filter.approving_facility === "" ? "" : resourceFacilityData, + }); + } + }, [resourceFacilityData]); + + const { isLoading: assignedFacilityLoading, data: assignedFacilityData } = + useQuery({ + queryKey: [routes.getAnyFacility.path, filter.assigned_facility], + queryFn: () => + query(routes.getAnyFacility, { + pathParams: { id: filter.assigned_facility }, + }), + enabled: filter.assigned_facility !== undefined, + }); + + useEffect(() => { + if (assignedFacilityData) { + setFilterState({ + assigned_facility_ref: + filter.assigned_facility === "" ? "" : assignedFacilityData, + }); + } + }, [assignedFacilityData]); const setFacility = (selected: any, name: string) => { setFilterState({ From c5b42a4896a5b0090544022fcedff6a9706fc0aa Mon Sep 17 00:00:00 2001 From: mahendar Date: Thu, 26 Dec 2024 10:17:17 +0530 Subject: [PATCH 3/7] added changes --- src/components/Resource/ResourceFilter.tsx | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/components/Resource/ResourceFilter.tsx b/src/components/Resource/ResourceFilter.tsx index 49d61f1eb69..c493a3c667f 100644 --- a/src/components/Resource/ResourceFilter.tsx +++ b/src/components/Resource/ResourceFilter.tsx @@ -45,10 +45,9 @@ export default function ListFilter(props: any) { const { isLoading: orginFacilityLoading, data: originFacilityData } = useQuery({ queryKey: [routes.getAnyFacility.path, filter.origin_facility], - queryFn: () => - query(routes.getAnyFacility, { - pathParams: { id: filter.origin_facility }, - }), + queryFn: query(routes.getAnyFacility, { + pathParams: { id: filter.origin_facility }, + }), enabled: filter.origin_facility !== undefined, }); @@ -64,10 +63,9 @@ export default function ListFilter(props: any) { const { isLoading: resourceFacilityLoading, data: resourceFacilityData } = useQuery({ queryKey: [routes.getAnyFacility.path, filter.approving_facility], - queryFn: () => - query(routes.getAnyFacility, { - pathParams: { id: filter.approving_facility }, - }), + queryFn: query(routes.getAnyFacility, { + pathParams: { id: filter.approving_facility }, + }), enabled: filter.approving_facility !== undefined, }); @@ -83,10 +81,9 @@ export default function ListFilter(props: any) { const { isLoading: assignedFacilityLoading, data: assignedFacilityData } = useQuery({ queryKey: [routes.getAnyFacility.path, filter.assigned_facility], - queryFn: () => - query(routes.getAnyFacility, { - pathParams: { id: filter.assigned_facility }, - }), + queryFn: query(routes.getAnyFacility, { + pathParams: { id: filter.assigned_facility }, + }), enabled: filter.assigned_facility !== undefined, }); From 5cfef9dd8f1f43e4f9df2ff2b8ad4bbccf4e6388 Mon Sep 17 00:00:00 2001 From: mahendar Date: Thu, 26 Dec 2024 11:42:54 +0530 Subject: [PATCH 4/7] Trigger From 56c3407ce5246c905e6be147ccecd23635f77c72 Mon Sep 17 00:00:00 2001 From: mahendar Date: Thu, 26 Dec 2024 14:39:24 +0530 Subject: [PATCH 5/7] Trigger From 3561183c2e08049f1787d7b44b47f2c9b22e19f8 Mon Sep 17 00:00:00 2001 From: mahendar Date: Fri, 27 Dec 2024 19:38:32 +0530 Subject: [PATCH 6/7] updated query key --- src/components/Resource/ResourceFilter.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Resource/ResourceFilter.tsx b/src/components/Resource/ResourceFilter.tsx index c493a3c667f..dc9eb7ab326 100644 --- a/src/components/Resource/ResourceFilter.tsx +++ b/src/components/Resource/ResourceFilter.tsx @@ -44,7 +44,7 @@ export default function ListFilter(props: any) { const { isLoading: orginFacilityLoading, data: originFacilityData } = useQuery({ - queryKey: [routes.getAnyFacility.path, filter.origin_facility], + queryKey: ["getAnyFacility", filter.origin_facility], queryFn: query(routes.getAnyFacility, { pathParams: { id: filter.origin_facility }, }), @@ -62,7 +62,7 @@ export default function ListFilter(props: any) { const { isLoading: resourceFacilityLoading, data: resourceFacilityData } = useQuery({ - queryKey: [routes.getAnyFacility.path, filter.approving_facility], + queryKey: ["getAnyFacility", filter.approving_facility], queryFn: query(routes.getAnyFacility, { pathParams: { id: filter.approving_facility }, }), @@ -80,7 +80,7 @@ export default function ListFilter(props: any) { const { isLoading: assignedFacilityLoading, data: assignedFacilityData } = useQuery({ - queryKey: [routes.getAnyFacility.path, filter.assigned_facility], + queryKey: ["getAnyFacility", filter.assigned_facility], queryFn: query(routes.getAnyFacility, { pathParams: { id: filter.assigned_facility }, }), From 741ab187b358f27ad771a98907731e284ee941c5 Mon Sep 17 00:00:00 2001 From: mahendar Date: Sat, 28 Dec 2024 15:47:18 +0530 Subject: [PATCH 7/7] updated range in useFilters --- src/hooks/useFilters.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hooks/useFilters.tsx b/src/hooks/useFilters.tsx index 63ffa58822e..697ff9339ac 100644 --- a/src/hooks/useFilters.tsx +++ b/src/hooks/useFilters.tsx @@ -143,11 +143,12 @@ export default function useFilters({ const paramKeys = [paramKey + "_" + minKey, paramKey + "_" + maxKey]; const values = [qParams[paramKeys[0]], qParams[paramKeys[1]]]; if (values[0] === values[1]) - return [{ name, value: values[0], paramKey: paramKeys }]; + return [{ name, value: values[0], paramKey: paramKeys[0] }]; return [name + " " + minKey, name + " " + maxKey].map((name, i) => { return { name, value: values[i], paramKey: paramKeys[i] }; }); }, + dateRange(name = "Date", paramKey = "date") { return badgeUtils.range(name, paramKey, "after", "before"); },