mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 00:08:25 +00:00
* fix: handle calendar boundaries in date comparisons * feat: add a single-date filter to the dashboard API * feat: send the viewer timezone with dashboard data requests * refactor: share dashboard filter controls and target settings * feat: configure dashboard filter conditions on date fields * feat: add the Date filter to the dashboard widget picker Implement the single-date mode of #6886. * fix: restore dragging dashboard filters by their titles * feat: persist the dashboard date filter display format * feat: choose how dashboard filter dates are displayed * test: align numeric filter checks with shared dashboard controls * style: format the dashboard date filter component test * fix: accept fixed UTC offsets in dashboard date filters * fix: expose dashboard filter dates as ISO strings in formulas * fix: seed dashboard conditions with compatible operators * feat: expose date ranges in dashboard formulas and viewer selections * feat: configure inclusive date range conditions for dashboard targets * feat: persist and dispatch inclusive dashboard date ranges * docs: describe date range selections in the dashboard dispatch API * feat: select and configure dashboard date ranges * fix: let viewers clear each dashboard date range endpoint * fix: preserve unfinished dashboard date range bounds on refresh * fix: refresh public dashboards after a date filter mode change * test: group dashboard date filter mode transitions * fix: warn about incompatible date range formula operands * fix: convert dashboard date defaults from the saved widget * fix: keep dashboard filter controls aligned when a condition has a warning * fix: clear incompatible dashboard conditions when switching date modes * fix: show cleared date conditions without warnings or redundant saves * fix: ignore empty dashboard date conditions after switching modes * fix: ignore dashboard date conditions without a single date and simplify mode switch clearing --------- Co-authored-by: peter_baserow <peter@baserow.io>
516 lines
16 KiB
Vue
516 lines
16 KiB
Vue
<template>
|
|
<div class="form-view__field-wrapper">
|
|
<div
|
|
class="form-view__field form-view__field--editable"
|
|
:class="{ 'form-view__field--selected': selected }"
|
|
@click="select()"
|
|
>
|
|
<div class="form-view__field-head">
|
|
<a
|
|
v-if="addHandle"
|
|
v-show="!readOnly"
|
|
class="form-view__field-head-handle"
|
|
data-field-handle
|
|
></a>
|
|
|
|
<i
|
|
class="form-view__field-head-icon"
|
|
:class="field._.type.iconClass"
|
|
></i>
|
|
|
|
<div class="form-view__field-head-name">{{ field.name }}</div>
|
|
<a
|
|
v-if="!readOnly"
|
|
v-tooltip="'Remove field'"
|
|
class="form-view__field-head-hide"
|
|
@click="$emit('hide', field)"
|
|
>
|
|
<i class="iconoir-eye-off"></i>
|
|
</a>
|
|
</div>
|
|
<div class="form-view__field-inner">
|
|
<div class="form-view__field-name">
|
|
<Editable
|
|
ref="name"
|
|
:value="fieldOptions.name || field.name"
|
|
@change="$emit('updated-field-options', { name: $event.value })"
|
|
@editing="editingName = $event"
|
|
></Editable>
|
|
<span v-if="fieldOptions.required" class="form-view__field-required">
|
|
*
|
|
</span>
|
|
<a
|
|
v-if="!readOnly"
|
|
class="form-view__edit form-view-field-edit"
|
|
:class="{ 'form-view__edit--hidden': editingName }"
|
|
@click="$refs.name.edit()"
|
|
>
|
|
<i class="form-view__edit-icon iconoir-edit-pencil"></i>
|
|
</a>
|
|
</div>
|
|
<div
|
|
v-if="selected || fieldOptions.description"
|
|
class="form-view__field-description"
|
|
>
|
|
<FormViewDescription
|
|
:value="fieldOptions.description || ''"
|
|
:read-only="readOnly"
|
|
:placeholder="$t('formViewField.descriptionPlaceholder')"
|
|
:get-scroll-area-element="getScrollAreaElement"
|
|
@change="$emit('updated-field-options', { description: $event })"
|
|
></FormViewDescription>
|
|
</div>
|
|
<p
|
|
v-if="!readOnly && cannotSubmitValues"
|
|
class="error form-view__field-read-only"
|
|
>
|
|
<i class="iconoir-warning-triangle"></i>
|
|
{{ $t('formViewField.cannotSumitValues') }}
|
|
</p>
|
|
<component
|
|
:is="selectedFieldComponent.component"
|
|
v-else
|
|
ref="field"
|
|
:slug="view.slug"
|
|
:workspace-id="database.workspace.id"
|
|
:field="preparedFieldForEditInputComponent"
|
|
:value="value"
|
|
:read-only="readOnly"
|
|
:lazy-load="true"
|
|
:touched="false"
|
|
:required="fieldOptions.required"
|
|
@update="updateValue"
|
|
/>
|
|
<div class="form-view__field-options">
|
|
<FormGroup
|
|
v-if="Object.keys(fieldComponents).length > 1 && !readOnly"
|
|
horizontal
|
|
:label="$t('formViewField.showFieldAs')"
|
|
required
|
|
small-label
|
|
horizontal-variable
|
|
class="margin-bottom-3"
|
|
>
|
|
<RadioGroup
|
|
type="button"
|
|
:model-value="fieldOptions.field_component"
|
|
:options="fieldComponentsOptions"
|
|
@input="
|
|
$emit('updated-field-options', { field_component: $event })
|
|
"
|
|
></RadioGroup>
|
|
</FormGroup>
|
|
<SwitchInput
|
|
class="margin-bottom-1"
|
|
small
|
|
:value="fieldOptions.required"
|
|
:disabled="readOnly"
|
|
@input="$emit('updated-field-options', { required: $event })"
|
|
>{{ $t('formViewField.required') }}</SwitchInput
|
|
>
|
|
<component
|
|
:is="fieldOptionsComponent"
|
|
v-if="fieldOptionsComponent"
|
|
:field="field"
|
|
:field-options="fieldOptions"
|
|
:read-only="readOnly"
|
|
@updated-field-options="$emit('updated-field-options', $event)"
|
|
></component>
|
|
<SwitchInput
|
|
v-if="allowedConditionalFields.length > 0"
|
|
small
|
|
:value="fieldOptions.show_when_matching_conditions"
|
|
:disabled="readOnly"
|
|
@input="setShowWhenMatchingConditions($event)"
|
|
>{{ $t('formViewField.showWhenMatchingConditions') }}</SwitchInput
|
|
>
|
|
<div
|
|
v-if="
|
|
allowedConditionalFields.length > 0 &&
|
|
fieldOptions.show_when_matching_conditions
|
|
"
|
|
class="form-view__conditions"
|
|
>
|
|
<ViewFieldConditionsForm
|
|
:filters="fieldOptions.conditions"
|
|
:filter-groups="fieldOptions.condition_groups"
|
|
:disable-filter="readOnly"
|
|
:filter-type="fieldOptions.condition_type"
|
|
:view="view"
|
|
:fields="allowedConditionalFields"
|
|
:read-only="readOnly"
|
|
:full-width="true"
|
|
:variant="'dark'"
|
|
:sorted="true"
|
|
:can-add-filter-groups="false"
|
|
@add-filter="addCondition(fieldOptions, $event)"
|
|
@add-filter-group="addConditionGroup(fieldOptions, $event)"
|
|
@delete-filter="deleteCondition(fieldOptions, $event)"
|
|
@update-filter="updateCondition(fieldOptions, $event)"
|
|
@update-filter-type="updateFilterType(fieldOptions, $event)"
|
|
@delete-filter-group="deleteConditionGroup(fieldOptions, $event)"
|
|
@filter-focussed="
|
|
$store.dispatch('view/setFocusFilter', { view, filterId: null })
|
|
"
|
|
/>
|
|
<div class="form-view__condition-actions">
|
|
<a
|
|
class="form-view__add-condition"
|
|
@click="addCondition(fieldOptions)"
|
|
>
|
|
<i class="iconoir-plus"></i>
|
|
{{ $t('formViewField.addCondition') }}
|
|
</a>
|
|
<a
|
|
class="form-view__add-condition"
|
|
@click="addConditionGroup(fieldOptions)"
|
|
>
|
|
<i class="iconoir-plus"></i>
|
|
{{ $t('formViewField.addConditionGroup') }}
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import {
|
|
collectTeleportRootsForOutsideClick,
|
|
onClickOutside,
|
|
} from '@baserow/modules/core/utils/dom'
|
|
import { clone } from '@baserow/modules/core/utils/object'
|
|
import { DEFAULT_FORM_VIEW_FIELD_COMPONENT_KEY } from '@baserow/modules/database/constants'
|
|
import ViewFieldConditionsForm from '@baserow/modules/database/components/view/ViewFieldConditionsForm'
|
|
import { createFiltersTree } from '@baserow/modules/database/utils/view'
|
|
import { getFirstCompatibleFilterType } from '@baserow/modules/database/utils/field'
|
|
import FormViewDescription from '@baserow/modules/database/components/view/form/FormViewDescription'
|
|
|
|
export default {
|
|
name: 'FormViewField',
|
|
components: { ViewFieldConditionsForm, FormViewDescription },
|
|
provide() {
|
|
return {
|
|
registerChild: this.registerChild,
|
|
}
|
|
},
|
|
props: {
|
|
database: {
|
|
type: Object,
|
|
required: true,
|
|
},
|
|
table: {
|
|
type: Object,
|
|
required: true,
|
|
},
|
|
view: {
|
|
type: Object,
|
|
required: true,
|
|
},
|
|
field: {
|
|
type: Object,
|
|
required: true,
|
|
},
|
|
fields: {
|
|
type: Array,
|
|
required: true,
|
|
},
|
|
fieldOptions: {
|
|
type: Object,
|
|
required: true,
|
|
},
|
|
readOnly: {
|
|
type: Boolean,
|
|
required: true,
|
|
},
|
|
addHandle: {
|
|
type: Boolean,
|
|
required: false,
|
|
default: true,
|
|
},
|
|
// Resolves the scrollable preview container owned by FormViewPreview.
|
|
getScrollAreaElement: {
|
|
type: Function,
|
|
required: false,
|
|
default: null,
|
|
},
|
|
},
|
|
emits: ['updated-field-options', 'hide'],
|
|
data() {
|
|
return {
|
|
selected: false,
|
|
editingName: false,
|
|
value: null,
|
|
children: [],
|
|
}
|
|
},
|
|
computed: {
|
|
preparedFieldForEditInputComponent() {
|
|
return this.getFieldType().prepareFormViewFieldForFormEditInput(
|
|
this.field,
|
|
this.fieldOptions
|
|
)
|
|
},
|
|
allowedConditionalFields() {
|
|
const index = this.fields.findIndex((f) => f.id === this.field.id)
|
|
return this.fields.slice(0, index)
|
|
},
|
|
fieldComponents() {
|
|
return this.getFieldType().getFormViewFieldComponents(this.field, this)
|
|
},
|
|
fieldOptionsComponent() {
|
|
return this.getFieldType().getFormViewFieldOptionsComponent(this.field)
|
|
},
|
|
selectedFieldComponent() {
|
|
const components = this.fieldComponents
|
|
return Object.prototype.hasOwnProperty.call(
|
|
components,
|
|
this.fieldOptions.field_component
|
|
)
|
|
? components[this.fieldOptions.field_component]
|
|
: components[DEFAULT_FORM_VIEW_FIELD_COMPONENT_KEY]
|
|
},
|
|
fieldComponentsOptions() {
|
|
const options = []
|
|
|
|
for (const [key, value] of Object.entries(this.fieldComponents)) {
|
|
options.push({ label: value.name, value: key })
|
|
}
|
|
|
|
return options
|
|
},
|
|
cannotSubmitValues() {
|
|
return !this.$registry
|
|
.get('field', this.field.type)
|
|
.canSubmitAnonymousValues(this.field)
|
|
},
|
|
},
|
|
watch: {
|
|
field: {
|
|
deep: true,
|
|
handler() {
|
|
this.resetValue()
|
|
},
|
|
},
|
|
preparedFieldForEditInputComponent: {
|
|
deep: true,
|
|
handler() {
|
|
this.$nextTick(() => {
|
|
this.resetValue()
|
|
})
|
|
},
|
|
},
|
|
},
|
|
created() {
|
|
this.resetValue()
|
|
},
|
|
methods: {
|
|
select() {
|
|
this.selected = true
|
|
this.$el.clickOutsideEventCancel = onClickOutside(
|
|
this.$el,
|
|
(_target, event) => {
|
|
if (
|
|
this.selected &&
|
|
// If the event was not related to deleting the filter.
|
|
!event.deletedFilterEvent
|
|
) {
|
|
this.unselect()
|
|
}
|
|
},
|
|
{
|
|
ignoreElements: () => {
|
|
return this.children.flatMap(collectTeleportRootsForOutsideClick)
|
|
},
|
|
}
|
|
)
|
|
},
|
|
unselect() {
|
|
this.selected = false
|
|
this.$el.clickOutsideEventCancel()
|
|
},
|
|
updateValue(value) {
|
|
this.value = value
|
|
},
|
|
getFieldType() {
|
|
return this.$registry.get('field', this.field.type)
|
|
},
|
|
resetValue() {
|
|
this.value = this.getFieldType().getDefaultValue(
|
|
this.preparedFieldForEditInputComponent
|
|
)
|
|
},
|
|
createConditionGroup(parentGroupId) {
|
|
return {
|
|
id: 0,
|
|
filter_type: 'AND',
|
|
parent_group: parentGroupId,
|
|
}
|
|
},
|
|
generateCompatibleCondition(conditionGroupId = null) {
|
|
const field =
|
|
this.allowedConditionalFields[this.allowedConditionalFields.length - 1]
|
|
const viewFilterTypes = this.$registry.getAll('viewFilter')
|
|
const compatibleType = getFirstCompatibleFilterType(
|
|
field,
|
|
viewFilterTypes
|
|
)
|
|
const newCondition = {
|
|
id: 0,
|
|
field: field.id,
|
|
type: compatibleType.type,
|
|
value: '',
|
|
}
|
|
if (conditionGroupId !== null) {
|
|
newCondition.group = conditionGroupId
|
|
}
|
|
return newCondition
|
|
},
|
|
setShowWhenMatchingConditions(value) {
|
|
const values = { show_when_matching_conditions: value }
|
|
if (value && this.fieldOptions.conditions.length === 0) {
|
|
values.conditions = [this.generateCompatibleCondition()]
|
|
}
|
|
this.$emit('updated-field-options', values)
|
|
},
|
|
addCondition(
|
|
{ conditions, condition_groups: conditionGroups },
|
|
{ filterGroupId = null } = {}
|
|
) {
|
|
const newConditions = conditions.slice()
|
|
const newCondition = this.generateCompatibleCondition(filterGroupId)
|
|
newConditions.push(newCondition)
|
|
this.$emit('updated-field-options', {
|
|
conditions: newConditions,
|
|
condition_groups: conditionGroups,
|
|
})
|
|
this.$store.dispatch('view/setFocusFilter', {
|
|
view: this.view,
|
|
filterId: newCondition.id,
|
|
})
|
|
},
|
|
addConditionGroup(
|
|
{ conditions, condition_groups: filterGroups },
|
|
{ parentGroupId = null } = {}
|
|
) {
|
|
const newConditionGroup = this.createConditionGroup(parentGroupId)
|
|
const newConditionGroups = filterGroups.slice()
|
|
newConditionGroups.push(newConditionGroup)
|
|
|
|
const newConditions = conditions.slice()
|
|
const newCondition = this.generateCompatibleCondition(
|
|
newConditionGroup.id
|
|
)
|
|
newConditions.push(newCondition)
|
|
this.$emit('updated-field-options', {
|
|
condition_groups: newConditionGroups,
|
|
conditions: newConditions,
|
|
})
|
|
this.$store.dispatch('view/setFocusFilter', {
|
|
view: this.view,
|
|
filterId: newCondition.id,
|
|
})
|
|
},
|
|
updateFilterType(
|
|
{ conditions, condition_groups: conditionGroups },
|
|
{ value, filterGroup }
|
|
) {
|
|
const newFieldOptions = {}
|
|
if (filterGroup === undefined) {
|
|
newFieldOptions.condition_type = value
|
|
} else {
|
|
conditionGroups = clone(conditionGroups.slice())
|
|
conditionGroups.forEach((group, index) => {
|
|
if (group.id === filterGroup.id) {
|
|
Object.assign(conditionGroups[index], { filter_type: value })
|
|
}
|
|
})
|
|
newFieldOptions.condition_groups = conditionGroups
|
|
newFieldOptions.conditions = conditions
|
|
}
|
|
this.$emit('updated-field-options', newFieldOptions)
|
|
},
|
|
updateCondition(
|
|
{ conditions, condition_groups: conditionGroups },
|
|
condition
|
|
) {
|
|
conditions = clone(conditions.slice())
|
|
conditions.forEach((c, index) => {
|
|
if (c.id === condition.filter.id) {
|
|
Object.assign(conditions[index], condition.values)
|
|
}
|
|
})
|
|
this.$emit('updated-field-options', {
|
|
conditions,
|
|
condition_groups: conditionGroups,
|
|
})
|
|
},
|
|
deleteCondition(
|
|
{ conditions, condition_groups: conditionGroups },
|
|
condition
|
|
) {
|
|
// We need to wait for the next tick, otherwise the condition is already deleted
|
|
// before the event completes, resulting in a click outside of the field.
|
|
this.$nextTick(() => {
|
|
conditions = conditions.filter((c) => c.id !== condition.id)
|
|
this.$emit('updated-field-options', {
|
|
conditions,
|
|
condition_groups: conditionGroups,
|
|
})
|
|
})
|
|
},
|
|
deleteConditionGroup(
|
|
{
|
|
conditions,
|
|
condition_groups: conditionGroups,
|
|
filter_type: filterType,
|
|
},
|
|
{ group }
|
|
) {
|
|
const filtersTree = createFiltersTree(
|
|
filterType,
|
|
conditions,
|
|
conditionGroups
|
|
)
|
|
const groupNode = filtersTree.findNodeByGroupId(group.id)
|
|
if (groupNode === null) {
|
|
return
|
|
}
|
|
// given a group, find all the filters/groups that are children
|
|
const groupsToRemove = [group.id]
|
|
const removeChildGroup = (treeNode) => {
|
|
for (const child of treeNode.children) {
|
|
groupsToRemove.push(child.groupId)
|
|
removeChildGroup(child)
|
|
}
|
|
}
|
|
removeChildGroup(groupNode)
|
|
|
|
const conditionIdsToRemove = conditions
|
|
.filter((c) => groupsToRemove.includes(c.group))
|
|
.map((c) => c.id)
|
|
conditions = conditions.filter(
|
|
(c) => !conditionIdsToRemove.includes(c.id)
|
|
)
|
|
conditionGroups = conditionGroups.filter(
|
|
(g) => !groupsToRemove.includes(g.id)
|
|
)
|
|
|
|
// We need to wait for the next tick, otherwise the condition is already deleted
|
|
// before the event completes, resulting in a click outside of the field.
|
|
this.$nextTick(() => {
|
|
this.$emit('updated-field-options', {
|
|
conditions,
|
|
condition_groups: conditionGroups,
|
|
})
|
|
})
|
|
},
|
|
registerChild(child) {
|
|
this.children.push(child)
|
|
},
|
|
},
|
|
}
|
|
</script>
|