Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: separate ui and business logic #3

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions src/editors/IED.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,22 @@ export default class IedPlugin extends LitElement {
this.selectedIEDs = [iedName];
}
}
this.selectedLNClasses = this.lnClassList.map(
lnClassInfo => lnClassInfo[0]
);
}
}

private calcSelectedLNClasses(): string[] {
const somethingSelected = this.selectedLNClasses.length > 0;
const lnClasses = this.lnClassList.map( lnClassInfo => lnClassInfo[0] );

let selectedLNClasses = lnClasses;

if(somethingSelected){
selectedLNClasses = lnClasses.filter( lnClass => this.selectedLNClasses.includes(lnClass));
}

return selectedLNClasses;
}

Comment on lines +135 to +147
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main logic.
I've went for readability. You could argue, that we could wait with the mapping until nothing is selected, but I don't think this so such a big performance problem and it would be the code less readable.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it!

render(): TemplateResult {
const iedList = this.iedList;
if (iedList.length > 0) {
Expand Down Expand Up @@ -165,9 +175,7 @@ export default class IedPlugin extends LitElement {

this.lNClassListOpenedOnce = false;
this.selectedIEDs = e.detail.selectedItems;
this.selectedLNClasses = this.lnClassList.map(
lnClassInfo => lnClassInfo[0]
);
this.selectedLNClasses = [];
this.requestUpdate('selectedIed');
}}"
>
Expand Down Expand Up @@ -195,17 +203,9 @@ export default class IedPlugin extends LitElement {
multi="true"
.header="${translate('iededitor.lnFilter')}"
@selected-items-changed="${(e: SelectedItemsChangedEvent) => {
let selectedItems = e.detail.selectedItems;
const nothingSelected = selectedItems.length === 0;
if (nothingSelected) {
selectedItems = this.lnClassList.map(
lnClassInfo => lnClassInfo[0]
);
}

this.selectedLNClasses = selectedItems;
this.selectedLNClasses = e.detail.selectedItems;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically reverting as it was

this.requestUpdate('selectedIed');
this.lNClassListOpenedOnce = true;
}}"
>
<span slot="icon">${getIcon('lNIcon')}</span>
Expand All @@ -214,8 +214,7 @@ export default class IedPlugin extends LitElement {
const label = lnClassInfo[1];
return html`<mwc-check-list-item
value="${value}"
?selected="${this.lNClassListOpenedOnce &&
this.selectedLNClasses.includes(value)}"
?selected="${this.selectedLNClasses.includes(value)}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverting this too

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less sure about reverting the "opened once" logic.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the improvement and I checked this out and had a look.

However when I select a new IED then all LNs are selected again.

  1. Open file.
  2. Open LN class filter. Looks good.
  3. Close LN filter.
  4. Open IED filter.
  5. Select new IED
  6. Open LN filter.
  7. Alas, all LNs are selected

Also, there is another issue alas which is quite visible when I merge this PR which is that

  1. Select some LNs in the LN class filter.
  2. Change the IED using the IED filter.
  3. Open the LN class filter -- the same LNs are selected.
  4. However the selection is not correctly being applied.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about like this? (PR has been updated)
20230908033556_ied_ln_class

>
${label}
</mwc-check-list-item>`;
Expand All @@ -229,7 +228,7 @@ export default class IedPlugin extends LitElement {
.editCount=${this.editCount}
.doc=${this.doc}
.element=${this.selectedIed}
.selectedLNClasses=${this.selectedLNClasses}
.selectedLNClasses=${this.calcSelectedLNClasses()}
.nsdoc=${this.nsdoc}
></ied-container>
</section>`;
Expand Down