mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Allow adding rows to widgets filtered by a link using a formula column
Summary: When a widget `A` is selected by a widget `B` so that `A` is filtered, adding a new row to `A` uses the values in the selected row of `B` and the columns relevant to the linking as default values for the new row. This ensures that the new row matches the current linking filter and remains visible. However this would previously cause a sandbox error when one of the linking columns was a formula column, which doesn't allow setting values. This diff ignores formula columns when picking default values. Since the value of the formula column in the new row typically won't match the linking filter, extra measures are needed to avoid the new row immediately disappearing. Regular filters already have a mechanism for this, but I didn't manage to extend it to also work for linking. Thanks @dsagal for creating `UnionRowSource` (originally in D4017) which is now used as the solution for temporarily exempting rows from both kinds of filtering. While testing, I also came across another bug in linking summary tables that caused incorrect filtering, which I fixed with some changes to `DynamicQuerySet`. Test Plan: Extended an nbrowser test, which both tests for the main change as well as the secondary bugfix. Reviewers: georgegevoian Reviewed By: georgegevoian Subscribers: dsagal Differential Revision: https://phab.getgrist.com/D4135
This commit is contained in:
@@ -106,10 +106,9 @@ describe('SelectByRefList', function() {
|
||||
],
|
||||
];
|
||||
// LINKTARGET is being filtered by the `id` column
|
||||
// There's no column to set a default value for that would help
|
||||
// The newly added row disappears immediately
|
||||
// There's no column to set a default value for.
|
||||
// TODO should we be appending the new row ID to the reflist in the source table?
|
||||
newRow = ['', '', ''];
|
||||
newRow = ['99', '', ''];
|
||||
await checkSelectingRecords('REFLISTS • LinkTarget_reflist', sourceData, newRow);
|
||||
|
||||
// Similar to the above but indirect. We connect LINKTARGET.ref and REFLISTS.reflist,
|
||||
|
||||
@@ -118,17 +118,60 @@ describe('SelectBySummary', function() {
|
||||
// so those values will be used as defaults in the source table
|
||||
await gu.getCell({section: 'TABLE1 [by onetwo, choices]', col: 'rownum', rowNum: 2}).click();
|
||||
|
||||
// Create a new record with rownum=99
|
||||
// Create new records with rownum = 99 and 100
|
||||
await gu.getCell({section: 'TABLE1', col: 'rownum', rowNum: 3}).click();
|
||||
await gu.enterCell('99');
|
||||
await gu.enterCell('100');
|
||||
|
||||
assert.deepEqual(
|
||||
await gu.getVisibleGridCells({
|
||||
section: 'TABLE1',
|
||||
cols: ['onetwo', 'choices', 'rownum'],
|
||||
rowNums: [3],
|
||||
rowNums: [1, 2, 3, 4, 5],
|
||||
}),
|
||||
['2', 'a', '99'],
|
||||
[
|
||||
'2', 'a', '2',
|
||||
'2', 'a\nb', '6',
|
||||
// The two rows we just added.
|
||||
// The filter link sets the default value 'a'.
|
||||
// It can't set a default value for 'onetwo' because that's a formula column.
|
||||
// This first row doesn't match the filter link, but it still shows temporarily.
|
||||
'1', 'a', '99',
|
||||
'2', 'a', '100',
|
||||
'', '', '', // new row
|
||||
],
|
||||
);
|
||||
|
||||
// Select a different record in the summary table, sanity check the linked table.
|
||||
await gu.getCell({section: 'TABLE1 [by onetwo, choices]', col: 'rownum', rowNum: 3}).click();
|
||||
assert.deepEqual(
|
||||
await gu.getVisibleGridCells({
|
||||
section: 'TABLE1',
|
||||
cols: ['onetwo', 'choices', 'rownum'],
|
||||
rowNums: [1, 2, 3],
|
||||
}),
|
||||
[
|
||||
'1', 'b', '3',
|
||||
'1', 'a\nb', '5',
|
||||
'', '', '', // new row
|
||||
],
|
||||
);
|
||||
|
||||
// Now go back to the previously selected summary table row.
|
||||
await gu.getCell({section: 'TABLE1 [by onetwo, choices]', col: 'rownum', rowNum: 2}).click();
|
||||
assert.deepEqual(
|
||||
await gu.getVisibleGridCells({
|
||||
section: 'TABLE1',
|
||||
cols: ['onetwo', 'choices', 'rownum'],
|
||||
rowNums: [1, 2, 3, 4],
|
||||
}),
|
||||
[
|
||||
'2', 'a', '2',
|
||||
'2', 'a\nb', '6',
|
||||
// The row ['1', 'a', '99'] is now filtered out as normal.
|
||||
'2', 'a', '100',
|
||||
'', '', '', // new row
|
||||
],
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user