Skip to content

Commit a5ab327

Browse files
committed
add scrolls and fit pipeline view
1 parent dfe9530 commit a5ab327

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

web/src/components/forms/flowCollector-status.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const FlowCollectorStatus: FC<FlowCollectorStatusProps> = props => {
3434
<Pipeline existing={existing} />
3535
</FlexItem>
3636
)}
37-
<FlexItem flex={{ default: 'flex_1' }}>
37+
<FlexItem className="status-list-container" flex={{ default: 'flex_1' }}>
3838
<ResourceStatus group={group} version={version} kind={kind} existing={existing} />
3939
</FlexItem>
4040
</Flex>

web/src/components/forms/forms.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
margin-right: 1.5rem;
5656
}
5757

58+
.status-list-container {
59+
overflow-y: auto;
60+
}
61+
5862
.calculator-item {
5963
padding-bottom: 1.5rem;
6064
}

web/src/components/forms/pipeline.tsx

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
getSpacerNodes,
1818
Graph,
1919
GraphComponent,
20+
GRAPH_LAYOUT_END_EVENT,
2021
Layout,
2122
ModelKind,
2223
Node,
@@ -32,6 +33,7 @@ import {
3233
WhenDecorator
3334
} from '@patternfly/react-topology';
3435

36+
import { getResizeObserver } from '@patternfly/react-core';
3537
import { t } from 'i18next';
3638
import _ from 'lodash';
3739
import * as React from 'react';
@@ -90,8 +92,17 @@ export type FlowCollectorPipelineProps = {
9092
};
9193

9294
export const Pipeline: React.FC<FlowCollectorPipelineProps> = ({ existing }) => {
95+
const containerRef = React.createRef<HTMLDivElement>();
9396
const [controller, setController] = React.useState<Visualization>();
9497

98+
const fit = React.useCallback(() => {
99+
if (controller && controller.hasGraph()) {
100+
controller.getGraph().fit();
101+
} else {
102+
console.error('onResize called before controller graph');
103+
}
104+
}, [controller]);
105+
95106
const getStatus = React.useCallback(
96107
(types: string[], status: string) => {
97108
for (let i = 0; i < types.length; i++) {
@@ -199,11 +210,26 @@ export const Pipeline: React.FC<FlowCollectorPipelineProps> = ({ existing }) =>
199210
}, [existing, getStatus]);
200211

201212
React.useEffect(() => {
213+
if (containerRef.current) {
214+
getResizeObserver(
215+
containerRef.current,
216+
() => {
217+
fit();
218+
},
219+
true
220+
);
221+
}
222+
}, [containerRef, controller, fit]);
223+
224+
React.useEffect(() => {
225+
if (!controller) {
226+
return;
227+
}
202228
const steps = getSteps();
203229
const spacerNodes = getSpacerNodes(steps);
204230
const nodes = [...steps, ...spacerNodes];
205231
const edges = getEdgesFromNodes(steps);
206-
controller?.fromModel(
232+
controller.fromModel(
207233
{
208234
nodes,
209235
edges,
@@ -222,15 +248,17 @@ export const Pipeline: React.FC<FlowCollectorPipelineProps> = ({ existing }) =>
222248
const c = new Visualization();
223249
c.registerComponentFactory(pipelineComponentFactory);
224250
c.registerLayoutFactory((type: string, graph: Graph): Layout | undefined => new PipelineDagreLayout(graph));
225-
c.setFitToScreenOnLayout(true);
251+
c.addEventListener(GRAPH_LAYOUT_END_EVENT, fit);
226252
setController(c);
227253
// eslint-disable-next-line react-hooks/exhaustive-deps
228254
}, []);
229255

230256
return (
231-
<VisualizationProvider controller={controller}>
232-
<VisualizationSurface />
233-
</VisualizationProvider>
257+
<div id="pipeline-container-div" style={{ width: '100%', height: '100%' }} ref={containerRef}>
258+
<VisualizationProvider controller={controller}>
259+
<VisualizationSurface />
260+
</VisualizationProvider>
261+
</div>
234262
);
235263
};
236264

0 commit comments

Comments
 (0)