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:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user