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
…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 <[email protected]>
Signed-off-by: Cherry Picker <[email protected]>

Signed-off-by: Ian Bolton <[email protected]>
Signed-off-by: Cherry Picker <[email protected]>
Co-authored-by: Ian Bolton <[email protected]>
  • Loading branch information
github-actions[bot] and ibolton336 authored Feb 28, 2024
1 parent 3ab62f6 commit 3114082
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 3114082

Please sign in to comment.