Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 10 additions & 6 deletions src/app/examples/rowdetail-preload.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Component } from '@angular/core';
import { Component, OnDestroy } from '@angular/core';

@Component({
template: `<h4>
<i class="mdi mdi-sync mdi-spin-1s mdi-50px"></i>
Loading...
</h4>`,
template: `<div class="container-fluid d-flex align-items-center" style="margin-top: 10px">
<i class="mdi mdi-sync mdi-spin mdi-50px"></i>
<h4>Loading...</h4>
</div>`,
})
export class RowDetailPreloadComponent {}
export class RowDetailPreloadComponent implements OnDestroy {
ngOnDestroy(): void {
console.log('preload destroyed');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ describe('SlickRowDetailView', () => {
const onBeforeRowSpy = jest.spyOn(gridOptionsMock.rowDetailView as RowDetailView, 'onBeforeRowDetailToggle');
const onRowOutViewSpy = jest.spyOn(gridOptionsMock.rowDetailView as RowDetailView, 'onRowOutOfViewportRange');
const onRowBackViewSpy = jest.spyOn(gridOptionsMock.rowDetailView as RowDetailView, 'onRowBackToViewportRange');
const appendSpy = jest
.spyOn(angularUtilServiceStub, 'createAngularComponentAppendToDom')
.mockReturnValue({ componentRef: { instance: jest.fn() } } as any);

plugin.init(gridStub);
plugin.onAfterRowDetailToggle = new SlickEvent();
Expand All @@ -295,6 +298,7 @@ describe('SlickRowDetailView', () => {
// { notify: expect.anything(), subscribe: expect.anything(), unsubscribe: expect.anything(), },
// expect.anything()
// );
expect(appendSpy).toHaveBeenCalled();
expect(onAsyncRespSpy).not.toHaveBeenCalled();
expect(onAsyncEndSpy).not.toHaveBeenCalled();
expect(onAfterRowSpy).toHaveBeenCalledWith(expect.anything(), { item: columnsMock[0], expandedRows: [0], grid: gridStub });
Expand Down Expand Up @@ -406,7 +410,7 @@ describe('SlickRowDetailView', () => {
const handlerSpy = jest.spyOn(plugin.eventHandler, 'subscribe');
const appendSpy = jest
.spyOn(angularUtilServiceStub, 'createAngularComponentAppendToDom')
.mockReturnValue({ componentRef: { instance: jest.fn() } } as any);
.mockReturnValue({ componentRef: { instance: jest.fn(), destroy: jest.fn() } } as any);

plugin.init(gridStub);
plugin.onBeforeRowDetailToggle = new SlickEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface CreatedView {
export class SlickRowDetailView extends UniversalSlickRowDetailView {
rowDetailContainer!: ViewContainerRef;
protected _preloadComponent: Type<object> | undefined;
protected _preloadCompRef?: ComponentRef<any>;
protected _views: CreatedView[] = [];
protected _viewComponent!: Type<object>;
protected _subscriptions: EventSubscription[] = [];
Expand Down Expand Up @@ -154,6 +155,9 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {

if (this.onAsyncEndUpdate) {
this.eventHandler.subscribe(this.onAsyncEndUpdate, (e, args) => {
// destroy preload if exists
this._preloadCompRef?.destroy();

// triggers after backend called "onAsyncResponse.notify()"
this.renderViewModel(args?.item);

Expand Down Expand Up @@ -269,10 +273,11 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
`${PRELOAD_CONTAINER_PREFIX}`
) as HTMLCollectionOf<HTMLElement>;
if (this._preloadComponent && containerElements?.length >= 0) {
this.angularUtilService.createAngularComponentAppendToDom(
const preloadComp = this.angularUtilService.createAngularComponentAppendToDom(
this._preloadComponent,
containerElements[containerElements.length - 1]
);
this._preloadCompRef = preloadComp.componentRef;
}
}

Expand All @@ -282,6 +287,7 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
`${ROW_DETAIL_CONTAINER_PREFIX}${item[this.datasetIdPropName]}`
) as HTMLCollectionOf<HTMLElement>;
if (this._viewComponent && containerElements?.length > 0) {
// render row detail
const componentOutput = this.angularUtilService.createAngularComponentAppendToDom(
this._viewComponent,
containerElements[containerElements.length - 1],
Expand Down