Skip to content

Commit ecb0e40

Browse files
authored
fix(elements): inject grid instead of grid api in state component (#14594)
1 parent bab8ff8 commit ecb0e40

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

projects/igniteui-angular-elements/src/app/app.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,6 @@ declare global {
123123
'igc-grid': NgElement & WithProperties<GridType>;
124124
'igc-tree-grid': NgElement & WithProperties<IgxTreeGridElement>;
125125
'igc-paginator': NgElement & WithProperties<IgxPaginatorComponent>;
126+
'igc-grid-state': NgElement & WithProperties<IgxGridStateComponent>;
126127
}
127128
}

projects/igniteui-angular-elements/src/app/custom-strategy.spec.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { ApplicationRef, importProvidersFrom } from '@angular/core';
33
import { createApplication } from '@angular/platform-browser';
44
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
55
import { BrowserTestingModule } from '@angular/platform-browser/testing';
6-
import { IgxColumnComponent, IgxGridComponent, IgxHierarchicalGridComponent, IgxPaginatorComponent } from 'igniteui-angular';
6+
import { IgxColumnComponent, IgxGridComponent, IgxHierarchicalGridComponent, IgxPaginatorComponent, IgxPivotGridComponent } from 'igniteui-angular';
77
import { firstValueFrom, fromEvent, skip, timer } from 'rxjs';
88
import { registerConfig } from '../analyzer/elements.config';
99
import { createIgxCustomElement } from './create-custom-element';
1010
import { ComponentRefKey, IgcNgElement } from './custom-strategy';
1111
import hgridData from '../assets/data/projects-hgrid.js';
1212
import { SampleTestData } from 'igniteui-angular/src/lib/test-utils/sample-test-data.spec';
1313
import { ELEMENTS_TOKEN } from 'igniteui-angular/src/lib/core/utils';
14+
import { IgxGridStateComponent } from '../lib/state.component';
1415

1516
describe('Elements: ', () => {
1617
let testContainer: HTMLDivElement;
@@ -28,8 +29,13 @@ describe('Elements: ', () => {
2829
customElements.define("igc-grid", grid);
2930
const hgrid = createIgxCustomElement<IgxHierarchicalGridComponent>(IgxHierarchicalGridComponent, { injector: appRef.injector, registerConfig });
3031
customElements.define("igc-hierarchical-grid", hgrid);
32+
const pivotGrid = createIgxCustomElement<IgxPivotGridComponent>(IgxPivotGridComponent, { injector: appRef.injector, registerConfig });
33+
customElements.define("igc-pivot-grid", pivotGrid);
3134
const paginator = createIgxCustomElement<IgxPaginatorComponent>(IgxPaginatorComponent, { injector: appRef.injector, registerConfig });
3235
customElements.define("igc-paginator", paginator);
36+
const stateComponent = createIgxCustomElement<IgxGridStateComponent>(IgxGridStateComponent, { injector: appRef.injector, registerConfig });
37+
customElements.define("igc-grid-state", stateComponent);
38+
3339
});
3440

3541
beforeEach(async () => {
@@ -111,5 +117,19 @@ describe('Elements: ', () => {
111117
expect(gridEl.dataView.length).toEqual(3);
112118
expect(paginator.totalRecords).toEqual(gridEl.data.length);
113119
});
120+
121+
it(`should initialize pivot grid with state persistence component`, async () => {
122+
const gridEl = document.createElement("igc-pivot-grid");
123+
124+
const stateComponent = document.createElement("igc-grid-state");
125+
126+
gridEl.appendChild(stateComponent);
127+
128+
testContainer.appendChild(gridEl);
129+
130+
// TODO: Better way to wait - potentially expose the queue or observable for update on the strategy
131+
await firstValueFrom(timer(10 /* SCHEDULE_DELAY */ * 2));
132+
expect(() => stateComponent.getStateAsString()).not.toThrow();
133+
});
114134
});
115135
});

projects/igniteui-angular-elements/src/lib/state.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, EnvironmentInjector, EventEmitter, Inject, Injector, Output, ViewContainerRef } from '@angular/core';
2-
import { IGX_GRID_SERVICE_BASE, GridServiceType, IPinningConfig} from '../../../igniteui-angular/src/lib/grids/common/grid.interface';
2+
import { IPinningConfig, GridType, IGX_GRID_BASE} from '../../../igniteui-angular/src/lib/grids/common/grid.interface';
33
import { IFilteringExpressionsTree } from '../../../igniteui-angular/src/lib/data-operations/filtering-expressions-tree';
44
import { IPagingState } from '../../../igniteui-angular/src/lib/data-operations/paging-state.interface';
55
import { ISortingExpression } from '../../../igniteui-angular/src/lib/data-operations/sorting-strategy';
@@ -50,11 +50,11 @@ export interface IGridStateInfo {
5050
export class IgxGridStateComponent extends IgxGridStateBaseDirective {
5151

5252
constructor(
53-
@Inject(IGX_GRID_SERVICE_BASE) private api: GridServiceType,
53+
@Inject(IGX_GRID_BASE) grid: GridType,
5454
protected override viewRef: ViewContainerRef, protected override envInjector: EnvironmentInjector,
5555
protected override injector: Injector,
5656
) {
57-
super(api.grid, viewRef, envInjector, injector);
57+
super(grid, viewRef, envInjector, injector);
5858
}
5959

6060
/**

0 commit comments

Comments
 (0)