Skip to content

Commit

Permalink
🐛 Accurately represent upload state in binary upload step (#1487)
Browse files Browse the repository at this point in the history
- Address https://issues.redhat.com/browse/MTA-1420 
- Removes bg polling while wizard is open 
- Adds a check for ongoing mutations while the file upload operation is
underway.

Signed-off-by: ibolton336 <ibolton@redhat.com>
  • Loading branch information
ibolton336 authored Oct 25, 2023
1 parent ded98a9 commit ed39248
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,9 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
<WizardStep
id={StepId.AnalysisMode}
name={t("wizard.terms.analysisMode")}
isDisabled={!isStepEnabled(StepId.AnalysisMode)}
footer={{
isNextDisabled:
!isMutating && !isStepEnabled(StepId.AnalysisMode + 1),
!!isMutating || !isStepEnabled(StepId.AnalysisMode + 1),
}}
>
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export const UploadBinary: React.FC = () => {
title: "Uploaded binary file.",
variant: "success",
});
setFileUploadStatus("success");
setFileUploadProgress(100);
};

const failedUpload = (error: AxiosError) => {
Expand Down Expand Up @@ -82,10 +84,8 @@ export const UploadBinary: React.FC = () => {
failedUpload
);

const { mutate: removeFile } = useRemoveUploadedFileMutation(
completedRemove,
failedRemove
);
const { mutate: removeFile, isLoading: isRemovingFile } =
useRemoveUploadedFileMutation(completedRemove, failedRemove);
const onCreateTaskgroupSuccess = (data: Taskgroup) => {
updateTaskGroup(data);
};
Expand Down Expand Up @@ -133,9 +133,8 @@ export const UploadBinary: React.FC = () => {
readFile(droppedFiles[0])
.then((data) => {
if (data) {
setFileUploadProgress(100);
setFileUploadStatus("success");
setValue("artifact", droppedFiles[0]);
setFileUploadProgress(0);
}
})
.catch((error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ import {
useFetchApplications,
} from "@app/queries/applications";
import { useCancelTaskMutation, useFetchTasks } from "@app/queries/tasks";
import { useFetchReviews } from "@app/queries/reviews";
import { useFetchIdentities } from "@app/queries/identities";
import { useFetchTagCategories } from "@app/queries/tags";

Expand Down Expand Up @@ -116,7 +115,7 @@ export const ApplicationsTableAnalyze: React.FC = () => {
const getTask = (application: Application) =>
tasks.find((task: Task) => task.application?.id === application.id);

const { tasks } = useFetchTasks({ addon: "analyzer" });
const { tasks } = useFetchTasks({ addon: "analyzer" }, isAnalyzeModalOpen);

const { tagCategories: tagCategories } = useFetchTagCategories();

Expand All @@ -127,7 +126,7 @@ export const ApplicationsTableAnalyze: React.FC = () => {
isFetching: isFetchingApplications,
error: applicationsFetchError,
refetch: fetchApplications,
} = useFetchApplications();
} = useFetchApplications(isAnalyzeModalOpen);

const onDeleteApplicationSuccess = (appIDCount: number) => {
pushNotification({
Expand Down Expand Up @@ -350,8 +349,6 @@ export const ApplicationsTableAnalyze: React.FC = () => {
selectionState: { selectedItems: selectedRows },
} = tableControls;

const { reviews } = useFetchReviews();

const [
saveApplicationsCredentialsModalState,
setSaveApplicationsCredentialsModalState,
Expand Down
4 changes: 2 additions & 2 deletions client/src/app/queries/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ interface DownloadOptions {
mimeType: MimeType;
}

export const useFetchApplications = () => {
export const useFetchApplications = (refetchDisabled: boolean = false) => {
const queryClient = useQueryClient();
const { isLoading, error, refetch, data } = useQuery({
initialData: [],
queryKey: [ApplicationsQueryKey],
queryFn: getApplications,
refetchInterval: 5000,
refetchInterval: !refetchDisabled ? 5000 : false,
onSuccess: () => {
queryClient.invalidateQueries([reviewsQueryKey]);
queryClient.invalidateQueries([assessmentsQueryKey]);
Expand Down
7 changes: 5 additions & 2 deletions client/src/app/queries/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ interface FetchTasksFilters {

export const TasksQueryKey = "tasks";

export const useFetchTasks = (filters: FetchTasksFilters = {}) => {
export const useFetchTasks = (
filters: FetchTasksFilters = {},
refetchDisabled: boolean = false
) => {
const { isLoading, error, refetch, data } = useQuery({
queryKey: [TasksQueryKey],
queryFn: getTasks,
refetchInterval: 5000,
refetchInterval: !refetchDisabled ? 5000 : false,
select: (allTasks) => {
const uniqSorted = allTasks
.filter((task) =>
Expand Down

0 comments on commit ed39248

Please sign in to comment.