gr-file-list-header: Use change-model for fetching latest patchNum
Release-Notes: skip
Change-Id: If522e164a1de62078546253d57849099b3d90577
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 2246671..10ac3bf 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
@@ -1523,7 +1523,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 69297f6..f391d18 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';
@@ -48,9 +48,6 @@
@property({type: Object})
account: AccountInfo | undefined;
- @property({type: Array})
- allPatchSets?: PatchSet[];
-
@property({type: Object})
change: ChangeInfo | undefined;
@@ -72,6 +69,8 @@
@property({type: String})
filesExpanded?: FilesExpandedState;
+ @state() latestPatchNum?: PatchSetNumber;
+
@state() patchNum?: PatchSetNum;
@state() basePatchNum?: BasePatchSetNum;
@@ -132,6 +131,11 @@
() => this.getChangeModel().basePatchNum$,
x => (this.basePatchNum = x)
);
+ subscribe(
+ this,
+ () => this.getChangeModel().latestPatchNum$,
+ x => (this.latestPatchNum = x)
+ );
}
static override styles = [
@@ -251,10 +255,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);
return html`
<div class="patchInfo-header ${editModeClass} ${patchInfoClass}">
@@ -416,9 +417,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 6c2282b..831366a 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';
@@ -250,23 +249,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', () => {
@@ -277,11 +269,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(