Skip to content

Commit 249d5cc

Browse files
committed
feat: save searchValue on editor change
1 parent e17c142 commit 249d5cc

File tree

5 files changed

+52
-46
lines changed

5 files changed

+52
-46
lines changed

editors/dataset/data-set-editor.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ export class DataSetEditor extends ScopedElementsMixin(LitElement) {
3838

3939
@property({ type: String }) searchValue = '';
4040

41-
private handleSearchChange = (event: CustomEvent) => {
42-
this.dispatchEvent(
43-
new CustomEvent('search-change', {
44-
detail: event.detail,
45-
bubbles: true,
46-
})
47-
);
48-
};
49-
5041
@state()
5142
selectedDataSet?: Element;
5243

@@ -72,6 +63,13 @@ export class DataSetEditor extends ScopedElementsMixin(LitElement) {
7263
super.update(props);
7364
} */
7465

66+
updated(changedProps: Map<string | number | symbol, unknown>) {
67+
super.updated?.(changedProps);
68+
if (changedProps.has('searchValue') && this.selectionList) {
69+
this.selectionList.searchValue = this.searchValue;
70+
}
71+
}
72+
7573
private renderElementEditorContainer(): TemplateResult {
7674
if (this.selectedDataSet)
7775
return html`<div class="elementeditorcontainer">
@@ -148,8 +146,6 @@ export class DataSetEditor extends ScopedElementsMixin(LitElement) {
148146
return html`<action-list
149147
class="selectionlist"
150148
.items=${items}
151-
.searchValue=${this.searchValue}
152-
@search-change=${this.handleSearchChange}
153149
filterable
154150
searchhelper="Filter DataSet's"
155151
></action-list>`;

editors/gsecontrol/gse-control-editor.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ export class GseControlEditor extends BaseElementEditor {
4040

4141
@property({ type: String }) searchValue = '';
4242

43-
private handleSearchChange = (event: CustomEvent) => {
44-
this.dispatchEvent(
45-
new CustomEvent('search-change', {
46-
detail: event.detail,
47-
bubbles: true,
48-
})
49-
);
50-
};
51-
5243
@query('.selectionlist') selectionList!: ActionList;
5344

5445
@query('.change.scl.element') selectGSEControlButton!: MdOutlinedButton;
@@ -80,6 +71,13 @@ export class GseControlEditor extends BaseElementEditor {
8071
}
8172
} */
8273

74+
updated(changedProps: Map<string | number | symbol, unknown>) {
75+
super.updated?.(changedProps);
76+
if (changedProps.has('searchValue') && this.selectionList) {
77+
this.selectionList.searchValue = this.searchValue;
78+
}
79+
}
80+
8381
protected renderElementEditorContainer(): TemplateResult {
8482
if (this.selectCtrlBlock !== undefined)
8583
return html`<div class="elementeditorcontainer">
@@ -197,8 +195,6 @@ export class GseControlEditor extends BaseElementEditor {
197195
filterable
198196
searchhelper="Filter GSEControl's"
199197
.items=${items}
200-
.searchValue=${this.searchValue}
201-
@search-change=${this.handleSearchChange}
202198
></action-list>`;
203199
}
204200

editors/report/report-control-editor.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,6 @@ export class ReportControlEditor extends BaseElementEditor {
4141
'md-checkbox': MdCheckbox,
4242
};
4343

44-
@property({ type: String }) searchValue = '';
45-
46-
private handleSearchChange = (event: CustomEvent) => {
47-
this.dispatchEvent(
48-
new CustomEvent('search-change', {
49-
detail: event.detail,
50-
bubbles: true,
51-
})
52-
);
53-
};
54-
5544
@query('.selectionlist') selectionList!: ActionList;
5645

5746
@query('.change.scl.element') selectReportControlButton!: MdOutlinedButton;
@@ -62,6 +51,8 @@ export class ReportControlEditor extends BaseElementEditor {
6251
@query('data-set-element-editor')
6352
dataSetElementEditor!: DataSetElementEditor;
6453

54+
@property({ type: String }) searchValue = '';
55+
6556
/** Resets selected Report and its DataSet, if not existing in new doc
6657
update(props: Map<string | number | symbol, unknown>): void {
6758
super.update(props);
@@ -87,6 +78,13 @@ export class ReportControlEditor extends BaseElementEditor {
8778
}
8879
} */
8980

81+
updated(changedProps: Map<string | number | symbol, unknown>) {
82+
super.updated?.(changedProps);
83+
if (changedProps.has('searchValue') && this.selectionList) {
84+
this.selectionList.searchValue = this.searchValue;
85+
}
86+
}
87+
9088
private renderElementEditorContainer(): TemplateResult {
9189
if (this.selectCtrlBlock !== undefined)
9290
return html`<div class="elementeditorcontainer">
@@ -204,8 +202,6 @@ export class ReportControlEditor extends BaseElementEditor {
204202
filterable
205203
searchhelper="Filter ReportControl's"
206204
.items=${items}
207-
.searchValue=${this.searchValue}
208-
@search-change=${this.handleSearchChange}
209205
></action-list>`;
210206
}
211207

editors/sampledvalue/sampled-value-control-editor.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,6 @@ export class SampledValueControlEditor extends BaseElementEditor {
4747

4848
@property({ type: String }) searchValue = '';
4949

50-
private handleSearchChange = (event: CustomEvent) => {
51-
this.dispatchEvent(
52-
new CustomEvent('search-change', {
53-
detail: event.detail,
54-
bubbles: true,
55-
})
56-
);
57-
};
58-
5950
@query('.selectionlist') selectionList!: ActionList;
6051

6152
@query('.change.scl.element')
@@ -92,6 +83,13 @@ export class SampledValueControlEditor extends BaseElementEditor {
9283
}
9384
} */
9485

86+
updated(changedProps: Map<string | number | symbol, unknown>) {
87+
super.updated?.(changedProps);
88+
if (changedProps.has('searchValue') && this.selectionList) {
89+
this.selectionList.searchValue = this.searchValue;
90+
}
91+
}
92+
9593
private renderElementEditorContainer(): TemplateResult {
9694
if (this.selectCtrlBlock !== undefined)
9795
return html`<div class="elementeditorcontainer">
@@ -197,8 +195,6 @@ export class SampledValueControlEditor extends BaseElementEditor {
197195
filterable
198196
searchhelper="Filter SampledValueControl's"
199197
.items=${items}
200-
.searchValue=${this.searchValue}
201-
@search-change=${this.handleSearchChange}
202198
></action-list>`;
203199
}
204200

oscd-publisher.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@ import { GseControlEditor } from './editors/gsecontrol/gse-control-editor.js';
1111
import { ReportControlEditor } from './editors/report/report-control-editor.js';
1212
import { SampledValueControlEditor } from './editors/sampledvalue/sampled-value-control-editor.js';
1313

14+
const EditorSelector = {
15+
Report: 'report-control-editor',
16+
GOOSE: 'gse-control-editor',
17+
SampledValue: 'sampled-value-control-editor',
18+
DataSet: 'data-set-editor',
19+
} as const;
20+
1421
type PublisherType = 'Report' | 'GOOSE' | 'SampledValue' | 'DataSet';
1522

23+
type EditorSelectorType = (typeof EditorSelector)[keyof typeof EditorSelector];
24+
1625
/** An editor [[`plugin`]] to configure `Report`, `GOOSE`, `SampledValue` control blocks and its `DataSet` */
1726
export default class PublisherPlugin extends ScopedElementsMixin(LitElement) {
1827
static scopedElements = {
@@ -47,7 +56,20 @@ export default class PublisherPlugin extends ScopedElementsMixin(LitElement) {
4756
this.requestUpdate();
4857
};
4958

59+
private saveCurrentSearchValue() {
60+
const selector: EditorSelectorType = EditorSelector[this.publisherType];
61+
const editor = this.renderRoot.querySelector(selector) as {
62+
selectionList?: { searchValue: string };
63+
} | null;
64+
65+
if (editor) {
66+
this.filterValues[this.publisherType] =
67+
editor.selectionList?.searchValue || '';
68+
}
69+
}
70+
5071
private handlePublisherTypeChange(newType: PublisherType) {
72+
this.saveCurrentSearchValue();
5173
this.publisherType = newType;
5274
}
5375

0 commit comments

Comments
 (0)