Merge pull request #20901 from acierto/preserve-tasks-step-execution-2

Preserve step's time execution for a non-running task.
This commit is contained in:
Fredrik Adelöw
2023-11-08 16:44:30 +01:00
committed by GitHub
3 changed files with 19 additions and 5 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-react': patch
---
Preserve step's time execution for a non-running task.
@@ -31,6 +31,16 @@ export const StepTime = (props: {
const [time, setTime] = useState('');
const { step } = props;
const getDelay = () => {
if (step.startedAt && step.endedAt && time) {
return null;
}
if (step.startedAt && step.endedAt) {
return 1;
}
return 1000;
};
const calculate = useCallback(() => {
if (!step.startedAt) {
setTime('');
@@ -49,9 +59,8 @@ export const StepTime = (props: {
setTime(humanizeDuration(formatted, { round: true }));
}, [step.endedAt, step.startedAt]);
useMountEffect(() => calculate());
useInterval(() => !step.endedAt && calculate(), 1000);
useMountEffect(calculate);
useInterval(calculate, getDelay());
return <Typography variant="caption">{time}</Typography>;
};
@@ -59,7 +59,7 @@ export const TaskSteps = (props: TaskStepsProps) => {
alternativeLabel
variant="elevation"
>
{props.steps.map((step, index) => {
{props.steps.map(step => {
const isCompleted = step.status === 'completed';
const isFailed = step.status === 'failed';
const isActive = step.status === 'processing';
@@ -73,7 +73,7 @@ export const TaskSteps = (props: TaskStepsProps) => {
};
return (
<MuiStep key={index}>
<MuiStep key={step.id}>
<MuiStepButton>
<MuiStepLabel
StepIconProps={stepIconProps}