1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-23 12:50:16 +00:00
bramw_baserow/web-frontend/modules/database/mixins/viewHelpers.js
2022-05-24 09:19:07 +00:00

66 lines
1.8 KiB
JavaScript

import { notifyIf } from '@baserow/modules/core/utils/error'
export default {
methods: {
/**
* Must be called when a new field is created. It emits the refresh event when
* needed. It expects the event parameter propagated from the
* `CreateFieldContext` component.
*/
fieldCreated({ fetchNeeded, ...context }) {
const viewType = this.$registry.get('view', this.view.type)
if (
fetchNeeded ||
viewType.shouldRefreshWhenFieldCreated(
this.$registry,
this.$store,
context.newField,
this.storePrefix
)
) {
this.$emit('refresh', context)
} else if (context.callback) {
context.callback()
}
},
/**
* Toggle the visibility for the field provided
*/
async toggleFieldVisibility({ field }) {
const exists = Object.prototype.hasOwnProperty.call(
this.fieldOptions,
field.id
)
const currentlyHidden = exists && this.fieldOptions[field.id].hidden
try {
await this.$store.dispatch(
`${this.storePrefix}view/${this.view.type}/updateFieldOptionsOfField`,
{
field,
values: { hidden: !currentlyHidden },
oldValues: { hidden: currentlyHidden },
readOnly: this.readOnly,
}
)
} catch (error) {
notifyIf(error, 'view')
}
},
/**
* Called when the user change the visibleFields order from the RowEditModal.
*/
async orderFields({ newOrder }) {
try {
await this.$store.dispatch(
`${this.storePrefix}view/${this.view.type}/updateFieldOptionsOrder`,
{
order: newOrder,
}
)
} catch (error) {
notifyIf(error, 'view')
}
},
},
}