forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] Coverage Overview Dashboard (elastic#161556)
- Loading branch information
Showing
38 changed files
with
1,660 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...solution/public/detection_engine/rule_management/api/hooks/use_fetch_coverage_overview.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { UseQueryOptions } from '@tanstack/react-query'; | ||
import { useQuery, useQueryClient } from '@tanstack/react-query'; | ||
import { useCallback } from 'react'; | ||
import type { CoverageOverviewFilter } from '../../../../../common/api/detection_engine'; | ||
import { RULE_MANAGEMENT_COVERAGE_OVERVIEW_URL } from '../../../../../common/api/detection_engine'; | ||
import { fetchCoverageOverview } from '../api'; | ||
import { buildCoverageOverviewDashboardModel } from '../../logic/coverage_overview/build_coverage_overview_dashboard_model'; | ||
import type { CoverageOverviewDashboard } from '../../model/coverage_overview/dashboard'; | ||
import { DEFAULT_QUERY_OPTIONS } from './constants'; | ||
|
||
const COVERAGE_OVERVIEW_QUERY_KEY = ['POST', RULE_MANAGEMENT_COVERAGE_OVERVIEW_URL]; | ||
|
||
/** | ||
* A wrapper around useQuery provides default values to the underlying query, | ||
* like query key, abortion signal, and error handler. | ||
* | ||
* @param filter - coverage overview filter, see CoverageOverviewFilter type | ||
* @param options - react-query options | ||
* @returns useQuery result | ||
*/ | ||
export const useFetchCoverageOverviewQuery = ( | ||
filter: CoverageOverviewFilter = {}, | ||
options?: UseQueryOptions<CoverageOverviewDashboard> | ||
) => { | ||
return useQuery<CoverageOverviewDashboard>( | ||
[...COVERAGE_OVERVIEW_QUERY_KEY, filter], | ||
async ({ signal }) => { | ||
const response = await fetchCoverageOverview({ signal, filter }); | ||
|
||
return buildCoverageOverviewDashboardModel(response); | ||
}, | ||
{ | ||
...DEFAULT_QUERY_OPTIONS, | ||
...options, | ||
} | ||
); | ||
}; | ||
|
||
/** | ||
* We should use this hook to invalidate the coverage overview cache. For example, rule | ||
* mutations that affect rule set size, like creation or deletion, should lead | ||
* to cache invalidation. | ||
* | ||
* @returns A coverage overview cache invalidation callback | ||
*/ | ||
export const useInvalidateFetchCoverageOverviewQuery = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useCallback(() => { | ||
queryClient.invalidateQueries(COVERAGE_OVERVIEW_QUERY_KEY, { | ||
refetchType: 'active', | ||
}); | ||
}, [queryClient]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.