dataviz: hide time range field from filters cell if templates are used (#63397)
This commit is contained in:
parent
8f7a50217d
commit
3e04d37cd7
|
@ -290,7 +290,12 @@ class ChartFiltersForm(ChartFiltersMixin, forms.ModelForm):
|
|||
self.fields[field].initial = getattr(first_cell, field)
|
||||
dynamic_fields = self.get_filter_fields(first_cell)
|
||||
dynamic_fields_values = {k: v for k, v in first_cell.filter_params.items()}
|
||||
self.update_time_range_choices(first_cell.statistic, exclude_template_choice=True)
|
||||
|
||||
if first_cell.time_range == 'range-template':
|
||||
for field in self._meta.fields:
|
||||
self.fields.pop(field, None)
|
||||
else:
|
||||
self.update_time_range_choices(first_cell.statistic, exclude_template_choice=True)
|
||||
|
||||
for cell in chart_cells[1:]:
|
||||
cell_filter_fields = self.get_filter_fields(cell)
|
||||
|
|
|
@ -2477,6 +2477,29 @@ def test_chart_filters_cell_future_data(app, admin_user, new_api_statistics):
|
|||
]
|
||||
|
||||
|
||||
@with_httmock(new_api_mock)
|
||||
def test_chart_filters_cell_range_template(new_api_statistics, app, admin_user, nocache):
|
||||
page = Page.objects.create(title='One', slug='index')
|
||||
cell = ChartNgCell(page=page, order=1, placeholder='content')
|
||||
cell.statistic = Statistic.objects.get(slug='one-serie')
|
||||
cell.save()
|
||||
ChartFiltersCell.objects.create(page=page, order=2, placeholder='content')
|
||||
|
||||
app = login(app)
|
||||
resp = app.get('/')
|
||||
assert 'time_range' in resp.form.fields
|
||||
assert 'time_range_start' in resp.form.fields
|
||||
assert 'time_range_end' in resp.form.fields
|
||||
|
||||
# if time range is set using templates, time range fields are hidden from filters
|
||||
cell.time_range = 'range-template'
|
||||
cell.save()
|
||||
resp = app.get('/')
|
||||
assert 'time_range' not in resp.form.fields
|
||||
assert 'time_range_start' not in resp.form.fields
|
||||
assert 'time_range_end' not in resp.form.fields
|
||||
|
||||
|
||||
@with_httmock(new_api_mock)
|
||||
def test_chart_filters_cell_with_subfilters(new_api_statistics, app, admin_user, nocache):
|
||||
page = Page.objects.create(title='One', slug='index')
|
||||
|
|
Loading…
Reference in New Issue