Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.

Commit 9e028f4

Browse files
committed
feat: add prefix field to ln dialog
1 parent 0292e39 commit 9e028f4

6 files changed

Lines changed: 60 additions & 6 deletions

File tree

packages/openscd/src/translations/de.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ export const de: Translations = {
278278
addLnDialog: {
279279
title: 'LN hinzufügen',
280280
amount: 'Menge',
281+
prefix: 'Prefix',
281282
filter: 'Logical Node Types filtern',
282283
noResults: 'Keine Logical Node Types gefunden',
283284
},

packages/openscd/src/translations/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ export const en = {
275275
addLnDialog: {
276276
title: 'Add LN',
277277
amount: 'Amount',
278+
prefix: 'Prefix',
278279
filter: 'Filter Logical Node Types',
279280
noResults: 'No Logical Node Types found',
280281
},

packages/plugins/src/editors/ied/add-ln-dialog.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface LNData {
2323
lnType: string;
2424
lnClass: string;
2525
amount: number;
26+
prefix?: string;
2627
}
2728

2829
/** Dialog for adding a new LN to a LDevice. */
@@ -46,6 +47,9 @@ export class AddLnDialog extends LitElement {
4647
@state()
4748
filterText = '';
4849

50+
@state()
51+
prefix: string = '';
52+
4953
private get lNodeTypes(): Array<{
5054
id: string;
5155
lnClass: string;
@@ -74,21 +78,31 @@ export class AddLnDialog extends LitElement {
7478
this.lnType = '';
7579
this.amount = 1;
7680
this.filterText = '';
81+
this.prefix = '';
7782
this.dialog.show();
7883
}
7984

8085
private close(): void {
8186
this.dialog.close();
8287
}
8388

89+
private isPrefixValid(prefix: string): boolean {
90+
if (prefix === '') return true;
91+
if (prefix.length > 11) return false;
92+
return /^[A-Za-z][0-9A-Za-z_]*$/.test(prefix);
93+
}
94+
8495
private handleCreate(): void {
8596
const selectedType = this.lNodeTypes.find(t => t.id === this.lnType);
8697
if (!selectedType) return;
87-
this.onConfirm({
98+
const data: LNData = {
8899
lnType: selectedType.id,
89100
lnClass: selectedType.lnClass,
90101
amount: this.amount,
91-
});
102+
...(this.prefix && { prefix: this.prefix }),
103+
};
104+
105+
this.onConfirm(data);
92106
this.close();
93107
}
94108

@@ -145,6 +159,19 @@ export class AddLnDialog extends LitElement {
145159
</mwc-list>
146160
</div>
147161
</div>
162+
<mwc-textfield
163+
label="${translate('iededitor.addLnDialog.prefix')}"
164+
type="text"
165+
maxlength="11"
166+
.value=${this.prefix}
167+
@input=${(e: Event) => {
168+
e.stopPropagation();
169+
this.prefix = (e.target as HTMLInputElement).value;
170+
}}
171+
pattern="[A-Za-z][0-9A-Za-z_]*"
172+
style="width: 100%; margin-top: 12px;"
173+
data-testid="prefix"
174+
></mwc-textfield>
148175
<mwc-textfield
149176
label=${translate('iededitor.addLnDialog.amount')}
150177
type="number"
@@ -174,13 +201,17 @@ export class AddLnDialog extends LitElement {
174201
trailingIcon
175202
data-testid="add-ln-button"
176203
@click=${this.handleCreate}
177-
?disabled=${!this.lnType || this.amount < 1 || this.amount % 1 != 0}
204+
?disabled=${!this.lnType ||
205+
this.amount < 1 ||
206+
this.amount % 1 != 0 ||
207+
!this.isPrefixValid(this.prefix)}
178208
>
179209
${translate('add')}
180210
</mwc-button>
181211
</mwc-dialog>
182212
`;
183213
}
214+
184215
static styles = css`
185216
.dialog-content {
186217
margin-top: 16px;

packages/plugins/src/editors/ied/ldevice-container.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ export class LDeviceContainer extends Container {
9191
for (let i = 0; i < data.amount; i++) {
9292
const inst = getInst(data.lnClass);
9393
if (!inst) break;
94-
const ln = createElement(this.doc, 'LN', {
94+
const lnAttrs = {
9595
lnClass: data.lnClass,
9696
lnType: data.lnType,
97-
inst,
98-
});
97+
inst: inst,
98+
...(data.prefix ? { prefix: data.prefix } : {}),
99+
};
100+
const ln = createElement(this.doc, 'LN', lnAttrs);
99101
inserts.push({ parent: this.element, node: ln, reference: null });
100102
}
101103

packages/plugins/test/unit/editors/ied/__snapshots__/add-ln-dialog.test.snap.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ snapshots["add-ln-dialog looks like the latest snapshot"] =
3737
</mwc-list>
3838
</div>
3939
</div>
40+
<mwc-textfield
41+
data-testid="prefix"
42+
label="[iededitor.addLnDialog.prefix]"
43+
maxlength="11"
44+
pattern="[A-Za-z][0-9A-Za-z_]*"
45+
style="width: 100%; margin-top: 12px;"
46+
type="text"
47+
>
48+
</mwc-textfield>
4049
<mwc-textfield
4150
data-testid="amount"
4251
label="[iededitor.addLnDialog.amount]"

packages/plugins/test/unit/editors/ied/add-ln-dialog.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,22 @@ describe('add-ln-dialog', () => {
6060
await element.updateComplete;
6161
}
6262

63+
const prefixInput = element.shadowRoot?.querySelector(
64+
'[data-testid="prefix"]'
65+
);
66+
(prefixInput as HTMLInputElement).value = 'MyPrefix';
67+
(prefixInput as HTMLInputElement).dispatchEvent(
68+
new Event('input', { bubbles: true, composed: true })
69+
);
70+
6371
const amountInput = element.shadowRoot?.querySelector(
6472
'[data-testid="amount"]'
6573
);
6674
(amountInput as HTMLInputElement).value = '3';
6775
(amountInput as HTMLInputElement).dispatchEvent(
6876
new Event('input', { bubbles: true, composed: true })
6977
);
78+
7079
await element.updateComplete;
7180
const addButton = element.shadowRoot?.querySelector(
7281
'[data-testid="add-ln-button"]'
@@ -78,6 +87,7 @@ describe('add-ln-dialog', () => {
7887
expect(onConfirmSpy.firstCall.args[0]).to.deep.include({
7988
lnType: 'PlaceholderLLN0',
8089
lnClass: 'LLN0',
90+
prefix: 'MyPrefix',
8191
amount: 3,
8292
});
8393
});

0 commit comments

Comments
 (0)