From 1170e46477493860947c2d161492f74ae5a6c911 Mon Sep 17 00:00:00 2001 From: Ivan Li Date: Mon, 5 Apr 2021 16:33:22 +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=E9=A1=B5=E9=9D=A2=E6=95=88=E6=9E=9C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pipeline-tasks/pipeline-task-details.scss | 5 +- .../pipeline-tasks/pipeline-task-details.tsx | 98 ++++++++----------- 2 files changed, 44 insertions(+), 59 deletions(-) diff --git a/src/components/pipeline-tasks/pipeline-task-details.scss b/src/components/pipeline-tasks/pipeline-task-details.scss index 48b6aee..168f2f2 100644 --- a/src/components/pipeline-tasks/pipeline-task-details.scss +++ b/src/components/pipeline-tasks/pipeline-task-details.scss @@ -11,6 +11,9 @@ &:not(:first-child) { @apply border-l border-gray-200; } + & > svg { + @apply ml-2 text-sm; + } } .LogListOfUnit { @apply overflow-scroll; @@ -19,7 +22,7 @@ @apply bg-gray-200; } .unitLogs { - @apply whitespace-pre-line font-mono text-sm; + @apply whitespace-pre-line font-mono text-xs; @apply p-1 my-px; @apply bg-gray-100; } diff --git a/src/components/pipeline-tasks/pipeline-task-details.tsx b/src/components/pipeline-tasks/pipeline-task-details.tsx index 89bf51d..a19e379 100644 --- a/src/components/pipeline-tasks/pipeline-task-details.tsx +++ b/src/components/pipeline-tasks/pipeline-task-details.tsx @@ -1,7 +1,7 @@ import { gql, useSubscription, useQuery } from '@apollo/client'; import { h } from 'preact'; import { useMemo } from 'preact/hooks'; -import { find, last, propEq } from 'ramda'; +import { find, findIndex, last, propEq } from 'ramda'; import { observer, useLocalObservable, useObserver } from 'mobx-react'; import { autorun, makeAutoObservable } from 'mobx'; import styles from './pipeline-task-details.scss'; @@ -12,13 +12,7 @@ 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'; +import { PipelineTaskStatus } from './pipeline-task-status'; interface Props { taskId: string; } @@ -44,12 +38,26 @@ class Store { } addLogsFromTask(task: PipelineTask) { + if (task.status !== TaskStatuses.Pending) { + const unit = (task.logs[0]?.unit as unknown) as PipelineUnits; + if (unit) { + const log = find(propEq('unit', unit), this.logs); + if (!log) { + this.logs.push({ + unit: unit, + status: TaskStatuses.Working, + startedAt: task.startedAt, + logs: '' + }); + } + } + } for (const log of task.logs) { - const taskLog = find(propEq('unit', log.unit), this.logs); - if (!taskLog) { + const index = findIndex(propEq('unit', log.unit), this.logs); + if (index === -1) { this.logs.push(log); } else { - taskLog.logs = log.logs + taskLog.logs; + this.logs[index] = log; } } } @@ -66,7 +74,6 @@ class Store { taskLog.logs += log.message; } } - setTask(task: PipelineTask) { this.task = task; } @@ -84,13 +91,16 @@ const FIND_PIPELINE_TASK = gql` logs { unit logs + status + startedAt + endedAt } } } `; const PIPELINE_TASK_CHANGED = gql` - subscription Pipelinetaskchanged($taskId: String!) { + subscription PipelineTaskChanged($taskId: String!) { task: pipelineTaskChanged(id: $taskId) { id units @@ -98,6 +108,13 @@ const PIPELINE_TASK_CHANGED = gql` status startedAt endedAt + logs { + unit + status + logs + startedAt + endedAt + } } } `; @@ -167,11 +184,15 @@ const UnitList = observer(({ store }: { store: Store }) => { return
Loading...
; } - const tabs = store.task.units.map(unit => ( -
  • - {unit} -
  • - )); + const tabs = store.task.units.map(unit => { + const log = find(propEq('unit', unit), store.logs); + return ( +
  • + {unit} + +
  • + ); + }); return
      {tabs}
    ; }); @@ -197,48 +218,9 @@ const TaskInfo = observer(({ store }: { store: Store }) => { } 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; - } -};