-
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.
clean up + reformating option rendering
- Loading branch information
Showing
6 changed files
with
81 additions
and
33 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
34 changes: 34 additions & 0 deletions
34
x-pack/plugins/osquery/public/agents/use_agent_policies.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 { useQueries, UseQueryResult } from 'react-query'; | ||
import { useKibana } from '../common/lib/kibana'; | ||
import { AgentPolicy, agentPolicyRouteService, GetOneAgentPolicyResponse } from '../../../fleet/common'; | ||
|
||
export const useAgentPolicies = (policyIds: string[] = []) => { | ||
const { http } = useKibana().services; | ||
|
||
const agentResponse = useQueries( | ||
policyIds.map((policyId) => ({ | ||
queryKey: ['agentPolicy', policyId], | ||
queryFn: () => http.get(agentPolicyRouteService.getInfoPath(policyId)), | ||
options: {enabled: policyIds.length > 0} | ||
})), | ||
) as Array<UseQueryResult<GetOneAgentPolicyResponse>>; | ||
|
||
const agentPoliciesLoading = agentResponse.some(p => p.isLoading) | ||
const agentPolicies = agentResponse.map(p => p.data?.item) | ||
const agentPolicyById = agentPolicies.reduce((acc, p) => { | ||
if (!p) { | ||
return acc | ||
} | ||
acc[p.id] = p | ||
return acc | ||
}, {} as {[key: string]: AgentPolicy}) | ||
|
||
return { agentPoliciesLoading, agentPolicies, agentPolicyById }; | ||
}; |
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