From e0061153d9b27201a5cd8699aa3119602abd148e Mon Sep 17 00:00:00 2001 From: Dan Wilson Date: Wed, 13 Sep 2023 10:22:12 +0100 Subject: [PATCH] small execution fixes --- .../ExecutionPageHeader/ExecutionPageHeader.tsx | 2 +- .../components/ExecutionStageList/ExecutionStageList.tsx | 2 +- web/src/hooks/useSpaceSSE.tsx | 4 ++-- web/src/i18n/strings.en.yaml | 6 +++--- web/src/layouts/menu/DefaultMenu.tsx | 8 -------- web/src/pages/Execution/Execution.tsx | 2 +- web/src/pages/ExecutionList/ExecutionList.tsx | 4 ++-- web/src/pages/PipelineList/PipelineList.tsx | 8 +++----- web/src/utils/{PipelineUtils.ts => ExecutionUtils.ts} | 2 +- 9 files changed, 14 insertions(+), 24 deletions(-) rename web/src/utils/{PipelineUtils.ts => ExecutionUtils.ts} (96%) diff --git a/web/src/components/ExecutionPageHeader/ExecutionPageHeader.tsx b/web/src/components/ExecutionPageHeader/ExecutionPageHeader.tsx index d5a30db3e..57714c1c2 100644 --- a/web/src/components/ExecutionPageHeader/ExecutionPageHeader.tsx +++ b/web/src/components/ExecutionPageHeader/ExecutionPageHeader.tsx @@ -10,7 +10,7 @@ import { useGetSpaceParam } from 'hooks/useGetSpaceParam' import type { CODEProps } from 'RouteDefinitions' import type { GitInfoProps } from 'utils/GitUtils' import { ExecutionStatus } from 'components/ExecutionStatus/ExecutionStatus' -import { getStatus } from 'utils/PipelineUtils' +import { getStatus } from 'utils/ExecutionUtils' import { PipeSeparator } from 'components/PipeSeparator/PipeSeparator' import { timeDistance } from 'utils/Utils' import css from './ExecutionPageHeader.module.scss' diff --git a/web/src/components/ExecutionStageList/ExecutionStageList.tsx b/web/src/components/ExecutionStageList/ExecutionStageList.tsx index 3a5098ea3..5e0058a34 100644 --- a/web/src/components/ExecutionStageList/ExecutionStageList.tsx +++ b/web/src/components/ExecutionStageList/ExecutionStageList.tsx @@ -3,7 +3,7 @@ import { Container, FlexExpander, Layout, Text } from '@harnessio/uicore' import cx from 'classnames' import type { TypesStage } from 'services/code' import { ExecutionState, ExecutionStatus } from 'components/ExecutionStatus/ExecutionStatus' -import { getStatus } from 'utils/PipelineUtils' +import { getStatus } from 'utils/ExecutionUtils' import { timeDistance } from 'utils/Utils' import css from './ExecutionStageList.module.scss' diff --git a/web/src/hooks/useSpaceSSE.tsx b/web/src/hooks/useSpaceSSE.tsx index 8b7454f47..ebfbc3dc7 100644 --- a/web/src/hooks/useSpaceSSE.tsx +++ b/web/src/hooks/useSpaceSSE.tsx @@ -3,7 +3,7 @@ import { useEffect, useRef } from 'react' type UseSpaceSSEProps = { space: string events: string[] - onEvent: (type: string, data: any) => void + onEvent: (data: any, type: string) => void onError?: (event: Event) => void shouldRun?: boolean } @@ -20,7 +20,7 @@ const useSpaceSSE = ({ space, events, onEvent, onError, shouldRun = true }: UseS const handleMessage = (event: MessageEvent) => { const data = JSON.parse(event.data) - onEvent(event.type, data) + onEvent(data, event.type) } const handleError = (event: Event) => { diff --git a/web/src/i18n/strings.en.yaml b/web/src/i18n/strings.en.yaml index 83cd7d5a5..eb8109dc0 100644 --- a/web/src/i18n/strings.en.yaml +++ b/web/src/i18n/strings.en.yaml @@ -627,7 +627,7 @@ repoDelete: deleteToastSuccess: Repository deleted successfully deleteConfirmButton2: Delete this repository pipelines: - noData: There are no pipelines :( + noData: There are no pipelines newPipelineButton: New Pipeline name: Pipeline Name createNewPipeline: Create New Pipeline @@ -645,7 +645,7 @@ pipelines: executionStarted: Pipeline execution started successfully executionCouldNotStart: Failure while starting Pipeline execution executions: - noData: There are no executions :( + noData: There are no executions newExecutionButton: Run Pipeline name: Execution Name description: Description @@ -657,7 +657,7 @@ executions: selectRange: Shift-click to select a range allCommits: All Commits secrets: - noData: There are no secrets :( + noData: There are no secrets newSecretButton: New Secret name: Secret Name failedToCreate: Failed to create Secret. Please try again. diff --git a/web/src/layouts/menu/DefaultMenu.tsx b/web/src/layouts/menu/DefaultMenu.tsx index 4ecca3f79..d5b09e6d7 100644 --- a/web/src/layouts/menu/DefaultMenu.tsx +++ b/web/src/layouts/menu/DefaultMenu.tsx @@ -126,14 +126,6 @@ export const DefaultMenu: React.FC = () => { })} /> )} - {!standalone && ( { useSpaceSSE({ space, events: ['execution_updated', 'execution_completed'], - onEvent: (_: string, data: any) => { + onEvent: data => { if ( data?.repo_id === execution?.repo_id && data?.pipeline_id === execution?.pipeline_id && diff --git a/web/src/pages/ExecutionList/ExecutionList.tsx b/web/src/pages/ExecutionList/ExecutionList.tsx index aa051a7bc..b0954cfe8 100644 --- a/web/src/pages/ExecutionList/ExecutionList.tsx +++ b/web/src/pages/ExecutionList/ExecutionList.tsx @@ -29,7 +29,7 @@ import { ResourceListingPagination } from 'components/ResourceListingPagination/ import { useGetRepositoryMetadata } from 'hooks/useGetRepositoryMetadata' import { RepositoryPageHeader } from 'components/RepositoryPageHeader/RepositoryPageHeader' import { ExecutionStatus } from 'components/ExecutionStatus/ExecutionStatus' -import { getStatus } from 'utils/PipelineUtils' +import { getStatus } from 'utils/ExecutionUtils' import useSpaceSSE from 'hooks/useSpaceSSE' import { ExecutionText, ExecutionTrigger } from 'components/ExecutionText/ExecutionText' import useRunPipelineModal from 'components/RunPipelineModal/RunPipelineModal' @@ -70,7 +70,7 @@ const ExecutionList = () => { useSpaceSSE({ space, events: ['execution_updated', 'execution_completed'], - onEvent: (_: string, data: any) => { + onEvent: data => { // ideally this would include number - so we only check for executions on the page - but what if new executions are kicked off? - could check for ids that are higher than the lowest id on the page? if ( executions?.some( diff --git a/web/src/pages/PipelineList/PipelineList.tsx b/web/src/pages/PipelineList/PipelineList.tsx index 8e66de2d5..9b8d259c3 100644 --- a/web/src/pages/PipelineList/PipelineList.tsx +++ b/web/src/pages/PipelineList/PipelineList.tsx @@ -32,7 +32,7 @@ import { useAppContext } from 'AppContext' import { useGetRepositoryMetadata } from 'hooks/useGetRepositoryMetadata' import { RepositoryPageHeader } from 'components/RepositoryPageHeader/RepositoryPageHeader' import { ExecutionStatus, ExecutionState } from 'components/ExecutionStatus/ExecutionStatus' -import { getStatus } from 'utils/PipelineUtils' +import { getStatus } from 'utils/ExecutionUtils' import { PipeSeparator } from 'components/PipeSeparator/PipeSeparator' import useNewPipelineModal from 'components/NewPipelineModal/NewPipelineModal' import { useGetSpaceParam } from 'hooks/useGetSpaceParam' @@ -77,11 +77,9 @@ const PipelineList = () => { useSpaceSSE({ space, events: ['execution_updated', 'execution_completed'], - onEvent: (_: string, data: any) => { + onEvent: data => { // should I include pipeline id here? what if a new pipeline is created? coould check for ids that are higher than the lowest id on the page? - if ( - pipelines?.some(pipeline => pipeline.repo_id === data?.repo_id && pipeline.id === data?.pipeline_id) - ) { + if (pipelines?.some(pipeline => pipeline.repo_id === data?.repo_id && pipeline.id === data?.pipeline_id)) { //TODO - revisit full refresh - can I use the message to update the execution? pipelinesRefetch() } diff --git a/web/src/utils/PipelineUtils.ts b/web/src/utils/ExecutionUtils.ts similarity index 96% rename from web/src/utils/PipelineUtils.ts rename to web/src/utils/ExecutionUtils.ts index e7cfae3c3..c5b55e35b 100644 --- a/web/src/utils/PipelineUtils.ts +++ b/web/src/utils/ExecutionUtils.ts @@ -4,7 +4,7 @@ export const getStatus = (status: string | undefined): ExecutionState => { switch (status) { case 'success': return ExecutionState.SUCCESS - case 'failed': + case 'failure': return ExecutionState.FAILURE case 'running': return ExecutionState.RUNNING