From 07c675f7ebd4fe3b72a808ff6cfd35c3f4b15af6 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 25 Jan 2023 10:14:48 +0100 Subject: [PATCH] chore: added times to the dropdown box Signed-off-by: blam --- plugins/scaffolder/src/next/Router/Router.tsx | 1 - .../scaffolder/src/next/TaskPage/TaskPage.tsx | 5 +- .../src/next/TaskPage/TaskSteps/StepIcon.tsx | 71 +++++++++++++++++++ .../src/next/TaskPage/TaskSteps/StepTime.tsx | 53 ++++++++++++++ .../src/next/TaskPage/TaskSteps/TaskSteps.tsx | 17 +++-- 5 files changed, 136 insertions(+), 11 deletions(-) create mode 100644 plugins/scaffolder/src/next/TaskPage/TaskSteps/StepIcon.tsx create mode 100644 plugins/scaffolder/src/next/TaskPage/TaskSteps/StepTime.tsx diff --git a/plugins/scaffolder/src/next/Router/Router.tsx b/plugins/scaffolder/src/next/Router/Router.tsx index f5e186eb67..8de9ac57e4 100644 --- a/plugins/scaffolder/src/next/Router/Router.tsx +++ b/plugins/scaffolder/src/next/Router/Router.tsx @@ -29,7 +29,6 @@ import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common'; import { TemplateGroupFilter } from '../TemplateListPage/TemplateGroups'; import { DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS } from '../../extensions/default'; -import { FormProps } from '../types'; import { nextScaffolderTaskRouteRef, nextSelectedTemplateRouteRef, diff --git a/plugins/scaffolder/src/next/TaskPage/TaskPage.tsx b/plugins/scaffolder/src/next/TaskPage/TaskPage.tsx index f9a84d2355..138c6ac24e 100644 --- a/plugins/scaffolder/src/next/TaskPage/TaskPage.tsx +++ b/plugins/scaffolder/src/next/TaskPage/TaskPage.tsx @@ -52,11 +52,10 @@ export const TaskPage = () => { /> - {!taskStream.completed && ( - - )} + {!taskStream.completed && } + {/* */} diff --git a/plugins/scaffolder/src/next/TaskPage/TaskSteps/StepIcon.tsx b/plugins/scaffolder/src/next/TaskPage/TaskSteps/StepIcon.tsx new file mode 100644 index 0000000000..39ef37c771 --- /dev/null +++ b/plugins/scaffolder/src/next/TaskPage/TaskSteps/StepIcon.tsx @@ -0,0 +1,71 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React from 'react'; + +import { BackstageTheme } from '@backstage/theme'; +import { CircularProgress, makeStyles, StepIconProps } from '@material-ui/core'; +import RemoveCircleOutline from '@material-ui/icons/RemoveCircleOutline'; +import FiberManualRecordIcon from '@material-ui/icons/FiberManualRecord'; +import classNames from 'classnames'; +import CheckCircleOutline from '@material-ui/icons/CheckCircleOutline'; +import DeleteOutline from '@material-ui/icons/DeleteOutline'; + +const useStepIconStyles = makeStyles((theme: BackstageTheme) => ({ + root: { + color: theme.palette.text.disabled, + }, + completed: { + color: theme.palette.status.ok, + }, + error: { + color: theme.palette.status.error, + }, +})); + +export const StepIcon = (props: StepIconProps & { skipped: boolean }) => { + const classes = useStepIconStyles(); + const { active, completed, error, skipped } = props; + + const getMiddle = () => { + if (active) { + return ; + } + if (completed) { + return ; + } + + if (error) { + return ; + } + + if (skipped) { + return ; + } + + return ; + }; + + return ( +
+ {getMiddle()} +
+ ); +}; diff --git a/plugins/scaffolder/src/next/TaskPage/TaskSteps/StepTime.tsx b/plugins/scaffolder/src/next/TaskPage/TaskSteps/StepTime.tsx new file mode 100644 index 0000000000..f2d3116854 --- /dev/null +++ b/plugins/scaffolder/src/next/TaskPage/TaskSteps/StepTime.tsx @@ -0,0 +1,53 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React, { useState } from 'react'; +import useInterval from 'react-use/lib/useInterval'; +import { DateTime, Interval } from 'luxon'; +import humanizeDuration from 'humanize-duration'; +import { Typography } from '@material-ui/core'; + +export const StepTime = ({ + step, +}: { + step: { + id: string; + name: string; + startedAt?: string; + endedAt?: string; + }; +}) => { + const [time, setTime] = useState(''); + + useInterval(() => { + if (!step.startedAt) { + setTime(''); + return; + } + + const end = step.endedAt + ? DateTime.fromISO(step.endedAt) + : DateTime.local(); + + const startedAt = DateTime.fromISO(step.startedAt); + const formatted = Interval.fromDateTimes(startedAt, end) + .toDuration() + .valueOf(); + + setTime(humanizeDuration(formatted, { round: true })); + }, 1000); + + return {time}; +}; diff --git a/plugins/scaffolder/src/next/TaskPage/TaskSteps/TaskSteps.tsx b/plugins/scaffolder/src/next/TaskPage/TaskSteps/TaskSteps.tsx index 4095872465..40f9f9c189 100644 --- a/plugins/scaffolder/src/next/TaskPage/TaskSteps/TaskSteps.tsx +++ b/plugins/scaffolder/src/next/TaskPage/TaskSteps/TaskSteps.tsx @@ -23,7 +23,8 @@ import { } from '@material-ui/core'; import { TaskStep } from '@backstage/plugin-scaffolder-common'; import { Step } from '../../../components/hooks/useEventStream'; -import RemoveCircleOutlineIcon from '@material-ui/icons/RemoveCircleOutline'; +import { StepIcon } from './StepIcon'; +import { StepTime } from './StepTime'; interface StepperProps { steps: (TaskStep & Step)[]; @@ -43,21 +44,23 @@ export const TaskSteps = (props: StepperProps) => { const isFailed = step.status === 'failed'; const isActive = step.status === 'processing'; const isSkipped = step.status === 'skipped'; - const stepIconProps: Partial = { + const stepIconProps: Partial = { completed: isCompleted, error: isFailed, active: isActive, + skipped: isSkipped, }; - if (isSkipped) { - stepIconProps.icon = ; - } - return ( - + {step.name} +
+