From ffeab944cc0185bc7c6d835bed143473925eda7b Mon Sep 17 00:00:00 2001 From: Alex Hall Date: Tue, 10 Aug 2021 21:26:00 +0200 Subject: [PATCH] (core) Fix detaching summary tables grouped by list column Summary: Detached formula uses CONTAINS() Test Plan: Added to existing unit test Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2972 --- sandbox/grist/summary.py | 11 ++++++++-- sandbox/grist/test_summary_choicelist.py | 26 +++++++++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/sandbox/grist/summary.py b/sandbox/grist/summary.py index c94c774d..6f3adeff 100644 --- a/sandbox/grist/summary.py +++ b/sandbox/grist/summary.py @@ -301,8 +301,15 @@ class SummaryActions(object): col_info = [_make_col_info(col=c) for c in field_col_recs if c.colId != 'group'] # Prepare the 'group' column, which is that one column that's different from the original. - group_args = ', '.join('%s=$%s' % (c.summarySourceCol.colId, c.colId) - for c in field_col_recs if c.summarySourceCol) + group_args = ', '.join( + '%s=%s' % ( + c.summarySourceCol.colId, + 'CONTAINS($%s)' % c.colId + if c.summarySourceCol.type.startswith(('ChoiceList', 'RefList:')) else + '$%s' % c.colId, + ) + for c in field_col_recs if c.summarySourceCol + ) col_info.append(_make_col_info(colId='group', type='RefList:%s' % source_table_id, isFormula=True, formula='%s.lookupRecords(%s)' % (source_table_id, group_args))) diff --git a/sandbox/grist/test_summary_choicelist.py b/sandbox/grist/test_summary_choicelist.py index 368937e7..f6d90b28 100644 --- a/sandbox/grist/test_summary_choicelist.py +++ b/sandbox/grist/test_summary_choicelist.py @@ -257,11 +257,35 @@ class TestSummaryChoiceList(EngineTestCase): [2, "b", [102, 103, 105, 106, 108, 109], 6], ]) - self.assertTableData('GristSummary_6_Source2', data=[ + summary_data = [ ["id", "choices1", "choices2", "group", "count"], [1, "a", "c", [101, 103, 107, 109], 4], [2, "a", "d", [104, 106, 107, 109], 4], [3, "b", "c", [102, 103, 108, 109], 4], [4, "b", "d", [105, 106, 108, 109], 4], [5, "a", "e", [], 0], + ] + + self.assertTableData('GristSummary_6_Source2', data=summary_data) + + # Verify that "DetachSummaryViewSection" useraction works correctly. + self.apply_user_action(["DetachSummaryViewSection", 2]) + + self.assertTables([ + self.starting_table, summary_table1, summary_table3, summary_table4, + Table( + 6, "Table1", primaryViewId=5, summarySourceTable=0, + columns=[ + Column(27, "manualSort", "ManualSortPos", isFormula=False, formula="", summarySourceCol=0), + Column(28, "choices1", "Choice", isFormula=False, formula="", summarySourceCol=0), + Column(29, "choices2", "Choice", isFormula=False, formula="", summarySourceCol=0), + Column(30, "count", "Int", isFormula=True, summarySourceCol=0, + formula="len($group)"), + Column(31, "group", "RefList:Source", isFormula=True, summarySourceCol=0, + formula="Source.lookupRecords(choices1=CONTAINS($choices1), choices2=CONTAINS($choices2))"), + + ], + ) ]) + + self.assertTableData('Table1', data=summary_data, cols="subset")