Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

Commit

Permalink
fix: watch changes to project name and update git repo if default (#558)
Browse files Browse the repository at this point in the history
fixes: #557
  • Loading branch information
edewit authored Dec 17, 2018
1 parent f2de063 commit 5ac2bf4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {
AfterViewInit,
Component,
DoCheck,
ElementRef,
Host,
Input,
KeyValueDiffer,
KeyValueDiffers,
OnDestroy,
OnInit,
Optional,
Expand All @@ -18,28 +21,30 @@ import { LauncherComponent } from '../../launcher.component';
import { GitHubDetails } from '../../model/github-details.model';
import { Projectile, StepState } from '../../model/projectile.model';
import { GitProviderService } from '../../service/git-provider.service';
import { broadcast } from '../../shared/telemetry.decorator';

@Component({
encapsulation: ViewEncapsulation.None,
selector: 'f8launcher-gitprovider-step',
templateUrl: './gitprovider-step.component.html',
styleUrls: ['./gitprovider-step.component.less']
})
export class GitproviderStepComponent extends LauncherStep implements AfterViewInit, OnDestroy, OnInit {
export class GitproviderStepComponent extends LauncherStep implements AfterViewInit, OnDestroy, OnInit, DoCheck {
@Input() import: boolean;
@ViewChild('form') form: NgForm;
@ViewChild('versionSelect') versionSelect: ElementRef;

private projectNameDiff: KeyValueDiffer<string, any>;
private subscriptions: Subscription[] = [];
private _organizationsKeys;
gitHubDetails: GitHubDetails = {};
gitHubReposSubscription: Subscription;

constructor(@Host() @Optional() public launcherComponent: LauncherComponent,
private projectile: Projectile<GitHubDetails>,
differs: KeyValueDiffers,
private gitProviderService: GitProviderService) {
super(projectile);
this.projectNameDiff = differs.find(this.projectile.sharedState.state).create();
}

ngAfterViewInit() {
Expand All @@ -52,6 +57,17 @@ export class GitproviderStepComponent extends LauncherStep implements AfterViewI
}
}

ngDoCheck(): void {
const changes = this.projectNameDiff.diff(this.projectile.sharedState.state);
if (changes) {
changes.forEachChangedItem(item => {
if (item.key === 'projectName' && item.previousValue === this.gitHubDetails.repository) {
this.gitHubDetails.repository = item.currentValue;
}
});
}
}

ngOnInit() {
this.gitHubDetails.repository = this.import ? '' : this.projectile.sharedState.state.projectName;
this.gitHubDetails.repositoryList = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Component,
Host,
Input,
OnDestroy,
OnInit,
Expand Down Expand Up @@ -30,11 +29,11 @@ export class StepIndicatorComponent implements OnInit, OnDestroy {
dependencyCheck: DependencyCheck = new DependencyCheck();

constructor(public launcherComponent: LauncherComponent,
public projectile: Projectile<any>,
private route: ActivatedRoute,
broadcaster: Broadcaster) {
broadcaster.on<string>('navigate-to').subscribe(id => this.navToStep(id));
broadcaster.on<string>('navigate-from').subscribe(id => this.navToNextStep(id));
public projectile: Projectile<any>,
private route: ActivatedRoute,
broadcaster: Broadcaster) {
broadcaster.on<string>('navigate-to').subscribe(id => this.navToStep(id));
broadcaster.on<string>('navigate-from').subscribe(id => this.navToNextStep(id));
}

ngOnInit(): void {
Expand Down

0 comments on commit 5ac2bf4

Please sign in to comment.