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 Dec 5, 2024
1 parent 6846d52 commit 3ed791a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/components/cylc/Mutation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ import {
} from '@/utils/aotf'
import { mdiClose } from '@mdi/js'
import { useDynamicVuetifyDefaults } from '@/plugins/vuetify'
import { inputDefaults } from '@/components/graphqlFormGenerator/components/vuetify'

export default {
name: 'mutation',
Expand Down Expand Up @@ -177,7 +178,7 @@ export default {
},

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

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
19 changes: 12 additions & 7 deletions src/components/graphqlFormGenerator/components/vuetify.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import GList from '@/components/graphqlFormGenerator/components/List.vue'
import GObject from '@/components/graphqlFormGenerator/components/Object.vue'
import GBroadcastSetting from '@/components/graphqlFormGenerator/components/BroadcastSetting.vue'
import GMapItem from '@/components/graphqlFormGenerator/components/MapItem.vue'
import { inputComponents } from '@/plugins/vuetify'

const NumberFieldProps = {
is: VTextField,
Expand Down Expand Up @@ -55,14 +56,18 @@ 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 inputDefaults = Object.fromEntries(
inputComponents.map((name) => [
name,
{
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 = [

Check warning on line 30 in src/plugins/vuetify.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/vuetify.js#L30

Added line #L30 was not covered by tests
VAutocomplete,
VCombobox,
VSelect,
VTextarea,
VTextField
].map(({ name }) => [
name,
{
density: 'compact',
variant: 'outlined',
clearIcon: mdiClose,
hideDetails: true,
}
]))
VTextField,
].map(({ name }) => name)

Check warning on line 36 in src/plugins/vuetify.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/vuetify.js#L36

Added line #L36 was not covered by tests

const inputDefaults = Object.fromEntries(
inputComponents.map((name) => [

Check warning on line 39 in src/plugins/vuetify.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/vuetify.js#L38-L39

Added lines #L38 - L39 were not covered by tests
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()

Check warning on line 96 in src/plugins/vuetify.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/vuetify.js#L96

Added line #L96 was not covered by tests

return computed(() => ({
global: {
transition: reducedAnimation.value ? 'no' : undefined,
ripple: reducedAnimation.value ? false : undefined,
}
}))
return computed(() => merge(

Check warning on line 98 in src/plugins/vuetify.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/vuetify.js#L98

Added line #L98 was not covered by tests
{
global: {
transition: reducedAnimation.value ? 'no' : undefined,
ripple: reducedAnimation.value ? false : undefined,
},
},
other
))
}

0 comments on commit 3ed791a

Please sign in to comment.