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

Commit

Permalink
[Issue 683] - when changing columns displayed, grid will only make on…
Browse files Browse the repository at this point in the history
…e service call to update data

unit tests passing, 100% coverage. No changes to visual component were made.
  • Loading branch information
Blackbaud-LuisBello committed Aug 21, 2017
1 parent 7059d25 commit 7e58167
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 12 deletions.
7 changes: 5 additions & 2 deletions src/modules/list-view-grid/list-view-grid.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import {
ListItemModel,
ListSortFieldSelectorModel,
ListSearchModel,
ListStateDispatcher,
ListState
} from '../list/state';
Expand Down Expand Up @@ -213,8 +214,10 @@ export class SkyListViewGridComponent
)
.filter(c => c !== undefined);

this.dispatcher.searchSetFieldSelectors(displayedColumns.map(d => d.field));
this.dispatcher.searchSetFunctions(setFunctions);
this.dispatcher.searchSetOptions(new ListSearchModel({
functions: setFunctions,
fieldSelectors: displayedColumns.map(d => d.field)
}));
});
this.subscriptions.push(sub);
}
Expand Down
39 changes: 39 additions & 0 deletions src/modules/list/list.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,45 @@ describe('List Component', () => {
expect(action).not.toBeUndefined();
}));

describe('list load search options action', () => {
let dispatcher: ListStateDispatcher;
let state: ListState;

beforeEach(fakeAsync(() => {
dispatcher = new ListStateDispatcher();
state = new ListState(dispatcher);

state.skip(1).take(1).subscribe(() => tick());
tick();
}));

it('should call searchSetOptions with undefined parameters', fakeAsync(() => {
dispatcher.searchSetOptions(new ListSearchModel());

state.map(s => s.search).take(1).subscribe(search => {
expect(search.searchText).toBe('');
expect(search.functions.length).toBe(0);
expect(search.fieldSelectors.length).toBe(0);
});
}));

it('should call searchSetOptions with defined actions', fakeAsync(() => {
let searchFunc = (data: any, searchText: string) => {return true;}

dispatcher.searchSetOptions(new ListSearchModel({
searchText: 'search text',
functions: [searchFunc],
fieldSelectors: ['fields']
}));

state.map(s => s.search).take(1).subscribe(search => {
expect(search.searchText).toBe('search text');
expect(search.functions.length).toBe(1);
expect(search.fieldSelectors.length).toBe(1);
});
}));
});

