fix(registries): Cannot read properties of null error on change of namespace EE-3747 (#7363)

pull/7400/head
Prabhat Khera 2022-08-02 14:39:53 +12:00 committed by GitHub
parent 2c25e1d48e
commit fb3d333453
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 5 deletions

View File

@ -26,10 +26,13 @@ class porImageRegistryController {
} }
isKnownRegistry(registry) { isKnownRegistry(registry) {
return !(registry instanceof DockerHubViewModel) && registry.URL; return registry && !(registry instanceof DockerHubViewModel) && registry.URL;
} }
getRegistryURL(registry) { getRegistryURL(registry) {
if (!registry) {
return;
}
let url = registry.URL; let url = registry.URL;
if (registry.Type === RegistryTypes.GITLAB) { if (registry.Type === RegistryTypes.GITLAB) {
url = registry.URL + '/' + registry.Gitlab.ProjectPath; url = registry.URL + '/' + registry.Gitlab.ProjectPath;
@ -54,12 +57,12 @@ class porImageRegistryController {
} }
isDockerHubRegistry() { isDockerHubRegistry() {
return this.model.UseRegistry && (this.model.Registry.Type === RegistryTypes.DOCKERHUB || this.model.Registry.Type === RegistryTypes.ANONYMOUS); return this.model.UseRegistry && this.model.Registry && (this.model.Registry.Type === RegistryTypes.DOCKERHUB || this.model.Registry.Type === RegistryTypes.ANONYMOUS);
} }
async onRegistryChange() { async onRegistryChange() {
this.prepareAutocomplete(); this.prepareAutocomplete();
if (this.model.Registry.Type === RegistryTypes.GITLAB && this.model.Image) { if (this.model.Registry && this.model.Registry.Type === RegistryTypes.GITLAB && this.model.Image) {
this.model.Image = _.replace(this.model.Image, this.model.Registry.Gitlab.ProjectPath, ''); this.model.Image = _.replace(this.model.Image, this.model.Registry.Gitlab.ProjectPath, '');
} }
} }
@ -71,7 +74,7 @@ class porImageRegistryController {
} }
displayedRegistryURL() { displayedRegistryURL() {
return this.getRegistryURL(this.model.Registry) || 'docker.io'; return (this.model.Registry && this.getRegistryURL(this.model.Registry)) || 'docker.io';
} }
async reloadRegistries() { async reloadRegistries() {
@ -90,7 +93,7 @@ class porImageRegistryController {
this.registries.splice(0, 0, this.defaultRegistry); this.registries.splice(0, 0, this.defaultRegistry);
} }
const id = this.model.Registry.Id; const id = this.model.Registry && this.model.Registry.Id;
const registry = _.find(this.registries, { Id: id }); const registry = _.find(this.registries, { Id: id });
if (!registry) { if (!registry) {
this.model.Registry = showDefaultRegistry ? this.defaultRegistry : this.registries[0]; this.model.Registry = showDefaultRegistry ? this.defaultRegistry : this.registries[0];