Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty string default variable values #73

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pkg/capi/components/CCVariables/Variable.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script lang="ts">
import Vue from 'vue';
import type { PropType } from 'vue';
import isEqual from 'lodash/isEqual';

import LabeledInput from '@components/Form/LabeledInput/LabeledInput.vue';
import Checkbox from '@components/Form/Checkbox/Checkbox.vue';
import KeyValue from '@shell/components/form/KeyValue.vue';
Expand Down Expand Up @@ -46,6 +48,7 @@ export default Vue.extend({

computed: {
...mapGetters({ t: 'i18n/t' }),

componentForType(): {component: any, name: string} | undefined {
const { type } = this.schema;
let out: any;
Expand Down Expand Up @@ -101,6 +104,9 @@ export default Vue.extend({
},

validationRules() {
if (this.isDefaultValue) {
return [];
}
const t = this.t as Translation;
const out = openAPIV3SchemaValidators(t, { key: this.variable.name }, this.schema);

Expand All @@ -113,6 +119,16 @@ export default Vue.extend({
return out;
},

isDefaultValue() {
const defaulVal = this.schema.default;

if (defaulVal !== undefined) {
return isEqual(defaulVal, this.value);
}

return false;
},

isValid() {
return !this.validationErrors.length;
},
Expand Down
8 changes: 4 additions & 4 deletions pkg/capi/components/CCVariables/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default Vue.extend({
});

return out;
},
}
},

methods: {
Expand Down Expand Up @@ -147,7 +147,7 @@ export default Vue.extend({
const oldDefault = (old || []).find(d => d.name === existingVar.name)?.schema?.openAPIV3Schema?.default;

// if a variable is set to the previous definition's default, clear it out
if (isDefined(oldDefault) && existingVar.value === oldDefault) {
if (oldDefault !== undefined && existingVar.value === oldDefault) {
delete existingVar.value;
}
let newDefault = neuDef.schema?.openAPIV3Schema?.default;
Expand All @@ -159,7 +159,7 @@ export default Vue.extend({
}

// if the value hasn't been touched by the user set it to the new cc default
if (isDefined(newDefault) && !existingVar.value) {
if (newDefault !== undefined && !existingVar.value) {
existingVar.value = newDefault;
}
acc.push(existingVar);
Expand All @@ -174,7 +174,7 @@ export default Vue.extend({
if (def.schema?.openAPIV3Schema?.type === 'boolean' && !newDefault) {
newDefault = false;
}
if (isDefined(newDefault) && !out.find(v => v.name === def.name)) {
if (newDefault !== undefined && !out.find(v => v.name === def.name)) {
out.push({ name: def.name, value: newDefault });
}
});
Expand Down
30 changes: 6 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2944,10 +2944,10 @@
dependencies:
lodash.debounce "4.0.8"

"@rancher/shell@0.5.1":
version "0.5.1"
resolved "https://registry.yarnpkg.com/@rancher/shell/-/shell-0.5.1.tgz#4ee59f4f60b6bba54995f00e289dcd64d97f162a"
integrity sha512-oCmXZ9MDw9jh7plGmYT9ZnB2gHqs5FLgB22HEgUl46R7t94Tms3Z5VivN1JMS77R++C3jdC/EVpjgisKslK4Pg==
"@rancher/shell@0.5.3":
version "0.5.3"
resolved "https://registry.npmjs.org/@rancher/shell/-/shell-0.5.3.tgz#4cf97b5b4992fcd0c008169bdfcdd778db9bdac2"
integrity sha512-/CogLZYw/k63Wn0Y6TI8CmBvKDPKHDqJGPTRK/+B6CBNimmPKCWedqeCi9IjJzk1Exj2Lv0e3csjgbK/TUaXFg==
dependencies:
"@aws-sdk/client-ec2" "3.1.0"
"@aws-sdk/client-eks" "3.1.0"
Expand Down Expand Up @@ -9020,9 +9020,9 @@ glob-to-regexp@^0.3.0:
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab"
integrity sha512-Iozmtbqv0noj0uDDqoL0zNq0VBEfK2YFoMAZoxJe4cwphvLR+JskfF30QhXHOR4m3KrE6NLRYw+U9MRXvifyig==

glob@^7.0.3, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6, glob@^7.1.7, glob@^7.2.0:
glob@7.2.3, glob@^7.0.3, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6, glob@^7.1.7, glob@^7.2.0, glob@^8.1.0:
version "7.2.3"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b"
resolved "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b"
integrity sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==
dependencies:
fs.realpath "^1.0.0"
Expand All @@ -9032,17 +9032,6 @@ glob@^7.0.3, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6, gl
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e"
integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^5.0.1"
once "^1.3.0"

global-dirs@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/global-dirs/-/global-dirs-3.0.1.tgz#0c488971f066baceda21447aecb1a8b911d22485"
Expand Down Expand Up @@ -11786,13 +11775,6 @@ minimatch@^3.0.4, minimatch@^3.1.1, minimatch@^3.1.2:
dependencies:
brace-expansion "^1.1.7"

minimatch@^5.0.1:
version "5.1.6"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96"
integrity sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==
dependencies:
brace-expansion "^2.0.1"

minimist@^1.2.0, minimist@^1.2.5, minimist@^1.2.6:
version "1.2.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
Expand Down