Introduce ColumnNames Enum
Release-Notes: skip
Change-Id: I4e8eec0781255f7d7b22ba18c3d24bc2f68ff170
diff --git a/polygerrit-ui/app/constants/constants.ts b/polygerrit-ui/app/constants/constants.ts
index 8cdd765..a0a6417 100644
--- a/polygerrit-ui/app/constants/constants.ts
+++ b/polygerrit-ui/app/constants/constants.ts
@@ -107,6 +107,20 @@
SUCCESSFUL = 'SUCCESSFUL',
}
+export enum ColumnNames {
+ SUBJECT = 'Subject',
+ // TODO(milutin) - remove once Submit Requirements are rolled out.
+ STATUS = 'Status',
+ OWNER = 'Owner',
+ REVIEWERS = 'Reviewers',
+ COMMENTS = 'Comments',
+ REPO = 'Repo',
+ BRANCH = 'Branch',
+ UPDATED = 'Updated',
+ SIZE = 'Size',
+ STATUS2 = ' Status ', // spaces to differentiate from old 'Status'
+}
+
/**
* @description Modes for gr-diff-cursor
* The scroll behavior for the cursor. Values are 'never' and
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list-item/gr-change-list-item.ts b/polygerrit-ui/app/elements/change-list/gr-change-list-item/gr-change-list-item.ts
index 15532d2..92f6f62 100644
--- a/polygerrit-ui/app/elements/change-list/gr-change-list-item/gr-change-list-item.ts
+++ b/polygerrit-ui/app/elements/change-list/gr-change-list-item/gr-change-list-item.ts
@@ -53,7 +53,7 @@
import {submitRequirementsStyles} from '../../../styles/gr-submit-requirements-styles';
import {ifDefined} from 'lit/directives/if-defined';
import {KnownExperimentId} from '../../../services/flags/flags';
-import {WAITING} from '../../../constants/constants';
+import {ColumnNames, WAITING} from '../../../constants/constants';
import {bulkActionsModelToken} from '../../../models/bulk-actions/bulk-actions-model';
import {resolve} from '../../../models/dependency';
import {subscribe} from '../../lit/subscription-controller';
@@ -346,7 +346,12 @@
}
private renderCellSubject(changeUrl: string) {
- if (this.computeIsColumnHidden('Subject', this.visibleChangeTableColumns))
+ if (
+ this.computeIsColumnHidden(
+ ColumnNames.SUBJECT,
+ this.visibleChangeTableColumns
+ )
+ )
return;
return html`
@@ -367,7 +372,12 @@
}
private renderCellStatus() {
- if (this.computeIsColumnHidden('Status', this.visibleChangeTableColumns))
+ if (
+ this.computeIsColumnHidden(
+ ColumnNames.STATUS,
+ this.visibleChangeTableColumns
+ )
+ )
return;
return html` <td class="cell status">${this.renderChangeStatus()}</td> `;
@@ -387,7 +397,12 @@
}
private renderCellOwner() {
- if (this.computeIsColumnHidden('Owner', this.visibleChangeTableColumns))
+ if (
+ this.computeIsColumnHidden(
+ ColumnNames.OWNER,
+ this.visibleChangeTableColumns
+ )
+ )
return;
return html`
@@ -403,7 +418,12 @@
}
private renderCellReviewers() {
- if (this.computeIsColumnHidden('Reviewers', this.visibleChangeTableColumns))
+ if (
+ this.computeIsColumnHidden(
+ ColumnNames.REVIEWERS,
+ this.visibleChangeTableColumns
+ )
+ )
return;
return html`
@@ -455,7 +475,12 @@
}
private renderCellRepo() {
- if (this.computeIsColumnHidden('Repo', this.visibleChangeTableColumns))
+ if (
+ this.computeIsColumnHidden(
+ ColumnNames.REPO,
+ this.visibleChangeTableColumns
+ )
+ )
return;
return html`
@@ -475,7 +500,12 @@
}
private renderCellBranch() {
- if (this.computeIsColumnHidden('Branch', this.visibleChangeTableColumns))
+ if (
+ this.computeIsColumnHidden(
+ ColumnNames.BRANCH,
+ this.visibleChangeTableColumns
+ )
+ )
return;
return html`
@@ -567,7 +597,12 @@
}
private renderCellRequirements() {
- if (this.computeIsColumnHidden(' Status ', this.visibleChangeTableColumns))
+ if (
+ this.computeIsColumnHidden(
+ ColumnNames.STATUS2,
+ this.visibleChangeTableColumns
+ )
+ )
return;
return html`
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list-item/gr-change-list-item_test.ts b/polygerrit-ui/app/elements/change-list/gr-change-list-item/gr-change-list-item_test.ts
index 95a851e..e0ce6a8 100644
--- a/polygerrit-ui/app/elements/change-list/gr-change-list-item/gr-change-list-item_test.ts
+++ b/polygerrit-ui/app/elements/change-list/gr-change-list-item/gr-change-list-item_test.ts
@@ -47,7 +47,6 @@
} from '../../../types/common';
import {StandardLabels} from '../../../utils/label-util';
import {GerritNav} from '../../core/gr-navigation/gr-navigation';
-import {columnNames} from '../gr-change-list/gr-change-list';
import './gr-change-list-item';
import {GrChangeListItem, LabelCategory} from './gr-change-list-item';
import {
@@ -60,6 +59,7 @@
} from '../../../models/bulk-actions/bulk-actions-model';
import {createTestAppContext} from '../../../test/test-app-context-init';
import {tap} from '@polymer/iron-test-helpers/mock-interactions';
+import {ColumnNames} from '../../../constants/constants';
suite('gr-change-list-item tests', () => {
const account = createAccountWithId();
@@ -297,21 +297,21 @@
test('no hidden columns', async () => {
element.visibleChangeTableColumns = [
- 'Subject',
- 'Status',
- 'Owner',
- 'Reviewers',
- 'Comments',
- 'Repo',
- 'Branch',
- 'Updated',
- 'Size',
- ' Status ',
+ ColumnNames.SUBJECT,
+ ColumnNames.STATUS,
+ ColumnNames.OWNER,
+ ColumnNames.REVIEWERS,
+ ColumnNames.COMMENTS,
+ ColumnNames.REPO,
+ ColumnNames.BRANCH,
+ ColumnNames.UPDATED,
+ ColumnNames.SIZE,
+ ColumnNames.STATUS2,
];
await element.updateComplete;
- for (const column of columnNames) {
+ for (const column of Object.values(ColumnNames)) {
const elementClass = '.' + column.trim().toLowerCase();
assert.isFalse(
queryAndAssert(element, elementClass).hasAttribute('hidden')
@@ -388,20 +388,20 @@
test('repo column hidden', async () => {
element.visibleChangeTableColumns = [
- 'Subject',
- 'Status',
- 'Owner',
- 'Reviewers',
- 'Comments',
- 'Branch',
- 'Updated',
- 'Size',
- ' Status ',
+ ColumnNames.SUBJECT,
+ ColumnNames.STATUS,
+ ColumnNames.OWNER,
+ ColumnNames.REVIEWERS,
+ ColumnNames.COMMENTS,
+ ColumnNames.BRANCH,
+ ColumnNames.UPDATED,
+ ColumnNames.SIZE,
+ ColumnNames.STATUS2,
];
await element.updateComplete;
- for (const column of columnNames) {
+ for (const column of Object.values(ColumnNames)) {
const elementClass = '.' + column.trim().toLowerCase();
if (column === 'Repo') {
assert.isNotOk(query(element, elementClass));
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list-section/gr-change-list-section_test.ts b/polygerrit-ui/app/elements/change-list/gr-change-list-section/gr-change-list-section_test.ts
index 2cc5b3b..b1a33a9 100644
--- a/polygerrit-ui/app/elements/change-list/gr-change-list-section/gr-change-list-section_test.ts
+++ b/polygerrit-ui/app/elements/change-list/gr-change-list-section/gr-change-list-section_test.ts
@@ -24,8 +24,9 @@
waitUntilObserved,
} from '../../../test/test-utils';
import {GrChangeListItem} from '../gr-change-list-item/gr-change-list-item';
-import {columnNames, ChangeListSection} from '../gr-change-list/gr-change-list';
+import {ChangeListSection} from '../gr-change-list/gr-change-list';
import {fixture, html} from '@open-wc/testing-helpers';
+import {ColumnNames} from '../../../constants/constants';
suite('gr-change-list section', () => {
let element: GrChangeListSection;
@@ -52,7 +53,7 @@
html`<gr-change-list-section
.account=${createAccountDetailWithId(1)}
.config=${createServerInfo()}
- .visibleChangeTableColumns=${columnNames}
+ .visibleChangeTableColumns=${Object.values(ColumnNames)}
.changeSection=${changeSection}
></gr-change-list-section> `
);
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.ts b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.ts
index f433bfd..2792159 100644
--- a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.ts
+++ b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.ts
@@ -32,7 +32,7 @@
PreferencesInput,
} from '../../../types/common';
import {fire, fireEvent, fireReload} from '../../../utils/event-util';
-import {ScrollMode} from '../../../constants/constants';
+import {ColumnNames, ScrollMode} from '../../../constants/constants';
import {getRequirements} from '../../../utils/label-util';
import {addGlobalShortcut, Key} from '../../../utils/dom-util';
import {unique} from '../../../utils/common-util';
@@ -49,20 +49,6 @@
import {GrChangeListSection} from '../gr-change-list-section/gr-change-list-section';
import {Execution} from '../../../constants/reporting';
-export const columnNames = [
- 'Subject',
- // TODO(milutin) - remove once Submit Requirements are rolled out.
- 'Status',
- 'Owner',
- 'Reviewers',
- 'Comments',
- 'Repo',
- 'Branch',
- 'Updated',
- 'Size',
- ' Status ', // spaces to differentiate from old 'Status'
-];
-
export interface ChangeListSection {
countLabel?: string;
emptyStateSlotName?: string;
@@ -309,7 +295,7 @@
private computePreferences() {
if (!this.config) return;
- this.changeTableColumns = columnNames;
+ this.changeTableColumns = Object.values(ColumnNames);
this.showNumber = false;
this.visibleChangeTableColumns = this.changeTableColumns.filter(col =>
this._isColumnEnabled(col, this.config)
@@ -321,20 +307,20 @@
this.preferences.change_table.length > 0
) {
const prefColumns = this.preferences.change_table
- .map(column => (column === 'Project' ? 'Repo' : column))
+ .map(column => (column === 'Project' ? ColumnNames.REPO : column))
.map(column =>
this.flagsService.isEnabled(
KnownExperimentId.SUBMIT_REQUIREMENTS_UI
- ) && column === 'Status'
- ? ' Status '
+ ) && column === ColumnNames.STATUS
+ ? ColumnNames.STATUS2
: column
);
this.reporting.reportExecution(Execution.USER_PREFERENCES_COLUMNS, {
- statusColumn: prefColumns.includes(' Status '),
+ statusColumn: prefColumns.includes(ColumnNames.STATUS2),
});
// Order visible column names by columnNames, filter only one that
// are in prefColumns and enabled by config
- this.visibleChangeTableColumns = columnNames
+ this.visibleChangeTableColumns = Object.values(ColumnNames)
.filter(col => prefColumns.includes(col))
.filter(col => this._isColumnEnabled(col, this.config));
}
@@ -345,7 +331,8 @@
* Is the column disabled by a server config or experiment?
*/
_isColumnEnabled(column: string, config?: ServerInfo) {
- if (!columnNames.includes(column)) return false;
+ if (!Object.values(ColumnNames).includes(column as unknown as ColumnNames))
+ return false;
if (!config || !config.change) return true;
if (column === 'Comments')
return this.flagsService.isEnabled('comments-column');
@@ -354,7 +341,7 @@
KnownExperimentId.SUBMIT_REQUIREMENTS_UI
);
}
- if (column === ' Status ')
+ if (column === ColumnNames.STATUS2)
return this.flagsService.isEnabled(
KnownExperimentId.SUBMIT_REQUIREMENTS_UI
);
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list_test.ts b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list_test.ts
index a56ef7c..902fa45 100644
--- a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list_test.ts
+++ b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list_test.ts
@@ -27,7 +27,7 @@
waitUntil,
} from '../../../test/test-utils';
import {Key} from '../../../utils/dom-util';
-import {TimeFormat} from '../../../constants/constants';
+import {ColumnNames, TimeFormat} from '../../../constants/constants';
import {AccountId, NumericChangeId} from '../../../types/common';
import {
createChange,
@@ -207,7 +207,7 @@
'Branch',
'Updated',
'Size',
- ' Status ',
+ ColumnNames.STATUS2,
],
};
element.config = createServerInfo();
@@ -363,7 +363,7 @@
'Branch',
'Updated',
'Size',
- ' Status ',
+ ColumnNames.STATUS2,
],
};
element.config = createServerInfo();
@@ -401,7 +401,7 @@
'Branch',
'Updated',
'Size',
- ' Status ',
+ ColumnNames.STATUS2,
],
};
element.config = createServerInfo();
@@ -454,7 +454,7 @@
'Branch',
'Updated',
'Size',
- ' Status ',
+ ColumnNames.STATUS2,
],
};
element.config = createServerInfo();
@@ -518,7 +518,7 @@
element.config = createServerInfo();
await element.updateComplete;
assert.isTrue(
- element.visibleChangeTableColumns?.includes(' Status '),
+ element.visibleChangeTableColumns?.includes(ColumnNames.STATUS2),
'Show new status'
);
const section = queryAndAssert(element, 'gr-change-list-section');
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 34e376b..73be9f3 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
@@ -17,7 +17,6 @@
import '../../shared/gr-button/gr-button';
import {ServerInfo} from '../../../types/common';
import {getAppContext} from '../../../services/app-context';
-import {columnNames} from '../../change-list/gr-change-list/gr-change-list';
import {KnownExperimentId} from '../../../services/flags/flags';
import {LitElement, css, html} from 'lit';
import {customElement, property} from 'lit/decorators';
@@ -26,6 +25,7 @@
import {PropertyValues} from 'lit';
import {fire} from '../../../utils/event-util';
import {ValueChangedEvent} from '../../../types/events';
+import {ColumnNames} from '../../../constants/constants';
@customElement('gr-change-table-editor')
export class GrChangeTableEditor extends LitElement {
@@ -119,7 +119,7 @@
}
private configChanged() {
- this.defaultColumns = columnNames.filter(column =>
+ this.defaultColumns = Object.values(ColumnNames).filter(column =>
this.isColumnEnabled(column)
);
if (!this.displayedColumns) return;
@@ -134,13 +134,13 @@
*/
isColumnEnabled(column: string) {
if (!this.serverConfig?.change) return true;
- if (column === 'Comments')
+ if (column === ColumnNames.COMMENTS)
return this.flagsService.isEnabled('comments-column');
- if (column === 'Status')
+ if (column === ColumnNames.STATUS)
return !this.flagsService.isEnabled(
KnownExperimentId.SUBMIT_REQUIREMENTS_UI
);
- if (column === ' Status ')
+ if (column === ColumnNames.STATUS2)
return this.flagsService.isEnabled(
KnownExperimentId.SUBMIT_REQUIREMENTS_UI
);
diff --git a/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor_test.ts b/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor_test.ts
index c37c3f9..fdea387 100644
--- a/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor_test.ts
+++ b/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor_test.ts
@@ -20,6 +20,7 @@
import {queryAndAssert} from '../../../test/test-utils';
import {createServerInfo} from '../../../test/test-data-generators';
import {fixture, html} from '@open-wc/testing-helpers';
+import {ColumnNames} from '../../../constants/constants';
suite('gr-change-table-editor tests', () => {
let element: GrChangeTableEditor;
@@ -37,8 +38,8 @@
'Reviewers',
'Comments',
'Repo',
- 'Branch',
- 'Updated',
+ ColumnNames.BRANCH,
+ ColumnNames.UPDATED,
];
element.displayedColumns = columns;
@@ -150,7 +151,13 @@
});
test('show item', async () => {
- element.displayedColumns = ['Status', 'Owner', 'Repo', 'Branch', 'Updated'];
+ element.displayedColumns = [
+ ColumnNames.STATUS,
+ ColumnNames.OWNER,
+ ColumnNames.REPO,
+ ColumnNames.BRANCH,
+ ColumnNames.UPDATED,
+ ];
// trigger computation of enabled displayed columns
element.serverConfig = createServerInfo();
await element.updateComplete;
diff --git a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.ts b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.ts
index ca3f11d..d62629d 100644
--- a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.ts
+++ b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.ts
@@ -48,6 +48,7 @@
import {getAppContext} from '../../../services/app-context';
import {GerritView} from '../../../services/router/router-model';
import {
+ ColumnNames,
DateFormat,
DefaultBase,
DiffViewMode,
@@ -55,7 +56,6 @@
EmailStrategy,
TimeFormat,
} from '../../../constants/constants';
-import {columnNames} from '../../change-list/gr-change-list/gr-change-list';
import {windowLocationReload} from '../../../utils/dom-util';
import {BindValueChangeEvent, ValueChangedEvent} from '../../../types/events';
import {LitElement, css, html} from 'lit';
@@ -228,7 +228,7 @@
this.copyPrefs(CopyPrefsDirection.PrefsToLocalPrefs);
this.localChangeTableColumns =
prefs.change_table.length === 0
- ? columnNames
+ ? Object.values(ColumnNames)
: prefs.change_table.map(column =>
column === 'Project' ? 'Repo' : column
);