mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Improve alert summary data fetching in Alerts and Overview pages (#150298)
## Summary
Use useMemo to avoid extra fetching of alert summary data.
|Before|After|
|---|---|
||
This commit is contained in:
parent
1b8960bee6
commit
edc8265de8
2 changed files with 22 additions and 17 deletions
|
@ -5,15 +5,12 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
|
||||
import { BoolQuery } from '@kbn/es-query';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { useKibana } from '@kbn/kibana-react-plugin/public';
|
||||
import {
|
||||
loadRuleAggregations,
|
||||
AlertSummaryTimeRange,
|
||||
} from '@kbn/triggers-actions-ui-plugin/public';
|
||||
import { loadRuleAggregations } from '@kbn/triggers-actions-ui-plugin/public';
|
||||
import { AlertConsumers } from '@kbn/rule-data-utils';
|
||||
import { useToasts } from '../../../../hooks/use_toast';
|
||||
import {
|
||||
|
@ -80,12 +77,16 @@ function InternalAlertsPage() {
|
|||
const { hasAnyData, isAllRequestsComplete } = useHasData();
|
||||
const [esQuery, setEsQuery] = useState<{ bool: BoolQuery }>();
|
||||
const timeBuckets = useTimeBuckets();
|
||||
const alertSummaryTimeRange: AlertSummaryTimeRange = getAlertSummaryTimeRange(
|
||||
{
|
||||
from: alertSearchBarStateProps.rangeFrom,
|
||||
to: alertSearchBarStateProps.rangeTo,
|
||||
},
|
||||
timeBuckets
|
||||
const alertSummaryTimeRange = useMemo(
|
||||
() =>
|
||||
getAlertSummaryTimeRange(
|
||||
{
|
||||
from: alertSearchBarStateProps.rangeFrom,
|
||||
to: alertSearchBarStateProps.rangeTo,
|
||||
},
|
||||
timeBuckets
|
||||
),
|
||||
[alertSearchBarStateProps.rangeFrom, alertSearchBarStateProps.rangeTo, timeBuckets]
|
||||
);
|
||||
|
||||
useBreadcrumbs([
|
||||
|
|
|
@ -92,12 +92,16 @@ export function OverviewPage() {
|
|||
})
|
||||
);
|
||||
const timeBuckets = useTimeBuckets();
|
||||
const alertSummaryTimeRange = getAlertSummaryTimeRange(
|
||||
{
|
||||
from: relativeStart,
|
||||
to: relativeEnd,
|
||||
},
|
||||
timeBuckets
|
||||
const alertSummaryTimeRange = useMemo(
|
||||
() =>
|
||||
getAlertSummaryTimeRange(
|
||||
{
|
||||
from: relativeStart,
|
||||
to: relativeEnd,
|
||||
},
|
||||
timeBuckets
|
||||
),
|
||||
[relativeEnd, relativeStart, timeBuckets]
|
||||
);
|
||||
|
||||
const chartThemes = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue