From b8427b66637e18886d8648399522844a119fcba4 Mon Sep 17 00:00:00 2001 From: Christian Zosel Date: Mon, 20 Dec 2021 17:17:28 +0100 Subject: [PATCH] fix(data-table): simplify sorting components --- addon/components/data-table/head.hbs | 5 +-- addon/components/data-table/head/column.hbs | 19 +++++++++ .../data-table/head/nonsortable.hbs | 3 -- addon/components/data-table/head/sortable.hbs | 15 ------- addon/templates/users/index.hbs | 26 ++++++------- .../head/{sortable.js => column.js} | 2 +- app/components/data-table/head/nonsortable.js | 1 - .../integration/components/data-table-test.js | 34 ++++++++-------- .../head/{sortable-test.js => column-test.js} | 22 +++++------ .../data-table/head/nonsortable-test.js | 39 ------------------- 10 files changed, 62 insertions(+), 104 deletions(-) create mode 100644 addon/components/data-table/head/column.hbs delete mode 100644 addon/components/data-table/head/nonsortable.hbs delete mode 100644 addon/components/data-table/head/sortable.hbs rename app/components/data-table/head/{sortable.js => column.js} (85%) delete mode 100644 app/components/data-table/head/nonsortable.js rename tests/integration/components/data-table/head/{sortable-test.js => column-test.js} (82%) delete mode 100644 tests/integration/components/data-table/head/nonsortable-test.js diff --git a/addon/components/data-table/head.hbs b/addon/components/data-table/head.hbs index ad0a3ce6..7b8fe0eb 100644 --- a/addon/components/data-table/head.hbs +++ b/addon/components/data-table/head.hbs @@ -1,8 +1,5 @@ - {{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)}} \ No newline at end of file diff --git a/addon/components/data-table/head/column.hbs b/addon/components/data-table/head/column.hbs new file mode 100644 index 00000000..7531ea0b --- /dev/null +++ b/addon/components/data-table/head/column.hbs @@ -0,0 +1,19 @@ + + {{#if @sort}} + + {{yield}} + {{#if (eq @sortedBy @sort)}} + + {{else if (eq @sortedBy (concat "-" @sort))}} + + {{/if}} + + {{else}} + {{yield}} + {{/if}} + \ No newline at end of file diff --git a/addon/components/data-table/head/nonsortable.hbs b/addon/components/data-table/head/nonsortable.hbs deleted file mode 100644 index 3ae27564..00000000 --- a/addon/components/data-table/head/nonsortable.hbs +++ /dev/null @@ -1,3 +0,0 @@ - - {{yield}} - \ No newline at end of file diff --git a/addon/components/data-table/head/sortable.hbs b/addon/components/data-table/head/sortable.hbs deleted file mode 100644 index 5d2bf5a1..00000000 --- a/addon/components/data-table/head/sortable.hbs +++ /dev/null @@ -1,15 +0,0 @@ - - - {{yield}} - {{#if (eq @sortedBy @sort)}} - - {{else if (eq @sortedBy (concat "-" @sort))}} - - {{/if}} - - \ No newline at end of file diff --git a/addon/templates/users/index.hbs b/addon/templates/users/index.hbs index f52a9234..0a86af84 100644 --- a/addon/templates/users/index.hbs +++ b/addon/templates/users/index.hbs @@ -9,27 +9,27 @@ @include={{array "acls.role" "acls.scope"}} as |table| > - + {{#unless this.emailAsUsername}} - + {{t "emeis.users.headings.username"}} - + {{/unless}} - + {{t "emeis.users.headings.lastName"}} - - + + {{t "emeis.users.headings.firstName"}} - - + + {{t "emeis.users.headings.email"}} - - + + {{t "emeis.roles.title"}} - - + + {{t "emeis.scopes.title"}} - + diff --git a/app/components/data-table/head/sortable.js b/app/components/data-table/head/column.js similarity index 85% rename from app/components/data-table/head/sortable.js rename to app/components/data-table/head/column.js index f804684c..eac99981 100644 --- a/app/components/data-table/head/sortable.js +++ b/app/components/data-table/head/column.js @@ -1 +1 @@ -export { default } from "ember-emeis/components/data-table/head/sortable"; +export { default } from "ember-emeis/components/data-table/head/column"; diff --git a/app/components/data-table/head/nonsortable.js b/app/components/data-table/head/nonsortable.js deleted file mode 100644 index 0cc1c6c9..00000000 --- a/app/components/data-table/head/nonsortable.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from "ember-emeis/components/data-table/head/nonsortable"; diff --git a/tests/integration/components/data-table-test.js b/tests/integration/components/data-table-test.js index a886ca3a..a7f339aa 100644 --- a/tests/integration/components/data-table-test.js +++ b/tests/integration/components/data-table-test.js @@ -18,9 +18,9 @@ module("Integration | Component | data-table", function (hooks) { await render(hbs` - - Heading 1 - Heading 2 + + Heading 1 + Heading 2 @@ -38,8 +38,8 @@ module("Integration | Component | data-table", function (hooks) { assert.dom('form button[type="submit"]').exists(); assert.dom("thead tr").exists({ count: 1 }); - assert.dom("thead tr td:first-child").hasText("Heading 1"); - assert.dom("thead tr td:last-child").hasText("Heading 2"); + assert.dom("thead tr th:first-child").hasText("Heading 1"); + assert.dom("thead tr th:last-child").hasText("Heading 2"); assert.dom("tbody tr").exists({ count: 10 }); assert @@ -65,13 +65,13 @@ module("Integration | Component | data-table", function (hooks) { @modelName={{this.modelName}} @page={{this.page}} as |table|> - - + + Heading One - - + + Heading One - + @@ -150,16 +150,16 @@ module("Integration | Component | data-table", function (hooks) { @modelName={{this.modelName}} @include={{array "acls.role" "acls.scope"}} as |table|> - - + + Heading One - - + + Roles - - + + Scopes - + diff --git a/tests/integration/components/data-table/head/sortable-test.js b/tests/integration/components/data-table/head/column-test.js similarity index 82% rename from tests/integration/components/data-table/head/sortable-test.js rename to tests/integration/components/data-table/head/column-test.js index d5aadf71..b1b58a96 100644 --- a/tests/integration/components/data-table/head/sortable-test.js +++ b/tests/integration/components/data-table/head/column-test.js @@ -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) { @@ -16,10 +16,10 @@ module("Integration | Component | data-table/head/sortable", function (hooks) { test("it renders", async function (assert) { await render(hbs` - - + + test - + `); @@ -29,9 +29,9 @@ module("Integration | Component | data-table/head/sortable", function (hooks) { test("it renders as block", async function (assert) { await render(hbs` - + template block text - + `); assert.dom(this.element).hasText("template block text"); @@ -39,13 +39,13 @@ module("Integration | Component | data-table/head/sortable", function (hooks) { test("it toggles sort state", async function (assert) { await render(hbs` - - + + one - - + + two - + `); diff --git a/tests/integration/components/data-table/head/nonsortable-test.js b/tests/integration/components/data-table/head/nonsortable-test.js deleted file mode 100644 index a212f637..00000000 --- a/tests/integration/components/data-table/head/nonsortable-test.js +++ /dev/null @@ -1,39 +0,0 @@ -import { render } from "@ember/test-helpers"; -import { hbs } from "ember-cli-htmlbars"; -import { setupRenderingTest } from "ember-qunit"; -import { module, test } from "qunit"; - -module( - "Integration | Component | data-table/head/nonsortable", - function (hooks) { - setupRenderingTest(hooks); - - hooks.beforeEach(function (assert) { - this.set("update", () => { - assert.step("update"); - }); - }); - - test("it renders", async function (assert) { - await render(hbs` - - - test - - - `); - - assert.dom(this.element).hasText("test"); - }); - - test("it renders as block", async function (assert) { - await render(hbs` - - template block text - - `); - - assert.dom(this.element).hasText("template block text"); - }); - } -);