import classNames from 'classnames';
import React from 'react';
import { OverlayTrigger, Tooltip } from 'react-bootstrap';
import type { ITask } from '../domain';
import { robotToHuman } from '../presentation/robotToHumanFilter/robotToHuman.filter';
export interface ITaskProgressBarProps {
task: ITask;
className?: string;
}
export function TaskProgressBar(props: ITaskProgressBarProps) {
const { task, className } = props;
const { steps, id } = task;
let tooltip;
if (task.isRunning) {
const currentStep = steps.find((step) => step.hasNotStarted || step.isRunning);
if (currentStep) {
const currentStepIndex = steps.indexOf(currentStep) + 1;
tooltip = (
{`Step ${currentStepIndex} of ${steps.length}: ${robotToHuman(currentStep.name)}`}
);
}
}
if (task.isFailed) {
const failedStep = steps.find((step) => step.isFailed || step.isSuspended);
if (failedStep && task.failureMessage) {
const failedStepIndex = steps.indexOf(failedStep) + 1;
const ellipses = String.fromCharCode(8230);
const clipped =
task.failureMessage.length > 400 ? task.failureMessage.substring(0, 400) + ellipses : task.failureMessage;
tooltip = (
{`Failed on Step ${failedStepIndex} of ${steps.length}:`}
{robotToHuman(failedStep.name)}
Exception:
{clipped}
);
} else {
tooltip = Task failed; sorry, no reason provided;
}
}
const stepsComplete = steps.filter((step) => step.isCompleted);
const progressBarClassName = classNames({
'progress-bar': true,
'progress-bar-info': task.isRunning || task.hasNotStarted,
'progress-bar-success': task.isCompleted,
'progress-bar-disabled': task.isCanceled,
'progress-bar-danger': task.isFailed,
});
const progressBar = (
);
if (tooltip) {
return (
{progressBar}
);
}
return progressBar;
}