diff --git a/src/components/graphqlFormGenerator/FormInput.vue b/src/components/graphqlFormGenerator/FormInput.vue
index f01d0f86c..6b9726a78 100644
--- a/src/components/graphqlFormGenerator/FormInput.vue
+++ b/src/components/graphqlFormGenerator/FormInput.vue
@@ -20,113 +20,94 @@ This is a convenience component that wraps an input component, allowing
dynamically created inputs.
-->
-
diff --git a/src/components/graphqlFormGenerator/components/BroadcastSetting.vue b/src/components/graphqlFormGenerator/components/BroadcastSetting.vue
index b0c861605..33a0757ac 100644
--- a/src/components/graphqlFormGenerator/components/BroadcastSetting.vue
+++ b/src/components/graphqlFormGenerator/components/BroadcastSetting.vue
@@ -16,95 +16,112 @@ along with this program. If not, see .
-->
diff --git a/src/components/graphqlFormGenerator/components/List.vue b/src/components/graphqlFormGenerator/components/List.vue
index 8167ee359..68a1b32a7 100644
--- a/src/components/graphqlFormGenerator/components/List.vue
+++ b/src/components/graphqlFormGenerator/components/List.vue
@@ -18,12 +18,12 @@ along with this program. If not, see .
.
class="remove-btn"
>
- {{ $options.icons.mdiCloseCircle }}
+ {{ mdiCloseCircle }}
@@ -49,7 +49,7 @@ along with this program. If not, see .
@click="add()"
variant="text"
data-cy="add"
- :prepend-icon="$options.icons.mdiPlusCircle"
+ :prepend-icon="mdiPlusCircle"
>
Add Item
@@ -57,57 +57,50 @@ along with this program. If not, see .
-
diff --git a/src/components/graphqlFormGenerator/components/MapItem.vue b/src/components/graphqlFormGenerator/components/MapItem.vue
index e83dbd2f5..7908922fd 100644
--- a/src/components/graphqlFormGenerator/components/MapItem.vue
+++ b/src/components/graphqlFormGenerator/components/MapItem.vue
@@ -22,69 +22,66 @@ along with this program. If not, see .
class="c-key-val my-1"
no-gutters
>
-
-
-
-
- =
-
-
-
-
-
-
-
- Pre-existing settings cannot be removed
-
-
+
+
-
diff --git a/src/components/graphqlFormGenerator/components/NonNull.vue b/src/components/graphqlFormGenerator/components/NonNull.vue
index a087389be..5fc94260a 100644
--- a/src/components/graphqlFormGenerator/components/NonNull.vue
+++ b/src/components/graphqlFormGenerator/components/NonNull.vue
@@ -18,7 +18,7 @@ along with this program. If not, see .
@@ -29,17 +29,15 @@ along with this program. If not, see .
-
diff --git a/src/components/graphqlFormGenerator/components/Object.vue b/src/components/graphqlFormGenerator/components/Object.vue
index ce56f040c..3de87ac17 100644
--- a/src/components/graphqlFormGenerator/components/Object.vue
+++ b/src/components/graphqlFormGenerator/components/Object.vue
@@ -33,21 +33,23 @@ along with this program. If not, see .
-
diff --git a/src/components/graphqlFormGenerator/components/vuetify.js b/src/components/graphqlFormGenerator/components/vuetify.js
index a4514638a..caee9e9cb 100644
--- a/src/components/graphqlFormGenerator/components/vuetify.js
+++ b/src/components/graphqlFormGenerator/components/vuetify.js
@@ -19,7 +19,7 @@ import { VSwitch } from 'vuetify/components/VSwitch'
import { VTextField } from 'vuetify/components/VTextField'
import GEnum from '@/components/graphqlFormGenerator/components/Enum.vue'
-import GNonNull, { nonNullRule } from '@/components/graphqlFormGenerator/components/NonNull.vue'
+import GNonNull from '@/components/graphqlFormGenerator/components/NonNull.vue'
import GList from '@/components/graphqlFormGenerator/components/List.vue'
import GObject from '@/components/graphqlFormGenerator/components/Object.vue'
import GBroadcastSetting from '@/components/graphqlFormGenerator/components/BroadcastSetting.vue'
@@ -39,7 +39,9 @@ export const RE = {
}
export const RULES = {
- required: nonNullRule,
+ /** Disallow empty array/string or nullish */
+ nonNull:
+ (x) => Boolean(x?.length ?? x != null) || 'Required',
integer:
(x) => (!x || Number.isInteger(x)) || 'Must be integer',
noSpaces:
diff --git a/src/components/graphqlFormGenerator/mixins.js b/src/components/graphqlFormGenerator/mixins.js
index 1249aae07..803b746c7 100644
--- a/src/components/graphqlFormGenerator/mixins.js
+++ b/src/components/graphqlFormGenerator/mixins.js
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (C) NIWA & British Crown (Met Office) & Contributors.
*
* This program is free software: you can redistribute it and/or modify
@@ -15,71 +15,35 @@
* along with this program. If not, see .
*/
-import FormInput from '@/components/graphqlFormGenerator/FormInput.vue'
-
-export const formElement = {
- components: {}, // Filled on created()
+import { computed } from 'vue'
- props: {
- // the GraphQL type this input represents
- gqlType: {
- type: Object,
- required: true
- },
- // array of all GraphQL types in the schema
- types: {
- type: Array,
- default: () => []
- },
- // the value (v-model is actually syntactic sugar for this)
- modelValue: {
- required: true
- }
+/**
+ * @type {Record}
+ */
+export const formElementProps = {
+ // the GraphQL type this input represents
+ gqlType: {
+ type: Object,
+ required: true,
},
-
- emits: ['update:modelValue'],
-
- created () {
- // Avoid problem of circular reference by deferring
- // the population of $options.components
- // https://forum.vuejs.org/t/failed-to-resolve-component-when-not-using-hot-swap/113894/2
- // TODO: FormInput is not needed by all components that use this
- // mixin; we should replace this mixin with a composable.
- this.$options.components.FormInput = FormInput
+ // array of all GraphQL types in the schema
+ types: {
+ type: Array,
+ default: () => [],
},
+}
- computed: {
- /* The model we pass to the form input.
- *
- * Note the v-model approach does not work with nesting out of the box,
- * you need to capture and propagate "input" events up the component tree
- * to enable this nested structure of components to share the same model
- * and be managed by Vue correctly.
- */
- model: {
- get () {
- return this.modelValue
- },
- set (val) {
- this.$emit('update:modelValue', val)
- }
- },
-
- type () {
- for (const type of this.types) {
- if (type.name === this.gqlType.name && type.kind === this.gqlType.kind) {
- return type
- }
- }
- return null
- },
-
- help () {
- // TODO: provide argument help then default to type help if not found
- if (this.type && this.type.description) {
- return this.type.description.trim()
- }
- return null
- }
+export function useFormElement (props) {
+ const type = computed(
+ () => props.types.find(
+ (type) => type.name === props.gqlType.name && type.kind === props.gqlType.kind
+ )
+ )
+ // TODO: provide argument help then default to type help if not found
+ const help = computed(() => type.value?.description?.trim())
+
+ return {
+ help,
+ type,
}
}