Merge changes I13c3dd56,I156e7721
* changes: Rename getVisibleColumns method to renameProjectToRepoColumn Refactor cloneMenu method in gr-settings-view
This commit is contained in:
@@ -227,7 +227,9 @@ export class GrChangeList extends ChangeTableMixin(
|
|||||||
preferences && preferences.legacycid_in_change_table
|
preferences && preferences.legacycid_in_change_table
|
||||||
);
|
);
|
||||||
if (preferences.change_table && preferences.change_table.length > 0) {
|
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(
|
this.visibleChangeTableColumns = this.getEnabledColumns(
|
||||||
prefColumns,
|
prefColumns,
|
||||||
config,
|
config,
|
||||||
|
@@ -241,7 +241,7 @@ export class GrSettingsView extends ChangeTableMixin(
|
|||||||
this.prefs = prefs;
|
this.prefs = prefs;
|
||||||
this._showNumber = !!prefs.legacycid_in_change_table;
|
this._showNumber = !!prefs.legacycid_in_change_table;
|
||||||
this._copyPrefs(CopyPrefsDirection.PrefsToLocalPrefs);
|
this._copyPrefs(CopyPrefsDirection.PrefsToLocalPrefs);
|
||||||
this._cloneMenu(prefs.my);
|
this._localMenu = this._cloneMenu(prefs.my);
|
||||||
this._cloneChangeTableColumns(prefs.change_table);
|
this._cloneChangeTableColumns(prefs.change_table);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -341,19 +341,14 @@ export class GrSettingsView extends ChangeTableMixin(
|
|||||||
}
|
}
|
||||||
|
|
||||||
_cloneMenu(prefs: TopMenuItemInfo[]) {
|
_cloneMenu(prefs: TopMenuItemInfo[]) {
|
||||||
const menu = [];
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
for (const item of prefs) {
|
return prefs.map(({id, ...item}) => {
|
||||||
menu.push({
|
return item;
|
||||||
name: item.name,
|
|
||||||
url: item.url,
|
|
||||||
target: item.target,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this._localMenu = menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
_cloneChangeTableColumns(changeTable: string[]) {
|
_cloneChangeTableColumns(changeTable: string[]) {
|
||||||
let columns = this.getVisibleColumns(changeTable);
|
let columns = this.renameProjectToRepoColumn(changeTable);
|
||||||
|
|
||||||
if (columns.length === 0) {
|
if (columns.length === 0) {
|
||||||
columns = this.columnNames;
|
columns = this.columnNames;
|
||||||
@@ -453,7 +448,6 @@ export class GrSettingsView extends ChangeTableMixin(
|
|||||||
|
|
||||||
_handleSaveMenu() {
|
_handleSaveMenu() {
|
||||||
this.set('prefs.my', this._localMenu);
|
this.set('prefs.my', this._localMenu);
|
||||||
this._cloneMenu(this._localMenu);
|
|
||||||
return this.restApiService.savePreferences(this.prefs).then(() => {
|
return this.restApiService.savePreferences(this.prefs).then(() => {
|
||||||
this._menuChanged = false;
|
this._menuChanged = false;
|
||||||
});
|
});
|
||||||
@@ -462,7 +456,7 @@ export class GrSettingsView extends ChangeTableMixin(
|
|||||||
_handleResetMenuButton() {
|
_handleResetMenuButton() {
|
||||||
return this.restApiService.getDefaultPreferences().then(data => {
|
return this.restApiService.getDefaultPreferences().then(data => {
|
||||||
if (data?.my) {
|
if (data?.my) {
|
||||||
this._cloneMenu(data.my);
|
this._localMenu = this._cloneMenu(data.my);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -103,7 +103,7 @@ export const ChangeTableMixin = dedupingMixin(
|
|||||||
* @return If the column was renamed, returns a new array
|
* @return If the column was renamed, returns a new array
|
||||||
* with the corrected name. Otherwise, it returns the original param.
|
* with the corrected name. Otherwise, it returns the original param.
|
||||||
*/
|
*/
|
||||||
getVisibleColumns(columns: string[]) {
|
renameProjectToRepoColumn(columns: string[]) {
|
||||||
const projectIndex = columns.indexOf('Project');
|
const projectIndex = columns.indexOf('Project');
|
||||||
if (projectIndex === -1) {
|
if (projectIndex === -1) {
|
||||||
return columns;
|
return columns;
|
||||||
@@ -132,5 +132,5 @@ export interface ChangeTableMixinInterface {
|
|||||||
config: ServerInfo,
|
config: ServerInfo,
|
||||||
experiments: string[]
|
experiments: string[]
|
||||||
): string[];
|
): string[];
|
||||||
getVisibleColumns(columns: string[]): string[];
|
renameProjectToRepoColumn(columns: string[]): string[];
|
||||||
}
|
}
|
||||||
|
@@ -92,15 +92,16 @@ suite('gr-change-table-mixin tests', () => {
|
|||||||
assert.isTrue(element.isColumnHidden(columnToCheck, columnsToDisplay));
|
assert.isTrue(element.isColumnHidden(columnToCheck, columnsToDisplay));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getVisibleColumns maps Project to Repo', () => {
|
test('renameProjectToRepoColumn maps Project to Repo', () => {
|
||||||
const columns = [
|
const columns = [
|
||||||
'Subject',
|
'Subject',
|
||||||
'Status',
|
'Status',
|
||||||
'Owner',
|
'Owner',
|
||||||
];
|
];
|
||||||
assert.deepEqual(element.getVisibleColumns(columns), columns.slice(0));
|
assert.deepEqual(element.renameProjectToRepoColumn(columns),
|
||||||
|
columns.slice(0));
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
element.getVisibleColumns(columns.concat(['Project'])),
|
element.renameProjectToRepoColumn(columns.concat(['Project'])),
|
||||||
columns.slice(0).concat(['Repo']));
|
columns.slice(0).concat(['Repo']));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user