Skip to content

Commit

Permalink
🐛 Handle case when application.archetypes is passed but null (#1707)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ibolton336 authored Feb 28, 2024
1 parent 2febd18 commit 59ad200
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions client/src/app/queries/archetypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand All @@ -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,
Expand Down

0 comments on commit 59ad200

Please sign in to comment.