Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DefaultTaskGroup): support status #176

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {
ScaleDetailsLevel,
DEFAULT_LAYER,
Layer,
TOP_LAYER, GROUPS_LAYER
TOP_LAYER,
GROUPS_LAYER,
RunStatus
} from '@patternfly/react-topology';

type DemoTaskGroupProps = {
Expand All @@ -33,6 +35,7 @@ const DemoTaskGroup: React.FunctionComponent<DemoTaskGroupProps> = ({ element, .
const verticalLayout = (element.getGraph().getLayoutOptions?.() as DagreLayoutOptions)?.rankdir === TOP_TO_BOTTOM;
const [hover, hoverRef] = useHover();
const detailsLevel = element.getGraph().getDetailsLevel();
const data = element.getData();

if (!isNode(element)) {
return null;
Expand All @@ -53,6 +56,9 @@ const DemoTaskGroup: React.FunctionComponent<DemoTaskGroupProps> = ({ element, .
scaleNode={hover && detailsLevel !== ScaleDetailsLevel.high}
showLabel={detailsLevel === ScaleDetailsLevel.high}
hideDetailsAtMedium
showStatusState
status={data.status}
hiddenDetailsShownStatuses={[RunStatus.Succeeded]}
{...rest}
/>
</g>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import * as React from 'react';
import { observer } from 'mobx-react';
import {
OnSelect,
WithDndDragProps,
ConnectDragSource,
ConnectDropTarget,
} from '../../../behavior';
import { OnSelect, WithDndDragProps, ConnectDragSource, ConnectDropTarget } from '../../../behavior';
import { ShapeProps } from '../../../components';
import { Dimensions } from '../../../geom';
import { GraphElement, LabelPosition, BadgeLocation, isNode, Node } from '../../../types';
import { action } from '../../../mobx-exports';
import { getEdgesFromNodes, getSpacerNodes } from '../../utils';
import DefaultTaskGroupCollapsed from './DefaultTaskGroupCollapsed';
import DefaultTaskGroupExpanded from './DefaultTaskGroupExpanded';
import { RunStatus } from '../../types';

export interface EdgeCreationTypes {
spacerNodeType?: string;
Expand All @@ -39,6 +35,12 @@ export interface DefaultTaskGroupProps {
dragging?: boolean;
/** Flag if drag operation is a regroup operation */
dragRegroupable?: boolean;
/** RunStatus to depict, supported on collapsed groups only. */
status?: RunStatus;
/** Flag indicating the status indicator, supported on collapsed groups only */
showStatusState?: boolean;
/** Statuses to show at when details are hidden, supported on collapsed groups only */
hiddenDetailsShownStatuses?: RunStatus[];
/** Flag indicating the node should be scaled, best on hover of the node at lowest scale level */
scaleNode?: boolean;
/** Flag to hide details at medium scale */
Expand Down Expand Up @@ -117,16 +119,17 @@ export interface DefaultTaskGroupProps {

type PipelinesDefaultGroupInnerProps = Omit<DefaultTaskGroupProps, 'element'> & { element: Node };

const DefaultTaskGroupInner: React.FunctionComponent<PipelinesDefaultGroupInnerProps> = observer(({
className,
element,
badge,
onCollapseChange,
collapsedShadowCount,
recreateLayoutOnCollapseChange,
getEdgeCreationTypes,
...rest
}) => {
const DefaultTaskGroupInner: React.FunctionComponent<PipelinesDefaultGroupInnerProps> = observer(
({
className,
element,
badge,
onCollapseChange,
collapsedShadowCount,
recreateLayoutOnCollapseChange,
getEdgeCreationTypes,
...rest
}) => {
const childCount = element.getAllNodeChildren().length;

const handleCollapse = action((group: Node, collapsed: boolean): void => {
Expand All @@ -141,11 +144,17 @@ const DefaultTaskGroupInner: React.FunctionComponent<PipelinesDefaultGroupInnerP
const model = controller.toModel();
const creationTypes: EdgeCreationTypes = getEdgeCreationTypes ? getEdgeCreationTypes() : {};

const pipelineNodes = model.nodes.filter((n) => n.type !== creationTypes.spacerNodeType).map((n) => ({
const pipelineNodes = model.nodes
.filter((n) => n.type !== creationTypes.spacerNodeType)
.map((n) => ({
...n,
visible: true
}));
const spacerNodes = getSpacerNodes(pipelineNodes, creationTypes.spacerNodeType, creationTypes.finallyNodeTypes);
const spacerNodes = getSpacerNodes(
pipelineNodes,
creationTypes.spacerNodeType,
creationTypes.finallyNodeTypes
);
const nodes = [...pipelineNodes, ...spacerNodes];
const edges = getEdgesFromNodes(
pipelineNodes,
Expand Down Expand Up @@ -176,6 +185,7 @@ const DefaultTaskGroupInner: React.FunctionComponent<PipelinesDefaultGroupInnerP
);
}
return (
// TODO: Support status indicators on expanded state.
<DefaultTaskGroupExpanded
className={className}
labelPosition={LabelPosition.top}
Expand All @@ -198,13 +208,15 @@ const DefaultTaskGroup: React.FunctionComponent<DefaultTaskGroupProps> = ({
throw new Error('DefaultTaskGroup must be used only on Node elements');
}

return <DefaultTaskGroupInner
element={element}
badgeColor={badgeColor}
badgeBorderColor={badgeBorderColor}
badgeTextColor={badgeTextColor}
{...rest}
/>;
return (
<DefaultTaskGroupInner
element={element}
badgeColor={badgeColor}
badgeBorderColor={badgeBorderColor}
badgeTextColor={badgeTextColor}
{...rest}
/>
);
};

export default DefaultTaskGroup;
Loading