gr-file-list-header: Use change-model for fetching latest patchNum
Release-Notes: skip
Change-Id: If522e164a1de62078546253d57849099b3d90577
(cherry picked from commit 101bebaf9a389c863f44ad2054741a2ecab80fef)
diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts
index 27c36ba..3adad7a 100644
--- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts
+++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts
@@ -1582,7 +1582,6 @@
<gr-file-list-header
id="fileListHeader"
.account=${this.account}
- .allPatchSets=${this.allPatchSets}
.change=${this.change}
.changeNum=${this.changeNum}
.commitInfo=${this.commitInfo}
diff --git a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.ts b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.ts
index 481a488..5debc0c 100644
--- a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.ts
+++ b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.ts
@@ -12,7 +12,6 @@
import '../gr-commit-info/gr-commit-info';
import {FilesExpandedState} from '../gr-file-list-constants';
import {navigationToken} from '../../core/gr-navigation/gr-navigation';
-import {computeLatestPatchNum, PatchSet} from '../../../utils/patch-set-util';
import {property, customElement, query, state} from 'lit/decorators.js';
import {
AccountInfo,
@@ -21,6 +20,7 @@
CommitInfo,
ServerInfo,
BasePatchSetNum,
+ PatchSetNumber,
} from '../../../types/common';
import {DiffPreferencesInfo} from '../../../types/diff';
import {GrDiffModeSelector} from '../../../embed/diff/gr-diff-mode-selector/gr-diff-mode-selector';
@@ -63,9 +63,6 @@
@property({type: Object})
account: AccountInfo | undefined;
- @property({type: Array})
- allPatchSets?: PatchSet[];
-
@property({type: Object})
change: ChangeInfo | undefined;
@@ -87,6 +84,8 @@
@property({type: String})
filesExpanded?: FilesExpandedState;
+ @state() latestPatchNum?: PatchSetNumber;
+
@state() patchNum?: PatchSetNum;
@state() basePatchNum?: BasePatchSetNum;
@@ -147,6 +146,11 @@
() => this.getChangeModel().basePatchNum$,
x => (this.basePatchNum = x)
);
+ subscribe(
+ this,
+ () => this.getChangeModel().latestPatchNum$,
+ x => (this.latestPatchNum = x)
+ );
}
static override styles = [
@@ -266,10 +270,7 @@
return;
}
const editModeClass = this.computeEditModeClass(this.editMode);
- const patchInfoClass = this.computePatchInfoClass(
- this.patchNum,
- this.allPatchSets
- );
+ const patchInfoClass = this.computePatchInfoClass();
const expandedClass = this.computeExpandedClass(this.filesExpanded);
const prefsButtonHidden = this.computePrefsButtonHidden(
this.diffPrefs,
@@ -443,9 +444,8 @@
return editMode ? 'editMode' : '';
}
- computePatchInfoClass(patchNum?: PatchSetNum, allPatchSets?: PatchSet[]) {
- const latestNum = computeLatestPatchNum(allPatchSets);
- if (patchNum === latestNum) {
+ computePatchInfoClass() {
+ if (this.patchNum === this.latestPatchNum) {
return '';
}
return 'patchInfoOldPatchSet';
diff --git a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header_test.ts b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header_test.ts
index bfe91da..f2121b3 100644
--- a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header_test.ts
+++ b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header_test.ts
@@ -23,7 +23,6 @@
PatchSetNumber,
} from '../../../types/common';
import {ChangeInfo, ChangeStatus} from '../../../api/rest-api';
-import {PatchSet} from '../../../utils/patch-set-util';
import {createDefaultDiffPrefs} from '../../../constants/constants';
import {fixture, html, assert} from '@open-wc/testing';
import {GrButton} from '../../shared/gr-button/gr-button';
@@ -253,23 +252,16 @@
});
test('class is applied to file list on old patch set', () => {
- const allPatchSets: PatchSet[] = [
- {num: 4 as PatchSetNumber, desc: undefined, sha: ''},
- {num: 2 as PatchSetNumber, desc: undefined, sha: ''},
- {num: 1 as PatchSetNumber, desc: undefined, sha: ''},
- ];
- assert.equal(
- element.computePatchInfoClass(1 as PatchSetNum, allPatchSets),
- 'patchInfoOldPatchSet'
- );
- assert.equal(
- element.computePatchInfoClass(2 as PatchSetNum, allPatchSets),
- 'patchInfoOldPatchSet'
- );
- assert.equal(
- element.computePatchInfoClass(4 as PatchSetNum, allPatchSets),
- ''
- );
+ element.latestPatchNum = 4 as PatchSetNumber;
+
+ element.patchNum = 1 as PatchSetNumber;
+ assert.equal(element.computePatchInfoClass(), 'patchInfoOldPatchSet');
+
+ element.patchNum = 2 as PatchSetNumber;
+ assert.equal(element.computePatchInfoClass(), 'patchInfoOldPatchSet');
+
+ element.patchNum = 4 as PatchSetNumber;
+ assert.equal(element.computePatchInfoClass(), '');
});
suite('editMode behavior', () => {
@@ -280,11 +272,6 @@
test('patch specific elements', async () => {
element.editMode = true;
- element.allPatchSets = [
- {num: 1 as PatchSetNumber, desc: undefined, sha: ''},
- {num: 2 as PatchSetNumber, desc: undefined, sha: ''},
- {num: 3 as PatchSetNumber, desc: undefined, sha: ''},
- ];
await element.updateComplete;
assert.isFalse(