Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Contrib > Close modal on route change #1683

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3f4222e
Resolving Card action bar still visable after hiding with *ngIf #1421
blackbaud-conorwright Mar 7, 2018
a450054
Addressed PR style comments
blackbaud-conorwright Mar 8, 2018
4b809aa
Merge remote-tracking branch 'upstream/master'
blackbaud-conorwright Mar 9, 2018
d55f351
Merge branch 'master' into master
Blackbaud-SteveBrush Mar 9, 2018
833bcc7
Merge remote-tracking branch 'upstream/master'
blackbaud-conorwright Mar 12, 2018
b553659
Merge remote-tracking branch 'upstream/master'
blackbaud-conorwright Mar 15, 2018
ab82ba3
Merge remote-tracking branch 'upstream/master'
blackbaud-conorwright Mar 19, 2018
db21c76
Merge remote-tracking branch 'upstream/master'
blackbaud-conorwright Mar 27, 2018
a282a86
Merge remote-tracking branch 'upstream/master'
blackbaud-conorwright Mar 30, 2018
d210c2b
Merge remote-tracking branch 'upstream/master'
blackbaud-conorwright Apr 10, 2018
35e789d
Merge remote-tracking branch 'upstream/master'
blackbaud-conorwright Apr 17, 2018
636c5dd
Merge remote-tracking branch 'upstream/master'
blackbaud-conorwright Apr 23, 2018
7e9fece
Fixed issue #1390 where modal remained open on back button
blackbaud-conorwright Apr 27, 2018
bdc97a6
Merge remote-tracking branch 'upstream/master'
blackbaud-conorwright May 1, 2018
6f0a70d
Merge remote-tracking branch 'origin/master' into fix-modal-history-n…
blackbaud-conorwright May 1, 2018
6104aaf
Merge remote-tracking branch 'upstream/master'
blackbaud-conorwright May 2, 2018
e9e44b5
Merge remote-tracking branch 'origin/master' into fix-modal-history-n…
blackbaud-conorwright May 4, 2018
de9ea2e
switched to using Location instead of PlatformLocation
blackbaud-conorwright May 4, 2018
3c5f9dc
Merge branch 'master' into fix-modal-history-navigation-close
Blackbaud-SteveBrush May 7, 2018
37f50ec
Merge remote-tracking branch 'upstream/master'
blackbaud-conorwright May 8, 2018
20e6821
Merge remote-tracking branch 'origin/master' into fix-modal-history-n…
blackbaud-conorwright May 9, 2018
ca6dc0f
switched to using location. Still column test provider bug
blackbaud-conorwright May 10, 2018
65a52d9
Minor cleanup
Blackbaud-SteveBrush May 11, 2018
ea725aa
RouterTestingModule fixes everything
blackbaud-conorwright May 11, 2018
38e8a20
removing a leftover "fit"
blackbaud-conorwright May 11, 2018
4418b87
Merge branch 'fix-modal-history-navigation-close' into contrib-fix-mo…
Blackbaud-SteveBrush May 11, 2018
69638a0
Unit test adjustments
Blackbaud-SteveBrush May 11, 2018
b34576c
Adjusted code style
Blackbaud-SteveBrush May 11, 2018
767e6e8
Merge branch 'master' into contrib-fix-modal-history-navigation-close
Blackbaud-SteveBrush May 11, 2018
b6e7955
Fixed unit tests
Blackbaud-SteveBrush May 11, 2018
f3f1bbc
Updated modal service to trigger host component OnDestroy
Blackbaud-SteveBrush May 14, 2018
211cf04
Merge branch 'master' into contrib-fix-modal-history-navigation-close
Blackbaud-SteveBrush May 22, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
ComponentFixture
} from '@angular/core/testing';

import {
RouterTestingModule
} from '@angular/router/testing';

