dataviz: show filter value even if option is unavailable (#61607)
This commit is contained in:
parent
18784da9a0
commit
0f202b12fd
|
@ -70,6 +70,11 @@ class ChartFiltersMixin:
|
|||
choices = [(option['id'], option['label']) for option in filter_['options']]
|
||||
initial = cell.filter_params.get(filter_id, filter_.get('default'))
|
||||
|
||||
possible_choices = {choice[0] for choice in choices}
|
||||
for choice in initial if isinstance(initial, list) else [initial]:
|
||||
if choice and choice not in possible_choices:
|
||||
choices.append((choice, _('%s (unavailable)') % choice))
|
||||
|
||||
required = filter_.get('required', False)
|
||||
multiple = filter_.get('multiple')
|
||||
if not required and not multiple:
|
||||
|
|
|
@ -1243,6 +1243,18 @@ def test_chartng_cell_manager_new_api(app, admin_user, new_api_statistics):
|
|||
cell.refresh_from_db()
|
||||
assert cell.get_filter_params() == {'ou': 'default', 'time_interval': 'month'}
|
||||
|
||||
ou_filter = next(x for x in cell.statistic.filters if x['id'] == 'ou')
|
||||
ou_filter['options'] = [{'id': 'new', 'label': 'New'}]
|
||||
cell.statistic.save()
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
|
||||
assert resp.form[field_prefix + 'ou'].value == 'default'
|
||||
assert resp.form[field_prefix + 'ou'].options == [
|
||||
('', False, '---------'),
|
||||
('new', False, 'New'),
|
||||
('default', True, 'default (unavailable)'),
|
||||
]
|
||||
|
||||
resp.form[field_prefix + 'ou'] = ''
|
||||
resp = resp.form.submit().follow()
|
||||
assert resp.form[field_prefix + 'ou'].value == ''
|
||||
|
@ -1289,6 +1301,18 @@ def test_chartng_cell_manager_new_api(app, admin_user, new_api_statistics):
|
|||
cell.refresh_from_db()
|
||||
assert cell.filter_params == {'color': ['green', 'blue']}
|
||||
|
||||
color_filter = next(x for x in cell.statistic.filters if x['id'] == 'color')
|
||||
color_filter['options'] = [{'id': 'black', 'label': 'Black'}, {'id': 'green', 'label': 'Green'}]
|
||||
cell.statistic.save()
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
|
||||
assert resp.form[field_prefix + 'color'].value == ['green', 'blue']
|
||||
assert resp.form[field_prefix + 'color'].options == [
|
||||
('black', False, 'Black'),
|
||||
('green', True, 'Green'),
|
||||
('blue', True, 'blue (unavailable)'),
|
||||
]
|
||||
|
||||
resp.form[field_prefix + 'color'].select_multiple(texts=[])
|
||||
resp = resp.form.submit().follow()
|
||||
assert resp.form[field_prefix + 'color'].value is None
|
||||
|
|
Loading…
Reference in New Issue