Skip to content

Commit 92e7390

Browse files
fix(editors/cleanup): Fix filter issue with in cleanup plugin (openscd#910)
* refactor(editors/cleanup): make linter happy * fix(editors/cleanup): make type and string filter work together * fix(editors/cleanup/control-clock-list): make sure check all works
1 parent 2aee3cc commit 92e7390

File tree

3 files changed

+31
-27
lines changed

3 files changed

+31
-27
lines changed

src/editors/cleanup/control-blocks-container.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
query,
1111
queryAll,
1212
} from 'lit-element';
13+
import { classMap } from 'lit-html/directives/class-map';
1314
import { translate } from 'lit-translate';
1415

1516
import '@material/mwc-button';
@@ -76,7 +77,7 @@ function getCommAddress(controlBlock: Element): Element | null | undefined {
7677
@customElement('cleanup-control-blocks')
7778
export class CleanupControlBlocks extends LitElement {
7879
/** The document being edited as provided to plugins by [[`OpenSCD`]]. */
79-
@property()
80+
@property({ attribute: false })
8081
doc!: XMLDocument;
8182

8283
@property({ type: Boolean })
@@ -85,7 +86,7 @@ export class CleanupControlBlocks extends LitElement {
8586
@property({ type: Array })
8687
unreferencedControls: Element[] = [];
8788

88-
@property()
89+
@property({ attribute: false })
8990
selectedControlItems: MWCListIndex | [] = [];
9091

9192
@query('.deleteButton')
@@ -118,7 +119,9 @@ export class CleanupControlBlocks extends LitElement {
118119
*/
119120
private toggleHiddenClass(selectorType: string) {
120121
this.cleanupList!.querySelectorAll(`.${selectorType}`).forEach(element => {
121-
element.classList.toggle('hidden');
122+
element.classList.toggle('hiddenontypefilter');
123+
if (element.hasAttribute('disabled')) element.removeAttribute('disabled');
124+
else element.setAttribute('disabled', 'true');
122125
});
123126
}
124127

@@ -164,7 +167,13 @@ export class CleanupControlBlocks extends LitElement {
164167
private renderListItem(controlBlock: Element): TemplateResult {
165168
return html`<mwc-check-list-item
166169
twoline
167-
class="cleanupListItem t${controlBlock.tagName}"
170+
class="${classMap({
171+
cleanupListItem: true,
172+
tReportControl: controlBlock.tagName === 'ReportControl',
173+
tLogControl: controlBlock.tagName === 'LogControl',
174+
tGSEControl: controlBlock.tagName === 'GSEControl',
175+
tSampledValueControl: controlBlock.tagName === 'SampledValueControl',
176+
})}"
168177
value="${identity(controlBlock)}"
169178
graphic="large"
170179
><span class="unreferencedControl"
@@ -228,13 +237,15 @@ export class CleanupControlBlocks extends LitElement {
228237
* @returns html for the Delete Button of this container.
229238
*/
230239
private renderDeleteButton(): TemplateResult {
240+
const sizeSelectedItems = (<Set<number>>this.selectedControlItems).size;
241+
231242
return html`<mwc-button
232243
outlined
233244
icon="delete"
234245
class="deleteButton"
235-
label="${translate('cleanup.unreferencedControls.deleteButton')} (${(<
236-
Set<number>
237-
>this.selectedControlItems).size || '0'})"
246+
label="${translate(
247+
'cleanup.unreferencedControls.deleteButton'
248+
)} (${sizeSelectedItems || '0'})"
238249
?disabled=${(<Set<number>>this.selectedControlItems).size === 0 ||
239250
(Array.isArray(this.selectedControlItems) &&
240251
!this.selectedControlItems.length)}
@@ -399,22 +410,12 @@ export class CleanupControlBlocks extends LitElement {
399410
opacity: 1;
400411
}
401412
402-
/* items are disabled if the filter is deselected */
403-
.tGSEControl,
404-
.tSampledValueControl,
405-
.tLogControl,
406-
.tReportControl {
413+
/* Make sure to type filter here
414+
.hidden is set on string filter in filtered-list and must always filter*/
415+
.cleanupListItem.hiddenontypefilter:not(.hidden) {
407416
display: none;
408417
}
409418
410-
/* items enabled if filter is selected */
411-
.tGSEControlFilter[on] ~ .cleanupList > .tGSEControl,
412-
.tSampledValueControlFilter[on] ~ .cleanupList > .tSampledValueControl,
413-
.tLogControlFilter[on] ~ .cleanupList > .tLogControl,
414-
.tReportControlFilter[on] ~ .cleanupList > .tReportControl {
415-
display: flex;
416-
}
417-
418419
/* filter disabled, Material Design guidelines for opacity */
419420
.tGSEControlFilter,
420421
.tSampledValueControlFilter,

src/editors/cleanup/datasets-container.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { cleanSCLItems, identitySort } from './foundation.js';
3838
@customElement('cleanup-datasets')
3939
export class CleanupDatasets extends LitElement {
4040
/** The document being edited as provided to plugins by [[`OpenSCD`]]. */
41-
@property()
41+
@property({ attribute: false })
4242
doc!: XMLDocument;
4343

4444
@property({ type: Boolean })
@@ -47,7 +47,7 @@ export class CleanupDatasets extends LitElement {
4747
@property({ type: Array })
4848
unreferencedDataSets: Element[] = [];
4949

50-
@property()
50+
@property({ attribute: false })
5151
selectedDatasetItems: MWCListIndex | [] = [];
5252

5353
@query('.deleteButton')
@@ -107,13 +107,15 @@ export class CleanupDatasets extends LitElement {
107107
* @returns html for the Delete Button of this container.
108108
*/
109109
private renderDeleteButton(): TemplateResult {
110+
const sizeSelectedItems = (<Set<number>>this.selectedDatasetItems).size;
111+
110112
return html` <mwc-button
111113
outlined
112114
icon="delete"
113115
class="deleteButton cleanupDeleteButton"
114-
label="${translate('cleanup.unreferencedDataSets.deleteButton')} (${(<
115-
Set<number>
116-
>this.selectedDatasetItems).size || '0'})"
116+
label="${translate(
117+
'cleanup.unreferencedDataSets.deleteButton'
118+
)} (${sizeSelectedItems || '0'})"
117119
?disabled=${(<Set<number>>this.selectedDatasetItems).size === 0 ||
118120
(Array.isArray(this.selectedDatasetItems) &&
119121
!this.selectedDatasetItems.length)}

test/unit/editors/cleanup/__snapshots__/control-blocks-container.test.snap.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,9 @@ snapshots["Cleanup: Control Blocks Container With a test file loaded looks like
241241
</mwc-icon>
242242
</mwc-check-list-item>
243243
<mwc-check-list-item
244-
aria-disabled="false"
245-
class="cleanupListItem hidden tReportControl"
244+
aria-disabled="true"
245+
class="cleanupListItem hiddenontypefilter tReportControl"
246+
disabled=""
246247
graphic="large"
247248
mwc-list-item=""
248249
tabindex="-1"

0 commit comments

Comments
 (0)