1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-10 15:47:32 +00:00

Correctly handle trashed fields in chart config form

This commit is contained in:
Petr Stribny 2025-03-10 07:03:35 +00:00
parent 38c77ab190
commit c35ff10041
3 changed files with 53 additions and 11 deletions
enterprise/web-frontend/modules/baserow_enterprise/dashboard/components/data_source

View file

@ -6,6 +6,7 @@
<Dropdown <Dropdown
:value="aggregationGroupBy" :value="aggregationGroupBy"
:show-search="true" :show-search="true"
:error="v$.aggregationGroupBy?.$error || false"
fixed-items fixed-items
@change="groupByChangedByUser($event)" @change="groupByChangedByUser($event)"
> >
@ -22,6 +23,15 @@
</template> </template>
<script> <script>
import { useVuelidate } from '@vuelidate/core'
const includesIfSet = (array) => (value) => {
if (value === null || value === undefined) {
return true
}
return array.includes(value)
}
export default { export default {
name: 'AggregationGroupByForm', name: 'AggregationGroupByForm',
props: { props: {
@ -34,6 +44,9 @@ export default {
required: true, required: true,
}, },
}, },
setup() {
return { v$: useVuelidate() }
},
data() { data() {
return { return {
aggregationGroupBy: 'none', aggregationGroupBy: 'none',
@ -70,6 +83,22 @@ export default {
immediate: true, immediate: true,
}, },
}, },
mounted() {
this.v$.$touch()
},
validations() {
const self = this
return {
aggregationGroupBy: {
isValidGroupBy: (value) => {
const validGroupByValues = self.groupByOptions.map(
(item) => item.value
)
return includesIfSet(validGroupByValues)(value)
},
},
}
},
methods: { methods: {
groupByChangedByUser(value) { groupByChangedByUser(value) {
this.aggregationGroupBy = value this.aggregationGroupBy = value

View file

@ -33,7 +33,6 @@
<Dropdown <Dropdown
v-model="values.field_id" v-model="values.field_id"
:error="fieldHasErrors('field_id')" :error="fieldHasErrors('field_id')"
:disabled="fieldsAvailableForSelection.length === 0"
@change="v$.values.field_id.$touch" @change="v$.values.field_id.$touch"
> >
<DropdownItem <DropdownItem
@ -188,7 +187,10 @@ export default {
const field = this.tableFields.find( const field = this.tableFields.find(
(field) => field.id === this.values.field_id (field) => field.id === this.values.field_id
) )
if (field && !aggType.fieldIsCompatible(field)) { if (
(field && !aggType.fieldIsCompatible(field)) ||
this.fieldHasErrors('field_id')
) {
this.values.field_id = null this.values.field_id = null
} }
this.v$.values.aggregation_type.$touch() this.v$.values.aggregation_type.$touch()

View file

@ -220,7 +220,12 @@ export default {
}, },
allowedSortReferences() { allowedSortReferences() {
const seriesSortReferences = this.values.aggregation_series const seriesSortReferences = this.values.aggregation_series
.filter((item) => item.field_id && item.aggregation_type) .filter(
(item) =>
item.field_id &&
item.aggregation_type &&
this.getTableFieldById(item.field_id)
)
.map((item) => { .map((item) => {
const field = this.getTableFieldById(item.field_id) const field = this.getTableFieldById(item.field_id)
return { return {
@ -232,19 +237,25 @@ export default {
)})`, )})`,
} }
}) })
const groupBySortReferences = this.values.aggregation_group_bys.map( const groupBySortReferences = this.values.aggregation_group_bys.reduce(
(item) => { (acc, item) => {
const field = const field =
item.field_id === null item.field_id === null
? this.primaryTableField ? this.primaryTableField
: this.getTableFieldById(item.field_id) : this.getTableFieldById(item.field_id)
return {
sort_on: 'GROUP_BY', if (field !== undefined) {
reference: `field_${field.id}`, acc.push({
field, sort_on: 'GROUP_BY',
name: field.name, reference: `field_${field.id}`,
field,
name: field.name,
})
} }
}
return acc
},
[]
) )
return seriesSortReferences.concat(groupBySortReferences) return seriesSortReferences.concat(groupBySortReferences)
}, },