mirror of
https://github.com/baserow/baserow.git
synced 2026-12-05 00:38:35 +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>
418 lines
12 KiB
JavaScript
418 lines
12 KiB
JavaScript
import { defineComponent } from 'vue'
|
|
|
|
import LocalBaserowTableServiceConditionalForm from '@baserow/modules/integrations/localBaserow/components/services/LocalBaserowTableServiceConditionalForm'
|
|
import ViewFieldConditionsForm from '@baserow/modules/database/components/view/ViewFieldConditionsForm.vue'
|
|
import { TestApp } from '@baserow/test/helpers/testApp'
|
|
|
|
const ViewFieldConditionsFormStub = defineComponent({
|
|
name: 'ViewFieldConditionsForm',
|
|
props: {
|
|
filters: { type: Array, required: true },
|
|
},
|
|
setup() {
|
|
return {
|
|
filterType: {
|
|
hasEditableValue: true,
|
|
isDeprecated: () => false,
|
|
getInputComponent: () => 'input',
|
|
},
|
|
}
|
|
},
|
|
template: `
|
|
<div>
|
|
<slot
|
|
name="filterInputComponent"
|
|
:slot-props="{
|
|
filter: filters[0],
|
|
field: { id: filters[0].field },
|
|
filterType,
|
|
}"
|
|
/>
|
|
</div>
|
|
`,
|
|
})
|
|
|
|
const InjectedFormulaInputStub = defineComponent({
|
|
name: 'InjectedFormulaInput',
|
|
props: {
|
|
modelValue: { type: Object, required: true },
|
|
},
|
|
emits: ['input'],
|
|
template: `
|
|
<button
|
|
class="formula-input-stub"
|
|
:data-mode="modelValue.mode"
|
|
@click="$emit('input', { formula: "'Alice'", mode: 'simple' })"
|
|
/>
|
|
`,
|
|
})
|
|
|
|
const FormulaInputStub = defineComponent({
|
|
name: 'FormulaInputStub',
|
|
template: '<button class="formula-input-field__mode-toggle" />',
|
|
})
|
|
|
|
describe('LocalBaserowTableServiceConditionalForm', () => {
|
|
let testApp = null
|
|
|
|
beforeEach(() => {
|
|
testApp = new TestApp()
|
|
})
|
|
|
|
afterEach(async () => {
|
|
await testApp.afterEach()
|
|
})
|
|
|
|
const fields = [{ id: 1, name: 'Name', type: 'text', primary: true }]
|
|
|
|
async function mountComponent(props = {}, global = {}) {
|
|
return await testApp.mount(LocalBaserowTableServiceConditionalForm, {
|
|
props: {
|
|
modelValue: [],
|
|
filterGroups: [],
|
|
filterType: 'AND',
|
|
fields,
|
|
...props,
|
|
},
|
|
global,
|
|
})
|
|
}
|
|
|
|
test('adding a filter group emits a new group and a seeded filter', async () => {
|
|
const wrapper = await mountComponent()
|
|
expect(wrapper.text()).toContain(
|
|
'localBaserowTableServiceConditionalForm.noFilterTitle'
|
|
)
|
|
expect(
|
|
wrapper
|
|
.findAll('.filters_footer .button-text')
|
|
.map((button) => button.text())
|
|
).toEqual([
|
|
'localBaserowTableServiceConditionalForm.addFilter',
|
|
'localBaserowTableServiceConditionalForm.addFilterGroup',
|
|
])
|
|
const child = wrapper.findComponent(ViewFieldConditionsForm)
|
|
|
|
child.vm.$emit('addFilterGroup', {
|
|
filterGroupId: 'group-1',
|
|
parentGroupId: null,
|
|
})
|
|
await wrapper.vm.$nextTick()
|
|
|
|
const groups = wrapper.emitted('update:filterGroups').at(-1)[0]
|
|
expect(groups).toEqual([
|
|
{ id: 'group-1', filter_type: 'AND', parent_group: null },
|
|
])
|
|
|
|
// A first filter is seeded inside the new group.
|
|
const filters = wrapper.emitted('update:modelValue').at(-1)[0]
|
|
expect(filters).toHaveLength(1)
|
|
expect(filters[0].group).toBe('group-1')
|
|
expect(filters[0].field).toBe(fields[0].id)
|
|
})
|
|
|
|
test('seeds the first allowed operator compatible with the selected field', async () => {
|
|
const dateField = {
|
|
id: 2,
|
|
name: 'Order date',
|
|
type: 'date',
|
|
primary: false,
|
|
}
|
|
const { equal, date_is_before, date_is } = testApp
|
|
.getRegistry()
|
|
.getAll('viewFilter')
|
|
const wrapper = await mountComponent({
|
|
fields: [...fields, dateField],
|
|
allowedFilterTypes: { equal, date_is_before, date_is },
|
|
})
|
|
|
|
wrapper.findComponent(ViewFieldConditionsForm).vm.$emit('addFilter', {
|
|
field: dateField,
|
|
})
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(wrapper.emitted('update:modelValue').at(-1)[0][0]).toMatchObject({
|
|
field: dateField.id,
|
|
type: 'date_is_before',
|
|
value: { formula: '', mode: 'raw' },
|
|
})
|
|
})
|
|
|
|
test('adding a nested filter group carries the parent group id', async () => {
|
|
const wrapper = await mountComponent({
|
|
filterGroups: [{ id: 'group-1', filter_type: 'AND', parent_group: null }],
|
|
})
|
|
const child = wrapper.findComponent(ViewFieldConditionsForm)
|
|
|
|
child.vm.$emit('addFilterGroup', {
|
|
filterGroupId: 'group-2',
|
|
parentGroupId: 'group-1',
|
|
})
|
|
await wrapper.vm.$nextTick()
|
|
|
|
const groups = wrapper.emitted('update:filterGroups').at(-1)[0]
|
|
expect(groups).toEqual([
|
|
{ id: 'group-1', filter_type: 'AND', parent_group: null },
|
|
{ id: 'group-2', filter_type: 'AND', parent_group: 'group-1' },
|
|
])
|
|
})
|
|
|
|
test('deleting a filter group removes it and its filters', async () => {
|
|
const wrapper = await mountComponent({
|
|
modelValue: [
|
|
{
|
|
id: 'f1',
|
|
field: 1,
|
|
type: 'equal',
|
|
value: { formula: 'a', mode: 'raw' },
|
|
group: 'group-1',
|
|
},
|
|
{
|
|
id: 'f2',
|
|
field: 1,
|
|
type: 'equal',
|
|
value: { formula: 'b', mode: 'raw' },
|
|
group: null,
|
|
},
|
|
],
|
|
filterGroups: [{ id: 'group-1', filter_type: 'AND', parent_group: null }],
|
|
})
|
|
const child = wrapper.findComponent(ViewFieldConditionsForm)
|
|
|
|
child.vm.$emit('deleteFilterGroup', {
|
|
group: { id: 'group-1' },
|
|
})
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(wrapper.emitted('update:filterGroups').at(-1)[0]).toEqual([])
|
|
// Only the ungrouped filter survives.
|
|
const filters = wrapper.emitted('update:modelValue').at(-1)[0]
|
|
expect(filters.map((f) => f.id)).toEqual(['f2'])
|
|
})
|
|
|
|
test('updating a group filter type emits the updated groups', async () => {
|
|
const wrapper = await mountComponent({
|
|
filterGroups: [{ id: 'group-1', filter_type: 'AND', parent_group: null }],
|
|
})
|
|
const child = wrapper.findComponent(ViewFieldConditionsForm)
|
|
|
|
child.vm.$emit('updateFilterType', {
|
|
value: 'OR',
|
|
filterGroup: { id: 'group-1' },
|
|
})
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(wrapper.emitted('update:filterGroups').at(-1)[0]).toEqual([
|
|
{ id: 'group-1', filter_type: 'OR', parent_group: null },
|
|
])
|
|
// The top-level filter type is not touched.
|
|
expect(wrapper.emitted('update:filterType')).toBeFalsy()
|
|
})
|
|
|
|
test('updating the top-level filter type emits update:filterType', async () => {
|
|
const wrapper = await mountComponent()
|
|
const child = wrapper.findComponent(ViewFieldConditionsForm)
|
|
|
|
child.vm.$emit('updateFilterType', { value: 'OR' })
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(wrapper.emitted('update:filterType').at(-1)[0]).toBe('OR')
|
|
expect(wrapper.emitted('update:filterGroups')).toBeFalsy()
|
|
})
|
|
|
|
test('the formula toggle is rendered for a filter inside a group', async () => {
|
|
// The raw-value/formula toggle (sigma) slot must reach filters nested in a
|
|
// group, not just root-level filters.
|
|
const wrapper = await mountComponent(
|
|
{
|
|
modelValue: [
|
|
{
|
|
id: 'f1',
|
|
field: 1,
|
|
type: 'equal',
|
|
value: { formula: 'a', mode: 'raw' },
|
|
group: 'group-1',
|
|
},
|
|
],
|
|
filterGroups: [
|
|
{ id: 'group-1', filter_type: 'AND', parent_group: null },
|
|
],
|
|
},
|
|
{
|
|
provide: {
|
|
formulaComponent: FormulaInputStub,
|
|
dataProvidersAllowed: [],
|
|
},
|
|
}
|
|
)
|
|
|
|
expect(
|
|
wrapper
|
|
.find('.filters__group-item .formula-input-field__mode-toggle')
|
|
.exists()
|
|
).toBe(true)
|
|
})
|
|
|
|
test.each([
|
|
[undefined, ['tool_input']],
|
|
[[], []],
|
|
])(
|
|
'filter values read what the host allows them, %s, or else what the form allows',
|
|
async (filterDataProvidersAllowed, expected) => {
|
|
const FormulaComponent = defineComponent({
|
|
props: { dataProvidersAllowed: { type: Array, required: true } },
|
|
template: `<span class="formula" :data-providers="dataProvidersAllowed.join()" />`,
|
|
})
|
|
const wrapper = await mountComponent(
|
|
{
|
|
modelValue: [
|
|
{
|
|
id: 'filter-1',
|
|
field: 1,
|
|
type: 'equal',
|
|
value: { formula: 'Alice', mode: 'raw' },
|
|
group: null,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
stubs: { ViewFieldConditionsForm: ViewFieldConditionsFormStub },
|
|
provide: {
|
|
formulaComponent: FormulaComponent,
|
|
dataProvidersAllowed: ['tool_input'],
|
|
...(filterDataProvidersAllowed
|
|
? { filterDataProvidersAllowed }
|
|
: {}),
|
|
},
|
|
}
|
|
)
|
|
|
|
expect(wrapper.get('.formula').attributes('data-providers')).toBe(
|
|
expected.join()
|
|
)
|
|
}
|
|
)
|
|
|
|
test.each([
|
|
['raw', undefined, 'raw'],
|
|
['simple', undefined, 'simple'],
|
|
['advanced', undefined, 'advanced'],
|
|
['advanced', true, 'advanced'],
|
|
['simple', false, 'raw'],
|
|
])(
|
|
'renders mode %s with legacy flag %s as %s',
|
|
async (mode, valueIsFormula, expectedMode) => {
|
|
const wrapper = await mountComponent(
|
|
{
|
|
modelValue: [
|
|
{
|
|
id: 'filter-1',
|
|
field: 1,
|
|
type: 'equal',
|
|
value: { formula: 'Alice', mode },
|
|
...(valueIsFormula === undefined
|
|
? {}
|
|
: { value_is_formula: valueIsFormula }),
|
|
group: null,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
stubs: {
|
|
ViewFieldConditionsForm: ViewFieldConditionsFormStub,
|
|
InjectedFormulaInput: InjectedFormulaInputStub,
|
|
},
|
|
}
|
|
)
|
|
|
|
expect(wrapper.find('.formula-input-stub').attributes('data-mode')).toBe(
|
|
expectedMode
|
|
)
|
|
}
|
|
)
|
|
|
|
test('emits filters using formula mode instead of value_is_formula', async () => {
|
|
const wrapper = await mountComponent(
|
|
{
|
|
modelValue: [
|
|
{
|
|
id: 'filter-1',
|
|
field: 1,
|
|
type: 'equal',
|
|
value: { formula: 'Alice', mode: 'raw' },
|
|
value_is_formula: false,
|
|
group: null,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
stubs: {
|
|
ViewFieldConditionsForm: ViewFieldConditionsFormStub,
|
|
InjectedFormulaInput: InjectedFormulaInputStub,
|
|
},
|
|
}
|
|
)
|
|
|
|
await wrapper.find('.formula-input-stub').trigger('click')
|
|
|
|
expect(wrapper.emitted('update:modelValue').at(-1)[0]).toEqual([
|
|
{
|
|
id: 'filter-1',
|
|
field: 1,
|
|
type: 'equal',
|
|
value: { formula: "'Alice'", mode: 'simple' },
|
|
group: null,
|
|
},
|
|
])
|
|
})
|
|
|
|
test('renders the plugin components after the add links', async () => {
|
|
const FooterStub = defineComponent({
|
|
name: 'FooterStub',
|
|
template: '<span class="footer-stub" />',
|
|
})
|
|
const registry = testApp.getRegistry()
|
|
const getAll = registry.getAll.bind(registry)
|
|
vi.spyOn(registry, 'getAll').mockImplementation((namespace) =>
|
|
namespace === 'plugin'
|
|
? {
|
|
...getAll('plugin'),
|
|
footer: { getServiceFilterFooterComponents: () => [FooterStub] },
|
|
}
|
|
: getAll(namespace)
|
|
)
|
|
|
|
const wrapper = await mountComponent()
|
|
|
|
const footer = wrapper.find('.filters_footer')
|
|
expect(footer.find('.footer-stub').exists()).toBe(true)
|
|
expect(footer.element.lastElementChild.classList).toContain('footer-stub')
|
|
})
|
|
|
|
test('freezes the filters and the add buttons on request', async () => {
|
|
const wrapper = await mountComponent({
|
|
modelValue: [
|
|
{
|
|
id: 1,
|
|
field: 1,
|
|
type: 'equal',
|
|
value: { formula: 'a', mode: 'raw' },
|
|
group: null,
|
|
},
|
|
],
|
|
})
|
|
|
|
wrapper.vm.frozen = true
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(wrapper.find('.filters__items').attributes('inert')).toBeDefined()
|
|
expect(
|
|
wrapper.findAll('.filters__add').map((b) => b.attributes('disabled'))
|
|
).toEqual(['', ''])
|
|
|
|
wrapper.vm.frozen = false
|
|
await wrapper.vm.$nextTick()
|
|
expect(wrapper.find('.filters__items').attributes('inert')).toBeUndefined()
|
|
})
|
|
})
|