Reload repo and group list after creating a repo or group
Bug: Issue 8701 Change-Id: I2b9bef67cc0c4ca8e5f379609ba473f30c4344fb
This commit is contained in:

committed by
Logan Hanks

parent
25828e08e0
commit
02fab7a08f
@@ -128,8 +128,17 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_refreshGroupsList() {
|
||||||
|
this.$.restAPI.invalidateGroupsCache(this._filter,
|
||||||
|
this._groupsPerPage, this._offset);
|
||||||
|
return this._getGroups(this._filter, this._groupsPerPage,
|
||||||
|
this._offset);
|
||||||
|
},
|
||||||
|
|
||||||
_handleCreateGroup() {
|
_handleCreateGroup() {
|
||||||
this.$.createNewModal.handleCreateGroup();
|
this.$.createNewModal.handleCreateGroup().then(() => {
|
||||||
|
this._refreshGroupsList();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_handleCloseCreate() {
|
_handleCloseCreate() {
|
||||||
|
@@ -125,8 +125,17 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_refreshReposList() {
|
||||||
|
this.$.restAPI.invalidateReposCache(this._filter,
|
||||||
|
this._reposPerPage, this._offset);
|
||||||
|
return this._getRepos(this._filter, this._reposPerPage,
|
||||||
|
this._offset);
|
||||||
|
},
|
||||||
|
|
||||||
_handleCreateRepo() {
|
_handleCreateRepo() {
|
||||||
this.$.createNewModal.handleCreateRepo();
|
this.$.createNewModal.handleCreateRepo().then(() => {
|
||||||
|
this._refreshReposList();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_handleCloseCreate() {
|
_handleCloseCreate() {
|
||||||
|
@@ -169,6 +169,16 @@
|
|||||||
delete(key) {
|
delete(key) {
|
||||||
this._cache().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({
|
Polymer({
|
||||||
@@ -1207,6 +1217,20 @@
|
|||||||
return this._sharedFetchPromises[req.url];
|
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() {
|
_isNarrowScreen() {
|
||||||
return window.innerWidth < MAX_UNIFIED_DEFAULT_WINDOW_WIDTH_PX;
|
return window.innerWidth < MAX_UNIFIED_DEFAULT_WINDOW_WIDTH_PX;
|
||||||
},
|
},
|
||||||
@@ -1527,25 +1551,20 @@
|
|||||||
* @param {string} filter
|
* @param {string} filter
|
||||||
* @param {number} groupsPerPage
|
* @param {number} groupsPerPage
|
||||||
* @param {number=} opt_offset
|
* @param {number=} opt_offset
|
||||||
* @return {!Promise<?Object>}
|
|
||||||
*/
|
*/
|
||||||
getGroups(filter, groupsPerPage, opt_offset) {
|
_getGroupsUrl(filter, groupsPerPage, opt_offset) {
|
||||||
const offset = opt_offset || 0;
|
const offset = opt_offset || 0;
|
||||||
|
|
||||||
return this._fetchSharedCacheURL({
|
return `/groups/?n=${groupsPerPage + 1}&S=${offset}` +
|
||||||
url: `/groups/?n=${groupsPerPage + 1}&S=${offset}` +
|
this._computeFilter(filter);
|
||||||
this._computeFilter(filter),
|
|
||||||
anonymizedUrl: '/groups/?*',
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} filter
|
* @param {string} filter
|
||||||
* @param {number} reposPerPage
|
* @param {number} reposPerPage
|
||||||
* @param {number=} opt_offset
|
* @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 defaultFilter = 'state:active OR state:read-only';
|
||||||
const namePartDelimiters = /[@.\-\s\/_]/g;
|
const namePartDelimiters = /[@.\-\s\/_]/g;
|
||||||
const offset = opt_offset || 0;
|
const offset = opt_offset || 0;
|
||||||
@@ -1572,11 +1591,46 @@
|
|||||||
filter = filter.trim();
|
filter = filter.trim();
|
||||||
const encodedFilter = encodeURIComponent(filter);
|
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
|
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
|
||||||
// supports it.
|
// supports it.
|
||||||
return this._fetchSharedCacheURL({
|
return this._fetchSharedCacheURL({
|
||||||
url: `/projects/?n=${reposPerPage + 1}&S=${offset}` +
|
url,
|
||||||
`&query=${encodedFilter}`,
|
|
||||||
anonymizedUrl: '/projects/?*',
|
anonymizedUrl: '/projects/?*',
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@@ -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', () => {
|
test('params are properly encoded', () => {
|
||||||
let url = element._urlWithParams('/path/', {
|
let url = element._urlWithParams('/path/', {
|
||||||
sp: 'hola',
|
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', () => {
|
suite('getRepos', () => {
|
||||||
const defaultQuery = 'state%3Aactive%20OR%20state%3Aread-only';
|
const defaultQuery = 'state%3Aactive%20OR%20state%3Aread-only';
|
||||||
|
|
||||||
@@ -999,11 +1036,57 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getGroups filter regex', () => {
|
test('_getGroupsUrl normal use', () => {
|
||||||
sandbox.stub(element, '_fetchSharedCacheURL');
|
assert.equal(element._getGroupsUrl('test', 25),
|
||||||
element.getGroups('^test.*', 25);
|
'/groups/?n=26&S=0&m=test');
|
||||||
assert.equal(element._fetchSharedCacheURL.lastCall.args[0].url,
|
|
||||||
'/groups/?n=26&S=0&r=%5Etest.*');
|
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', () => {
|
test('gerrit auth is used', () => {
|
||||||
|
Reference in New Issue
Block a user