From 0c2ae5c512e9cfea0c3c8719df5b4edd43fb035e Mon Sep 17 00:00:00 2001 From: Nancy Butler <42977925+mantis-toboggan-md@users.noreply.github.com> Date: Mon, 11 Dec 2023 09:31:59 -0800 Subject: [PATCH 01/23] enums --- pkg/capi/components/CCVariables/Enum.vue | 65 +++++++++++ pkg/capi/components/CCVariables/Variable.vue | 111 +++++++++++++++++++ pkg/capi/components/CCVariables/data.ts | 76 +++++++++++++ pkg/capi/components/CCVariables/index.vue | 84 ++++++++++++++ pkg/capi/pages/blerg.vue | 25 +++++ pkg/capi/routes/capi-routing.ts | 6 + pkg/capi/types/clusterClass.ts | 39 +++++++ 7 files changed, 406 insertions(+) create mode 100644 pkg/capi/components/CCVariables/Enum.vue create mode 100644 pkg/capi/components/CCVariables/Variable.vue create mode 100644 pkg/capi/components/CCVariables/data.ts create mode 100644 pkg/capi/components/CCVariables/index.vue create mode 100644 pkg/capi/pages/blerg.vue create mode 100644 pkg/capi/types/clusterClass.ts diff --git a/pkg/capi/components/CCVariables/Enum.vue b/pkg/capi/components/CCVariables/Enum.vue new file mode 100644 index 0000000..15af2a2 --- /dev/null +++ b/pkg/capi/components/CCVariables/Enum.vue @@ -0,0 +1,65 @@ + + + diff --git a/pkg/capi/components/CCVariables/Variable.vue b/pkg/capi/components/CCVariables/Variable.vue new file mode 100644 index 0000000..3d9113e --- /dev/null +++ b/pkg/capi/components/CCVariables/Variable.vue @@ -0,0 +1,111 @@ + + + diff --git a/pkg/capi/components/CCVariables/data.ts b/pkg/capi/components/CCVariables/data.ts new file mode 100644 index 0000000..2d31517 --- /dev/null +++ b/pkg/capi/components/CCVariables/data.ts @@ -0,0 +1,76 @@ +export default [{ + name: 'region', + required: false, + schema: + { + openAPIV3Schema: + { + type: 'string', + // default: 'us-east-1', + description: 'The Azure region to create machines in' + } + } +}, + +{ + name: 'sshKeyName', + required: true, + schema: + { + openAPIV3Schema: + { + type: 'string', + default: 'default', + description: 'SSH key name description text go here', + example: 'sshkeyexample' + } + } +}, +{ + name: 'controlPlaneMachineType', + required: true, + schema: + { + openAPIV3Schema: + { + type: 'string', + default: 't3.large' + } + } +}, +{ + name: 'workerMachineType', + required: true, + schema: + { + openAPIV3Schema: + { + type: 'string', + default: 't3.large' + } + } +}, +{ + name: 'testBoolean', + schema: + { + openAPIV3Schema: + { + type: 'boolean', + description: 'This is a test value' + } + } +}, +{ + name: 'testArrayStrings', + schema: + { + openAPIV3Schema: + { + type: 'array', + description: 'This is a test array value', + items: + { type: 'string' } + } + } +}]; diff --git a/pkg/capi/components/CCVariables/index.vue b/pkg/capi/components/CCVariables/index.vue new file mode 100644 index 0000000..a35563b --- /dev/null +++ b/pkg/capi/components/CCVariables/index.vue @@ -0,0 +1,84 @@ + + + diff --git a/pkg/capi/pages/blerg.vue b/pkg/capi/pages/blerg.vue new file mode 100644 index 0000000..01baa4e --- /dev/null +++ b/pkg/capi/pages/blerg.vue @@ -0,0 +1,25 @@ + + + diff --git a/pkg/capi/routes/capi-routing.ts b/pkg/capi/routes/capi-routing.ts index 17bb917..ca3381e 100644 --- a/pkg/capi/routes/capi-routing.ts +++ b/pkg/capi/routes/capi-routing.ts @@ -1,4 +1,5 @@ import Dashboard from '../pages/index.vue'; +import blerg from '../pages/blerg.vue'; const routes = [ { @@ -6,6 +7,11 @@ const routes = [ path: '/c/:cluster/manager/capi', component: Dashboard, }, + { + name: 'c-cluster-manager-capi-blerg', + path: '/c/:cluster/manager/capi/blerg', + component: blerg, + }, ]; export default routes; diff --git a/pkg/capi/types/clusterClass.ts b/pkg/capi/types/clusterClass.ts new file mode 100644 index 0000000..c964af4 --- /dev/null +++ b/pkg/capi/types/clusterClass.ts @@ -0,0 +1,39 @@ + +export interface ClusterClassVariable { + name: String, + required: Boolean, + schema: { + openAPIV3Schema: { + additionalProperties?: Map + default?: any + description?: String, + enum?: Array, + example?: any, + exclusiveMaximum?: Boolean, + exclusiveMinimum?: Boolean, + format?: String, + items?: Array, + maxItems?: Number, + maxLength?: Number, + maximum?: Number, + minItems?: Number, + minLength?: Number + minimum?: Number, + pattern?: String, + properties?: Map, + required?: Array, + type: String, + uniqueItems?: Boolean, + ['x-kubernetes-preserve-unknown-fields']?: Boolean + } + } +} + +export interface ClusterClassSpec { + variables: Array +} + +export interface ClusterClass { +name: String, +spec: ClusterClassSpec +} From 89782ce34c1cbfb0aee7bafbd328e11ef18053f7 Mon Sep 17 00:00:00 2001 From: Nancy Butler <42977925+mantis-toboggan-md@users.noreply.github.com> Date: Tue, 12 Dec 2023 10:46:11 -0800 Subject: [PATCH 02/23] required validation --- pkg/capi/components/CCVariables/Enum.vue | 65 ------------------- pkg/capi/components/CCVariables/Variable.vue | 67 ++++++++++++++++++-- pkg/capi/components/CCVariables/data.ts | 27 ++++++++ pkg/capi/components/CCVariables/index.vue | 29 ++++++++- pkg/capi/pages/blerg.vue | 4 +- 5 files changed, 120 insertions(+), 72 deletions(-) delete mode 100644 pkg/capi/components/CCVariables/Enum.vue diff --git a/pkg/capi/components/CCVariables/Enum.vue b/pkg/capi/components/CCVariables/Enum.vue deleted file mode 100644 index 15af2a2..0000000 --- a/pkg/capi/components/CCVariables/Enum.vue +++ /dev/null @@ -1,65 +0,0 @@ - - - diff --git a/pkg/capi/components/CCVariables/Variable.vue b/pkg/capi/components/CCVariables/Variable.vue index 3d9113e..1ba11d2 100644 --- a/pkg/capi/components/CCVariables/Variable.vue +++ b/pkg/capi/components/CCVariables/Variable.vue @@ -4,6 +4,8 @@ import LabeledInput from '@components/Form/LabeledInput/LabeledInput.vue'; import Checkbox from '@components/Form/Checkbox/Checkbox.vue'; import KeyValue from '@shell/components/form/KeyValue'; import ArrayList from '@shell/components/form/ArrayList'; +import LabeledSelect from '@shell/components/form/LabeledSelect'; +import formRulesGenerator, { Validator } from '@shell/utils/validators/formRules'; import { ClusterClassVariable } from '../../types/clusterClass.ts'; @@ -23,19 +25,22 @@ export default defineComponent({ } }, + watch: { + isValid(neu) { + this.$emit('validation-passed', neu); + } + }, + computed: { componentForType() { const { type } = this.schema; let out = null; // if the schema has valid options defined, use a different input: - // <=3 options: radio group - // >3 options: labeled select + // options are string or integer: labeledselect // options are array or object: //TODO nb fuck if (this.variableOptions) { - if (this.variableOptions.length <= 3) { - out = RadioGroup; - } + out = LabeledSelect; } else { switch (type) { case 'object': @@ -90,6 +95,54 @@ export default defineComponent({ return null; } }); + }, + + isMultiSelect() { + return this.componentForType === LabeledSelect && this.schema.type === 'array' && typeof this.variableOptions?.[0] !== 'object'; + }, + + /** + * format (string) + * exclusiveMinimum (integer/number) + * exclusiveMaximum (integer/number) + * maxItems (array) + * maxLength (string) + * maximum (integer/number) + * minItems (array) + * minLength (string) + * minimum (integer/number) + * pattern (string) + * uniqueItems (array) + * required (object) + */ + validationRules() { + const out = [] as any; + const { + format, + exclusiveMinimum, + exclusiveMaximum, + maxItems, + maxLength, + maximum, + minItems, + minLength, + minimum, + pattern, + uniqueItems, + required: requiredFields + } = this.schema; + + const required = this.variable?.required; + + if (required) { + out.push(formRulesGenerator(this.$store.getters['i18n/t'], { key: this.variable.name }).required); + } + + return out; + }, + + isValid() { + return !this.validationRules.find((rule: Validator) => !!rule(this.value)); } }, @@ -100,12 +153,16 @@ export default defineComponent({ diff --git a/pkg/capi/components/CCVariables/data.ts b/pkg/capi/components/CCVariables/data.ts index 2d31517..1ff4609 100644 --- a/pkg/capi/components/CCVariables/data.ts +++ b/pkg/capi/components/CCVariables/data.ts @@ -52,6 +52,7 @@ export default [{ }, { name: 'testBoolean', + required: true, schema: { openAPIV3Schema: @@ -73,4 +74,30 @@ export default [{ { type: 'string' } } } +}, +{ + name: 'enums', + schema: + { + openAPIV3Schema: + { + type: 'string', + description: 'This is a string type with enum defined', + enum: + ['option_1', 'option_2', 'option_3'] + } + } +}, +{ + name: 'enums-multi', + schema: + { + openAPIV3Schema: + { + type: 'array', + description: 'This is an array type with enum defined', + enum: + ['option_1', 'option_2', 'option_3'] + } + } }]; diff --git a/pkg/capi/components/CCVariables/index.vue b/pkg/capi/components/CCVariables/index.vue index a35563b..6da22bc 100644 --- a/pkg/capi/components/CCVariables/index.vue +++ b/pkg/capi/components/CCVariables/index.vue @@ -1,4 +1,5 @@ - + From 850caa2a8e2c2244ca2f04af156b19e05353628f Mon Sep 17 00:00:00 2001 From: Nancy Butler <42977925+mantis-toboggan-md@users.noreply.github.com> Date: Tue, 12 Dec 2023 16:17:08 -0800 Subject: [PATCH 03/23] style --- pkg/capi/components/CCVariables/Variable.vue | 78 +++++++++++--------- pkg/capi/components/CCVariables/data.ts | 13 ++++ pkg/capi/components/CCVariables/index.vue | 26 +++++-- pkg/capi/pages/blerg.vue | 4 +- pkg/capi/types/cluster.x-k8s.io.cluster.ts | 13 ++++ pkg/capi/types/clusterClass.ts | 34 ++++----- 6 files changed, 111 insertions(+), 57 deletions(-) create mode 100644 pkg/capi/types/cluster.x-k8s.io.cluster.ts diff --git a/pkg/capi/components/CCVariables/Variable.vue b/pkg/capi/components/CCVariables/Variable.vue index 1ba11d2..4ef7742 100644 --- a/pkg/capi/components/CCVariables/Variable.vue +++ b/pkg/capi/components/CCVariables/Variable.vue @@ -1,5 +1,6 @@ diff --git a/pkg/capi/components/CCVariables/data.ts b/pkg/capi/components/CCVariables/data.ts index 1ff4609..d09cabe 100644 --- a/pkg/capi/components/CCVariables/data.ts +++ b/pkg/capi/components/CCVariables/data.ts @@ -100,4 +100,17 @@ export default [{ ['option_1', 'option_2', 'option_3'] } } +}, +{ + name: 'enums-object', + schema: + { + openAPIV3Schema: + { + type: 'object', + description: 'This is an object type with enum defined', + enum: + [{ option_1: '1' }, { option_2: '2' }, { option_3: '3' }] + } + } }]; diff --git a/pkg/capi/components/CCVariables/index.vue b/pkg/capi/components/CCVariables/index.vue index 6da22bc..874bd91 100644 --- a/pkg/capi/components/CCVariables/index.vue +++ b/pkg/capi/components/CCVariables/index.vue @@ -1,8 +1,9 @@ diff --git a/pkg/capi/edit/cluster.x-k8s.io.cluster.vue b/pkg/capi/edit/cluster.x-k8s.io.cluster.vue index e17e48e..0579a67 100644 --- a/pkg/capi/edit/cluster.x-k8s.io.cluster.vue +++ b/pkg/capi/edit/cluster.x-k8s.io.cluster.vue @@ -29,28 +29,21 @@ export default defineComponent({ }, data() { - return { clusterClass: null, variables: [] }; + return { + clusterClass: null, variables: [], variablesValid: true + }; }, - // computed: { - // variables: { - // get() { - // return this.value?.spec?.topology?.variables || []; - // }, - // set(neu) { - // this.$set(this.value, 'spec.topology.variables', neu); - // } - // } - // }, - });