mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Fleet] Fix invalid kuery when updating integration (#171559)
This commit is contained in:
parent
a723bd0cd7
commit
9be7fb0d87
4 changed files with 23 additions and 12 deletions
|
@ -141,6 +141,11 @@ export const SettingsPage: React.FC<Props> = memo(({ packageInfo, theme$ }: Prop
|
|||
[packagePoliciesData]
|
||||
);
|
||||
|
||||
const agentPolicyIds = useMemo(
|
||||
() => packagePoliciesData?.items.map(({ policy_id: agentPolicyId }) => agentPolicyId) ?? [],
|
||||
[packagePoliciesData]
|
||||
);
|
||||
|
||||
const { data: dryRunData } = useUpgradePackagePolicyDryRunQuery(
|
||||
packagePolicyIds ?? [],
|
||||
latestVersion,
|
||||
|
@ -329,6 +334,7 @@ export const SettingsPage: React.FC<Props> = memo(({ packageInfo, theme$ }: Prop
|
|||
<UpdateButton
|
||||
{...packageInfo}
|
||||
version={latestVersion}
|
||||
agentPolicyIds={agentPolicyIds}
|
||||
packagePolicyIds={packagePolicyIds}
|
||||
dryRunData={dryRunData}
|
||||
isUpgradingPackagePolicies={isUpgradingPackagePolicies}
|
||||
|
|
|
@ -29,7 +29,6 @@ import type {
|
|||
PackagePolicy,
|
||||
} from '../../../../../types';
|
||||
import { InstallStatus } from '../../../../../types';
|
||||
import { AGENT_POLICY_SAVED_OBJECT_TYPE, SO_SEARCH_LIMIT } from '../../../../../constants';
|
||||
import {
|
||||
useInstallPackage,
|
||||
useGetPackageInstallStatus,
|
||||
|
@ -37,12 +36,13 @@ import {
|
|||
useAuthz,
|
||||
useLink,
|
||||
useUpgradePackagePoliciesMutation,
|
||||
useGetAgentPoliciesQuery,
|
||||
useBulkGetAgentPoliciesQuery,
|
||||
} from '../../../../../hooks';
|
||||
|
||||
interface UpdateButtonProps extends Pick<PackageInfo, 'name' | 'title' | 'version'> {
|
||||
dryRunData?: UpgradePackagePolicyDryRunResponse | null;
|
||||
packagePolicyIds?: string[];
|
||||
agentPolicyIds: string[];
|
||||
isUpgradingPackagePolicies?: boolean;
|
||||
setIsUpgradingPackagePolicies?: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
theme$: Observable<CoreTheme>;
|
||||
|
@ -73,6 +73,7 @@ export const UpdateButton: React.FunctionComponent<UpdateButtonProps> = ({
|
|||
isUpgradingPackagePolicies = false,
|
||||
name,
|
||||
packagePolicyIds = [],
|
||||
agentPolicyIds = [],
|
||||
setIsUpgradingPackagePolicies = () => {},
|
||||
title,
|
||||
version,
|
||||
|
@ -92,16 +93,7 @@ export const UpdateButton: React.FunctionComponent<UpdateButtonProps> = ({
|
|||
const [isUpdateModalVisible, setIsUpdateModalVisible] = useState<boolean>(false);
|
||||
const [upgradePackagePolicies, setUpgradePackagePolicies] = useState<boolean>(true);
|
||||
|
||||
const { data: agentPolicyData } = useGetAgentPoliciesQuery({
|
||||
perPage: SO_SEARCH_LIMIT,
|
||||
page: 1,
|
||||
// Fetch all agent policies that include one of the eligible package policies
|
||||
kuery: packagePolicyIds.length
|
||||
? `${AGENT_POLICY_SAVED_OBJECT_TYPE}.package_policies:${packagePolicyIds
|
||||
.map((id) => `"${id}"`)
|
||||
.join(' or ')}`
|
||||
: '',
|
||||
});
|
||||
const { data: agentPolicyData } = useBulkGetAgentPoliciesQuery(agentPolicyIds, { full: true });
|
||||
|
||||
const packagePolicyCount = useMemo(() => packagePolicyIds.length, [packagePolicyIds]);
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import type {
|
|||
CopyAgentPolicyResponse,
|
||||
DeleteAgentPolicyRequest,
|
||||
DeleteAgentPolicyResponse,
|
||||
BulkGetAgentPoliciesResponse,
|
||||
} from '../../types';
|
||||
|
||||
import { useRequest, sendRequest, useConditionalRequest, sendRequestForRq } from './use_request';
|
||||
|
@ -47,6 +48,17 @@ export const useGetAgentPoliciesQuery = (query?: GetAgentPoliciesRequest['query'
|
|||
);
|
||||
};
|
||||
|
||||
export const useBulkGetAgentPoliciesQuery = (ids: string[], options?: { full?: boolean }) => {
|
||||
return useQuery<BulkGetAgentPoliciesResponse, RequestError>(['agentPolicies', ids], () =>
|
||||
sendRequestForRq<BulkGetAgentPoliciesResponse>({
|
||||
path: agentPolicyRouteService.getBulkGetPath(),
|
||||
method: 'post',
|
||||
body: JSON.stringify({ ids, full: options?.full }),
|
||||
version: API_VERSIONS.public.v1,
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
export const sendGetAgentPolicies = (query?: GetAgentPoliciesRequest['query']) => {
|
||||
return sendRequest<GetAgentPoliciesResponse>({
|
||||
path: agentPolicyRouteService.getListPath(),
|
||||
|
|
|
@ -137,6 +137,7 @@ export type {
|
|||
KibanaSavedObjectType,
|
||||
GetInputsTemplatesRequest,
|
||||
GetInputsTemplatesResponse,
|
||||
BulkGetAgentPoliciesResponse,
|
||||
} from '../../common/types';
|
||||
export {
|
||||
entries,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue