Skip to content

Commit

Permalink
refactor (sort-button): removed sortKey input since it was used for t…
Browse files Browse the repository at this point in the history
…wo-way binding in the template. We now use a service called from the class to sort (#101)
  • Loading branch information
mdelez committed Jun 9, 2020
1 parent bd17723 commit 13b5126
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { SortingService } from '../../services/sorting.service';
*/
@Component({
template: `
<dsp-sort-button #sortButton [sortProps]="sortProps" [(sortKey)]="sortKey" [position]="position" (sortKeyChange)="sortList($event)">
<dsp-sort-button #sortButton [sortProps]="sortProps" [position]="position" (sortKeyChange)="sortList($event)">
</dsp-sort-button>
<ul class="list">
<li *ngFor="let item of list" class="item">
<span [class.active]="sortKey === 'firstname'">{{item.firstname}} </span>
<span [class.active]="sortKey === 'lastname'">{{item.lastname}} </span>
<span>{{item.firstname}} </span>
<span>{{item.lastname}} </span>
by
<span [class.active]="sortKey === 'creator'">{{item.creator}}</span>
<span>{{item.creator}}</span>
</li>
</ul>
`
Expand All @@ -45,7 +45,6 @@ class TestHostComponent implements OnInit {
label: 'Creator'
}
];
sortKey = 'creator';
position = 'left';

list = [{
Expand Down Expand Up @@ -123,7 +122,6 @@ describe('SortButtonComponent', () => {

it('should sort the list by lastname', () => {
expect(testHostComponent.sortButtonComponent).toBeTruthy();
expect(testHostComponent.sortKey).toBe('creator');
expect(testHostComponent.list).toEqual(listData);

const hostCompDe = testHostFixture.debugElement;
Expand Down Expand Up @@ -157,8 +155,6 @@ describe('SortButtonComponent', () => {
item2.click();
testHostFixture.detectChanges();

// expect the list to be sorted by lastname
expect(testHostComponent.sortKey).toBe('lastname');

const listEl: DebugElement = hostCompDe.query(By.css('.list'));
const children = listEl.nativeNode.children;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export class SortButtonComponent implements OnInit {
*/
@Input() position = 'left';


/**
* @param icon
* Default icon is "sort" from material design.
Expand All @@ -51,14 +50,6 @@ export class SortButtonComponent implements OnInit {
*/
@Input() icon = 'sort';

/**
* @param sortKey
* set and get (two-way data binding) of current sort key
*/
@Input() sortKey(sortKey: string) {
this.activeKey = sortKey;
}

constructor() {
}

Expand Down
8 changes: 4 additions & 4 deletions src/app/action-playground/action-playground.component.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<p>Sorting</p>
<dsp-sort-button [sortProps]="sortProps" [(sortKey)]="sortKey" [position]="'right'" (sortKeyChange)="sortList($event)"></dsp-sort-button>
<dsp-sort-button [sortProps]="sortProps" [position]="'right'" (sortKeyChange)="sortList($event)"></dsp-sort-button>
<ul>
<li *ngFor="let item of list">
<span [class.active]="sortKey === 'firstname'">{{item.firstname}} </span>
<span [class.active]="sortKey === 'lastname'">{{item.lastname}} </span>
<span [class.active]="sortKey === 'creator'">{{item.creator}}</span>
<span>{{item.firstname}} </span>
<span>{{item.lastname}} </span>
<span>{{item.creator}}</span>
</li>
</ul>

Expand Down
2 changes: 0 additions & 2 deletions src/app/action-playground/action-playground.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export class ActionPlaygroundComponent implements OnInit {
}
];

sortKey = 'creator';

list = [
{
firstname: 'Gaston',
Expand Down

0 comments on commit 13b5126

Please sign in to comment.