Skip to content

Commit

Permalink
fix(data-table): simplify sorting components
Browse files Browse the repository at this point in the history
  • Loading branch information
czosel committed Dec 20, 2021
1 parent 5afa1d1 commit 6a7ae71
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 102 deletions.
5 changes: 1 addition & 4 deletions addon/components/data-table/head.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<thead>
<tr>
{{yield (hash
sortable=(component "data-table/head/sortable" update=@update sortedBy=@sortedBy)
nonsortable=(component "data-table/head/nonsortable")
)}}
{{yield (component "data-table/head/column" update=@update sortedBy=@sortedBy)}}
</tr>
</thead>
19 changes: 19 additions & 0 deletions addon/components/data-table/head/column.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<th>
{{#if @sort}}
<span
data-test-sortable-th={{@sort}}
class="sortable-th"
role="button"
{{on "click" (fn @update @sort)}}
>
{{yield}}
{{#if (eq @sortedBy @sort)}}
<UkIcon @icon="chevron-down"/>
{{else if (eq @sortedBy (concat "-" @sort))}}
<UkIcon @icon="chevron-up"/>
{{/if}}
</span>
{{else}}
{{yield}}
{{/if}}
</th>
3 changes: 0 additions & 3 deletions addon/components/data-table/head/nonsortable.hbs

This file was deleted.

15 changes: 0 additions & 15 deletions addon/components/data-table/head/sortable.hbs

This file was deleted.

26 changes: 13 additions & 13 deletions addon/templates/users/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@
@include={{array "acls.role" "acls.scope"}}
as |table|
>
<table.head as |head|>
<table.head as |Column|>
{{#unless this.emailAsUsername}}
<head.sortable @sort="username">
<Column @sort="username">
{{t "emeis.users.headings.username"}}
</head.sortable>
</Column>
{{/unless}}
<head.sortable @sort="last_name">
<Column @sort="last_name">
{{t "emeis.users.headings.lastName"}}
</head.sortable>
<head.sortable @sort="first_name">
</Column>
<Column @sort="first_name">
{{t "emeis.users.headings.firstName"}}
</head.sortable>
<head.sortable @sort="email">
</Column>
<Column @sort="email">
{{t "emeis.users.headings.email"}}
</head.sortable>
<head.nonsortable>
</Column>
<Column>
{{t "emeis.roles.title"}}
</head.nonsortable>
<head.nonsortable>
</Column>
<Column>
{{t "emeis.scopes.title"}}
</head.nonsortable>
</Column>
</table.head>
<table.body as |body|>
<body.row>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "ember-emeis/components/data-table/head/sortable";
export { default } from "ember-emeis/components/data-table/head/column";
1 change: 0 additions & 1 deletion app/components/data-table/head/nonsortable.js

This file was deleted.

30 changes: 15 additions & 15 deletions tests/integration/components/data-table-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ module("Integration | Component | data-table", function (hooks) {

await render(hbs`
<DataTable @modelName={{this.modelName}} as |table|>
<table.head as |role|>
<td>Heading 1</td>
<td>Heading 2</td>
<table.head as |Column|>
<Column>Heading 1</Column>
<Column>Heading 2</Column>
</table.head>
<table.body as |body|>
<body.row>
Expand Down Expand Up @@ -65,13 +65,13 @@ module("Integration | Component | data-table", function (hooks) {
@modelName={{this.modelName}}
@page={{this.page}}
as |table|>
<table.head as |role|>
<role.sortable @sort="one">
<table.head as |Column|>
<Column @sort="one">
Heading One
</role.sortable>
<role.nonsortable>
</Column>
<Column>
Heading One
</role.nonsortable>
</Column>
</table.head>
<table.body as |body|>
<body.row>
Expand Down Expand Up @@ -150,16 +150,16 @@ module("Integration | Component | data-table", function (hooks) {
@modelName={{this.modelName}}
@include={{array "acls.role" "acls.scope"}}
as |table|>
<table.head as |head|>
<head.sortable @sort="one">
<table.head as |Column|>
<Column @sort="one">
Heading One
</head.sortable>
<head.nonsortable>
</Column>
<Column>
Roles
</head.nonsortable>
<head.nonsortable>
</Column>
<Column>
Scopes
</head.nonsortable>
</Column>
</table.head>
<table.body as |body|>
<body.row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { hbs } from "ember-cli-htmlbars";
import { setupRenderingTest } from "ember-qunit";
import { module, test } from "qunit";

module("Integration | Component | data-table/head/sortable", function (hooks) {
module("Integration | Component | data-table/head/column", function (hooks) {
setupRenderingTest(hooks);

hooks.beforeEach(function (assert) {
Expand All @@ -16,10 +16,10 @@ module("Integration | Component | data-table/head/sortable", function (hooks) {

test("it renders", async function (assert) {
await render(hbs`
<DataTable::Head @sortedBy={{this.sort}} @update={{this.update}} as |head|>
<head.sortable @sort={{this.sort}}>
<DataTable::Head @sortedBy={{this.sort}} @update={{this.update}} as |Column|>
<Column @sort={{this.sort}}>
test
</head.sortable>
</Column>
</DataTable::Head>
`);

Expand All @@ -29,23 +29,23 @@ module("Integration | Component | data-table/head/sortable", function (hooks) {

test("it renders as block", async function (assert) {
await render(hbs`
<DataTable::Head::Sortable @update={{this.update}}>
<DataTable::Head::Column @update={{this.update}}>
template block text
</DataTable::Head::Sortable>
</DataTable::Head::Column>
`);

assert.dom(this.element).hasText("template block text");
});

test("it toggles sort state", async function (assert) {
await render(hbs`
<DataTable::Head @sortedBy={{this.sort}} @update={{this.update}} as |head|>
<head.sortable @sort={{"last_name"}}>
<DataTable::Head @sortedBy={{this.sort}} @update={{this.update}} as |Column|>
<Column @sort={{"last_name"}}>
one
</head.sortable>
<head.sortable @sort={{"first_name"}}>
</Column>
<Column @sort={{"first_name"}}>
two
</head.sortable>
</Column>
</DataTable::Head>
`);

Expand Down
39 changes: 0 additions & 39 deletions tests/integration/components/data-table/head/nonsortable-test.js

This file was deleted.

0 comments on commit 6a7ae71

Please sign in to comment.