fixed bug with policy upgrade and updated vars (#122767) (#122872)

(cherry picked from commit 42839e104e)

Co-authored-by: Julia Bardi <90178898+juliaElastic@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2022-01-12 15:16:43 -05:00 committed by GitHub
parent 83426b30cd
commit 15580f36a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -210,7 +210,24 @@ export const EditPackagePolicyForm = memo<{
...restOfPackagePolicy,
inputs: baseInputs.map((input: any) => {
// Remove `compiled_input` from all input info, we assign this after saving
const { streams, compiled_input: compiledInput, ...restOfInput } = input;
const { streams, compiled_input: compiledInput, vars, ...restOfInput } = input;
let basePolicyInputVars: any =
isUpgrade &&
basePolicy.inputs.find(
(i) => i.type === input.type && i.policy_template === input.policy_template
)?.vars;
let newVars = vars;
if (basePolicyInputVars && vars) {
// merging vars from dry run with updated ones
basePolicyInputVars = Object.keys(vars).reduce(
(acc, curr) => ({ ...acc, [curr]: basePolicyInputVars[curr] }),
{}
);
newVars = {
...vars,
...basePolicyInputVars,
};
}
return {
...restOfInput,
streams: streams.map((stream: any) => {
@ -218,6 +235,7 @@ export const EditPackagePolicyForm = memo<{
const { compiled_stream, ...restOfStream } = stream;
return restOfStream;
}),
vars: newVars,
};
}),
package: basePackage,