Skip to content

Commit

Permalink
Fix not persisting default values for new variables
Browse files Browse the repository at this point in the history
  • Loading branch information
kpollich committed May 12, 2022
1 parent 132f547 commit fede140
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ describe('Fleet - validatePackagePolicy()', () => {
],
},
],
vars: {},
};

const invalidPackagePolicy: NewPackagePolicy = {
Expand Down Expand Up @@ -332,6 +333,7 @@ describe('Fleet - validatePackagePolicy()', () => {
],
},
],
vars: {},
};

const noErrorsValidationResults = {
Expand Down Expand Up @@ -370,6 +372,7 @@ describe('Fleet - validatePackagePolicy()', () => {
vars: { 'var-name': null },
},
},
vars: {},
};

it('returns no errors for valid package policy', () => {
Expand Down Expand Up @@ -416,6 +419,7 @@ describe('Fleet - validatePackagePolicy()', () => {
streams: { 'with-no-stream-vars-bar': {} },
},
},
vars: {},
});
});

Expand Down Expand Up @@ -487,6 +491,7 @@ describe('Fleet - validatePackagePolicy()', () => {
streams: { 'with-no-stream-vars-bar': {} },
},
},
vars: {},
});
});

Expand All @@ -505,6 +510,7 @@ describe('Fleet - validatePackagePolicy()', () => {
description: null,
namespace: null,
inputs: null,
vars: {},
});
expect(
validatePackagePolicy(
Expand All @@ -520,6 +526,7 @@ describe('Fleet - validatePackagePolicy()', () => {
description: null,
namespace: null,
inputs: null,
vars: {},
});
});

Expand All @@ -538,6 +545,7 @@ describe('Fleet - validatePackagePolicy()', () => {
description: null,
namespace: null,
inputs: null,
vars: {},
});
expect(
validatePackagePolicy(
Expand All @@ -553,6 +561,7 @@ describe('Fleet - validatePackagePolicy()', () => {
description: null,
namespace: null,
inputs: null,
vars: {},
});
});

Expand Down Expand Up @@ -604,6 +613,7 @@ describe('Fleet - validatePackagePolicy()', () => {
},
},
},
vars: {},
});
});

Expand Down Expand Up @@ -729,6 +739,7 @@ describe('Fleet - validatePackagePolicy()', () => {
},
},
},
vars: {},
name: null,
namespace: null,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,17 @@ export const StepDefinePackagePolicy: React.FunctionComponent<{
{/* Required vars */}
{requiredVars.map((varDef) => {
const { name: varName, type: varType, default: defaultValue } = varDef;
const value = packagePolicy.vars?.[varName]?.value ?? defaultValue;

// Set up the `vars` object and assign the default value if it doesn't exist
if (!packagePolicy.vars) {
packagePolicy.vars = {};
}

if (!packagePolicy.vars[varName]) {
packagePolicy.vars[varName] = { value: defaultValue, type: varType };
}

const value = packagePolicy.vars?.[varName]?.value;

return (
<EuiFlexItem key={varName}>
Expand Down

0 comments on commit fede140

Please sign in to comment.