import React from "react";
import {
Card,
ContextMenu,
DecoupledOverlay,
IconButton,
MenuItem,
Notification,
NotificationProps,
OverflowText,
OverviewItem,
OverviewItemActions,
OverviewItemDepiction,
OverviewItemDescription,
OverviewItemLine,
ProgressBar,
Spinner,
Tooltip,
} from "../../components";
import { ValidIconName } from "../../components/Icon/canonicalIconNames";
import { IconProps } from "../../components/Icon/Icon";
import { TestIconProps } from "../../components/Icon/TestIcon";
import { TestableComponent } from "../../components/interfaces";
import { ProgressBarProps } from "../../components/ProgressBar/ProgressBar";
import { SpinnerProps } from "../../components/Spinner/Spinner";
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
export interface ActivityControlWidgetProps extends TestableComponent {
/**
* The label to be shown
*/
label?: string | React.JSX.Element;
/**
* Element that wraps around the label.
* Default: ``
*/
labelWrapper?: React.JSX.Element;
/**
* To add tags in addition to the widget status description
*/
tags?: React.JSX.Element;
/**
* The progress bar parameters if it should be show by a progres bar
*/
progressBar?: ProgressBarProps;
/**
* The spinner parameters if it should be show by a spinner
*/
progressSpinner?: SpinnerProps;
/**
* Status message
*/
statusMessage?: string;
/**
* The action buttons
*/
activityActions?: ActivityControlWidgetAction[];
/**
* Context menu items
*/
activityContextMenu?: IActivityContextMenu;
/**
* show small version of the widget
*/
small?: boolean;
/**
* display widget inside rectangle
*/
border?: boolean;
/**
* display a bit whitespace around widget, even without border
*/
hasSpacing?: boolean;
/**
* only use necessary width, not always the available 100% of parent element
*/
canShrink?: boolean;
/**
* if this is set the spinner is replaced when the progress has finished from 0 - 1
*/
progressSpinnerFinishedIcon?: React.ReactElement | React.ReactElement;
/**
* execution timer messages for waiting and running times.
*/
timerExecutionMsg?: React.JSX.Element | null;
/**
* additional actions that can serve as a complex component, positioned between the default actions and the context menu
*/
additionalActions?: React.ReactElement[];
}
interface IActivityContextMenu extends TestableComponent {
// Tooltip for the context menu
tooltip?: string;
// Optional badge shown on the context menu button.
badge?: string | number;
// The entries of the context menu
menuItems: IActivityMenuAction[];
}
export interface ActivityControlWidgetAction extends TestableComponent {
// The action that should be triggered
action: () => void;
// The tooltip that should be shown over the action icon on hover
tooltip?: string;
// The icon of the action button
icon: ValidIconName | React.ReactElement;
// Action is currently disabled (but shown)
disabled?: boolean;
// Warning state
hasStateWarning?: boolean;
// Active state
active?: boolean;
/** A notification that is shown in an overlay pointing at the activity action button. */
notification?: {
message: string;
onClose: () => void;
intent?: NotificationProps["intent"];
// Timeout in ms before notification is closed. Default: none
timeout?: number;
};
}
interface IActivityMenuAction extends ActivityControlWidgetAction {
// Optional link
href?: string;
}
/** Shows the status of activities and supports actions on these activities. */
export function ActivityControlWidget(props: ActivityControlWidgetProps) {
const {
"data-test-id": dataTestIdLegacy,
"data-testid": dataTestId,
progressBar,
progressSpinner,
activityActions,
activityContextMenu,
additionalActions,
small,
border,
hasSpacing,
canShrink,
tags,
progressSpinnerFinishedIcon,
timerExecutionMsg = "",
labelWrapper = ,
} = props;
const spinnerClassNames = (progressSpinner?.className ?? "") + ` ${eccgui}-spinner--permanent`;
const widget = (
{progressBar && }
{(progressSpinner || progressSpinnerFinishedIcon) && (
{progressSpinnerFinishedIcon ? (
React.cloneElement(progressSpinnerFinishedIcon as React.JSX.Element, { small, large: !small })
) : (
)}
)}
{props.label && (
{React.cloneElement(labelWrapper, {}, props.label)}
{timerExecutionMsg && (props.statusMessage || tags) && <> ({timerExecutionMsg})>}
)}
{(props.statusMessage || tags) && (
{tags}
{props.statusMessage && (
{props.statusMessage.length > 50 ? (
{props.statusMessage}
) : (
props.statusMessage
)}
)}
)}
{timerExecutionMsg && !(props.statusMessage || tags) && (
{timerExecutionMsg}
)}
{activityActions &&
activityActions.map((action, idx) => )}
{additionalActions}
{activityContextMenu && activityContextMenu.menuItems.length > 0 && (
}
>
{activityContextMenu.menuItems.map((menuAction, idx) => {
return (
);
})}
)}
);
const classname = `${eccgui}-addon-activitycontrol` + (canShrink ? ` ${eccgui}-addon-activitycontrol--shrink` : "");
return border ? (
{widget}
) : (
{widget}
);
}
interface ActivityActionButtonProps {
action: ActivityControlWidgetAction;
}
const ActivityActionButton = ({ action }: ActivityActionButtonProps) => {
const actionButtonRef = React.useRef(null);
const ActionButton = () => (
);
return action.notification ? (
<>
{actionButtonRef.current && (
)}
>
) : (
);
};