From a8966730351318327cb08453ffec60fbdec0defa Mon Sep 17 00:00:00 2001 From: Ivan Li Date: Wed, 24 Mar 2021 20:34:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(pipeline-tasks):=20=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E6=B7=BB=E5=8A=A0=E5=AE=9E=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=8A=B6=E6=80=81=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pipeline-tasks/pipeline-task-details.scss | 6 + .../pipeline-task-details.scss.d.ts | 2 + .../pipeline-tasks/pipeline-task-details.tsx | 107 +++++++++++++++++- 3 files changed, 109 insertions(+), 6 deletions(-) diff --git a/src/components/pipeline-tasks/pipeline-task-details.scss b/src/components/pipeline-tasks/pipeline-task-details.scss index 0dc81f9..48b6aee 100644 --- a/src/components/pipeline-tasks/pipeline-task-details.scss +++ b/src/components/pipeline-tasks/pipeline-task-details.scss @@ -23,3 +23,9 @@ @apply p-1 my-px; @apply bg-gray-100; } +.taskStatusIcon { + @apply text-lg; +} +.taskInfo { + @apply grid grid-flow-col; +} diff --git a/src/components/pipeline-tasks/pipeline-task-details.scss.d.ts b/src/components/pipeline-tasks/pipeline-task-details.scss.d.ts index 04b057b..4c115c9 100644 --- a/src/components/pipeline-tasks/pipeline-task-details.scss.d.ts +++ b/src/components/pipeline-tasks/pipeline-task-details.scss.d.ts @@ -5,6 +5,8 @@ declare namespace PipelineTaskDetailsScssNamespace { details: string; navContainer: string; navItem: string; + taskInfo: string; + taskStatusIcon: string; unitLogs: string; unitLogsContainer: string; } diff --git a/src/components/pipeline-tasks/pipeline-task-details.tsx b/src/components/pipeline-tasks/pipeline-task-details.tsx index 7591f8b..4562b93 100644 --- a/src/components/pipeline-tasks/pipeline-task-details.tsx +++ b/src/components/pipeline-tasks/pipeline-task-details.tsx @@ -1,9 +1,9 @@ import { gql, useSubscription, useQuery } from '@apollo/client'; import { h } from 'preact'; import { useMemo } from 'preact/hooks'; -import { find, propEq } from 'ramda'; +import { find, last, propEq } from 'ramda'; import { observer, useLocalObservable, useObserver } from 'mobx-react'; -import { makeAutoObservable } from 'mobx'; +import { autorun, makeAutoObservable } from 'mobx'; import styles from './pipeline-task-details.scss'; import { PipelineTaskLogs, @@ -12,6 +12,13 @@ import { PipelineTask, PipelineTaskLogMessage } from '../../generated/graphql'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { + faExclamationCircle, + faPauseCircle, + faSpinner +} from '@fortawesome/free-solid-svg-icons'; +import classNames from 'classnames'; interface Props { taskId: string; } @@ -19,8 +26,21 @@ interface Props { class Store { logs: PipelineTaskLogs[] = []; task?: PipelineTask; + currUnit?: PipelineUnits; constructor() { makeAutoObservable(this); + autorun(() => { + const units = this.task?.units.filter(unit => + this.logs.find(log => log.unit === unit) + ); + if (units) { + this.setCurrUnit(last(units)); + } + }); + } + + private setCurrUnit(unit?: PipelineUnits) { + this.currUnit = unit; } addLogsFromTask(task: PipelineTask) { @@ -58,6 +78,9 @@ const FIND_PIPELINE_TASK = gql` id units commit + status + startedAt + endedAt logs { unit logs @@ -66,6 +89,19 @@ const FIND_PIPELINE_TASK = gql` } `; +const PIPELINE_TASK_CHANGED = gql` + subscription Pipelinetaskchanged($taskId: String!) { + task: pipelineTaskChanged(id: $taskId) { + id + units + commit + status + startedAt + endedAt + } + } +`; + const PIPELINE_TASK_LOG = gql` subscription PipelineTaskLog($taskId: String!) { log: pipelineTaskLog(taskId: $taskId) { @@ -77,10 +113,15 @@ const PIPELINE_TASK_LOG = gql` `; export const PipelineTaskDetails = ({ taskId }: Props) => { - const { data } = useQuery<{ task: PipelineTask }, { taskId: string }>( - FIND_PIPELINE_TASK, - { variables: { taskId } } - ); + const { data, subscribeToMore } = useQuery< + { task: PipelineTask }, + { taskId: string } + >(FIND_PIPELINE_TASK, { variables: { taskId } }); + + subscribeToMore({ + document: PIPELINE_TASK_CHANGED, + variables: { taskId } + }); const store = useLocalObservable(() => new Store()); @@ -109,6 +150,7 @@ export const PipelineTaskDetails = ({ taskId }: Props) => { }); return useObserver(() => (
+ @@ -143,3 +185,56 @@ const LogListOfUnit = observer(({ store }: { store: Store }) => { ); }); + +const TaskInfo = observer(({ store }: { store: Store }) => { + const task = store.task; + if (!task) { + return
; + } + return ( +
+ +

{task.startedAt}

+

{task.status}

+
+ ); +}); + +const StatusIcon = ({ status }: { status: TaskStatuses }) => { + switch (status) { + case TaskStatuses.Working: + return ( + + ); + case TaskStatuses.Failed: + return ( + + ); + case TaskStatuses.Success: + return ( + + ); + case TaskStatuses.Pending: + return ( + + ); + default: + return null; + } +};