1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-13 16:49:07 +00:00
bramw_baserow/web-frontend/modules/builder/components/page/sidePanels/GeneralSidePanel.vue
2023-03-30 12:37:18 +00:00

58 lines
1.3 KiB
Vue

<template>
<component
:is="elementType.formComponent"
:key="element.id"
ref="elementForm"
:default-values="defaultValues"
class="element-form"
@values-changed="onChange($event)"
/>
</template>
<script>
import { mapActions, mapGetters } from 'vuex'
import { notifyIf } from '@baserow/modules/core/utils/error'
import _ from 'lodash'
export default {
name: 'GeneralSidePanel',
data() {
return {}
},
computed: {
...mapGetters({
element: 'element/getSelected',
}),
elementType() {
if (this.element) {
return this.$registry.get('element', this.element.type)
}
return null
},
defaultValues() {
return this.elementType.getComponentProps(this.element)
},
},
methods: {
...mapActions({
actionDebouncedUpdateSelectedElement: 'element/debouncedUpdateSelected',
}),
async onChange(newValues) {
const oldValues = this.elementType.getComponentProps(this.element)
if (!_.isEqual(newValues, oldValues)) {
try {
await this.actionDebouncedUpdateSelectedElement({
values: newValues,
})
} catch (error) {
// Restore the previous saved values from the store
this.$refs.elementForm.reset()
notifyIf(error)
}
}
},
},
}
</script>