fix: keep Symcon binding paths compact and allow direct unlinking

This commit is contained in:
jhartworks committed 2026-11-10 10:00:01 +01:00
1 parent 00fca890de
commit b9a095bc6e
12 files changed
+131 -46

No files matched your search

@@ -140,7 +140,7 @@ export function renderRoomClimate(host: EditorHost, room: Room, patch: (patch: P
// several sensors are averaged: once one is chosen, another can be added; "none" in a slot drops it
const save = (list: (string | null)[]) => {
const ids = list.filter((id): id is string => !!id && id !== "none");
change(key, list[0] === "none" ? "none" : ids.length > 1 ? ids : (ids[0] ?? null));
change(key, ids.length > 1 ? ids : (ids[0] ?? (list.includes("none") ? "none" : null)));
};
const real = picked[0] && picked[0] !== "none";
const slots = real ? [...picked, null] : picked;
+3 -1
View File
@@ -115,7 +115,7 @@ export class EntityPicker extends LitElement {
if (this.objectTree !== undefined) return html`<nf-symcon-object-picker
.objects=${this.objectTree} .options=${this.options} .fixed=${this.fixed} .value=${this.value}
.disabled=${this.disabled} .placeholder=${this.placeholder}
@change=${(event: CustomEvent<{ value: string }>) => { this.value = event.detail.value; }}
@change=${(event: CustomEvent<{ value: string | null }>) => { this.value = event.detail.value; }}
></nf-symcon-object-picker>`;
const current = this.current;
const hits = this._open ? this.hits : [];
@@ -169,6 +169,8 @@ export class EntityPicker extends LitElement {
:host {
display: block;
position: relative;
min-width: 0;
max-width: 100%;
}
input {
width: 100%;
@@ -81,6 +81,18 @@ export class SymconObjectPicker extends LitElement {
private close(): void { this.dialog?.close(); }
private clear(event: Event): void {
event.preventDefault();
event.stopPropagation();
if (this.disabled) return;
this.value = this.fixed.some((option) => option.id === "none") ? "none" : null;
this._pending = this.value;
this._selected = null;
this._active = null;
this.close();
this.dispatchEvent(new CustomEvent("change", { detail: { value: this.value }, bubbles: true, composed: true }));
}
private commit(): void {
if (this.disabled || !this._pending || !this.allowed.has(this._pending)) return;
this.value = this._pending;
@@ -178,10 +190,11 @@ export class SymconObjectPicker extends LitElement {
const pendingNode = (selectedObject && this.entityFor(selectedObject) === this._pending ? selectedObject : undefined) ?? this.variableNode(this._pending);
const rows = symconTreeRows(this.tree, this._expanded, this._query);
const active = rows.find((row) => row.node.object_id === this._active);
return html`<button type="button" class="trigger" ?disabled=${this.disabled} aria-haspopup="dialog" @click=${this.open}>
<span><strong>${selectedNode?.name ?? current?.label ?? "Datenpunkt auswählen"}</strong>
${selectedNode ? html`<small>${selectedNode.path}</small>` : nothing}</span><span aria-hidden="true">⌘</span>
</button>
const linked = !!this.value && !this.fixed.some((option) => option.id === this.value);
return html`<div class="field"><button type="button" class="trigger" ?disabled=${this.disabled} aria-haspopup="dialog" @click=${this.open}>
<span class="trigger-text"><strong>${selectedNode?.name ?? current?.label ?? "Datenpunkt auswählen"}</strong>
${selectedNode ? html`<small title=${selectedNode.path}>${selectedNode.path}</small>` : nothing}</span><span class="picker-icon" aria-hidden="true">⌘</span>
</button>${linked ? html`<button class="clear" type="button" ?disabled=${this.disabled} aria-label="Verknüpfung entfernen" title="Verknüpfung entfernen" @click=${this.clear}>×</button>` : nothing}</div>
<dialog aria-labelledby="picker-title" @click=${(event: MouseEvent) => {
event.stopPropagation();
if (event.target === this.dialog) {
@@ -211,13 +224,17 @@ export class SymconObjectPicker extends LitElement {
}
static styles = [tokens, css`
:host { display:block; min-width:0; font:inherit; color:var(--nf-text); }
:host { display:block; min-width:0; max-width:100%; font:inherit; color:var(--nf-text); }
button,input { font:inherit; box-sizing:border-box; }
button { cursor:pointer; color:var(--nf-text); border:1px solid var(--nf-line); background:var(--nf-chrome-solid); border-radius:9px; padding:8px 12px; }
button:disabled { opacity:.45; cursor:default; }
button:focus-visible,input:focus-visible { outline:2px solid var(--nf-accent); outline-offset:2px; }
.trigger { width:100%; display:flex; align-items:center; justify-content:space-between; text-align:left; gap:12px; padding:9px 11px; }
.trigger>span:first-child { min-width:0; }
.field { display:flex; gap:6px; min-width:0; }
.trigger { flex:1; min-width:0; width:100%; display:flex; align-items:center; justify-content:space-between; text-align:left; gap:12px; padding:9px 11px; }
.trigger-text { flex:1; min-width:0; overflow:hidden; }
.trigger strong { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.picker-icon { flex:none; }
.clear { flex:none; width:32px; padding:0; font-size:22px; }
strong { font-weight:500; } small { display:block; color:var(--nf-muted); font-size:11px; }
.trigger small { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; margin-top:3px; }
dialog { width:min(780px,calc(100vw - 32px)); max-width:none; height:min(690px,calc(100dvh - 32px)); max-height:none; box-sizing:border-box; padding:0; border:1px solid var(--nf-line); border-radius:16px; color:var(--nf-text); background:var(--nf-chrome-solid); box-shadow:0 24px 80px #0008; font:14px system-ui,sans-serif; }
+20 -2
View File
@@ -30,12 +30,12 @@ try {
await page.evaluate(async () => {
window.humidityValue = 51.6;
window.bootstrapCalls = 0;
const raw = (id, name, type, value, unit, domain = "sensor") => ({ entity_id: `${domain}.${id}`, name, path: `Haus / Messwerte / ${name}`, state: domain === "cover" ? "open" : String(value), attributes: { symcon_id: id, symcon_variable_type: type, symcon_numeric_value: value, unit_of_measurement: unit } });
const raw = (id, name, type, value, unit, domain = "sensor") => ({ entity_id: `${domain}.${id}`, name, path: `Haus / DP KNX / OG Allgemein / Heizen Kühlen / RAT Teeküche / Weiterer Unterordner / Messwerte / ${name}`, state: domain === "cover" ? "open" : String(value), attributes: { symcon_id: id, symcon_variable_type: type, symcon_numeric_value: value, unit_of_measurement: unit } });
const originalFetch = window.fetch;
window.fetch = async (url, init) => {
if (!String(url).includes("/hook/climate-fixture/")) return originalFetch(url, init);
window.bootstrapCalls++;
const variables = [raw(201, "Raumtemperatur", 2, 21.5, "°C"), raw(202, "Messwert Raumfeuchtigkeit", 2, window.humidityValue, "%", "cover"), raw(203, "CO₂", 1, 780, "ppm"), raw(204, "Raumhelligkeit", 2, 320.5, "lx")];
const variables = [raw(201, "Raumtemperatur", 2, 21.5, "°C"), raw(202, "Messwert Raumfeuchtigkeit", 2, window.humidityValue, "%", "cover"), raw(203, "CO₂", 1, 780, "ppm"), raw(204, "Raumhelligkeit", 2, 320.5, "lx"), raw(205, "Zusatztemperatur", 2, 21.5, "°C")];
const objects = [{ object_id: 100, parent_id: 0, name: "Haus", path: "Haus", object_type: 0, position: 0, hidden: true, icon: "" },
...variables.map((v) => ({ object_id: v.attributes.symcon_id, parent_id: 100, entity_id: v.entity_id, name: v.name, path: v.path, object_type: 2, position: 0, hidden: false, icon: "" }))];
return new Response(JSON.stringify({ state_revision: window.bootstrapCalls, building_revision: 1, variables, objects, areas: [] }));
@@ -89,6 +89,24 @@ try {
await window.pickClimate("Luftfeuchte", 202, "Messwert Raumfeuchtigkeit");
await window.pickClimate("CO₂", 203, "CO₂");
await window.pickClimate("Helligkeit", 204, "Raumhelligkeit");
await window.pickClimate("… und noch ein Sensor", 205, "Zusatztemperatur");
window.unlinkTemperature = async () => {
const field = [...window.climateSection.querySelectorAll("label.nf-field")].find((el) => el.textContent.trim().startsWith("Temperatur"));
const picker = field.querySelector("nf-entity-picker");
await picker.updateComplete;
const native = picker.shadowRoot.querySelector("nf-symcon-object-picker");
await native.updateComplete;
native.shadowRoot.querySelector(".clear").click();
await e.updateComplete;
await window.nfPanel.updateComplete;
await e.updateComplete;
};
await window.unlinkTemperature();
if (e._doc.floors[0].rooms[0].climate.temperature !== "sensor.205") throw new Error("Clearing the first averaged sensor removed its remaining link");
if (e._doc.floors[0].rooms[0].climate.humidity !== "cover.202") throw new Error("Unlinking temperature changed another metric");
await window.unlinkTemperature();
if (e._doc.floors[0].rooms[0].climate.temperature !== "none") throw new Error("The last temperature link must stay explicitly unlinked");
await window.pickClimate("Temperatur", 201, "Raumtemperatur");
const label = [...window.climateSection.querySelectorAll("label.nf-check")].find((el) => el.textContent.includes("schwebende Karte"));
label.querySelector("input").click();
await e.updateComplete;
+28 -1
View File
@@ -154,9 +154,36 @@ try {
assert.ok((await state()).rows.some((row) => row.id === "object-601" && row.selected === "true"), "a selected system variable reopens its virtual path");
await page.screenshot({ path: join(out, "symcon-picker-system.png") });
await page.keyboard.press("Escape");
await page.evaluate(async () => {
const picker = document.querySelector("#symcon");
const node = picker.objectTree.find((n) => n.object_id === 601);
picker.objectTree = picker.objectTree.map((n) => n === node ? { ...n, name: "Wert mit einem sehr langen Namen für eine verknüpfte Variable", path: `DP KNX / OG Allgemein / Heizen Kühlen / RAT Teeküche / ${"Weiterer Unterordner / ".repeat(10)}Wert` } : n);
document.querySelector("main").style.width = "250px";
await picker.updateComplete;
await picker.shadowRoot.querySelector("nf-symcon-object-picker").updateComplete;
});
assert.ok(await page.evaluate(() => {
const picker = document.querySelector("#symcon");
const native = picker.shadowRoot.querySelector("nf-symcon-object-picker");
const root = native.shadowRoot, field = root.querySelector(".field"), clear = root.querySelector(".clear"), path = root.querySelector(".trigger small"), name = root.querySelector(".trigger strong");
const bounds = field.getBoundingClientRect(), button = clear.getBoundingClientRect();
return bounds.width <= 250 && button.right <= bounds.right && button.left >= bounds.left && button.width >= 30 && path.scrollWidth > path.clientWidth && name.scrollWidth > name.clientWidth && getComputedStyle(path).textOverflow === "ellipsis" && path.title === path.textContent;
}), "long names and paths truncate without hiding the unlink button; the complete path remains in the tooltip");
await page.screenshot({ path: join(out, "symcon-picker-long-path.png") });
await page.evaluate(async () => { const p = document.querySelector("#symcon"); p.disabled = true; await p.updateComplete; await p.shadowRoot.querySelector("nf-symcon-object-picker").updateComplete; });
const beforeClear = (await state()).changes.length;
await click(".clear");
assert.equal((await state()).value, "sensor.601", "read-only pickers cannot unlink");
await page.evaluate(async () => { const p = document.querySelector("#symcon"); p.disabled = false; await p.updateComplete; await p.shadowRoot.querySelector("nf-symcon-object-picker").updateComplete; });
await click(".clear");
await settle();
assert.equal((await state()).value, "none", "the clear button removes the saved binding");
assert.equal((await state()).open, false, "clearing a label's picker must not reopen its modal");
assert.equal((await state()).changes.length, beforeClear + 1, "unlink emits exactly one saved change");
assert.ok(await page.evaluate(() => !document.querySelector("#symcon").shadowRoot.querySelector("nf-symcon-object-picker").shadowRoot.querySelector(".clear")), "an unlinked picker has no clear button");
assert.ok(await page.evaluate(() => !!document.querySelector("#ha").shadowRoot.querySelector("input[role=combobox]")), "HA picker remains unchanged");
assert.deepEqual(errors, [], "no browser errors");
console.log("OK: hidden categories, virtual system groups, system-variable search/selection, modal, confirm/cancel, Escape, mobile layout and HA compatibility");
console.log("OK: hidden categories, system groups, modal selection, narrow long-path truncation, direct unlink, read-only guard, single change event and HA compatibility");
console.log(`Screenshots: ${out}`);
} finally {
await browser.close();