Skip to content

Commit

Permalink
🐛 [backport release-0.3] Re-enable fetching applications after applic…
Browse files Browse the repository at this point in the history
…ation import (#1876)

After successful import re-enable useFetchApplications() hook for the
next 15 seconds.
    
Resolves: https://issues.redhat.com/browse/MTA-2451
Cherry-picked from: #1856

Signed-off-by: Radoslaw Szwajkowski <[email protected]>
  • Loading branch information
rszwajko authored Apr 22, 2024
1 parent ba49734 commit aaacc9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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 @@ -109,6 +108,7 @@ import { ApplicationIdentityForm } from "../components/application-identity-form
import { ApplicationReviewStatus } from "../components/application-review-status/application-review-status";
import { useFetchArchetypes } from "@app/queries/archetypes";
import { ApplicationFormModal } from "../components/application-form";
import dayjs from "dayjs";

export const ApplicationsTable: React.FC = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -213,12 +213,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: isFetchingAssesments } =
useFetchAssessments();
Expand Down Expand Up @@ -503,8 +508,6 @@ export const ApplicationsTable: React.FC = () => {
isSelectionEnabled: true,
});

const queryClient = useQueryClient();

const {
currentPageItems,
numRenderedColumns,
Expand Down Expand Up @@ -1135,19 +1138,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 @@ -1172,7 +1162,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 aaacc9f

Please sign in to comment.