summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaladox none <thomasmulhall410@yahoo.com>2018-10-12 13:47:18 +0000
committerPaladox none <thomasmulhall410@yahoo.com>2018-11-14 11:44:49 +0000
commit7fc10a364a760ad630ed952017298f254bc28f4b (patch)
treeda27cae3d2d17a2946c757c87d8d466b48a86463
parent12f16056cac955757a7628302fdca2d667ee2ef2 (diff)
Reload repo and group list after creating a repo or group
Bug: Issue 8701 Change-Id: I2b9bef67cc0c4ca8e5f379609ba473f30c4344fb (cherry picked from commit 02fab7a08f8c2df44cd8aff1e8ef15aa9d252912)
-rw-r--r--polygerrit-ui/app/elements/admin/gr-admin-group-list/gr-admin-group-list.js11
-rw-r--r--polygerrit-ui/app/elements/admin/gr-repo-list/gr-repo-list.js11
-rw-r--r--polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js76
-rw-r--r--polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.html93
4 files changed, 173 insertions, 18 deletions
diff --git a/polygerrit-ui/app/elements/admin/gr-admin-group-list/gr-admin-group-list.js b/polygerrit-ui/app/elements/admin/gr-admin-group-list/gr-admin-group-list.js
index 5a463beb04..4073798f23 100644
--- a/polygerrit-ui/app/elements/admin/gr-admin-group-list/gr-admin-group-list.js
+++ b/polygerrit-ui/app/elements/admin/gr-admin-group-list/gr-admin-group-list.js
@@ -128,8 +128,17 @@
});
},
+ _refreshGroupsList() {
+ this.$.restAPI.invalidateGroupsCache(this._filter,
+ this._groupsPerPage, this._offset);
+ return this._getGroups(this._filter, this._groupsPerPage,
+ this._offset);
+ },
+
_handleCreateGroup() {
- this.$.createNewModal.handleCreateGroup();
+ this.$.createNewModal.handleCreateGroup().then(() => {
+ this._refreshGroupsList();
+ });
},
_handleCloseCreate() {
diff --git a/polygerrit-ui/app/elements/admin/gr-repo-list/gr-repo-list.js b/polygerrit-ui/app/elements/admin/gr-repo-list/gr-repo-list.js
index 4b82e5755e..116f084faf 100644
--- a/polygerrit-ui/app/elements/admin/gr-repo-list/gr-repo-list.js
+++ b/polygerrit-ui/app/elements/admin/gr-repo-list/gr-repo-list.js
@@ -129,8 +129,17 @@
});
},
+ _refreshReposList() {
+ this.$.restAPI.invalidateReposCache(this._filter,
+ this._reposPerPage, this._offset);
+ return this._getRepos(this._filter, this._reposPerPage,
+ this._offset);
+ },
+
_handleCreateRepo() {
- this.$.createNewModal.handleCreateRepo();
+ this.$.createNewModal.handleCreateRepo().then(() => {
+ this._refreshReposList();
+ });
},
_handleCloseCreate() {
diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
index 2a1ad9eec1..a736de20ca 100644
--- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
+++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
@@ -169,6 +169,16 @@
delete(key) {
this._cache().delete(key);
}
+
+ invalidatePrefix(prefix) {
+ const newMap = new Map();
+ for (const [key, value] of this._cache().entries()) {
+ if (!key.startsWith(prefix)) {
+ newMap.set(key, value);
+ }
+ }
+ this._data.set(window.CANONICAL_PATH, newMap);
+ }
}
Polymer({
@@ -1207,6 +1217,20 @@
return this._sharedFetchPromises[req.url];
},
+ /**
+ * @param {string} prefix
+ */
+ _invalidateSharedFetchPromisesPrefix(prefix) {
+ const newObject = {};
+ Object.entries(this._sharedFetchPromises).forEach(([key, value]) => {
+ if (!key.startsWith(prefix)) {
+ newObject[key] = value;
+ }
+ });
+ this._sharedFetchPromises = newObject;
+ this._cache.invalidatePrefix(prefix);
+ },
+
_isNarrowScreen() {
return window.innerWidth < MAX_UNIFIED_DEFAULT_WINDOW_WIDTH_PX;
},
@@ -1527,25 +1551,20 @@
* @param {string} filter
* @param {number} groupsPerPage
* @param {number=} opt_offset
- * @return {!Promise<?Object>}
*/
- getGroups(filter, groupsPerPage, opt_offset) {
+ _getGroupsUrl(filter, groupsPerPage, opt_offset) {
const offset = opt_offset || 0;
- return this._fetchSharedCacheURL({
- url: `/groups/?n=${groupsPerPage + 1}&S=${offset}` +
- this._computeFilter(filter),
- anonymizedUrl: '/groups/?*',
- });
+ return `/groups/?n=${groupsPerPage + 1}&S=${offset}` +
+ this._computeFilter(filter);
},
/**
* @param {string} filter
* @param {number} reposPerPage
* @param {number=} opt_offset
- * @return {!Promise<?Object>}
*/
- getRepos(filter, reposPerPage, opt_offset) {
+ _getReposUrl(filter, reposPerPage, opt_offset) {
const defaultFilter = 'state:active OR state:read-only';
const namePartDelimiters = /[@.\-\s\/_]/g;
const offset = opt_offset || 0;
@@ -1572,11 +1591,46 @@
filter = filter.trim();
const encodedFilter = encodeURIComponent(filter);
+ return `/projects/?n=${reposPerPage + 1}&S=${offset}` +
+ `&query=${encodedFilter}`;
+ },
+
+ invalidateGroupsCache() {
+ this._invalidateSharedFetchPromisesPrefix('/groups/?');
+ },
+
+ invalidateReposCache(filter, reposPerPage, opt_offset) {
+ this._invalidateSharedFetchPromisesPrefix('/projects/?');
+ },
+
+ /**
+ * @param {string} filter
+ * @param {number} groupsPerPage
+ * @param {number=} opt_offset
+ * @return {!Promise<?Object>}
+ */
+ getGroups(filter, groupsPerPage, opt_offset) {
+ const url = this._getGroupsUrl(filter, groupsPerPage, opt_offset);
+
+ return this._fetchSharedCacheURL({
+ url,
+ anonymizedUrl: '/groups/?*',
+ });
+ },
+
+ /**
+ * @param {string} filter
+ * @param {number} reposPerPage
+ * @param {number=} opt_offset
+ * @return {!Promise<?Object>}
+ */
+ getRepos(filter, reposPerPage, opt_offset) {
+ const url = this._getReposUrl(filter, reposPerPage, opt_offset);
+
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
// supports it.
return this._fetchSharedCacheURL({
- url: `/projects/?n=${reposPerPage + 1}&S=${offset}` +
- `&query=${encodedFilter}`,
+ url,
anonymizedUrl: '/projects/?*',
});
},
diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.html b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.html
index eaac5efd69..b2bf42ba87 100644
--- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.html
+++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.html
@@ -96,6 +96,18 @@ limitations under the License.
});
});
+ test('cache invalidation', () => {
+ element._cache.set('/foo/bar', 1);
+ element._cache.set('/bar', 2);
+ element._sharedFetchPromises['/foo/bar'] = 3;
+ element._sharedFetchPromises['/bar'] = 4;
+ element._invalidateSharedFetchPromisesPrefix('/foo/');
+ assert.isFalse(element._cache.has('/foo/bar'));
+ assert.isTrue(element._cache.has('/bar'));
+ assert.isUndefined(element._sharedFetchPromises['/foo/bar']);
+ assert.strictEqual(4, element._sharedFetchPromises['/bar']);
+ });
+
test('params are properly encoded', () => {
let url = element._urlWithParams('/path/', {
sp: 'hola',
@@ -935,6 +947,31 @@ limitations under the License.
});
});
+ test('normal use', () => {
+ const defaultQuery = 'state%3Aactive%20OR%20state%3Aread-only';
+
+ assert.equal(element._getReposUrl('test', 25),
+ '/projects/?n=26&S=0&query=test');
+
+ assert.equal(element._getReposUrl(null, 25),
+ `/projects/?n=26&S=0&query=${defaultQuery}`);
+
+ assert.equal(element._getReposUrl('test', 25, 25),
+ '/projects/?n=26&S=25&query=test');
+ });
+
+ test('invalidateReposCache', () => {
+ const url = '/projects/?n=26&S=0&query=test';
+
+ element._cache.set(url, {});
+
+ element.invalidateReposCache('test', 25);
+
+ assert.isUndefined(element._sharedFetchPromises[url]);
+
+ assert.isFalse(element._cache.has(url));
+ });
+
suite('getRepos', () => {
const defaultQuery = 'state%3Aactive%20OR%20state%3Aread-only';
@@ -999,11 +1036,57 @@ limitations under the License.
});
});
- test('getGroups filter regex', () => {
- sandbox.stub(element, '_fetchSharedCacheURL');
- element.getGroups('^test.*', 25);
- assert.equal(element._fetchSharedCacheURL.lastCall.args[0].url,
- '/groups/?n=26&S=0&r=%5Etest.*');
+ test('_getGroupsUrl normal use', () => {
+ assert.equal(element._getGroupsUrl('test', 25),
+ '/groups/?n=26&S=0&m=test');
+
+ assert.equal(element._getGroupsUrl(null, 25),
+ '/groups/?n=26&S=0');
+
+ assert.equal(element._getGroupsUrl('test', 25, 25),
+ '/groups/?n=26&S=25&m=test');
+ });
+
+ test('invalidateGroupsCache', () => {
+ const url = '/groups/?n=26&S=0&m=test';
+
+ element._cache.set(url, {});
+
+ element.invalidateGroupsCache('test', 25);
+
+ assert.isUndefined(element._sharedFetchPromises[url]);
+
+ assert.isFalse(element._cache.has(url));
+ });
+
+ suite('getGroups', () => {
+ setup(() => {
+ sandbox.stub(element, '_fetchSharedCacheURL');
+ });
+
+ test('normal use', () => {
+ element.getGroups('test', 25);
+ assert.equal(element._fetchSharedCacheURL.lastCall.args[0].url,
+ '/groups/?n=26&S=0&m=test');
+
+ element.getGroups(null, 25);
+ assert.equal(element._fetchSharedCacheURL.lastCall.args[0].url,
+ '/groups/?n=26&S=0');
+
+ element.getGroups('test', 25, 25);
+ assert.equal(element._fetchSharedCacheURL.lastCall.args[0].url,
+ '/groups/?n=26&S=25&m=test');
+ });
+
+ test('regex', () => {
+ element.getGroups('^test.*', 25);
+ assert.equal(element._fetchSharedCacheURL.lastCall.args[0].url,
+ '/groups/?n=26&S=0&r=%5Etest.*');
+
+ element.getGroups('^test.*', 25, 25);
+ assert.equal(element._fetchSharedCacheURL.lastCall.args[0].url,
+ '/groups/?n=26&S=25&r=%5Etest.*');
+ });
});
test('gerrit auth is used', () => {