Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Fix duration reassignment for When-Then rules conditions (#1594)

Dominique Kleeven972f5427f1a3
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts b/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts
index 930cadbd3..043474cc2 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts
@@ -824,12 +824,16 @@ export class OrRuleAssetQuery extends translate(i18next)(LitElement) {
if (index >= 0) {
group.items!.splice(index, 1);
- if(this.duration.has(index)) {
- const newEntries = Array.from(this.duration.entries())
- .filter(([k, v]) => k !== index)
- .map(([k, v], i) => [i, v] as [number, string | undefined]);
-
- this.duration = new Map<number, string | undefined>(newEntries);
+ if (this.duration) {
+ // re-assign durations
+ const newDurationEntries = Array.from(this.duration.entries())
+ .filter(([k, _]) => k !== index) // filter out the index
+ .map(([k, v]) => {
+ const newIndex = k > index ? k - 1 : k;
+ return [newIndex, v] as [number, string | undefined]; // adjust indices after the removed index
+ })
+
+ this.duration = new Map<number, string | undefined>(newDurationEntries);
}
}
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());