elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.76k stars 8.16k forks source link

[AO] Extract into a package alerts summary time-range utilities #151593

Open tonyghiani opened 1 year ago

tonyghiani commented 1 year ago

📓 Summary

With the implementation of the AlertSummary component in #149579, it would be better to move these utilities to a package and then use them in both the observability and infra plugins:

✔️ Acceptance criteria

👨‍💻 Implementation hints

Over the extraction of these utilities, we could export an additional custom hook that organizes the usage of these utilities and provide a ready-to-use custom hook to retrieve the alerts summary time range, something like this:

const useSummaryTimeRange = (timeRange: TimeRange) => {
  const timeBuckets = useTimeBuckets();

  const bucketSize = useMemo(
    () => calculateTimeRangeBucketSize(unifiedSearchDateRange, timeRange),
    [timeRange, timeBuckets]
  );

  return getAlertSummaryTimeRange(
    timeRange,
    bucketSize?.intervalString || DEFAULT_INTERVAL,
    bucketSize?.dateFormat || DEFAULT_DATE_FORMAT
  );
};
elasticmachine commented 1 year ago

Pinging @elastic/actionable-observability (Team: Actionable Observability)