describe('toolbar load action', () => {
let dispatcher: ListStateDispatcher;
let state: ListState;
Expand Down
6 changes: 3 additions & 3 deletions src/modules/list/list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class SkyListComponent implements AfterContentInit, OnChanges {
return Observable.combineLatest(
this.state.map(s => s.filters).distinctUntilChanged(),
this.state.map(s => s.search).distinctUntilChanged(),
this.state.map(s => s.sort).distinctUntilChanged(),
this.state.map(s => s.sort.fieldSelectors).distinctUntilChanged(),
this.state.map(s => s.paging.itemsPerPage).distinctUntilChanged(),
this.state.map(s => s.paging.pageNumber).distinctUntilChanged(),
selectedIds.distinctUntilChanged().map((selectedId: any) => {
Expand All @@ -229,7 +229,7 @@ export class SkyListComponent implements AfterContentInit, OnChanges {
(
filters: ListFilterModel[],
search: ListSearchModel,
sort: ListSortModel,
sortFieldSelectors: Array<ListSortFieldSelectorModel>,
itemsPerPage: number,
pageNumber: number,
selected: Array<string>,
Expand Down Expand Up @@ -258,7 +258,7 @@ export class SkyListComponent implements AfterContentInit, OnChanges {
pageSize: itemsPerPage,
pageNumber: pageNumber,
search: search,
sort: sort
sort: new ListSortModel({ fieldSelectors: sortFieldSelectors })
}));
}

Expand Down
11 changes: 6 additions & 5 deletions src/modules/list/state/list-state-action.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
import {
ListSearchSetSearchTextAction,
ListSearchSetFunctionsAction,
ListSearchSetFieldSelectorsAction
ListSearchSetFieldSelectorsAction,
ListSearchSetOptionsAction
} from './search/actions';

import {
Expand All @@ -48,7 +49,7 @@ export type ListStateAction =
ListPagingSetMaxPagesAction | ListPagingSetItemsPerPageAction | ListPagingSetPageNumberAction |
ListViewsLoadAction | ListViewsSetActiveAction | ListToolbarItemsLoadAction |
ListToolbarSetExistsAction | ListSearchSetSearchTextAction | ListSearchSetFunctionsAction |
ListSearchSetFieldSelectorsAction | ListSelectedSetLoadingAction | ListSelectedLoadAction |
ListSelectedSetItemSelectedAction | ListSelectedSetItemsSelectedAction | ListToolbarSetTypeAction
| ListSortSetFieldSelectorsAction | ListSortSetAvailableAction | ListSortSetGlobalAction |
ListFiltersUpdateAction | ListToolbarItemsRemoveAction;
ListSearchSetFieldSelectorsAction | ListSearchSetOptionsAction | ListSelectedSetLoadingAction |
ListSelectedLoadAction | ListSelectedSetItemSelectedAction | ListSelectedSetItemsSelectedAction |
ListToolbarSetTypeAction | ListSortSetFieldSelectorsAction | ListSortSetAvailableAction |
ListSortSetGlobalAction | ListFiltersUpdateAction | ListToolbarItemsRemoveAction;
12 changes: 11 additions & 1 deletion src/modules/list/state/list-state.rxstate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { ListToolbarItemModel } from './toolbar/toolbar-item.model';
import {
ListSearchSetFunctionsAction,
ListSearchSetSearchTextAction,
ListSearchSetFieldSelectorsAction
ListSearchSetFieldSelectorsAction,
ListSearchSetOptionsAction
} from './search/actions';

import {
Expand All @@ -29,6 +30,7 @@ import {
import { ListSortLabelModel } from './sort/label.model';
import { ListSortFieldSelectorModel } from './sort/field-selector.model';
import { ListFilterModel } from './filters/filter.model';
import { ListSearchModel } from './search/search.model';
import {
ListFiltersUpdateAction
} from './filters/actions';
Expand Down Expand Up @@ -67,6 +69,14 @@ export class ListStateDispatcher extends StateDispatcher<ListStateAction> {
this.next(new ListSearchSetSearchTextAction(searchText));
}

public searchSetOptions(searchOptions: ListSearchModel) {
this.next(new ListSearchSetOptionsAction(
new ListSearchSetSearchTextAction(searchOptions.searchText),
new ListSearchSetFieldSelectorsAction(searchOptions.fieldSelectors),
new ListSearchSetFunctionsAction(searchOptions.functions)
));
}

public sortSetAvailable(sortLabels: ListSortLabelModel[]): void {
this.next(new ListSortSetAvailableAction(sortLabels));
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/list/state/search/actions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { ListSearchSetSearchTextAction } from './set-search-text.action';
export { ListSearchSetFunctionsAction } from './set-functions.action';
export { ListSearchSetFieldSelectorsAction } from './set-field-selectors.action';
export { ListSearchSetOptionsAction } from './set-options.action';
25 changes: 24 additions & 1 deletion src/modules/list/state/search/search.orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ListSearchModel } from './search.model';
import { ListSearchSetSearchTextAction } from './set-search-text.action';
import { ListSearchSetFunctionsAction } from './set-functions.action';
import { ListSearchSetFieldSelectorsAction } from './set-field-selectors.action';
import { ListSearchSetOptionsAction } from './set-options.action';

export class ListSearchOrchestrator extends ListStateOrchestrator<ListSearchModel> {
/* istanbul ignore next */
Expand All @@ -12,7 +13,8 @@ export class ListSearchOrchestrator extends ListStateOrchestrator<ListSearchMode
this
.register(ListSearchSetSearchTextAction, this.setSearchText)
.register(ListSearchSetFunctionsAction, this.setFunctions)
.register(ListSearchSetFieldSelectorsAction, this.setFieldSelectors);
.register(ListSearchSetFieldSelectorsAction, this.setFieldSelectors)
.register(ListSearchSetOptionsAction, this.setOptions);
}

private setSearchText(
Expand All @@ -36,4 +38,25 @@ export class ListSearchOrchestrator extends ListStateOrchestrator<ListSearchMode
Object.assign({}, state, { fieldSelectors: [...action.fieldSelectors] })
);
}

private setOptions(state: ListSearchModel, action: ListSearchSetOptionsAction) {
let result = state;

/* istanbul ignore else */
if (action.searchTextAction) {
result = this.setSearchText(result, action.searchTextAction);
}

/* istanbul ignore else */
if (action.setFieldSelectorsAction) {
result = this.setFieldSelectors(result, action.setFieldSelectorsAction);
}

/* istanbul ignore else */
if (action.setFunctionsAction) {
result = this.setFunctions(result, action.setFunctionsAction);
}

return result;
}
}
11 changes: 11 additions & 0 deletions src/modules/list/state/search/set-options.action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ListSearchSetSearchTextAction } from './set-search-text.action';
import { ListSearchSetFieldSelectorsAction } from './set-field-selectors.action';
import { ListSearchSetFunctionsAction } from './set-functions.action';

export class ListSearchSetOptionsAction {
constructor(
public searchTextAction: ListSearchSetSearchTextAction,
public setFieldSelectorsAction: ListSearchSetFieldSelectorsAction,
public setFunctionsAction: ListSearchSetFunctionsAction
) {}
}

0 comments on commit 7e58167

Please sign in to comment.