Fix flakiness for gr-repo-access_test
Change-Id: Ia52c1e01b6249a854f4884ac681e09faa07b058b
diff --git a/polygerrit-ui/app/elements/admin/gr-repo-access/gr-repo-access.ts b/polygerrit-ui/app/elements/admin/gr-repo-access/gr-repo-access.ts
index 80c58ca..411bb27 100644
--- a/polygerrit-ui/app/elements/admin/gr-repo-access/gr-repo-access.ts
+++ b/polygerrit-ui/app/elements/admin/gr-repo-access/gr-repo-access.ts
@@ -91,7 +91,7 @@
_groups?: ProjectAccessGroups;
@property({type: Object})
- _inheritsFrom?: ProjectInfo | null | {};
+ _inheritsFrom?: ProjectInfo;
@property({type: Object})
_labels?: LabelNameToLabelTypeInfoMap;
@@ -114,7 +114,7 @@
@property({type: Boolean})
_loading = true;
- private originalInheritsFrom?: ProjectInfo | null;
+ private originalInheritsFrom?: ProjectInfo;
private readonly restApiService = appContext.restApiService;
@@ -159,16 +159,13 @@
// Keep a copy of the original inherit from values separate from
// the ones data bound to gr-autocomplete, so the original value
// can be restored if the user cancels.
- this._inheritsFrom = res.inherits_from
- ? {
- ...res.inherits_from,
- }
- : null;
- this.originalInheritsFrom = res.inherits_from
- ? {
- ...res.inherits_from,
- }
- : null;
+ if (res.inherits_from) {
+ this._inheritsFrom = {...res.inherits_from};
+ this.originalInheritsFrom = {...res.inherits_from};
+ } else {
+ this._inheritsFrom = undefined;
+ this.originalInheritsFrom = undefined;
+ }
// Initialize the filter value so when the user clicks edit, the
// current value appears. If there is no parent repo, it is
// initialized as an empty string.
@@ -218,19 +215,11 @@
}
_handleUpdateInheritFrom(e: CustomEvent<{value: string}>) {
- const parentProject: ProjectInfo = {
+ this._inheritsFrom = {
+ ...(this._inheritsFrom ?? {}),
id: e.detail.value as UrlEncodedRepoName,
name: this._inheritFromFilter,
};
- if (!this._inheritsFrom) {
- this._inheritsFrom = parentProject;
- } else {
- // TODO(TS): replace with
- // this._inheritsFrom = {...this._inheritsFrom, ...parentProject};
- const projectInfo = this._inheritsFrom as ProjectInfo;
- projectInfo.id = parentProject.id;
- projectInfo.name = parentProject.name;
- }
this._handleAccessModified();
}
@@ -268,8 +257,8 @@
return weblinks && weblinks.length ? 'show' : '';
}
- _computeShowInherit(inheritsFrom?: RepoName) {
- return inheritsFrom ? 'show' : '';
+ _computeShowInherit(inheritsFrom?: ProjectInfo) {
+ return inheritsFrom?.id?.length ? 'show' : '';
}
// TODO(TS): Unclear what is model here, provide a better explanation
@@ -297,18 +286,10 @@
}
// Restore inheritFrom.
if (this._inheritsFrom) {
- // Can't assign this._inheritsFrom = {...this.originalInheritsFrom}
- // directly, because this._inheritsFrom is declared as
- // '...|null|undefined` and typescript reports error when trying
- // to access .name property (because 'name' in null and 'name' in undefined
- // lead to runtime error)
- // After migrating to Typescript v4.2 the code below can be rewritten as
- // const copy = {...this.originalInheritsFrom};
- const copy: ProjectInfo | {} = this.originalInheritsFrom
+ this._inheritsFrom = this.originalInheritsFrom
? {...this.originalInheritsFrom}
- : {};
- this._inheritsFrom = copy;
- this._inheritFromFilter = 'name' in copy ? copy.name : undefined;
+ : undefined;
+ this._inheritFromFilter = this.originalInheritsFrom?.name;
}
if (!this._local) {
return;
@@ -448,12 +429,10 @@
const originalInheritsFromId = this.originalInheritsFrom
? singleDecodeURL(this.originalInheritsFrom.id)
- : null;
- // TODO(TS): this._inheritsFrom as ProjectInfo might be a mistake.
- // _inheritsFrom can be {}
+ : undefined;
const inheritsFromId = this._inheritsFrom
- ? singleDecodeURL((this._inheritsFrom as ProjectInfo).id)
- : null;
+ ? singleDecodeURL(this._inheritsFrom.id)
+ : undefined;
const inheritFromChanged =
// Inherit from changed