import {
expect
} from '@blackbaud/skyux-builder/runtime/testing/browser';
Expand All @@ -30,6 +34,7 @@ describe('Column selector component', () => {
ColumnSelectorTestComponent
],
imports: [
RouterTestingModule,
SkyColumnSelectorModule,
SkyModalModule
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import {
NoopAnimationsModule
} from '@angular/platform-browser/animations';

import {
RouterTestingModule
} from '@angular/router/testing';

import {
expect
} from '@blackbaud/skyux-builder/runtime/testing/browser';
Expand Down Expand Up @@ -74,6 +78,7 @@ describe('List column selector action', () => {
ListColumnSelectorActionTestComponent
],
imports: [
RouterTestingModule,
SkyListColumnSelectorActionModule,
SkyListModule,
SkyListToolbarModule,
Expand Down
5 changes: 5 additions & 0 deletions src/modules/modal/fixtures/modal-fixtures.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import {
RouterTestingModule
} from '@angular/router/testing';

import { SkyWindowRefService } from '../../window';

import { SkyModalModule } from '../modal.module';
Expand All @@ -22,6 +26,7 @@ import { ModalTiledBodyTestComponent } from './modal-tiled-body.component.fixtur
],
imports: [
CommonModule,
RouterTestingModule,
SkyModalModule
],
providers: [
Expand Down
5 changes: 4 additions & 1 deletion src/modules/modal/modal-adapter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export class SkyModalAdapterService {
}

public removeHostEl(): void {
this.bodyEl.removeChild(this.docRef.querySelector('sky-modal-host'));
const element = this.docRef.querySelector('sky-modal-host');
if (element) {
this.bodyEl.removeChild(element);
}
}

public toggleFullPageModalClass(isAddFull: boolean): void {
Expand Down
32 changes: 30 additions & 2 deletions src/modules/modal/modal-host.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@ import {
Component,
ComponentFactoryResolver,
Injector,
OnDestroy,
ReflectiveInjector,
ViewChild,
ViewContainerRef
} from '@angular/core';

import {
NavigationStart,
Router
} from '@angular/router';

import {
Subject
} from 'rxjs/Subject';

import 'rxjs/add/operator/takeUntil';

import { SkyModalAdapterService } from './modal-adapter.service';
import { SkyModalInstance } from './modal-instance';
import { SkyModalHostService } from './modal-host.service';
Expand All @@ -20,7 +32,7 @@ import { SkyModalConfiguration } from './modal-configuration';
viewProviders: [SkyModalAdapterService]
})

export class SkyModalHostComponent {
export class SkyModalHostComponent implements OnDestroy {
public get modalOpen() {
return SkyModalHostService.openModalCount > 0;
}
Expand All @@ -32,12 +44,20 @@ export class SkyModalHostComponent {
@ViewChild('target', { read: ViewContainerRef })
public target: ViewContainerRef;

private ngUnsubscribe = new Subject();

constructor(
private resolver: ComponentFactoryResolver,
private adapter: SkyModalAdapterService,
private injector: Injector
private injector: Injector,
private router: Router
) { }

public ngOnDestroy() {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}

public open(modalInstance: SkyModalInstance, component: any, config?: IConfig) {
let params: IConfig = Object.assign({}, config);
let factory = this.resolver.resolveComponentFactory(component);
Expand Down Expand Up @@ -84,6 +104,14 @@ export class SkyModalHostComponent {
modalInstance.close();
});

this.router.events
.takeUntil(this.ngUnsubscribe)
.subscribe((event) => {
if (event instanceof NavigationStart) {
modalInstance.close();
}
});

modalInstance.closed.subscribe(() => {
closeModal();
});
Expand Down
24 changes: 22 additions & 2 deletions src/modules/modal/modal.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
TestBed
} from '@angular/core/testing';

import {
Router
} from '@angular/router';

import {
expect,
SkyAppTestUtility
Expand All @@ -27,6 +31,7 @@ import { SkyModalComponentAdapterService } from './modal-component-adapter.servi
describe('Modal component', () => {
let applicationRef: ApplicationRef;
let modalService: SkyModalService;
let router: Router;

function openModal(modalType: any, config?: Object) {
let modalInstance = modalService.open(modalType, config);
Expand Down Expand Up @@ -55,15 +60,18 @@ describe('Modal component', () => {
inject(
[
ApplicationRef,
SkyModalService
SkyModalService,
Router
],
(
_applicationRef: ApplicationRef,
_modalService: SkyModalService
_modalService: SkyModalService,
_router: Router
) => {
applicationRef = _applicationRef;
modalService = _modalService;
modalService.dispose();
router = _router;
}
)
);
Expand Down Expand Up @@ -268,6 +276,18 @@ describe('Modal component', () => {
applicationRef.tick();
}));

it('should close when the user navigates through history', fakeAsync(() => {
openModal(ModalTestComponent);

expect(document.querySelector('.sky-modal')).toExist();

router.navigate(['/']);

expect(document.querySelector('.sky-modal')).not.toExist();

applicationRef.tick();
}));

it('should trigger the help modal when the help button is clicked', fakeAsync(() => {
let modalInstance = openModal(ModalTestComponent, { helpKey: 'default.html' });
spyOn(modalInstance, 'openHelp').and.callThrough();
Expand Down
5 changes: 5 additions & 0 deletions src/modules/modal/modal.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import {
RouterModule
} from '@angular/router';

import { SkyModalAdapterService } from './modal-adapter.service';
import { SkyModalContentComponent } from './modal-content.component';
import { SkyModalFooterComponent } from './modal-footer.component';
Expand Down Expand Up @@ -29,6 +33,7 @@ import { SkyErrorModalFormComponent } from '../error/error-modal-form.component'
],
imports: [
CommonModule,
RouterModule,
SkyResourcesModule
],
exports: [
Expand Down
22 changes: 13 additions & 9 deletions src/modules/modal/modal.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
ApplicationRef,
ComponentFactoryResolver,
ComponentRef,
Injectable
} from '@angular/core';

Expand All @@ -11,7 +12,8 @@ import { SkyModalConfigurationInterface as IConfig } from './modal.interface';

@Injectable()
export class SkyModalService {
private static hostComponent: SkyModalHostComponent;
private static host: ComponentRef<SkyModalHostComponent>;

constructor(
private resolver: ComponentFactoryResolver,
private appRef: ApplicationRef,
Expand Down Expand Up @@ -43,18 +45,20 @@ export class SkyModalService {
useValue: modalInstance
});

SkyModalService.hostComponent.open(modalInstance, component, params);
SkyModalService.host.instance.open(modalInstance, component, params);

return modalInstance;
}

public dispose() {
/* istanbul ignore else */
/* sanity check */
if (SkyModalService.hostComponent) {
SkyModalService.hostComponent = undefined;
this.adapter.removeHostEl();
if (SkyModalService.host) {
// Trigger the host component's OnDestroy method:
this.appRef.detachView(SkyModalService.host.hostView);
SkyModalService.host.destroy();
SkyModalService.host = undefined;
}

this.adapter.removeHostEl();
}

private getConfigFromParameter(providersOrConfig: any) {
Expand Down Expand Up @@ -83,14 +87,14 @@ export class SkyModalService {
}

private createHostComponent() {
if (!SkyModalService.hostComponent) {
if (!SkyModalService.host) {
let factory = this.resolver.resolveComponentFactory(SkyModalHostComponent);

this.adapter.addHostEl();

let cmpRef = this.appRef.bootstrap(factory);

SkyModalService.hostComponent = cmpRef.instance;
SkyModalService.host = cmpRef;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import {
FormsModule
} from '@angular/forms';

import {
RouterTestingModule
} from '@angular/router/testing';

import { SkySelectFieldModule } from '../select-field.module';

import { SkySelectFieldTestComponent } from './select-field.component.fixture';
Expand All @@ -21,6 +25,7 @@ import { SkySelectFieldTestComponent } from './select-field.component.fixture';
imports: [
CommonModule,
FormsModule,
RouterTestingModule,
SkySelectFieldModule
],
exports: [
Expand Down
6 changes: 6 additions & 0 deletions src/modules/text-expand/text-expand.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import {
} from '@angular/core/testing';

import { BrowserModule } from '@angular/platform-browser';

import {
RouterTestingModule
} from '@angular/router/testing';

import { SkyWindowRefService } from '../window';
import { TextExpandTestComponent } from './fixtures/text-expand.component.fixture';
import { SkyTextExpandModule } from './text-expand.module';
Expand Down Expand Up @@ -34,6 +39,7 @@ describe('Text expand component', () => {
],
imports: [
BrowserModule,
RouterTestingModule,
SkyTextExpandModule,
SkyModalModule
],
Expand Down