Skip to content

Commit

Permalink
Prevent unneeded re-renders of tgrid on opening alert flyout (#108781) (
Browse files Browse the repository at this point in the history
#108805)

Co-authored-by: Kevin Qualters <56408403+kqualters-elastic@users.noreply.github.com>
  • Loading branch information
kibanamachine and kqualters-elastic committed Aug 17, 2021
1 parent ee2417c commit fb8d33b
Showing 1 changed file with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ interface AlertsTableTGridProps {
}

interface ObservabilityActionsProps extends ActionProps {
flyoutAlert: TopAlert | undefined;
setFlyoutAlert: React.Dispatch<React.SetStateAction<TopAlert | undefined>>;
}

Expand Down Expand Up @@ -162,12 +161,10 @@ function ObservabilityActions({
data,
eventId,
ecsData,
flyoutAlert,
setFlyoutAlert,
}: ObservabilityActionsProps) {
const { core, observabilityRuleTypeRegistry } = usePluginContext();
const dataFieldEs = data.reduce((acc, d) => ({ ...acc, [d.field]: d.value }), {});
const handleFlyoutClose = () => setFlyoutAlert(undefined);
const [openActionsPopoverId, setActionsPopover] = useState(null);
const { timelines } = useKibana<{ timelines: TimelinesUIStart }>().services;
const parseObservabilityAlert = useMemo(() => parseAlert(observabilityRuleTypeRegistry), [
Expand Down Expand Up @@ -223,15 +220,6 @@ function ObservabilityActions({
}, [afterCaseSelection, casePermissions, timelines, event]);
return (
<>
{flyoutAlert && (
<Suspense fallback={null}>
<LazyAlertsFlyout
alert={flyoutAlert}
observabilityRuleTypeRegistry={observabilityRuleTypeRegistry}
onClose={handleFlyoutClose}
/>
</Suspense>
)}
<EuiFlexGroup gutterSize="none" responsive={false}>
<EuiFlexItem>
<EuiButtonIcon
Expand Down Expand Up @@ -299,17 +287,11 @@ export function AlertsTableTGrid(props: AlertsTableTGridProps) {
);
},
rowCellRender: (actionProps: ActionProps) => {
return (
<ObservabilityActions
{...actionProps}
flyoutAlert={flyoutAlert}
setFlyoutAlert={setFlyoutAlert}
/>
);
return <ObservabilityActions {...actionProps} setFlyoutAlert={setFlyoutAlert} />;
},
},
];
}, [flyoutAlert]);
}, []);

const tGridProps = useMemo(() => {
const type: TGridType = 'standalone';
Expand Down Expand Up @@ -367,6 +349,21 @@ export function AlertsTableTGrid(props: AlertsTableTGridProps) {
setRefetch,
status,
]);
const handleFlyoutClose = () => setFlyoutAlert(undefined);
const { observabilityRuleTypeRegistry } = usePluginContext();

return <>{timelines.getTGrid<'standalone'>(tGridProps)}</>;
return (
<>
{flyoutAlert && (
<Suspense fallback={null}>
<LazyAlertsFlyout
alert={flyoutAlert}
observabilityRuleTypeRegistry={observabilityRuleTypeRegistry}
onClose={handleFlyoutClose}
/>
</Suspense>
)}
{timelines.getTGrid<'standalone'>(tGridProps)}
</>
);
}

0 comments on commit fb8d33b

Please sign in to comment.