From d831b1a438174b6d62863addcf0828c147e101e7 Mon Sep 17 00:00:00 2001 From: Abel Rodriguez Date: Wed, 27 Sep 2023 12:42:08 -0500 Subject: [PATCH] refactor request to gate --- .../pipelines/PipelineExecutions.tsx | 51 ++++++++----------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/spin-observatory-plugin-deck/src/components/pipelines/PipelineExecutions.tsx b/spin-observatory-plugin-deck/src/components/pipelines/PipelineExecutions.tsx index f98f650..1d13a14 100644 --- a/spin-observatory-plugin-deck/src/components/pipelines/PipelineExecutions.tsx +++ b/spin-observatory-plugin-deck/src/components/pipelines/PipelineExecutions.tsx @@ -60,20 +60,7 @@ export const PipelineExecutions = ({ return; } - const requestParams = { - pipelineName: pipeline.name, - pageSize: REQUEST_PAGE_SIZE, - startDate: dateRange.start, - endDate: dateRange.end, - }; - - gate.getExecutions(appName, requestParams).then((resp) => { - setExecutions(resp); - setFilteredExecutions(filterExecutions(resp)); - setStatusCount(getStatusCount(resp)); - setIsLoading(false); - setIsRequestInProgress(false); - }); + getExecutions(appName, getExecutionsParams); }, [pipeline, dateRange.start, dateRange.end]); useEffect(() => { @@ -94,24 +81,30 @@ export const PipelineExecutions = ({ console.log("end useInterval"); return; } - - setIsRequestInProgress(true); - console.log("making a request..."); - const resp = await gate.getExecutions(appName, { - pipelineName: pipeline.name, - pageSize: REQUEST_PAGE_SIZE, - startDate: dateRange.start, - endDate: dateRange.end, - }); - console.log("request completed"); - setExecutions(resp); - setFilteredExecutions(filterExecutions(resp)); - setStatusCount(getStatusCount(resp)); - setIsLoading(false); - setIsRequestInProgress(false); + + getExecutions(appName, getExecutionsParams); console.log("end useInterval"); }, POLL_DELAY_MS); + const getExecutions = (name, params) => { + setIsRequestInProgress(true); + console.log("making a request..."); + + gate.getExecutions(name, params) + .then((resp) => { + console.log("request completed"); + + setExecutions(resp); + setFilteredExecutions(filterExecutions(resp)); + setStatusCount(getStatusCount(resp)); + setIsLoading(false); + }) + .catch((e) => console.error('error retrieving executions: ', e)) + .finally(() => { + setIsRequestInProgress(false); + }); + }; + const filterExecutions = (ex: IExecution[]) => { const statusArr = statuses.length === 0 ? STATUSES : statuses;