ensure @Input bindings are not undefined before executing trigger logic
This commit is contained in:
parent
4750d1c5ef
commit
d5e35156e0
6 changed files with 64 additions and 53 deletions
|
@ -6,7 +6,7 @@
|
|||
section-id="namespace"
|
||||
section-title="::{{ 'Select ' + $ctrl.namespaceTitle }}"
|
||||
section-valid="$ctrl.local.selectedNamespace"
|
||||
skip-section="::$ctrl.githost == 'custom-git'">
|
||||
skip-section="$ctrl.githost == 'custom-git'">
|
||||
<div class="col-lg-7 col-md-7 col-sm-12 main-col"
|
||||
ng-if="$ctrl.local.namespaces">
|
||||
<h3>Select {{ ::$ctrl.namespaceTitle }}</h3>
|
||||
|
@ -72,7 +72,7 @@
|
|||
section-id="repo"
|
||||
section-title="Select Repository"
|
||||
section-valid="$ctrl.local.selectedRepository.full_name"
|
||||
skip-section="::$ctrl.githost == 'custom-git'">
|
||||
skip-section="$ctrl.githost == 'custom-git'">
|
||||
<div class="col-lg-7 col-md-7 col-sm-12 main-col"
|
||||
ng-if="$ctrl.local.repositories">
|
||||
<h3>Select Repository</h3>
|
||||
|
@ -164,7 +164,7 @@
|
|||
section-id="repo"
|
||||
section-title="Git Repository"
|
||||
section-valid="$ctrl.local.selectedRepository.full_name"
|
||||
skip-section="::$ctrl.githost != 'custom-git'">
|
||||
skip-section="$ctrl.githost != 'custom-git'">
|
||||
|
||||
<div class="col-lg-7 col-md-7 col-sm-12 main-col">
|
||||
<h3>Enter repository</h3>
|
||||
|
|
|
@ -31,7 +31,7 @@ describe("ManageTriggerComponent", () => {
|
|||
component.trigger = {id: "2cac6317-754e-47d4-88d3-2a50b3f09ee3", service: "github"};
|
||||
});
|
||||
|
||||
describe("ngOnInit", () => {
|
||||
describe("ngOnChanges", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
apiServiceMock.setup(mock => mock.listTriggerBuildSourceNamespaces).is(() => Promise.resolve({}));
|
||||
|
@ -40,7 +40,7 @@ describe("ManageTriggerComponent", () => {
|
|||
});
|
||||
|
||||
it("sets default values for config and selected namespace", () => {
|
||||
component.ngOnInit();
|
||||
component.ngOnChanges({});
|
||||
|
||||
expect(component.config).toEqual({});
|
||||
expect(component.local.selectedNamespace).toBe(null);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Input, Output, Component, Inject, EventEmitter, OnInit } from 'ng-metadata/core';
|
||||
import { Input, Output, Component, Inject, EventEmitter, OnChanges, SimpleChanges } from 'ng-metadata/core';
|
||||
import * as moment from 'moment';
|
||||
import { Local, Trigger, TriggerConfig, Repository, Namespace } from '../../../types/common.types';
|
||||
import { ContextChangeEvent } from '../context-path-select/context-path-select.component';
|
||||
|
@ -12,7 +12,7 @@ import { PathChangeEvent } from '../dockerfile-path-select/dockerfile-path-selec
|
|||
selector: 'manage-trigger',
|
||||
templateUrl: '/static/js/directives/ui/manage-trigger/manage-trigger.component.html'
|
||||
})
|
||||
export class ManageTriggerComponent implements OnInit {
|
||||
export class ManageTriggerComponent implements OnChanges {
|
||||
|
||||
@Input('<') public githost: string = 'custom-git';
|
||||
@Input('<') public repository: Repository;
|
||||
|
@ -43,26 +43,28 @@ export class ManageTriggerComponent implements OnInit {
|
|||
|
||||
}
|
||||
|
||||
public ngOnInit(): void {
|
||||
this.config = this.trigger.config || {};
|
||||
this.namespaceTitle = 'organization';
|
||||
this.local.selectedNamespace = null;
|
||||
if (this.githost != 'custom-git') {
|
||||
this.loadNamespaces();
|
||||
}
|
||||
public ngOnChanges(changes: SimpleChanges): void {
|
||||
if (this.githost && this.repository && this.trigger) {
|
||||
this.config = this.trigger.config || {};
|
||||
this.namespaceTitle = 'organization';
|
||||
this.local.selectedNamespace = null;
|
||||
if (this.githost != 'custom-git') {
|
||||
this.loadNamespaces();
|
||||
}
|
||||
|
||||
// FIXME: Need to have watchers here because cor-table doesn't have ng-change functionality yet
|
||||
this.$scope.$watch(() => this.local.selectedNamespace, (namespace: Namespace) => {
|
||||
if (namespace) {
|
||||
this.loadRepositories(namespace);
|
||||
}
|
||||
});
|
||||
this.$scope.$watch(() => this.local.selectedRepository, (selectedRepository: Repository) => {
|
||||
if (selectedRepository && this.githost != 'custom-git') {
|
||||
this.loadRepositoryRefs(selectedRepository);
|
||||
this.loadDockerfileLocations(selectedRepository);
|
||||
}
|
||||
});
|
||||
// FIXME (Alec 5/26/17): Need to have watchers here because cor-table doesn't have ng-change functionality yet
|
||||
this.$scope.$watch(() => this.local.selectedNamespace, (namespace: Namespace) => {
|
||||
if (namespace) {
|
||||
this.loadRepositories(namespace);
|
||||
}
|
||||
});
|
||||
this.$scope.$watch(() => this.local.selectedRepository, (selectedRepository: Repository) => {
|
||||
if (selectedRepository && this.githost != 'custom-git') {
|
||||
this.loadRepositoryRefs(selectedRepository);
|
||||
this.loadDockerfileLocations(selectedRepository);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public getTriggerIcon(): any {
|
||||
|
@ -120,20 +122,21 @@ export class ManageTriggerComponent implements OnInit {
|
|||
return this.apiService.getRobots(this.repository.namespace, null, {'permissions': true});
|
||||
} else {
|
||||
this.local.triggerAnalysis = Object.assign({}, resp);
|
||||
this.buildOrderedRobotAccounts();
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
this.apiService.errorDisplay('Could not analyze trigger');
|
||||
})
|
||||
.then((resp) => {
|
||||
this.local.triggerAnalysis = {
|
||||
status: 'publicbase',
|
||||
is_admin: true,
|
||||
robots: resp.robots,
|
||||
name: this.repository.name,
|
||||
namespace: this.repository.namespace
|
||||
};
|
||||
if (resp) {
|
||||
this.local.triggerAnalysis = {
|
||||
status: 'publicbase',
|
||||
is_admin: true,
|
||||
robots: resp.robots,
|
||||
name: this.repository.name,
|
||||
namespace: this.repository.namespace
|
||||
};
|
||||
}
|
||||
this.buildOrderedRobotAccounts();
|
||||
})
|
||||
.catch((error) => {
|
||||
|
|
Reference in a new issue