mirror of
https://github.com/grafana/grafana.git
synced 2025-09-19 16:12:50 +08:00

* Basic implementation in web worker * Move instances discovery to the worker * Remove filtering from the worker * Use normalized routes, use rtk query for alert groups fetching * Reorganize matchers utilities to be available for web workers * Move object matchers to the machers util file, rename worker * Move worker code to a separate hook, add perf logging * Add a mock for the web worker code, fix tests * Fix tests warnings * Remove notification policy feature flag * Add normalizeRoute tests, change the regex match to test for label matching * Move worker init to the file scope * Simplify useAsyncFn hook * Use CorsWorker as a workaround for web workers loading from CDN * Use a feature flag to enable/disable worker-based preview, add worker error handling * Add POC for react-enable working with grafana feature toggles * Code cleanup * Remove console error, add useRouteGroupsMatcher tests * Fix tests mock
21 lines
568 B
TypeScript
21 lines
568 B
TypeScript
import { useCallback } from 'react';
|
|
|
|
import { AlertmanagerGroup, RouteWithID } from '../../../../plugins/datasource/alertmanager/types';
|
|
|
|
export function useRouteGroupsMatcher() {
|
|
const getRouteGroupsMap = useCallback(async (route: RouteWithID, __: AlertmanagerGroup[]) => {
|
|
const groupsMap = new Map<string, AlertmanagerGroup[]>();
|
|
function addRoutes(route: RouteWithID) {
|
|
groupsMap.set(route.id, []);
|
|
|
|
route.routes?.forEach((r) => addRoutes(r));
|
|
}
|
|
|
|
addRoutes(route);
|
|
|
|
return groupsMap;
|
|
}, []);
|
|
|
|
return { getRouteGroupsMap };
|
|
}
|