[8.9] [Cloud Security] Fix auto increment issue on the integrations page (#161046) (#161383)

# Backport

This will backport the following commits from `main` to `8.9`:
- [[Cloud Security] Fix auto increment issue on the integrations page
(#161046)](https://github.com/elastic/kibana/pull/161046)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Paulo
Henrique","email":"paulo.henrique@elastic.co"},"sourceCommit":{"committedDate":"2023-07-06T18:08:56Z","message":"[Cloud
Security] Fix auto increment issue on the integrations page
(#161046)","sha":"2c01f7e290dfbb621de6a187f314323a735d1057","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Cloud
Security","backport:prev-minor","v8.9.0","v8.10.0"],"number":161046,"url":"https://github.com/elastic/kibana/pull/161046","mergeCommit":{"message":"[Cloud
Security] Fix auto increment issue on the integrations page
(#161046)","sha":"2c01f7e290dfbb621de6a187f314323a735d1057"}},"sourceBranch":"main","suggestedTargetBranches":["8.9"],"targetPullRequestStates":[{"branch":"8.9","label":"v8.9.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/161046","number":161046,"mergeCommit":{"message":"[Cloud
Security] Fix auto increment issue on the integrations page
(#161046)","sha":"2c01f7e290dfbb621de6a187f314323a735d1057"}}]}]
BACKPORT-->

Co-authored-by: Paulo Henrique <paulo.henrique@elastic.co>
This commit is contained in:
Kibana Machine 2023-07-06 15:18:36 -04:00 committed by GitHub
parent a6545e77f5
commit f50b05c50a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 9 deletions

View file

@ -42,13 +42,22 @@ jest.mock('../../common/api/use_package_policy_list');
const onChange = jest.fn();
const createReactQueryResponseWithRefetch = (
data: Parameters<typeof createReactQueryResponse>[0]
) => {
return {
...createReactQueryResponse(data),
refetch: jest.fn(),
};
};
describe('<CspPolicyTemplateForm />', () => {
beforeEach(() => {
(useParams as jest.Mock).mockReturnValue({
integration: undefined,
});
(usePackagePolicyList as jest.Mock).mockImplementation((packageName) =>
createReactQueryResponse({
createReactQueryResponseWithRefetch({
status: 'success',
data: {
items: [],
@ -57,7 +66,7 @@ describe('<CspPolicyTemplateForm />', () => {
);
onChange.mockClear();
(useCspSetupStatusApi as jest.Mock).mockImplementation(() =>
createReactQueryResponse({
createReactQueryResponseWithRefetch({
status: 'success',
data: { status: 'indexed', installedPackageVersion: '1.2.13' },
})
@ -240,7 +249,7 @@ describe('<CspPolicyTemplateForm />', () => {
});
(useCspSetupStatusApi as jest.Mock).mockImplementation(() =>
createReactQueryResponse({
createReactQueryResponseWithRefetch({
status: 'success',
data: {
kspm: { status: 'not-deployed', healthyAgents: 0, installedPackagePolicies: 1 },
@ -249,7 +258,7 @@ describe('<CspPolicyTemplateForm />', () => {
);
(usePackagePolicyList as jest.Mock).mockImplementation(() =>
createReactQueryResponse({
createReactQueryResponseWithRefetch({
status: 'success',
data: {
items: [
@ -329,7 +338,7 @@ describe('<CspPolicyTemplateForm />', () => {
integration: 'vuln_mgmt',
});
(useCspSetupStatusApi as jest.Mock).mockImplementation(() =>
createReactQueryResponse({
createReactQueryResponseWithRefetch({
status: 'success',
data: {
vuln_mgmt: { status: 'not-deployed', healthyAgents: 0, installedPackagePolicies: 1 },
@ -337,7 +346,7 @@ describe('<CspPolicyTemplateForm />', () => {
})
);
(usePackagePolicyList as jest.Mock).mockImplementation(() =>
createReactQueryResponse({
createReactQueryResponseWithRefetch({
status: 'success',
data: {
items: [
@ -419,7 +428,7 @@ describe('<CspPolicyTemplateForm />', () => {
});
(useCspSetupStatusApi as jest.Mock).mockImplementation(() =>
createReactQueryResponse({
createReactQueryResponseWithRefetch({
status: 'success',
data: {
cspm: { status: 'not-deployed', healthyAgents: 0, installedPackagePolicies: 1 },
@ -427,7 +436,7 @@ describe('<CspPolicyTemplateForm />', () => {
})
);
(usePackagePolicyList as jest.Mock).mockImplementation(() =>
createReactQueryResponse({
createReactQueryResponseWithRefetch({
status: 'success',
data: {
items: [

View file

@ -136,7 +136,7 @@ export const CspPolicyTemplateForm = memo<PackagePolicyReplaceDefineStepExtensio
setTimeout(() => setIsLoading(false), 200);
}, [validationResultsNonNullFields]);
const { data: packagePolicyList } = usePackagePolicyList(packageInfo.name, {
const { data: packagePolicyList, refetch } = usePackagePolicyList(packageInfo.name, {
enabled: canFetchIntegration,
});
@ -148,6 +148,7 @@ export const CspPolicyTemplateForm = memo<PackagePolicyReplaceDefineStepExtensio
// Required for mount only to ensure a single input type is selected
// This will remove errors in validationResults.vars
setEnabledPolicyInput(DEFAULT_INPUT_TYPE[input.policy_template]);
refetch();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isLoading, input.policy_template, isEditPage]);