From 084fefbe42752358fb460089d76b9494bf8fa287 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Sun, 18 Apr 2021 23:00:57 +0200 Subject: [PATCH] maint: Upgrade to Patternslib v4 final - sortable table customizations. --- bundle-config.js | 2 +- package.json | 11 ++++++----- src/pat-sortable-table.js | 18 ++++++------------ src/pat-sortable-table.test.js | 14 ++++---------- 4 files changed, 17 insertions(+), 28 deletions(-) diff --git a/bundle-config.js b/bundle-config.js index 8436cde..bf82db1 100644 --- a/bundle-config.js +++ b/bundle-config.js @@ -1,4 +1,4 @@ -import registry from "patternslib/src/core/registry.js"; +import registry from "@patternslib/patternslib/src/core/registry.js"; import "./src/pat-sortable-table.js"; registry.init(); diff --git a/package.json b/package.json index 62c9d4c..8536929 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { - "name": "pat-PATTERN_TEMPLATE", + "name": "pat-sortable-table", "version": "1.0.0", - "description": "A pattern for PATTERN_TEMPLATE", + "description": "A pattern for interactive tables.", "license": "MIT", - "main": "./src/PATTERN_TEMPLATE.js", + "main": "./src/pat-sortable-table.js", "dependencies": { + "datatables.net-dt": "^1.10.22", "@patternslib/patternslib": "4" }, "devDependencies": { @@ -69,9 +70,9 @@ "name": "Syslab GesmbH", "email": "dev@syslab.com" }, - "homepage": "https://gitub.com/patternslib/pat-PATTERN_TEMPLATE", + "homepage": "https://github.com/patternslib/pat-sortable-table", "repository": { "type": "git", - "url": "https://gitub.com/patternslib/pat-PATTERN_TEMPLATE.git" + "url": "https://github.com/patternslib/pat-sortable-table.git" } } diff --git a/src/pat-sortable-table.js b/src/pat-sortable-table.js index 06a90ae..1ea13d0 100644 --- a/src/pat-sortable-table.js +++ b/src/pat-sortable-table.js @@ -1,7 +1,6 @@ -import $ from "jquery"; import "regenerator-runtime/runtime"; // needed for ``await`` support -import Base from "patternslib/src/core/base"; -import Parser from "patternslib/src/core/parser"; +import Base from "@patternslib/patternslib/src/core/base"; +import Parser from "@patternslib/patternslib/src/core/parser"; const parser = new Parser("sortable-table"); parser.addArgument("paging-type", "numbers", [ @@ -26,12 +25,8 @@ export default Base.extend({ name: "sortable-table", trigger: ".pat-sortable-table", - async init(el, opts) { - if (el.jquery) { - el = el[0]; - } - this.el = el; - this.options = parser.parse(el, opts); + async init() { + this.options = parser.parse(this.$el, this.options); await import("datatables.net"); let pageLengthMenu = this.options.page["length-menu"]; @@ -39,9 +34,8 @@ export default Base.extend({ pageLengthMenu = JSON.parse(pageLengthMenu); } - $(el).DataTable({ - dom: - '<"data-table-top"if>rt<"data-table-bottom"lp><"data-table-clear">', + this.$el.DataTable({ + dom: '<"data-table-top"if>rt<"data-table-bottom"lp><"data-table-clear">', retrieve: true, pagingType: this.options.pagingType, pageLength: this.options.page.length, diff --git a/src/pat-sortable-table.test.js b/src/pat-sortable-table.test.js index 642ad09..b1d003a 100644 --- a/src/pat-sortable-table.test.js +++ b/src/pat-sortable-table.test.js @@ -1,6 +1,6 @@ import "regenerator-runtime/runtime"; // needed for ``await`` support import pattern from "./pat-sortable-table"; -import utils from "patternslib/src/core/utils"; +import utils from "@patternslib/patternslib/src/core/utils"; describe("pat-sortable-table", () => { beforeEach(() => { @@ -10,9 +10,7 @@ describe("pat-sortable-table", () => { it("is initialized correctly and allows sorting", async (done) => { document.body.innerHTML = small_table; - const instance = pattern.init( - document.querySelector(".pat-sortable-table") - ); + pattern.init(document.querySelector(".pat-sortable-table")); await utils.timeout(1); let td; @@ -62,9 +60,7 @@ describe("pat-sortable-table", () => { language-search-placeholder: type term;` ); - const instance = pattern.init( - document.querySelector(".pat-sortable-table") - ); + pattern.init(document.querySelector(".pat-sortable-table")); await utils.timeout(1); expect(document.querySelectorAll("tbody").length).toBe(1); @@ -76,9 +72,7 @@ describe("pat-sortable-table", () => { .querySelector(".dataTables_length") .textContent.indexOf("per page") > -1 ).toBeTruthy(); - expect(document.querySelector(".dataTables_filter").textContent).toBe( - "find" - ); + expect(document.querySelector(".dataTables_filter").textContent).toBe("find"); expect( document .querySelector(".dataTables_filter input[type=search]")