Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Sort Button #101

Merged
merged 1 commit into from Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
@@ -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
Expand Up @@ -26,8 +26,6 @@ export class ActionPlaygroundComponent implements OnInit {
}
];

sortKey = 'creator';

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