Fix loading spinner not appearing when running a script (#15936)

This commit is contained in:
Luke Heath 2024-01-05 12:48:07 -06:00 committed by GitHub
parent caac8fbbe2
commit c1f961ec30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -0,0 +1 @@
* Fix loading spinner not appearing when running a script on a host.

View File

@ -1,4 +1,4 @@
import React, { useContext } from "react"; import React, { useContext, useState } from "react";
import { useQuery } from "react-query"; import { useQuery } from "react-query";
import { AxiosResponse } from "axios"; import { AxiosResponse } from "axios";
import { InjectedRouter } from "react-router"; import { InjectedRouter } from "react-router";
@ -43,6 +43,7 @@ const Scripts = ({
router, router,
onShowDetails, onShowDetails,
}: IScriptsProps) => { }: IScriptsProps) => {
const [isScriptRunning, setIsScriptRunning] = useState(false);
const { renderFlash } = useContext(NotificationContext); const { renderFlash } = useContext(NotificationContext);
const hostId = host?.id; const hostId = host?.id;
@ -59,6 +60,9 @@ const Scripts = ({
refetchOnWindowFocus: false, refetchOnWindowFocus: false,
retry: false, retry: false,
enabled: Boolean(hostId), enabled: Boolean(hostId),
onSuccess: () => {
setIsScriptRunning(false);
},
} }
); );
@ -79,6 +83,7 @@ const Scripts = ({
break; break;
case "run": case "run":
try { try {
setIsScriptRunning(true);
await scriptsAPI.runScript({ await scriptsAPI.runScript({
host_id: host.id, host_id: host.id,
script_id: script.script_id, script_id: script.script_id,
@ -87,6 +92,7 @@ const Scripts = ({
} catch (e) { } catch (e) {
const error = e as AxiosResponse<IApiError>; const error = e as AxiosResponse<IApiError>;
renderFlash("error", error.data.errors[0].reason); renderFlash("error", error.data.errors[0].reason);
setIsScriptRunning(false);
} }
break; break;
default: default:
@ -125,7 +131,7 @@ const Scripts = ({
isAllPagesSelected={false} isAllPagesSelected={false}
columnConfigs={scriptColumnConfigs} columnConfigs={scriptColumnConfigs}
data={data} data={data}
isLoading={isLoadingScriptData} isLoading={isScriptRunning}
onQueryChange={onQueryChange} onQueryChange={onQueryChange}
disableNextPage={hostScriptResponse?.meta.has_next_results} disableNextPage={hostScriptResponse?.meta.has_next_results}
defaultPageIndex={page} defaultPageIndex={page}

View File

@ -21,6 +21,10 @@
} }
} }
.data-table-block .data-table__wrapper {
box-sizing: border-box;
}
.table-container__header-left { .table-container__header-left {
display: block; display: block;
} }