1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-05-12 04:11:49 +00:00
bramw_baserow/web-frontend/modules/integrations/localBaserow/mixins/localBaserowService.js
2025-03-24 17:10:06 +01:00

75 lines
2.1 KiB
JavaScript

import tableFields from '@baserow/modules/database/mixins/tableFields'
export default {
mixins: [tableFields],
props: {
builder: {
type: Object,
required: true,
},
contextData: {
type: Object,
required: false,
default: () => ({
databases: [],
}),
},
dataSource: {
type: Object,
required: true,
},
},
computed: {
/**
* Used by `LocalBaserowTableSelector` so that when read, we return the
* table ID. When writing, if the table ID has changed, it gives us an
* opportunity to reset the `filters`, `sortings` and `view_id`.
*/
fakeTableId: {
get() {
return this.values.table_id
},
set(newValue) {
// If we currently have a `table_id` selected, and the `newValue`
// is different to the current `table_id`, then reset the `filters`
// and `sortings` to a blank array, and `view_id` to `null`.
if (this.values.table_id && this.values.table_id !== newValue) {
this.values.filters = []
this.values.sortings = []
this.values.view_id = null
}
this.values.table_id = newValue
},
},
databases() {
return this.contextData?.databases || []
},
tables() {
return this.databases.map((database) => database.tables).flat()
},
tableSelected() {
return this.tables.find(({ id }) => id === this.values.table_id)
},
},
methods: {
/**
* Overrides the method in the tableFields mixin
*/
getTableId() {
return this.values.table_id
},
/**
* Given an array of objects containing a `field` property (e.g. the data
* source filters or sortings arrays), this method will return a new array
* containing only the objects where the field is part of the schema, so,
* untrashed.
*
* @param {Array} value - The array of objects to filter.
* @returns {Array} - The filtered array.
*/
excludeTrashedFields(value) {
const localBaserowFieldIds = this.tableFields.map(({ id }) => id)
return value.filter(({ field }) => localBaserowFieldIds.includes(field))
},
},
}