-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract explore pages refetch logic into a hook
- Loading branch information
Showing
3 changed files
with
38 additions
and
40 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...ck/plugins/security_solution/public/explore/hooks/use_refetch_overview_page_risk_score.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,34 @@ | ||
/* | ||
* 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 { TableId } from '@kbn/securitysolution-data-table'; | ||
import { useCallback, useMemo } from 'react'; | ||
import { useDeepEqualSelector } from '../../common/hooks/use_selector'; | ||
import { inputsSelectors } from '../../common/store'; | ||
import type { Refetch } from '../../common/types'; | ||
|
||
const useRefetchByQueryId = (QueryId: string) => { | ||
const getGlobalQuery = useMemo(() => inputsSelectors.globalQueryByIdSelector(), []); | ||
const { refetch } = useDeepEqualSelector((state) => getGlobalQuery(state, QueryId)); | ||
return refetch; | ||
}; | ||
|
||
export const useRefetchOverviewPageRiskScore = (overviewRiskScoreQueryId: string) => { | ||
const refetchOverviewRiskScore = useRefetchByQueryId(overviewRiskScoreQueryId); | ||
const refetchAlertsRiskInputs = useRefetchByQueryId(TableId.alertsRiskInputs); | ||
|
||
const refetchRiskScore = useCallback(() => { | ||
if (refetchOverviewRiskScore) { | ||
(refetchOverviewRiskScore as Refetch)(); | ||
} | ||
|
||
if (refetchAlertsRiskInputs) { | ||
(refetchAlertsRiskInputs as Refetch)(); | ||
} | ||
}, [refetchAlertsRiskInputs, refetchOverviewRiskScore]); | ||
return refetchRiskScore; | ||
}; |
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