From 3996cf70a26dc82a89d5770dafe9dfad7883de03 Mon Sep 17 00:00:00 2001 From: Radoslaw Szwajkowski Date: Mon, 22 Apr 2024 14:12:22 +0200 Subject: [PATCH] :bug: Re-enable fetching applications after application import (#1856) After successful import re-enable useFetchApplications() hook for the next 15 seconds. Resolves: https://issues.redhat.com/browse/MTA-2451 Signed-off-by: Radoslaw Szwajkowski --- .../applications-table/applications-table.tsx | 32 ++++++------------- client/src/app/queries/applications.ts | 6 ++-- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/client/src/app/pages/applications/applications-table/applications-table.tsx b/client/src/app/pages/applications/applications-table/applications-table.tsx index 0e2afe6cd0..61942abc7f 100644 --- a/client/src/app/pages/applications/applications-table/applications-table.tsx +++ b/client/src/app/pages/applications/applications-table/applications-table.tsx @@ -66,7 +66,6 @@ import { checkAccess } from "@app/utils/rbac-utils"; import WarningTriangleIcon from "@patternfly/react-icons/dist/esm/icons/warning-triangle-icon"; // Hooks -import { useQueryClient } from "@tanstack/react-query"; import { deserializeFilterUrlParams, useLocalTableControls, @@ -108,6 +107,7 @@ import { KebabDropdown } from "@app/components/KebabDropdown"; import { useFetchArchetypes } from "@app/queries/archetypes"; import { ApplicationFormModal } from "../components/application-form"; import { ManageColumnsToolbar } from "./components/manage-columns-toolbar"; +import dayjs from "dayjs"; export const ApplicationsTable: React.FC = () => { const { t } = useTranslation(); @@ -207,12 +207,17 @@ export const ApplicationsTable: React.FC = () => { const [reviewToDiscard, setReviewToDiscard] = React.useState(null); + const [endOfAppImportPeriod, setEndOfAppImportPeriod] = useState( + dayjs() + ); + const { data: applications, isFetching: isFetchingApplications, error: applicationsFetchError, - refetch: fetchApplications, - } = useFetchApplications(!hasActiveTasks); + } = useFetchApplications(() => + hasActiveTasks || dayjs().isBefore(endOfAppImportPeriod) ? 5000 : false + ); const { assessments, isFetching: isFetchingAssessments } = useFetchAssessments(); @@ -498,8 +503,6 @@ export const ApplicationsTable: React.FC = () => { isSelectionEnabled: true, }); - const queryClient = useQueryClient(); - const { currentPageItems, numRenderedColumns, @@ -559,10 +562,6 @@ export const ApplicationsTable: React.FC = () => { tasksWriteAccess = checkAccess(userScopes, tasksWriteScopes), reviewsWriteAccess = checkAccess(userScopes, reviewsWriteScopes); - const areAppsInWaves = selectedRows.some( - (application) => application.migrationWave !== null - ); - const importDropdownItems = importWriteAccess ? [ { documentId={taskToView?.task} onClose={() => setTaskToView(undefined)} /> - setIsApplicationImportModalOpen((current) => !current)} - > - { - setIsApplicationImportModalOpen(false); - fetchApplications(); - }} - /> - { { setIsApplicationImportModalOpen(false); - fetchApplications(); + setEndOfAppImportPeriod(dayjs().add(15, "s")); }} /> diff --git a/client/src/app/queries/applications.ts b/client/src/app/queries/applications.ts index 12639b102e..153a13d013 100644 --- a/client/src/app/queries/applications.ts +++ b/client/src/app/queries/applications.ts @@ -32,13 +32,15 @@ interface DownloadOptions { mimeType: MimeType; } -export const useFetchApplications = (refetchDisabled: boolean = false) => { +export const useFetchApplications = ( + refetchInterval: number | false | (() => number | false) = 5000 +) => { const queryClient = useQueryClient(); const { isLoading, error, refetch, data } = useQuery({ initialData: [], queryKey: [ApplicationsQueryKey], queryFn: getApplications, - refetchInterval: !refetchDisabled ? 5000 : false, + refetchInterval: refetchInterval, onSuccess: () => { queryClient.invalidateQueries([assessmentsByItemIdQueryKey]); },