Skip to content

Commit

Permalink
Move graphqlFormGenerator defaults into v-defaults-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Nov 28, 2024
1 parent 4aa9063 commit fbcea65
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 29 deletions.
9 changes: 7 additions & 2 deletions src/components/cylc/Mutation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -177,7 +182,7 @@ export default {
},

setup () {
const vuetifyDefaults = useDynamicVuetifyDefaults()
const vuetifyDefaults = useDynamicVuetifyDefaults(mutationFormInputDefaults)

return {
vuetifyDefaults,
Expand Down
1 change: 0 additions & 1 deletion src/components/graphqlFormGenerator/EditRuntimeForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion src/components/graphqlFormGenerator/FormInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export default {

// merge this in with default and override props
const propGroups = [
VuetifyConfig.defaultProps,
componentProps,
this.propOverrides || {}
]
Expand Down
13 changes: 6 additions & 7 deletions src/components/graphqlFormGenerator/components/vuetify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...}}
Expand Down
46 changes: 28 additions & 18 deletions src/plugins/vuetify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
))
}

0 comments on commit fbcea65

Please sign in to comment.