From 3a94927ad0b2b7b74782e555642a797aac5f34f8 Mon Sep 17 00:00:00 2001 From: Darter Date: Fri, 29 Mar 2024 13:06:35 +0100 Subject: [PATCH 1/3] init --- packages/v3/src/esp-entity-table.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/v3/src/esp-entity-table.ts b/packages/v3/src/esp-entity-table.ts index 164f33f..a798993 100644 --- a/packages/v3/src/esp-entity-table.ts +++ b/packages/v3/src/esp-entity-table.ts @@ -10,6 +10,8 @@ import "iconify-icon"; interface entityConfig { unique_id: string; + sorting_weight: number; + sorting_group: string; domain: string; id: string; state: string; @@ -98,15 +100,16 @@ export class EntityTable extends LitElement implements RestAction { this.has_controls = true; } this.entities.push(entity); - this.entities.sort((a, b) => + this.entities.sort((a, b) => a.entity_category < b.entity_category ? -1 : a.entity_category == b.entity_category - ? a.name < b.name + ? a.sorting_weight < b.sorting_weight ? -1 : 1 : 1 ); + this.requestUpdate(); } else { if (typeof data.value === "number") { From 1363b61e312ee55a2176464017d63b3da533f31b Mon Sep 17 00:00:00 2001 From: Darter Date: Thu, 4 Apr 2024 23:11:50 +0200 Subject: [PATCH 2/3] drop grouping --- packages/v3/src/esp-entity-table.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/v3/src/esp-entity-table.ts b/packages/v3/src/esp-entity-table.ts index a798993..276eaf4 100644 --- a/packages/v3/src/esp-entity-table.ts +++ b/packages/v3/src/esp-entity-table.ts @@ -11,7 +11,6 @@ import "iconify-icon"; interface entityConfig { unique_id: string; sorting_weight: number; - sorting_group: string; domain: string; id: string; state: string; From c4abef567c10f01c204746356d2906c9bcec5608 Mon Sep 17 00:00:00 2001 From: Darter Date: Thu, 18 Apr 2024 23:35:19 +0200 Subject: [PATCH 3/3] Fallback to sorting by name --- packages/v3/src/esp-entity-table.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/v3/src/esp-entity-table.ts b/packages/v3/src/esp-entity-table.ts index 276eaf4..4782c69 100644 --- a/packages/v3/src/esp-entity-table.ts +++ b/packages/v3/src/esp-entity-table.ts @@ -99,16 +99,17 @@ export class EntityTable extends LitElement implements RestAction { this.has_controls = true; } this.entities.push(entity); - this.entities.sort((a, b) => - a.entity_category < b.entity_category - ? -1 - : a.entity_category == b.entity_category - ? a.sorting_weight < b.sorting_weight - ? -1 - : 1 - : 1 - ); - + this.entities.sort((a, b) => { + const sortA = a.sorting_weight ?? a.name; + const sortB = b.sorting_weight ?? b.name; + return a.entity_category < b.entity_category + ? -1 + : a.entity_category == b.entity_category + ? sortA < sortB + ? -1 + : 1 + : 1 + }); this.requestUpdate(); } else { if (typeof data.value === "number") {