Skip to content

Commit

Permalink
🐛 Re-enable fetching applications after application import (konveyor#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
rszwajko authored Apr 22, 2024
1 parent 8b13af6 commit 3996cf7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -207,12 +207,17 @@ export const ApplicationsTable: React.FC = () => {
const [reviewToDiscard, setReviewToDiscard] =
React.useState<Application | null>(null);

const [endOfAppImportPeriod, setEndOfAppImportPeriod] = useState<dayjs.Dayjs>(
dayjs()
);

const {
data: applications,
isFetching: isFetchingApplications,
error: applicationsFetchError,
refetch: fetchApplications,
} = useFetchApplications(!hasActiveTasks);
} = useFetchApplications(() =>
hasActiveTasks || dayjs().isBefore(endOfAppImportPeriod) ? 5000 : false
);

const { assessments, isFetching: isFetchingAssessments } =
useFetchAssessments();
Expand Down Expand Up @@ -498,8 +503,6 @@ export const ApplicationsTable: React.FC = () => {
isSelectionEnabled: true,
});

const queryClient = useQueryClient();

const {
currentPageItems,
numRenderedColumns,
Expand Down Expand Up @@ -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
? [
<DropdownItem
Expand Down Expand Up @@ -1131,19 +1130,6 @@ export const ApplicationsTable: React.FC = () => {
documentId={taskToView?.task}
onClose={() => setTaskToView(undefined)}
/>
<Modal
isOpen={isApplicationImportModalOpen}
variant="medium"
title={t("dialog.title.importApplicationFile")}
onClose={() => setIsApplicationImportModalOpen((current) => !current)}
>
<ImportApplicationsForm
onSaved={() => {
setIsApplicationImportModalOpen(false);
fetchApplications();
}}
/>
</Modal>
<Modal
isOpen={isDependenciesModalOpen}
variant="medium"
Expand All @@ -1168,7 +1154,7 @@ export const ApplicationsTable: React.FC = () => {
<ImportApplicationsForm
onSaved={() => {
setIsApplicationImportModalOpen(false);
fetchApplications();
setEndOfAppImportPeriod(dayjs().add(15, "s"));
}}
/>
</Modal>
Expand Down
6 changes: 4 additions & 2 deletions client/src/app/queries/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
},
Expand Down

0 comments on commit 3996cf7

Please sign in to comment.