1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-26 13:44:41 +00:00
bramw_baserow/web-frontend/modules/builder/mixins/elementSidePanel.js
2023-12-08 14:15:07 +00:00

66 lines
1.6 KiB
JavaScript

import { mapActions, mapGetters } from 'vuex'
import _ from 'lodash'
import { clone } from '@baserow/modules/core/utils/object'
import { notifyIf } from '@baserow/modules/core/utils/error'
export default {
inject: ['builder', 'page'],
computed: {
...mapGetters({
element: 'element/getSelected',
}),
elementType() {
if (this.element) {
return this.$registry.get('element', this.element.type)
}
return null
},
parentElement() {
return this.$store.getters['element/getElementById'](
this.page,
this.element?.parent_element_id
)
},
defaultValues() {
return this.element
},
},
methods: {
...mapActions({
actionDebouncedUpdateSelectedElement: 'element/debouncedUpdateSelected',
}),
async onChange(newValues) {
if (!this.$refs.panelForm.isFormValid()) {
return
}
const differences = Object.fromEntries(
Object.entries(newValues).filter(
([key, value]) => !_.isEqual(value, this.element[key])
)
)
// We never want to update the order this way
delete differences.order
if (Object.keys(differences).length > 0) {
try {
await this.actionDebouncedUpdateSelectedElement({
page: this.page,
// Here we clone the values to prevent
// "modification outside of the store" error
values: clone(differences),
})
} catch (error) {
// Restore the previous saved values from the store
this.$refs.panelForm.reset()
notifyIf(error)
}
}
},
},
}