Skip to content

Commit 8cedc17

Browse files
committed
feat(state): Use GridFeatures typing #7025
1 parent fca28d7 commit 8cedc17

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

projects/igniteui-angular/src/lib/grids/state.directive.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export interface IGridStateOptions {
5252
rowPinning?: boolean;
5353
pinningConfig?: boolean;
5454
expansion?: boolean;
55-
inheritance?: boolean;
55+
rowIslands?: boolean;
5656
}
5757

5858
export interface IColumnState {
@@ -82,7 +82,7 @@ export type GridFeatures = keyof IGridStateOptions;
8282
export interface Feature {
8383
getFeatureState: (context: IgxGridStateDirective) => IGridState;
8484
restoreFeatureState: (context: IgxGridStateDirective, state: IColumnState[] | IPagingState | ISortingExpression[] |
85-
IGroupingState | FilteringExpressionsTree | GridSelectionRange[] | IPinningConfig | any[]) => void;
85+
IGroupingState | IFilteringExpressionsTree | GridSelectionRange[] | IPinningConfig | any[]) => void;
8686
}
8787

8888
@Directive({
@@ -93,7 +93,7 @@ export class IgxGridStateDirective {
9393
/**
9494
* @hidden @internal
9595
*/
96-
public features: string[] = [];
96+
public features: GridFeatures[] = [];
9797
/**
9898
* @hidden @internal
9999
*/
@@ -114,7 +114,7 @@ export class IgxGridStateDirective {
114114
columnSelection: true,
115115
rowPinning: true,
116116
expansion: true,
117-
inheritance: true
117+
rowIslands: true
118118
};
119119

120120
/**
@@ -136,7 +136,7 @@ export class IgxGridStateDirective {
136136
if (!(this.grid instanceof IgxGridComponent)) {
137137
delete this._options.groupBy;
138138
} else {
139-
delete this._options.inheritance;
139+
delete this._options.rowIslands;
140140
}
141141
}
142142

@@ -162,7 +162,7 @@ export class IgxGridStateDirective {
162162
* let state = this.state(false) // returns `IGridState` object
163163
* ```
164164
*/
165-
public getState(serialize = true, features?: string | string[]): IGridState | string {
165+
public getState(serialize = true, features?: GridFeatures | GridFeatures[]): IGridState | string {
166166
let state: IGridState | string;
167167
this.currGrid = this.grid;
168168
this.state = state = this.buildState(features) as IGridState;
@@ -184,7 +184,7 @@ export class IgxGridStateDirective {
184184
* this.state.setState(gridState);
185185
* ```
186186
*/
187-
public setState(state: IGridState | string, features?: string | string[]) {
187+
public setState(state: IGridState | string, features?: GridFeatures | GridFeatures[]) {
188188
if (typeof state === 'string') {
189189
state = JSON.parse(state) as IGridState;
190190
}
@@ -197,12 +197,11 @@ export class IgxGridStateDirective {
197197
* Builds an IGridState object.
198198
* @hidden @internal
199199
*/
200-
public buildState(keys?: string | string[]): IGridState {
200+
public buildState(keys?: GridFeatures | GridFeatures[]): IGridState {
201201
this.applyFeatures(keys);
202202
let gridState = {} as IGridState;
203203
this.features.forEach(f => {
204204
if (this.options[f]) {
205-
f = f === 'inheritance' ? 'rowIslands' : f;
206205
if (!(this.grid instanceof IgxGridComponent) && f === 'groupBy') {
207206
return;
208207
}
@@ -218,11 +217,10 @@ export class IgxGridStateDirective {
218217
* The method that calls corresponding methods to restore features from the passed IGridState object.
219218
* @hidden @internal
220219
*/
221-
public restoreGridState(state: IGridState, features?: string | string[]) {
220+
public restoreGridState(state: IGridState, features?: GridFeatures | GridFeatures[]) {
222221
this.applyFeatures(features);
223222
this.features.forEach(f => {
224223
if (this.options[f]) {
225-
f = f === 'inheritance' ? 'rowIslands' : f;
226224
const featureState = state[f];
227225
if (featureState) {
228226
const feature = this.getFeature(f);
@@ -235,14 +233,14 @@ export class IgxGridStateDirective {
235233
/**
236234
* Returns a collection of all grid features.
237235
*/
238-
private applyFeatures(keys?: string | string[]) {
236+
private applyFeatures(keys?: GridFeatures | GridFeatures[]) {
239237
this.features = [];
240238
if (!keys) {
241239
for (const key of Object.keys(this.options)) {
242-
this.features.push(key);
240+
this.features.push(key as GridFeatures);
243241
}
244242
} else if (Array.isArray(keys)) {
245-
this.features = [...keys as string[]];
243+
this.features = [...keys as GridFeatures[]];
246244
} else {
247245
this.features.push(keys);
248246
}

0 commit comments

Comments
 (0)