Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 01239cb

Browse files
committed
Simplified the setup for filters and paging
Since we always use the builder now, the card container will never need to pull the filters and pager off the data source. Instead we just need to set them there if present.
1 parent c2cae6f commit 01239cb

File tree

2 files changed

+21
-67
lines changed

2 files changed

+21
-67
lines changed

source/components/cardContainer/cardContainer.tests.ts

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ describe('CardContainerComponent', () => {
6464
};
6565
}
6666

67+
it('should set the filters on the data source', (): void => {
68+
let filters: IFilterMock[] = [{
69+
filter: sinon.spy(),
70+
}];
71+
72+
let dataSource: IDataSourceMock = buildMockedDataSource();
73+
74+
cardContainer.builder.dataSource = <any>dataSource;
75+
cardContainer.builder.filters = <any>filters;
76+
77+
cardContainer.ngOnInit();
78+
79+
expect(dataSource.filters).to.equal(filters);
80+
});
81+
6782
describe('hasItems', () => {
6883
it('should return true if the data set is not empty', () => {
6984
dataSource.dataSet$.next([]);
@@ -104,20 +119,6 @@ describe('CardContainerComponent', () => {
104119
cardContainer.ngOnInit();
105120
expect(cardContainer.dataSource.pager).to.not.exist;
106121
});
107-
108-
it('should use the data source\'s pager if paging is not specified', (): void => {
109-
let pager: IDataPagerMock = <any>{
110-
filter: sinon.spy(),
111-
};
112-
113-
let dataSource: IDataSourceMock = buildMockedDataSource();
114-
dataSource.pager = pager;
115-
116-
cardContainer.builder.dataSource = <any>dataSource;
117-
cardContainer.ngOnInit();
118-
119-
expect(cardContainer.dataSource.pager).to.equal(pager);
120-
});
121122
});
122123

123124
describe('card coordination', (): void => {
@@ -153,36 +154,4 @@ describe('CardContainerComponent', () => {
153154
expect(sortManager.updateSorts.firstCall.args[0]).to.equal(column);
154155
});
155156
});
156-
157-
describe('syncFilters', (): void => {
158-
it('should set the filters on the data source', (): void => {
159-
let filters: IFilterMock[] = [{
160-
filter: sinon.spy(),
161-
}];
162-
163-
let dataSource: IDataSourceMock = buildMockedDataSource();
164-
165-
cardContainer.builder.dataSource = <any>dataSource;
166-
cardContainer.builder.filters = <any>filters;
167-
168-
cardContainer.ngOnInit();
169-
170-
expect(dataSource.filters).to.equal(filters);
171-
});
172-
173-
it('should init filters from data source filters if no filters are specified', (): void => {
174-
let filters: IFilterMock[] = [{
175-
filter: sinon.spy(),
176-
}];
177-
178-
let dataSource: IDataSourceMock = buildMockedDataSource();
179-
dataSource.filters = filters;
180-
181-
cardContainer.builder.dataSource = <any>dataSource;
182-
183-
cardContainer.ngOnInit();
184-
185-
expect(cardContainer.filters).to.equal(filters);
186-
});
187-
});
188157
});

source/components/cardContainer/cardContainer.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,13 @@ export class CardContainerComponent<T> implements OnInit, AfterContentInit {
107107
this.maxColumnSorts = this.maxColumnSorts || defaultMaxColumnSorts;
108108
this.sortDirection = SortDirection;
109109

110-
this.syncFilters();
110+
if (this.filters) {
111+
this.dataSource.filters = this.filters;
112+
}
111113

112-
this.setupPaging();
114+
if (this.paging) {
115+
this.dataSource.pager = this.injectedPager;
116+
}
113117

114118
// need a way to customize the sorts?
115119
this.sortManager.setup([], name => this.lookupColumn(name), this.maxColumnSorts);
@@ -144,25 +148,6 @@ export class CardContainerComponent<T> implements OnInit, AfterContentInit {
144148
return this.columnHeaders.filter(column => column.name === columnName)[0];
145149
}
146150

147-
private syncFilters(): void {
148-
if (this.filters) {
149-
this.dataSource.filters = this.filters;
150-
} else if (this.dataSource.filters != null) {
151-
this.filters = this.dataSource.filters;
152-
}
153-
}
154-
155-
private setupPaging(): void {
156-
// If paging flag is specified, card container controls pager instance
157-
if (this.paging != null) {
158-
if (this.paging === false) {
159-
this.dataSource.pager = null;
160-
} else {
161-
this.dataSource.pager = this.injectedPager;
162-
}
163-
}
164-
}
165-
166151
private lookupColumn(label: string): IColumn<any> {
167152
return find(this.columns, (column: IColumn<any>): boolean => {
168153
return column.label === label;

0 commit comments

Comments
 (0)