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

[RAC][Observability] Prevent unneeded re-renders of tgrid on opening alert flyout #108781

Merged
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 @@ -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 @@ -298,17 +286,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 @@ -366,6 +348,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)}
</>
);
}