Update gr-list-view to support optional create-new buton
The create-new button will be used for list views that allow an item
of the same type as the list to be created (project, branches, tags,
etc).
Whether or not the create-new should be shown is up to the parent of
gr-list-view, as it depends on account capabilities that it is aware of
and varies per list.
The modal is included in <content></content> the same way that the table
is, as it also varies per list view type. The IDs and events fired must
be constant across list views implementing this.
Change-Id: Ifb76cb47867389dafcca5775d00d117d8e321f53
diff --git a/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view.html b/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view.html
index b471d55..01c4cde 100644
--- a/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view.html
+++ b/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view.html
@@ -13,23 +13,29 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<link rel="import" href="./gr-styled-table.html">
-<link rel="import" href="../../../behaviors/base-url-behavior/base-url-behavior.html">
-<link rel="import" href="../../../behaviors/gr-url-encoding-behavior.html">
<link rel="import" href="../../../bower_components/polymer/polymer.html">
+<link rel="import" href="../../../behaviors/base-url-behavior/base-url-behavior.html">
+<link rel="import" href="../../../behaviors/gr-url-encoding-behavior.html">
<link rel="import" href="../../../styles/shared-styles.html">
+<link rel="import" href="../../shared/gr-button/gr-button.html">
+<link rel="import" href="gr-styled-table.html">
<dom-module id="gr-list-view">
<template>
<style include="shared-styles">
- #filterContainer {
- margin: 1em;
- }
#filter {
font-size: 1em;
max-width: 25em;
}
+ #topContainer {
+ display: flex;
+ justify-content: space-between;
+ margin: 1em;
+ }
+ #createNewContainer:not(.show) {
+ display: none;
+ }
a {
color: var(--default-text-color);
text-decoration: none;
@@ -48,12 +54,20 @@
margin-right: .5em;
}
</style>
- <div id="filterContainer">
- <label>Filter:</label>
- <input is="iron-input"
- type="text"
- id="filter"
- bind-value="{{_filter}}">
+ <div id="topContainer">
+ <div>
+ <label>Filter:</label>
+ <input is="iron-input"
+ type="text"
+ id="filter"
+ bind-value="{{_filter}}">
+ </div>
+ <div id="createNewContainer"
+ class$="[[_computeCreateClass(createNew)]]">
+ <gr-button id="createNew" on-tap="_createNewItem">
+ Create New
+ </gr-button>
+ </div>
</div>
<gr-styled-table>
<content></content>
diff --git a/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view.js b/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view.js
index 4a45352..ce00c3f 100644
--- a/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view.js
+++ b/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view.js
@@ -20,6 +20,7 @@
is: 'gr-list-view',
properties: {
+ createNew: Boolean,
items: Array,
itemsPerPage: Number,
_filter: {
@@ -55,6 +56,10 @@
}, REQUEST_DEBOUNCE_INTERVAL_MS);
},
+ _createNewItem() {
+ this.fire('create-clicked');
+ },
+
_computeNavLink(offset, direction, itemsPerPage, filter) {
// Offset could be a string when passed from the router.
offset = +(offset || 0);
@@ -69,6 +74,10 @@
return href;
},
+ _computeCreateClass(createNew) {
+ return createNew ? 'show' : '';
+ },
+
_hidePrevArrow(offset) {
return offset === 0;
},
diff --git a/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view_test.html b/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view_test.html
index e4dc288..06a3065 100644
--- a/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view_test.html
+++ b/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view_test.html
@@ -107,5 +107,23 @@
assert.isFalse(element._hidePrevArrow(offset));
});
});
+
+ test('createNew link appears correctly', () => {
+ assert.isFalse(element.$$('#createNewContainer').classList
+ .contains('show'));
+ element.createNew = true;
+ flushAsynchronousOperations();
+ assert.isTrue(element.$$('#createNewContainer').classList
+ .contains('show'));
+ });
+
+ test('fires create clicked event when button tapped', () => {
+ const clickHandler = sandbox.stub();
+ element.addEventListener('create-clicked', clickHandler);
+ element.createNew = true;
+ flushAsynchronousOperations();
+ MockInteractions.tap(element.$$('#createNew'));
+ assert.isTrue(clickHandler.called);
+ });
});
</script>