Support any dashboard ref, not just "custom"

The dashboard list artificially filtered the list of dashboards down to
only "Default" and "Custom" refs. There was also an error in how it
sorted dashboards by ID within each section.

Bug: Issue 9903
Change-Id: I6efb64c4c03ca510cb4cc33e36534156ffcf6813
This commit is contained in:
Logan Hanks
2018-11-13 11:20:59 -08:00
committed by Paladox
parent 4d86635d50
commit bc603abc2d
2 changed files with 72 additions and 188 deletions

View File

@@ -43,24 +43,24 @@
this.$.restAPI.getRepoDashboards(this.repo, errFn).then(res => { this.$.restAPI.getRepoDashboards(this.repo, errFn).then(res => {
if (!res) { return Promise.resolve(); } if (!res) { return Promise.resolve(); }
// Flatten 2 dimenional array, and sort by id. // Group by ref and sort by id.
const dashboards = res.concat.apply([], res).sort((a, b) => const dashboards = res.concat.apply([], res).sort((a, b) =>
a.id > b.id); a.id < b.id ? -1 : 1);
const customList = dashboards.filter(a => a.ref === 'custom'); const dashboardsByRef = {};
const defaultList = dashboards.filter(a => a.ref === 'default'); dashboards.forEach(d => {
if (!dashboardsByRef[d.ref]) {
dashboardsByRef[d.ref] = [];
}
dashboardsByRef[d.ref].push(d);
});
const dashboardBuilder = []; const dashboardBuilder = [];
if (customList.length) { Object.keys(dashboardsByRef).sort().forEach(ref => {
dashboardBuilder.push({ dashboardBuilder.push({
section: 'Custom', section: ref,
dashboards: customList, dashboards: dashboardsByRef[ref],
}); });
}
if (defaultList.length) {
dashboardBuilder.push({
section: 'Default',
dashboards: defaultList,
}); });
}
this._dashboards = dashboardBuilder; this._dashboards = dashboardBuilder;
this._loading = false; this._loading = false;

View File

@@ -46,11 +46,10 @@ limitations under the License.
sandbox.restore(); sandbox.restore();
}); });
suite('with default only', () => { suite('dashboard table', () => {
setup(() => { setup(() => {
sandbox.stub(element.$.restAPI, 'getRepoDashboards').returns( sandbox.stub(element.$.restAPI, 'getRepoDashboards').returns(
Promise.resolve([ Promise.resolve([
[
{ {
id: 'default:contributor', id: 'default:contributor',
project: 'gerrit', project: 'gerrit',
@@ -72,13 +71,11 @@ limitations under the License.
}, },
], ],
}, },
],
[
{ {
id: 'default:open', id: 'custom:custom2',
project: 'gerrit', project: 'gerrit',
defining_project: 'Public-Projects', defining_project: 'Public-Projects',
ref: 'default', ref: 'custom',
path: 'open', path: 'open',
description: 'Recent open changes.', description: 'Recent open changes.',
url: '/dashboard/?params', url: '/dashboard/?params',
@@ -90,10 +87,20 @@ limitations under the License.
}, },
], ],
}, },
], {
id: 'default:abc',
project: 'gerrit',
ref: 'default',
},
{
id: 'custom:custom1',
project: 'gerrit',
ref: 'custom',
},
])); ]));
}); });
test('loading', done => {
test('loading, sections, and ordering', done => {
assert.isTrue(element._loading); assert.isTrue(element._loading);
assert.notEqual(getComputedStyle(element.$.loadingContainer).display, assert.notEqual(getComputedStyle(element.$.loadingContainer).display,
'none'); 'none');
@@ -101,143 +108,20 @@ limitations under the License.
'none'); 'none');
element.repo = 'test'; element.repo = 'test';
flush(() => { flush(() => {
assert.equal(element._dashboards.length, 1);
assert.equal(element._dashboards[0].section, 'Default');
assert.equal(element._dashboards[0].dashboards.length, 2);
assert.equal(getComputedStyle(element.$.loadingContainer).display, assert.equal(getComputedStyle(element.$.loadingContainer).display,
'none'); 'none');
assert.notEqual(getComputedStyle(element.$.dashboards).display, assert.notEqual(getComputedStyle(element.$.dashboards).display,
'none'); 'none');
done();
});
});
test('dispatched command-tap on button tap', done => {
element.repo = 'test';
flush(() => {
assert.equal(element._dashboards.length, 1);
assert.equal(element._dashboards[0].section, 'Default');
assert.equal(element._dashboards[0].dashboards.length, 2);
done();
});
});
});
suite('with custom only', () => {
setup(() => {
sandbox.stub(element.$.restAPI, 'getRepoDashboards').returns(
Promise.resolve([
[
{
id: 'custom:custom1',
project: 'gerrit',
defining_project: 'gerrit',
ref: 'custom',
path: 'contributor',
description: 'Own contributions.',
foreach: 'owner:self',
url: '/dashboard/?params',
title: 'Contributor Dashboard',
sections: [
{
name: 'Mine To Rebase',
query: 'is:open -is:mergeable',
},
{
name: 'My Recently Merged',
query: 'is:merged limit:10',
},
],
},
],
[
{
id: 'custom:custom2',
project: 'gerrit',
defining_project: 'Public-Projects',
ref: 'custom',
path: 'open',
description: 'Recent open changes.',
url: '/dashboard/?params',
title: 'Open Changes',
sections: [
{
name: 'Open Changes',
query: 'status:open project:${project} -age:7w',
},
],
},
],
]));
});
test('dispatched command-tap on button tap', done => {
element.repo = 'test';
flush(() => {
assert.equal(element._dashboards.length, 1);
assert.equal(element._dashboards[0].section, 'Custom');
assert.equal(element._dashboards[0].dashboards.length, 2);
done();
});
});
});
suite('with custom and default', () => {
setup(() => {
sandbox.stub(element.$.restAPI, 'getRepoDashboards').returns(
Promise.resolve([
[
{
id: 'default:contributor',
project: 'gerrit',
defining_project: 'gerrit',
ref: 'default',
path: 'contributor',
description: 'Own contributions.',
foreach: 'owner:self',
url: '/dashboard/?params',
title: 'Contributor Dashboard',
sections: [
{
name: 'Mine To Rebase',
query: 'is:open -is:mergeable',
},
{
name: 'My Recently Merged',
query: 'is:merged limit:10',
},
],
},
],
[
{
id: 'custom:custom2',
project: 'gerrit',
defining_project: 'Public-Projects',
ref: 'custom',
path: 'open',
description: 'Recent open changes.',
url: '/dashboard/?params',
title: 'Open Changes',
sections: [
{
name: 'Open Changes',
query: 'status:open project:${project} -age:7w',
},
],
},
],
]));
});
test('dispatched command-tap on button tap', done => {
element.repo = 'test';
flush(() => {
assert.equal(element._dashboards.length, 2); assert.equal(element._dashboards.length, 2);
assert.equal(element._dashboards[0].section, 'Custom'); assert.equal(element._dashboards[0].section, 'custom');
assert.equal(element._dashboards[1].section, 'Default'); assert.equal(element._dashboards[1].section, 'default');
assert.equal(element._dashboards[0].dashboards.length, 1);
assert.equal(element._dashboards[1].dashboards.length, 1); const dashboards = element._dashboards[0].dashboards;
assert.equal(dashboards.length, 2);
assert.equal(dashboards[0].id, 'custom:custom1');
assert.equal(dashboards[1].id, 'custom:custom2');
done(); done();
}); });
}); });