Merge changes I13c3dd56,I156e7721

* changes:
  Rename getVisibleColumns method to renameProjectToRepoColumn
  Refactor cloneMenu method in gr-settings-view
This commit is contained in:
Dhruv Srivastava
2020-12-23 17:14:36 +00:00
committed by Gerrit Code Review
4 changed files with 16 additions and 19 deletions

View File

@@ -227,7 +227,9 @@ export class GrChangeList extends ChangeTableMixin(
preferences && preferences.legacycid_in_change_table
);
if (preferences.change_table && preferences.change_table.length > 0) {
const prefColumns = this.getVisibleColumns(preferences.change_table);
const prefColumns = this.renameProjectToRepoColumn(
preferences.change_table
);
this.visibleChangeTableColumns = this.getEnabledColumns(
prefColumns,
config,

View File

@@ -241,7 +241,7 @@ export class GrSettingsView extends ChangeTableMixin(
this.prefs = prefs;
this._showNumber = !!prefs.legacycid_in_change_table;
this._copyPrefs(CopyPrefsDirection.PrefsToLocalPrefs);
this._cloneMenu(prefs.my);
this._localMenu = this._cloneMenu(prefs.my);
this._cloneChangeTableColumns(prefs.change_table);
})
);
@@ -341,19 +341,14 @@ export class GrSettingsView extends ChangeTableMixin(
}
_cloneMenu(prefs: TopMenuItemInfo[]) {
const menu = [];
for (const item of prefs) {
menu.push({
name: item.name,
url: item.url,
target: item.target,
});
}
this._localMenu = menu;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
return prefs.map(({id, ...item}) => {
return item;
});
}
_cloneChangeTableColumns(changeTable: string[]) {
let columns = this.getVisibleColumns(changeTable);
let columns = this.renameProjectToRepoColumn(changeTable);
if (columns.length === 0) {
columns = this.columnNames;
@@ -453,7 +448,6 @@ export class GrSettingsView extends ChangeTableMixin(
_handleSaveMenu() {
this.set('prefs.my', this._localMenu);
this._cloneMenu(this._localMenu);
return this.restApiService.savePreferences(this.prefs).then(() => {
this._menuChanged = false;
});
@@ -462,7 +456,7 @@ export class GrSettingsView extends ChangeTableMixin(
_handleResetMenuButton() {
return this.restApiService.getDefaultPreferences().then(data => {
if (data?.my) {
this._cloneMenu(data.my);
this._localMenu = this._cloneMenu(data.my);
}
});
}

View File

@@ -103,7 +103,7 @@ export const ChangeTableMixin = dedupingMixin(
* @return If the column was renamed, returns a new array
* with the corrected name. Otherwise, it returns the original param.
*/
getVisibleColumns(columns: string[]) {
renameProjectToRepoColumn(columns: string[]) {
const projectIndex = columns.indexOf('Project');
if (projectIndex === -1) {
return columns;
@@ -132,5 +132,5 @@ export interface ChangeTableMixinInterface {
config: ServerInfo,
experiments: string[]
): string[];
getVisibleColumns(columns: string[]): string[];
renameProjectToRepoColumn(columns: string[]): string[];
}

View File

@@ -92,15 +92,16 @@ suite('gr-change-table-mixin tests', () => {
assert.isTrue(element.isColumnHidden(columnToCheck, columnsToDisplay));
});
test('getVisibleColumns maps Project to Repo', () => {
test('renameProjectToRepoColumn maps Project to Repo', () => {
const columns = [
'Subject',
'Status',
'Owner',
];
assert.deepEqual(element.getVisibleColumns(columns), columns.slice(0));
assert.deepEqual(element.renameProjectToRepoColumn(columns),
columns.slice(0));
assert.deepEqual(
element.getVisibleColumns(columns.concat(['Project'])),
element.renameProjectToRepoColumn(columns.concat(['Project'])),
columns.slice(0).concat(['Repo']));
});
});