Skip to content

Commit

Permalink
Merge branch 'patternfly:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
wise-king-sullyman authored May 28, 2024
2 parents 380471b + c089767 commit 21c6254
Show file tree
Hide file tree
Showing 24 changed files with 1,061 additions and 255 deletions.
10 changes: 9 additions & 1 deletion packages/demo-app-ts/src/Demos.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { PipelineTasksDemo } from './demos/pipelinesDemo/PipelineTasksDemo';
import { PipelineLayoutDemo } from './demos/pipelinesDemo/PipelineLayoutDemo';
import { PipelineGroupsDemo } from './demos/pipelineGroupsDemo/PipelineGroupsDemo';
import {
PipelineGroupsComplexDemo,
PipelineGroupsDemo
} from './demos/pipelineGroupsDemo/PipelineGroupsDemo';
import { Basics } from './demos/Basics';
import { StyleEdges, StyleGroups, StyleLabels, StyleNodes } from './demos/stylesDemo/Styles';
import { Selection } from './demos/Selection';
Expand Down Expand Up @@ -56,6 +59,11 @@ export const Demos: DemoInterface[] = [
name: 'Pipeline Groups Layout',
componentType: PipelineGroupsDemo,
},
{
id: 'pipelines-groups-complex-layout-demo',
name: 'Pipeline Groups Complex Layout',
componentType: PipelineGroupsComplexDemo,
},
]
},
{
Expand Down
36 changes: 20 additions & 16 deletions packages/demo-app-ts/src/demos/pipelineGroupsDemo/DemoTaskEdge.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import * as React from 'react';
import { observer } from 'mobx-react';
import { Edge, EdgeTerminalType, GraphElement, TaskEdge } from '@patternfly/react-topology';
import {
DEFAULT_SPACER_NODE_TYPE,
Edge,
EdgeTerminalType,
GraphElement,
TaskEdge,
WithSelectionProps
} from '@patternfly/react-topology';

interface DemoTaskEdgeProps {
interface DemoTaskEdgeProps extends WithSelectionProps {
element: GraphElement;
}

const DemoTaskEdge: React.FunctionComponent<DemoTaskEdgeProps> = ({ element, ...props }) => {

const isDependency = (element as Edge).getTarget().getData()?.isDependency;

return (
<TaskEdge
element={element as Edge}
endTerminalType={
isDependency ? EdgeTerminalType.directional : EdgeTerminalType.none
}
{...props}
/>
);
};
const DemoTaskEdge: React.FunctionComponent<DemoTaskEdgeProps> = ({ element, ...props }) => (
<TaskEdge
element={element as Edge}
endTerminalType={
(element as Edge).getTarget().getType() !== DEFAULT_SPACER_NODE_TYPE
? EdgeTerminalType.directional
: undefined
}
{...props}
/>
);

export default observer(DemoTaskEdge);
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ import {
GROUPS_LAYER,
RunStatus
} from '@patternfly/react-topology';
import { DEFAULT_TASK_HEIGHT, GROUP_TASK_WIDTH } from './createDemoPipelineGroupsNodes';

type DemoTaskGroupProps = {
element: GraphElement;
} & WithSelectionProps;

export const DEFAULT_TASK_WIDTH = 180;
export const DEFAULT_TASK_HEIGHT = 32;

const getEdgeCreationTypes = (): EdgeCreationTypes => ({
edgeType: 'edge',
spacerEdgeType: 'edge'
Expand All @@ -48,7 +46,7 @@ const DemoTaskGroup: React.FunctionComponent<DemoTaskGroupProps> = ({ element, .
<DefaultTaskGroup
labelPosition={verticalLayout ? LabelPosition.top : LabelPosition.bottom}
collapsible
collapsedWidth={DEFAULT_TASK_WIDTH}
collapsedWidth={GROUP_TASK_WIDTH}
collapsedHeight={DEFAULT_TASK_HEIGHT}
element={element as Node}
recreateLayoutOnCollapseChange
Expand Down
18 changes: 9 additions & 9 deletions packages/demo-app-ts/src/demos/pipelineGroupsDemo/OptionsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ const OptionsBar: React.FC = observer(() => {
<ToolbarItem>
<Text className="pf-u-mr-sm">Layout:</Text>
</ToolbarItem>
<ToolbarItem>
<Radio
id="horizontal-layout-radio"
name="horizontalLayout"
isChecked={!pipelineOptions.verticalLayout}
onChange={() => pipelineOptions.setVerticalLayout(false)}
label="Horizontal"
/>
</ToolbarItem>
<ToolbarItem>
<Radio
id="vertical-layout-radio"
Expand All @@ -29,6 +20,15 @@ const OptionsBar: React.FC = observer(() => {
label="Vertical"
/>
</ToolbarItem>
<ToolbarItem>
<Radio
id="horizontal-layout-radio"
name="horizontalLayout"
isChecked={!pipelineOptions.verticalLayout}
onChange={() => pipelineOptions.setVerticalLayout(false)}
label="Horizontal"
/>
</ToolbarItem>
</>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,52 @@ import {
TOP_TO_BOTTOM,
PipelineNodeModel,
useVisualizationController,
addSpacerNodes,
pipelineElementFactory,
isEdge,
Edge,
} from '@patternfly/react-topology';
import pipelineGroupsComponentFactory from './pipelineGroupsComponentFactory';
import { createDemoPipelineGroupsNodes } from './createDemoPipelineGroupsNodes';
import {
createComplexDemoPipelineGroupsNodes,
createDemoPipelineGroupsNodes
} from './createDemoPipelineGroupsNodes';
import { PipelineGroupsDemoContext, PipelineGroupsDemoModel } from './PipelineGroupsDemoContext';
import OptionsBar from './OptionsBar';
import DemoControlBar from '../DemoControlBar';
import pipelineElementFactory
from '@patternfly/react-topology/dist/esm/pipelines/elements/pipelineElementFactory';

const TopologyPipelineGroups: React.FC<{ nodes: PipelineNodeModel[] }> = observer(({ nodes }) => {
const controller = useVisualizationController();
const options = React.useContext(PipelineGroupsDemoContext);
const [selectedIds, setSelectedIds] = React.useState<string[]>();

useEventListener<SelectionEventListener>(SELECTION_EVENT, ids => {
if (ids?.[0]) {
const element = controller?.getElementById(ids[0]);
if (element && isEdge(element)) {
const edge = element as Edge;
const selectedEdges = [edge.getId()];
const source = edge.getSource();
const target = edge.getTarget();
if (source.getType() === DEFAULT_SPACER_NODE_TYPE) {
const sourceEdges = source.getTargetEdges();
selectedEdges.push(...sourceEdges.map((e) => e.getId()));
}
if (target.getType() === DEFAULT_SPACER_NODE_TYPE) {
const targetEdges = target.getSourceEdges();
selectedEdges.push(...targetEdges.map((e) => e.getId()));
}
setSelectedIds(selectedEdges);
return;
}
}
setSelectedIds(ids);
});

React.useEffect(() => {
const edges = getEdgesFromNodes(nodes, DEFAULT_SPACER_NODE_TYPE, 'edge', 'edge');
const pipelineNodes = addSpacerNodes(nodes);
const edges = getEdgesFromNodes(pipelineNodes, DEFAULT_SPACER_NODE_TYPE, 'edge', 'edge');

controller.fromModel(
{
graph: {
Expand All @@ -48,7 +74,7 @@ const TopologyPipelineGroups: React.FC<{ nodes: PipelineNodeModel[] }> = observe
y: 25,
layout: options.verticalLayout ? TOP_TO_BOTTOM : LEFT_TO_RIGHT
},
nodes,
nodes: pipelineNodes,
edges,
},
false
Expand All @@ -64,7 +90,7 @@ const TopologyPipelineGroups: React.FC<{ nodes: PipelineNodeModel[] }> = observe

TopologyPipelineGroups.displayName = 'TopologyPipelineLayout';

export const PipelineGroupsDemo = observer(() => {
export const PipelineGroupsDemoComponent: React.FC<{ complex?: boolean }> = ({ complex }) => {
const controller = new Visualization();
controller.registerElementFactory(pipelineElementFactory);
controller.registerComponentFactory(pipelineGroupsComponentFactory);
Expand All @@ -77,7 +103,7 @@ export const PipelineGroupsDemo = observer(() => {
ignoreGroups: true,
})
);
const nodes = createDemoPipelineGroupsNodes();
const nodes = complex ? createComplexDemoPipelineGroupsNodes() : createDemoPipelineGroupsNodes();
return (
<div className="pf-ri__topology-demo">
<VisualizationProvider controller={controller}>
Expand All @@ -87,4 +113,13 @@ export const PipelineGroupsDemo = observer(() => {
</VisualizationProvider>
</div>
);
});
};

export const PipelineGroupsDemo = () => {
return <PipelineGroupsDemoComponent />
};

export const PipelineGroupsComplexDemo = () => {
return <PipelineGroupsDemoComponent complex />
};

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { makeObservable, observable, action } from 'mobx';

export class PipelineGroupsDemoModel {
protected verticalLayoutP: boolean = false;
protected verticalLayoutP: boolean = true;

constructor() {
makeObservable<
Expand Down
Loading

0 comments on commit 21c6254

Please sign in to comment.