Skip to content

Commit

Permalink
try to fix settings bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zAlweNy26 committed Apr 18, 2024
1 parent 40b9741 commit 5eb06ce
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
29 changes: 15 additions & 14 deletions src/components/DynamicForm.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang="ts">
import type { JSONSettings, SchemaField } from '@models/JSONSchema'
import { merge } from 'lodash'
import { Form, Field, ErrorMessage } from 'vee-validate'
// FEATURE: Improve form to allow any type of input based on json schema
Expand All @@ -9,34 +8,36 @@ import { Form, Field, ErrorMessage } from 'vee-validate'
const props = withDefaults(
defineProps<{
fields: SchemaField[]
values?: JSONSettings
disabled?: boolean
}>(),
{
disabled: false,
values: () => ({}),
},
)
const { fields } = toRefs(props)
const initValues = defineModel<JSONSettings>()
const { fields, values } = toRefs(props)
const dynamicForm = ref<InstanceType<typeof Form>>()
watchImmediate(
fields,
values,
() => {
const model = props.fields.reduce((p, c) => {
return {
...p,
[c.name]: c.default,
}
}, {})
initValues.value = merge(model, initValues.value)
dynamicForm.value?.resetForm()
dynamicForm.value?.setValues(values.value)
},
{ deep: true },
)
const initial = computed(() => {
return fields.value.reduce((p, c) => {
return {
...p,
[c.name]: c.default,
}
}, {}) as JSONSettings
})
defineEmits<{
submit: [payload: JSONSettings]
}>()
Expand All @@ -47,7 +48,7 @@ defineEmits<{
v-slot="{ errors }"
ref="dynamicForm"
class="flex h-full flex-col gap-4"
:initialValues="initValues"
:initialValues="initial"
:validateOnMount="true"
:keepValues="false"
@submit="$emit('submit', $event)">
Expand Down
2 changes: 1 addition & 1 deletion src/views/EmbeddersView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ watchDeep(
</a>
<span>{{ currentSchema?.description }}</span>
</div>
<DynamicForm v-model="currentSettings" :fields="currentFields" @submit="saveEmbedder" />
<DynamicForm :values="currentSettings" :fields="currentFields" @submit="saveEmbedder" />
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/views/PluginsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ watchEffect(() => {
</div>
</SidePanel>
<SidePanel ref="settingsPanel" title="Plugin Settings">
<DynamicForm v-model="currentSettings" :fields="currentFields" @submit="savePluginSettings" />
<DynamicForm :values="currentSettings" :fields="currentFields" @submit="savePluginSettings" />
</SidePanel>
<Teleport to="#modal">
<ModalBox ref="boxRemove">
Expand Down
2 changes: 1 addition & 1 deletion src/views/ProvidersView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ watchDeep(
</a>
<span>{{ currentSchema?.description }}</span>
</div>
<DynamicForm v-model="currentSettings" :fields="currentFields" @submit="saveProvider" />
<DynamicForm :values="currentSettings" :fields="currentFields" @submit="saveProvider" />
</div>
</div>
</div>
Expand Down

0 comments on commit 5eb06ce

Please sign in to comment.