Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Perspective drag errors #2300

Merged
merged 1 commit into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions panel/pane/perspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ def _process_property_change(self, msg):
if msg.get(prop):
msg[prop] = [self._as_digit(col) for col in msg[prop]]
if msg.get('sort'):
msg['sort'] = [[self._as_digit(col), d] for col, d in msg['sort']]
msg['sort'] = [[self._as_digit(col), *args] for col, *args in msg['sort']]
if msg.get('filters'):
msg['filters'] = [[self._as_digit(col), e, val] for col, e, val in msg['filters']]
msg['filters'] = [[self._as_digit(col), *args] for col, *args in msg['filters']]
if msg.get('aggregates'):
msg['aggregates'] = {self._as_digit(col): agg for col, agg in msg['aggregates'].items()}
return msg
Expand Down
35 changes: 34 additions & 1 deletion panel/tests/pane/test_perspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_perspective_int_cols():
assert model.sort == [['0', 'desc']]

psp2 = Perspective(data)

psp2._process_events({
'columns': ['0'],
'row_pivots': ['0'],
Expand All @@ -42,3 +42,36 @@ def test_perspective_int_cols():
assert psp2.aggregates == {0: 'mean'}
assert psp2.sort == [[0, 'desc']]
assert psp2.filters == [[0, '==', 'None']]

def test_perspective_can_drag_to_filter():
# Given
msg = {'filters': [['Curve', '==', None, 'integer', 'sum']]}
# When
actual = Perspective()._process_property_change(msg)
# Then
assert actual == msg

def test_perspective_can_filter_to_value():
# Given
msg = {'filters': [['Curve', '==', 4]]}
# When
actual = Perspective()._process_property_change(msg)
# Then
assert actual == msg

def test_perspective_can_drag_to_sort():
# Given
msg = {'sort': [['Curve']]}
# When
actual = Perspective()._process_property_change(msg)
# Then
assert actual == msg

def test_perspective_can_sort_desc():
# Given
msg = {'sort': [['Curve', 'desc']]}
# When
actual = Perspective()._process_property_change(msg)
# Then
assert actual == msg