From 6299db68722c1ffdc160a3d2312ca383e4f57878 Mon Sep 17 00:00:00 2001 From: Paul Fitzpatrick Date: Tue, 7 May 2024 17:52:51 -0400 Subject: [PATCH] support $id in dropdown condition (#969) This adds support for $id in dropdown conditions, using the same method used for supporting referencedColumn.id, and extends a test to exercise the variable. Without this, the dropdown editor gives an error if $id or rec.id is used, stating that the column is invalid. --- .../components/DropdownConditionConfig.ts | 2 +- test/nbrowser/DropdownConditionEditor.ts | 23 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/client/components/DropdownConditionConfig.ts b/app/client/components/DropdownConditionConfig.ts index c3cb2e08..a07da785 100644 --- a/app/client/components/DropdownConditionConfig.ts +++ b/app/client/components/DropdownConditionConfig.ts @@ -51,7 +51,7 @@ export class DropdownConditionConfig extends Disposable { const {recColIds = [], choiceColIds = []} = properties; const columns = use(this._columns); - const validRecColIds = new Set(columns.map((({colId}) => use(colId)))); + const validRecColIds = new Set(['id', ...columns.map((({colId}) => use(colId)))]); const invalidRecColIds = recColIds.filter(colId => !validRecColIds.has(colId)); if (invalidRecColIds.length > 0) { return t('Invalid columns: {{colIds}}', {colIds: invalidRecColIds.join(', ')}); diff --git a/test/nbrowser/DropdownConditionEditor.ts b/test/nbrowser/DropdownConditionEditor.ts index 3cf30bb9..cdab44ab 100644 --- a/test/nbrowser/DropdownConditionEditor.ts +++ b/test/nbrowser/DropdownConditionEditor.ts @@ -157,11 +157,11 @@ describe('DropdownConditionEditor', function () { 'choice\n.Supervisor\n ' ]); }); - await gu.sendKeys('.Role == "Supervisor" and $Role != "Supervisor"', Key.ENTER); + await gu.sendKeys('.Role == "Supervisor" and $Role != "Supervisor" and $id != 2', Key.ENTER); await gu.waitForServer(); assert.equal( await driver.find('.test-field-dropdown-condition .ace_line').getAttribute('textContent'), - 'choice.Role == "Supervisor" and $Role != "Supervisor"\n' + 'choice.Role == "Supervisor" and $Role != "Supervisor" and $id != 2\n' ); // Check that autocomplete values are filtered. @@ -171,6 +171,23 @@ describe('DropdownConditionEditor', function () { 'Marie Ziyad', ]); await gu.sendKeys(Key.ESCAPE); + + // Should be no options on row 2 because of $id != 2 part of condition. + await gu.getCell(2, 2).click(); + await gu.sendKeys(Key.ENTER); + assert.deepEqual(await driver.findAll('.test-autocomplete li', (el) => el.getText()), [ + ]); + await gu.sendKeys(Key.ESCAPE); + + // Row 3 should be like row 1. + await gu.getCell(2, 3).click(); + await gu.sendKeys(Key.ENTER); + assert.deepEqual(await driver.findAll('.test-autocomplete li', (el) => el.getText()), [ + 'Pavan Madilyn', + 'Marie Ziyad', + ]); + await gu.sendKeys(Key.ESCAPE); + await gu.getCell(2, 4).click(); await gu.sendKeys(Key.ENTER); assert.isEmpty(await driver.findAll('.test-autocomplete li', (el) => el.getText())); @@ -187,7 +204,7 @@ describe('DropdownConditionEditor', function () { await gu.setType('Reference List', {apply: true}); assert.equal( await driver.find('.test-field-dropdown-condition .ace_line').getAttribute('textContent'), - 'choice.Role == "Supervisor" and $Role != "Supervisor"\n' + 'choice.Role == "Supervisor" and $Role != "Supervisor" and $id != 2\n' ); await gu.getCell(2, 4).click(); await gu.sendKeys(Key.ENTER);