From 311408298019f7dcddb28f479bf02000ac7be9fe Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 27 Feb 2024 19:15:36 -0500 Subject: [PATCH] :bug: Handle case when application.archetypes is passed but null (#1707) (#1710) Resolves https://issues.redhat.com/browse/MTA-2320 - Missed a case when calculating associated assessed archetypes to an application. If application is passed to the useFetchArchetypes query but application.archetypes is null, still returning all archetypes instead of an empty list. --------- Signed-off-by: Ian Bolton Signed-off-by: Cherry Picker Signed-off-by: Ian Bolton Signed-off-by: Cherry Picker Co-authored-by: Ian Bolton --- client/src/app/queries/archetypes.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/src/app/queries/archetypes.ts b/client/src/app/queries/archetypes.ts index e2d6efc470..7cd3b45051 100644 --- a/client/src/app/queries/archetypes.ts +++ b/client/src/app/queries/archetypes.ts @@ -26,11 +26,12 @@ export const useFetchArchetypes = (forApplication?: Application | null) => { const { isLoading, isSuccess, error, refetch, data } = useQuery({ initialData: [], queryKey: [ARCHETYPES_QUERY_KEY, forApplication?.id], - queryFn: getArchetypes, refetchInterval: 5000, onSuccess: (fetchedArchetypes) => { - if (forApplication && forApplication.archetypes) { + if (!forApplication) { + setFilteredArchetypes(fetchedArchetypes); + } else if (Array.isArray(forApplication.archetypes)) { const archetypeIds = forApplication.archetypes.map( (archetype) => archetype.id ); @@ -39,18 +40,17 @@ export const useFetchArchetypes = (forApplication?: Application | null) => { ); setFilteredArchetypes(filtered); } else { - setFilteredArchetypes(fetchedArchetypes); + setFilteredArchetypes([]); } queryClient.invalidateQueries([reviewsQueryKey]); queryClient.invalidateQueries([assessmentsQueryKey]); queryClient.invalidateQueries([assessmentsByItemIdQueryKey]); }, - onError: (error: AxiosError) => console.log(error), }); return { - archetypes: filteredArchetypes || [], + archetypes: filteredArchetypes, isFetching: isLoading, isSuccess, error,