Skip to content

Commit dad73c1

Browse files
Merge pull request #195 from alanconway/coo-1383-disappearing
COO-1383: Fix disappearing graph when panel is re-opened.
2 parents 3c49e87 + d28adf3 commit dad73c1

3 files changed

Lines changed: 62 additions & 42 deletions

File tree

web/src/components/Korrel8rPanel.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
Form,
1414
FormGroup,
1515
Spinner,
16+
Stack,
17+
StackItem,
1618
TextArea,
1719
Title,
1820
Tooltip,
@@ -62,7 +64,14 @@ export default function Korrel8rPanel() {
6264
// Showing advanced query
6365
const [showQuery, setShowQuery] = React.useState(false);
6466

67+
// Skip the first fetch if we already have a stored result.
68+
const useStoredResult = React.useRef(result != null);
69+
6570
React.useEffect(() => {
71+
if (useStoredResult.current) {
72+
useStoredResult.current = false; // Fetch a new result next time.
73+
return;
74+
}
6675
// eslint-disable-next-line no-console
6776
console.debug('korrel8r search', search);
6877
const queryStr = search?.queryStr?.trim();
@@ -226,18 +235,18 @@ export default function Korrel8rPanel() {
226235

227236
return (
228237
<>
229-
<Flex direction={{ default: 'column' }} grow={{ default: 'grow' }}>
238+
<Stack>
230239
<Flex className="tp-plugin__panel-query-container" direction={{ default: 'row' }}>
231240
{focusButton}
232241
<FlexItem align={{ default: 'alignRight' }}>{advancedToggle}</FlexItem>
233242
{refreshButton}
234243
</Flex>
235-
<FlexItem>{advancedSection}</FlexItem>
244+
{advancedSection}
236245
<Divider />
237-
<FlexItem className="tp-plugin__panel-topology-container" grow={{ default: 'grow' }}>
246+
<StackItem className="tp-plugin__panel-topology-container" isFilled={true}>
238247
{topologySection}
239-
</FlexItem>
240-
</Flex>
248+
</StackItem>
249+
</Stack>
241250
</>
242251
);
243252
}

web/src/components/Popover.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useActivePerspective } from '@openshift-console/dynamic-plugin-sdk';
2-
import { Button, Flex, FlexItem, Title } from '@patternfly/react-core';
2+
import { Button, Flex, FlexItem, Stack, StackItem, Title } from '@patternfly/react-core';
33
import { TimesCircleIcon } from '@patternfly/react-icons';
44
import * as React from 'react';
55
import { useTranslation } from 'react-i18next';
@@ -33,11 +33,7 @@ export default function Popover() {
3333

3434
return (
3535
<>
36-
<Flex
37-
className="tp-plugin__popover"
38-
direction={{ default: 'column' }}
39-
gap={{ default: 'gapNone' }}
40-
>
36+
<Stack className="tp-plugin__popover">
4137
<Flex className="tp-plugin__popover-title-bar" gap={{ default: 'gapNone' }}>
4238
<FlexItem grow={{ default: 'grow' }}>
4339
<Title headingLevel="h1">
@@ -55,15 +51,10 @@ export default function Popover() {
5551
</Button>
5652
</FlexItem>
5753
</Flex>
58-
<Flex
59-
className="tp-plugin__popover-content"
60-
direction={{ default: 'column' }}
61-
grow={{ default: 'grow' }}
62-
gap={{ default: 'gapNone' }}
63-
>
54+
<StackItem className="tp-plugin__popover-content" isFilled={true}>
6455
<Korrel8rPanel />
65-
</Flex>
66-
</Flex>
56+
</StackItem>
57+
</Stack>
6758
</>
6859
);
6960
}

web/src/components/topology/Korrel8rTopology.tsx

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -223,29 +223,49 @@ export const Korrel8rTopology: React.FC<{
223223
return controller;
224224
}, [controller, selectionAction, componentFactory]);
225225

226+
const containerRef = React.useRef<HTMLDivElement>(null);
227+
React.useEffect(() => {
228+
const element = containerRef.current;
229+
if (!element) return;
230+
let timer: ReturnType<typeof setTimeout>;
231+
const observer = new ResizeObserver(() => {
232+
clearTimeout(timer);
233+
timer = setTimeout(() => controller.getGraph().fit(PADDING), 150);
234+
});
235+
observer.observe(element);
236+
return () => {
237+
clearTimeout(timer);
238+
observer.disconnect();
239+
};
240+
}, [controller]);
241+
226242
return (
227-
<TopologyView
228-
controlBar={
229-
<TopologyControlBar
230-
controlButtons={createTopologyControlButtons({
231-
...defaultControlButtonsOptions,
232-
zoomInCallback: action(() => {
233-
controller.getGraph().scaleBy(4 / 3);
234-
}),
235-
zoomOutCallback: action(() => {
236-
controller.getGraph().scaleBy(0.75);
237-
}),
238-
fitToScreenCallback: action(() => {
239-
controller.getGraph().fit(PADDING);
240-
}),
241-
legend: false,
242-
})}
243-
/>
244-
}
245-
>
246-
<VisualizationProvider controller={controller2}>
247-
<VisualizationSurface state={{ selectedIds }} />
248-
</VisualizationProvider>
249-
</TopologyView>
243+
<div ref={containerRef} style={{ width: '100%', height: '100%' }}>
244+
<TopologyView
245+
controlBar={
246+
<TopologyControlBar
247+
controlButtons={createTopologyControlButtons({
248+
...defaultControlButtonsOptions,
249+
zoomInCallback: action(() => {
250+
controller.getGraph().scaleBy(4 / 3);
251+
}),
252+
zoomOutCallback: action(() => {
253+
controller.getGraph().scaleBy(0.75);
254+
}),
255+
fitToScreen: false, // Same thing as resetView
256+
resetViewCallback: action(() => {
257+
controller.getGraph().reset();
258+
controller.getGraph().layout();
259+
}),
260+
legend: false,
261+
})}
262+
/>
263+
}
264+
>
265+
<VisualizationProvider controller={controller2}>
266+
<VisualizationSurface state={{ selectedIds }} />
267+
</VisualizationProvider>
268+
</TopologyView>
269+
</div>
250270
);
251271
};

0 commit comments

Comments
 (0)