diff options
author | Luca Milanesio <luca.milanesio@gmail.com> | 2024-04-10 19:47:50 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-04-10 19:47:50 +0000 |
commit | 163ae73f3abbadf74f5c881c13398bd90f408f6a (patch) | |
tree | 8d2702b5fa118e9e2f8d1ff953e740bba4c6c82f | |
parent | b307f5b8a66f60ebefc62ea039d08045da480f42 (diff) | |
parent | befd41e506fd24f58f400dbb28566c98349d59da (diff) |
Merge changes I9dfe61d6,I6b5457f7 into stable-3.8
* changes:
Emit value change event even when no items are matched
Fix gr-dropdown-list not updating on items change
3 files changed, 20 insertions, 12 deletions
diff --git a/polygerrit-ui/app/elements/admin/gr-admin-view/gr-admin-view.ts b/polygerrit-ui/app/elements/admin/gr-admin-view/gr-admin-view.ts index 8cadd23e31..21e032b816 100644 --- a/polygerrit-ui/app/elements/admin/gr-admin-view/gr-admin-view.ts +++ b/polygerrit-ui/app/elements/admin/gr-admin-view/gr-admin-view.ts @@ -73,8 +73,6 @@ export interface AdminSubsectionLink { @customElement('gr-admin-view') export class GrAdminView extends LitElement { - private account?: AccountDetailInfo; - @state() view?: GerritView; @@ -458,13 +456,18 @@ export class GrAdminView extends LitElement { async reload() { try { this.reloading = true; + // There is async barrier inside reload function, we need to clear + // subsectionLinks now, because the element might render while waiting for + // RestApi responses breaking the invariant that this.view is part of + // subsectionLinks if non-empty. + this.subsectionLinks = []; const promises: [Promise<AccountDetailInfo | undefined>, Promise<void>] = [ this.restApiService.getAccount(), this.getPluginLoader().awaitPluginsLoaded(), ]; const result = await Promise.all(promises); - this.account = result[0]; + const account = result[0]; let options: AdminNavLinksOption | undefined = undefined; if (this.repoName) { options = {repoName: this.repoName}; @@ -483,7 +486,7 @@ export class GrAdminView extends LitElement { } const res = await getAdminLinks( - this.account, + account, () => this.restApiService.getAccountCapabilities().then(capabilities => { if (!capabilities) { @@ -500,7 +503,6 @@ export class GrAdminView extends LitElement { : ''; if (!res.expandedSection) { - this.subsectionLinks = []; return; } this.subsectionLinks = [res.expandedSection] diff --git a/polygerrit-ui/app/elements/admin/gr-admin-view/gr-admin-view_test.ts b/polygerrit-ui/app/elements/admin/gr-admin-view/gr-admin-view_test.ts index 1d456c9bb6..d184f35550 100644 --- a/polygerrit-ui/app/elements/admin/gr-admin-view/gr-admin-view_test.ts +++ b/polygerrit-ui/app/elements/admin/gr-admin-view/gr-admin-view_test.ts @@ -90,10 +90,10 @@ suite('gr-admin-view tests', () => { assert.isNotOk(element.filteredLinks![0].subsection); // Groups - assert.isNotOk(element.filteredLinks![0].subsection); + assert.isNotOk(element.filteredLinks![1].subsection); // Plugins - assert.isNotOk(element.filteredLinks![0].subsection); + assert.isNotOk(element.filteredLinks![2].subsection); }); test('filteredLinks non admin authenticated', async () => { @@ -102,7 +102,7 @@ suite('gr-admin-view tests', () => { // Repos assert.isNotOk(element.filteredLinks![0].subsection); // Groups - assert.isNotOk(element.filteredLinks![0].subsection); + assert.isNotOk(element.filteredLinks![1].subsection); }); test('filteredLinks non admin unathenticated', async () => { @@ -239,6 +239,7 @@ suite('gr-admin-view tests', () => { test('Needs reload when changing from repo to group', async () => { element.repoName = 'Test Repo' as RepoName; + element.view = GerritView.REPO; stubRestApi('getAccount').returns( Promise.resolve({ name: 'test-user', @@ -255,9 +256,12 @@ suite('gr-admin-view tests', () => { const groupId = '1' as GroupId; element.view = GerritView.GROUP; element.groupViewState = {groupId, view: GerritView.GROUP}; + // Check for reload before update. This would normally be done as part of + // subscribe method that updates the view/viewState. + assert.isTrue(element.needsReload()); + element.reload(); await element.updateComplete; - assert.isTrue(element.needsReload()); assert.equal(element.groupId, groupId); }); diff --git a/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list.ts b/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list.ts index 465afce951..fb71983906 100644 --- a/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list.ts +++ b/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list.ts @@ -187,8 +187,11 @@ export class GrDropdownList extends LitElement { } protected override willUpdate(changedProperties: PropertyValues): void { + if (changedProperties.has('value') || changedProperties.has('items')) { + this.updateText(); + } if (changedProperties.has('value')) { - this.handleValueChange(); + fireNoBubble(this, 'value-change', {value: this.value}); } } @@ -307,7 +310,7 @@ export class GrDropdownList extends LitElement { }, 1); } - private handleValueChange() { + private updateText() { if (this.value === undefined || this.items === undefined) { return; } @@ -318,7 +321,6 @@ export class GrDropdownList extends LitElement { this.text = selectedObj.triggerText ? selectedObj.triggerText : selectedObj.text; - fireNoBubble(this, 'value-change', {value: this.value}); } /** |