Filter disabled experiments from settings view
When showing the list of default columns which user can enable/disable
in the settings view, filter out columns which are not enabled for the
user or are behind an experiment flag.
Issue: Bug 13843
Change-Id: Ibc20ced747759dbab50bc1a63488ef6288a5ad0c
diff --git a/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor.ts b/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor.ts
index b380ce4..df927d6 100644
--- a/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor.ts
+++ b/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor.ts
@@ -24,7 +24,9 @@
import {PolymerElement} from '@polymer/polymer/polymer-element';
import {htmlTemplate} from './gr-change-table-editor_html';
import {ChangeTableMixin} from '../../../mixins/gr-change-table-mixin/gr-change-table-mixin';
-import {customElement, property} from '@polymer/decorators';
+import {customElement, property, observe} from '@polymer/decorators';
+import {ServerInfo} from '../../../types/common';
+import {appContext} from '../../../services/app-context';
@customElement('gr-change-table-editor')
class GrChangeTableEditor extends ChangeTableMixin(
@@ -40,6 +42,27 @@
@property({type: Boolean, notify: true})
showNumber?: boolean;
+ @property({type: Object})
+ serverConfig?: ServerInfo;
+
+ @property({type: Array})
+ defaultColumns?: string[];
+
+ flagsService = appContext.flagsService;
+
+ @observe('serverConfig')
+ _configChanged(config: ServerInfo) {
+ this.defaultColumns = this.getEnabledColumns(
+ this.columnNames,
+ config,
+ this.flagsService.enabledExperiments
+ );
+ if (!this.displayedColumns) return;
+ this.displayedColumns = this.displayedColumns.filter(column =>
+ this.isColumnEnabled(column, config, this.flagsService.enabledExperiments)
+ );
+ }
+
/**
* Get the list of enabled column names from whichever checkboxes are
* checked (excluding the number checkbox).
diff --git a/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor_html.ts b/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor_html.ts
index 1233cf1..4c87d83 100644
--- a/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor_html.ts
+++ b/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor_html.ts
@@ -61,7 +61,7 @@
/>
</td>
</tr>
- <template is="dom-repeat" items="[[columnNames]]">
+ <template is="dom-repeat" items="[[defaultColumns]]">
<tr>
<td>[[item]]</td>
<td
diff --git a/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor_test.js b/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor_test.js
index 42085ff..db5c035 100644
--- a/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor_test.js
+++ b/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor_test.js
@@ -41,6 +41,9 @@
element.set('displayedColumns', columns);
element.showNumber = false;
+ element.serverConfig = {
+ change: {},
+ };
flush();
});
@@ -51,13 +54,25 @@
// The `+ 1` is for the number column, which isn't included in the change
// table behavior's list.
- assert.equal(rows.length, element.columnNames.length + 1);
- for (let i = 0; i < columns.length; i++) {
+ assert.equal(rows.length, element.defaultColumns.length + 1);
+ for (let i = 0; i < element.defaultColumns.length; i++) {
tds = rows[i + 1].querySelectorAll('td');
- assert.equal(tds[0].textContent, columns[i]);
+ assert.equal(tds[0].textContent, element.defaultColumns[i]);
}
});
+ test('disabled experiments are hidden', () => {
+ assert.isFalse(element.displayedColumns.includes('Assignee'));
+ element.set('displayedColumns', columns);
+ element.serverConfig = {
+ change: {
+ enable_assignee: true,
+ },
+ };
+ flush();
+ assert.isTrue(element.displayedColumns.includes('Assignee'));
+ });
+
test('hide item', () => {
const checkbox = element.shadowRoot
.querySelector('table tr:nth-child(2) input');
@@ -80,6 +95,10 @@
'Branch',
'Updated',
]);
+ // trigger computation of enabled displayed columns
+ element.serverConfig = {
+ change: {},
+ };
flush();
const checkbox = element.shadowRoot
.querySelector('table tr:nth-child(2) input');
@@ -97,12 +116,15 @@
});
test('_getDisplayedColumns', () => {
- assert.deepEqual(element._getDisplayedColumns(), columns);
+ const enabledColumns = columns.filter(column => element.isColumnEnabled(
+ column, element.serverConfig, []
+ ));
+ assert.deepEqual(element._getDisplayedColumns(), enabledColumns);
MockInteractions.tap(
element.shadowRoot
- .querySelector('.checkboxContainer input[name=Assignee]'));
+ .querySelector('.checkboxContainer input[name=Subject]'));
assert.deepEqual(element._getDisplayedColumns(),
- columns.filter(c => c !== 'Assignee'));
+ enabledColumns.filter(c => c !== 'Subject'));
});
test('_handleCheckboxContainerClick relays taps to checkboxes', () => {
@@ -140,12 +162,12 @@
test('_handleTargetClick', () => {
sinon.spy(element, '_handleTargetClick');
- assert.include(element.displayedColumns, 'Assignee');
+ assert.include(element.displayedColumns, 'Subject');
MockInteractions
.tap(element.shadowRoot
- .querySelector('.checkboxContainer input[name=Assignee]'));
+ .querySelector('.checkboxContainer input[name=Subject]'));
assert.isTrue(element._handleTargetClick.calledOnce);
- assert.notInclude(element.displayedColumns, 'Assignee');
+ assert.notInclude(element.displayedColumns, 'Subject');
});
});
diff --git a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view_html.ts b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view_html.ts
index d1d412f..ec8f6e7 100644
--- a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view_html.ts
+++ b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view_html.ts
@@ -340,6 +340,7 @@
<fieldset id="changeTableColumns">
<gr-change-table-editor
show-number="{{_showNumber}}"
+ server-config="[[_serverConfig]]"
displayed-columns="{{_localChangeTableColumns}}"
>
</gr-change-table-editor>