Fix issue in gr-repo with hasConfigChanged being triggered on page load

Change-Id: I572ce021261a99f54c0763f1e6c449ac53eff2c7
diff --git a/polygerrit-ui/app/elements/admin/gr-repo/gr-repo.ts b/polygerrit-ui/app/elements/admin/gr-repo/gr-repo.ts
index 89d798a..27ebf06 100644
--- a/polygerrit-ui/app/elements/admin/gr-repo/gr-repo.ts
+++ b/polygerrit-ui/app/elements/admin/gr-repo/gr-repo.ts
@@ -50,6 +50,8 @@
 import {deepClone} from '../../../utils/object-util';
 import {LitElement, PropertyValues, css, html} from 'lit';
 import {customElement, property, state} from 'lit/decorators';
+import {preferences$} from '../../../services/user/user-model';
+import {subscribe} from '../../lit/subscription-controller';
 
 const STATES = {
   active: {value: ProjectState.ACTIVE, label: 'Active'},
@@ -98,13 +100,13 @@
   @property({type: String})
   repo?: RepoName;
 
-  /* private but used in test */
+  // private but used in test
   @state() loading = true;
 
-  /* private but used in test */
+  // private but used in test
   @state() repoConfig?: ConfigInfo;
 
-  /* private but used in test */
+  // private but used in test
   @state() readOnly = true;
 
   @state() private states = Object.values(STATES);
@@ -113,7 +115,7 @@
 
   @state() private selectedScheme?: string;
 
-  /* private but used in test */
+  // private but used in test
   @state() schemesObj?: SchemesInfoMap;
 
   @state() private weblinks: WebLinkInfo[] = [];
@@ -122,9 +124,18 @@
 
   private readonly restApiService = appContext.restApiService;
 
+  constructor() {
+    super();
+    subscribe(this, preferences$, prefs => {
+      if (prefs?.download_scheme) {
+        // Note (issue 5180): normalize the download scheme with lower-case.
+        this.selectedScheme = prefs.download_scheme.toLowerCase();
+      }
+    });
+  }
+
   override connectedCallback() {
     super.connectedCallback();
-    this.loadRepo();
 
     fireTitleChange(this, `${this.repo}`);
   }
@@ -731,12 +742,15 @@
   }
 
   override willUpdate(changedProperties: PropertyValues) {
+    if (changedProperties.has('repo')) {
+      this.loadRepo();
+    }
     if (changedProperties.has('schemesObj')) {
       this.computeSchemesAndDefault();
     }
   }
 
-  /* private but used in test */
+  // private but used in test
   computePluginData() {
     if (!this.repoConfig || !this.repoConfig.plugin_config) return [];
     const pluginConfig = this.repoConfig.plugin_config;
@@ -745,7 +759,7 @@
     });
   }
 
-  /* private but used in test */
+  // private but used in test
   async loadRepo() {
     if (!this.repo) return Promise.resolve();
 
@@ -760,12 +774,6 @@
         if (loggedIn) {
           const repo = this.repo;
           if (!repo) throw new Error('undefined repo');
-          this.restApiService.getPreferences().then(prefs => {
-            if (prefs?.download_scheme) {
-              // Note (issue 5180): normalize the download scheme with lower-case.
-              this.selectedScheme = prefs.download_scheme.toLowerCase();
-            }
-          });
           this.restApiService.getRepo(repo).then(repo => {
             if (!repo?.web_links) return;
             this.weblinks = repo.web_links;
@@ -827,7 +835,7 @@
     await Promise.all(promises);
   }
 
-  /* private but used in test */
+  // private but used in test
   formatBooleanSelect(item?: InheritedBooleanInfo) {
     if (!item) return [];
     let inheritLabel = 'Inherit';
@@ -879,7 +887,7 @@
     ];
   }
 
-  /* private but used in test */
+  // private but used in test
   formatRepoConfigForSave(repoConfig?: ConfigInfo): ConfigInput {
     if (!repoConfig) return {};
     const configInputObj: ConfigInput = {};
@@ -908,7 +916,7 @@
     return configInputObj;
   }
 
-  /* private but used in test */
+  // private but used in test
   async handleSaveRepoConfig() {
     if (!this.repoConfig || !this.repo)
       return Promise.reject(new Error('undefined repoConfig or repo'));
@@ -1059,7 +1067,7 @@
   }
 
   private computeSchemesAndDefault() {
-    this.schemes = !this.schemesObj ? [] : Object.keys(this.schemesObj);
+    this.schemes = !this.schemesObj ? [] : Object.keys(this.schemesObj).sort();
     if (this.schemes.length > 0) {
       if (!this.selectedScheme || !this.schemes.includes(this.selectedScheme)) {
         this.selectedScheme = this.schemes.sort()[0];
@@ -1095,7 +1103,7 @@
     return GerritNav.getUrlForProjectChanges(name as RepoName);
   }
 
-  /* private but used in test */
+  // private but used in test
   handlePluginConfigChanged({
     detail: {name, config},
   }: {