From fbcea658cf559f39b16f5586b69e7cb981afcc04 Mon Sep 17 00:00:00 2001 From: Ronnie Dutta <61982285+MetRonnie@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:36:09 +0000 Subject: [PATCH] Move graphqlFormGenerator defaults into v-defaults-provider --- src/components/cylc/Mutation.vue | 9 +++- .../graphqlFormGenerator/EditRuntimeForm.vue | 1 - .../graphqlFormGenerator/FormInput.vue | 1 - .../components/vuetify.js | 13 +++--- src/plugins/vuetify.js | 46 +++++++++++-------- 5 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src/components/cylc/Mutation.vue b/src/components/cylc/Mutation.vue index 71875d6df..501c92f2a 100644 --- a/src/components/cylc/Mutation.vue +++ b/src/components/cylc/Mutation.vue @@ -137,7 +137,12 @@ import { mutationStatus } from '@/utils/aotf' import { mdiClose } from '@mdi/js' -import { useDynamicVuetifyDefaults } from '@/plugins/vuetify' +import { inputComponents, useDynamicVuetifyDefaults } from '@/plugins/vuetify' +import { defaults } from '@/components/graphqlFormGenerator/components/vuetify' + +const mutationFormInputDefaults = Object.fromEntries( + inputComponents.map((name) => [name, defaults]) +) export default { name: 'mutation', @@ -177,7 +182,7 @@ export default { }, setup () { - const vuetifyDefaults = useDynamicVuetifyDefaults() + const vuetifyDefaults = useDynamicVuetifyDefaults(mutationFormInputDefaults) return { vuetifyDefaults, diff --git a/src/components/graphqlFormGenerator/EditRuntimeForm.vue b/src/components/graphqlFormGenerator/EditRuntimeForm.vue index a352c725c..684571fc2 100644 --- a/src/components/graphqlFormGenerator/EditRuntimeForm.vue +++ b/src/components/graphqlFormGenerator/EditRuntimeForm.vue @@ -223,7 +223,6 @@ export default { getInputProps (fieldName) { const gqlType = findByName(this.type.fields, fieldName).type return { - ...VuetifyConfig.defaultProps, gqlType, ...getComponentProps(gqlType, NamedTypes, VuetifyConfig.kinds) } diff --git a/src/components/graphqlFormGenerator/FormInput.vue b/src/components/graphqlFormGenerator/FormInput.vue index 88e355201..f01d0f86c 100644 --- a/src/components/graphqlFormGenerator/FormInput.vue +++ b/src/components/graphqlFormGenerator/FormInput.vue @@ -96,7 +96,6 @@ export default { // merge this in with default and override props const propGroups = [ - VuetifyConfig.defaultProps, componentProps, this.propOverrides || {} ] diff --git a/src/components/graphqlFormGenerator/components/vuetify.js b/src/components/graphqlFormGenerator/components/vuetify.js index d98566726..ddb4e43b6 100644 --- a/src/components/graphqlFormGenerator/components/vuetify.js +++ b/src/components/graphqlFormGenerator/components/vuetify.js @@ -55,14 +55,13 @@ export const RULES = { export const RUNTIME_SETTING = 'RuntimeSetting' -export default { - defaultProps: { - // default props for all form inputs - variant: 'filled', - density: 'compact', - hideDetails: false, - }, +/** Defaults for all form inputs */ +export const defaults = { + variant: 'filled', + hideDetails: false, +} +export default { namedTypes: { // registry of GraphQL "named types" (e.g. String) // {namedType: {is: ComponentClass, prop1: value, ...}} diff --git a/src/plugins/vuetify.js b/src/plugins/vuetify.js index 68fcf411a..fc92bcfb5 100644 --- a/src/plugins/vuetify.js +++ b/src/plugins/vuetify.js @@ -25,22 +25,27 @@ import { VTextField } from 'vuetify/components/VTextField' import colors from 'vuetify/util/colors' import { mdiClose } from '@mdi/js' import { useReducedAnimation } from '@/composables/localStorage' +import { merge } from 'lodash-es' -const inputDefaults = Object.fromEntries([ +export const inputComponents = [ VAutocomplete, VCombobox, VSelect, VTextarea, - VTextField -].map(({ name }) => [ - name, - { - density: 'compact', - variant: 'outlined', - clearIcon: mdiClose, - hideDetails: true, - } -])) + VTextField, +].map(({ name }) => name) + +const inputDefaults = Object.fromEntries( + inputComponents.map((name) => [ + name, + { + density: 'compact', + variant: 'outlined', + clearIcon: mdiClose, + hideDetails: true, + } + ]) +) /** * @type {import('vuetify').VuetifyOptions} @@ -84,14 +89,19 @@ export const vuetifyOptions = { * the static defaults provided in `createVuetify(vuetifyOptions)`. * * For use with a v-defaults-provider. + * + * @param {Object=} other - Additional defaults to provide. */ -export function useDynamicVuetifyDefaults () { +export function useDynamicVuetifyDefaults (other = {}) { const reducedAnimation = useReducedAnimation() - return computed(() => ({ - global: { - transition: reducedAnimation.value ? 'no' : undefined, - ripple: reducedAnimation.value ? false : undefined, - } - })) + return computed(() => merge( + { + global: { + transition: reducedAnimation.value ? 'no' : undefined, + ripple: reducedAnimation.value ? false : undefined, + }, + }, + other + )) }