Git Product home page Git Product logo

oscd-filtered-list's Introduction

<oscd-filtered-list>

This webcomponent follows the open-wc recommendation.

Installation

npm i @openscd/oscd-filtered-list

Usage

<script type="module">
  import 'oscd-filtered-list';
</script>

<oscd-filtered-list></oscd-filtered-list>

Linting and formatting

To scan the project for linting and formatting errors, run

npm run lint

To automatically fix linting and formatting errors, run

npm run format

Testing with Web Test Runner

To execute a single test run:

npm run test

To run the tests in interactive watch mode run:

npm run test:watch

Demoing with Storybook

To run a local instance of Storybook for your component, run

npm run storybook

To build a production version of Storybook, run

npm run storybook:build

Tooling configs

For most of the tools, the configuration is in the package.json to reduce the amount of files in your project.

If you customize the configuration a lot, you can consider moving them to individual files.

Icon font

Material Icons are being used for the icons. This font needs to be added in the html first. You can add it like so:

<link
  href="https://fonts.googleapis.com/css?family=Material+Icons&display=block"
  rel="stylesheet"
/>

Local Demo with web-dev-server

npm start

To run a local development server that serves the basic demo located in demo/index.html

src/OscdFilteredList.ts:

Exports

Kind Name Declaration Module Package
custom-element-definition oscd-filtered-list OscdFilteredList /src/oscd-filtered-list.js
js OscdFilteredList OscdFilteredList src/OscdFilteredList.ts

src/oscd-filtered-list.ts:

class: OscdFilteredList, oscd-filtered-list

Superclass

Name Module Package
LitElement lit-element

Fields

Name Privacy Type Default Description Inherited From
searchFieldLabel string | undefined search mwc-textfield label property
disableCheckAll boolean false Whether the check all option (checkbox next to search text field) is activated
filter string | undefined The current input value of the filter textbox
wrapFocus boolean false When `true`, pressing `up` on the keyboard when focused on the first item will focus the last item and `down` when focused on the last item will focus the first item.
multi boolean false When `true`, enables selection of multiple items. This will result in `index` being of type `Set<number>` and selected returning `ListItemBase[]`.
activatable boolean false Sets activated attribute on selected items which provides a focus-persistent highlight.
list List
selected Currently-selected list item(s). When `multi` is `true`, `selected` is of type `ListItemBase[]` and when `false`, `selected` is of type `ListItemBase`. `selected` is `null` when no item is selected.
index Index / indices of selected item(s). When `multi` is `true`, `index` is of type `number` and when `false`, `index` is of type `Set<number>`. Unset indicies are `-1` and empty `Set<number>` for single and multi selection respectively.
items Array<ListItem> [] All list items that are available for selection. Eligible items have the `[mwc-list-item]` attribute which `ListItemBase` applies automatically.
searchField TextField

Methods

Name Privacy Description Parameters Return Inherited From
onFilterInput public Promise<void>

Events

Name Type Description Inherited From
action ActionEvent Fired when a selection has been made via click or keyboard action.
selected SelectedEvent Fired when a selection has been made. `index` is the selected index (will be of type `Set<number>` if multi and `number` if single), and `diff` (of type `IndexDiff`\*\*) represents the diff of added and removed indices from previous selection.

Functions

Name Description Parameters Return
redispatchEvent element: LitElement, event: Event

Exports

Kind Name Declaration Module Package
js redispatchEvent redispatchEvent src/oscd-filtered-list.ts
js OscdFilteredList OscdFilteredList src/oscd-filtered-list.ts

© 2023 Alliander N.V.

oscd-filtered-list's People

Contributors

ca-d avatar github-actions[bot] avatar juancho0202 avatar pascalwilbrink avatar stef3st avatar

Watchers

 avatar  avatar

oscd-filtered-list's Issues

Prevent browser issues (freezing) with "Select All"

Summary

As a user of the oscd-filtered-list I would like to avoid having browser performance issues with the "Select All" button when the list is too large.

To Refine:

  1. Determining the number of items that is our limit for providing a performant "Select All" functionality.
  2. Disabling the "Select All" button when we reach that limit.

Tooltip has incorrect text

Traditionally the tooltip for the search field is the word 'Filter'.

However after using the latest release of this component in a plugin, I notice there is code in the tooltip instead:

image

Implement debounce to improve performance

To improve performance with a large number of list items, I suggest using a debounce on the @input for the search box, something like:

function debounce(callback: any, delay = 250) {
  let timeout: any;

  return (...args: any) => {
    clearTimeout(timeout);
    timeout = setTimeout(() => {
      callback(...args);
    }, delay);
  };
}

  onFilterInput = debounce(() => {
    Array.from(
      this.querySelectorAll(
        'mwc-list-item, mwc-check-list-item, mwc-radio-list-item'
      )
    ).forEach(item =>
      hideFiltered(item as ListItemBase, this.searchField.value)
    );
  }, 500);

My use case is that the filtered list becomes unresponsive in a large (or even not so large file) when the full scd file's ExtRefs are shown in a single filtered list in the oscd-subscriber-later-binding plugin (in the subscriber view)

I found this article on debouncing/throttling helpful: https://blog.webdevsimplified.com/2022-03/debounce-vs-throttle/

This helps for moderate sized lists but not adequately for large lists but is probably worth doing any way. It is very likely that we should choose a number slightly lower than 500 ms (250? 300? 350? 400?)

This is for a file which has about 3620 ExtRef elements. Quite a few of these are "empty" but many relays fully expose their maximum capability in the quantity of ExtRefs they export.

IEC61850_GOOSE_2-section.scd.zip

I think this is a realistic scenario - we use schemes like this in production now.

Export list item types

Currently in the OscdFilteredList there are no types exported for the elements it encapsulates.

For instance I might want to type in my code:

  • a list item
  • a check box?
  • the search field?

Should this component be exporting some types to assist users with this?

Normally when we didn't fully encapsulate I would do something like:

import type { ListItemBase } from '@material/mwc-list/mwc-list-item-base.js';

I am not very proficient with types so please let me know if this is not the correct way this should be done.

Improve and cleanup filtered-list component

We now have a component guide (https://github.com/openscd/.github/blob/23491bd2408f3b7edaa8b0149a3d57aca1adaf40/docs/component_guide.md) where an explaination can be found on what a component should have. Some changes need to be made to the filtered-list to follow these rules.

Definition of Done:

  • Only the source files in the dist folder/README.md/package.json/license are to be published on NPM
  • CEM analyzer is being used. Be sure to use the correct annotations in the source files.
  • oscd-filtered-list and OscdFilteredList need to be the other way around
  • Screenshot tests need to be added

Create `oscd-filtered-list` based on `filtered-list`

As a plugin author and maintainer of already existing plugins, I need to have open-scds filtered-list available through nmp.

  • slot right and left to add filter icon buttons

Requirements:

  • move filtered-list to oscd-filtered-list repo
  • change tag name to oscd-filtered-list
  • do !NOT! extend from mwc-list but use it in the render method
  • add properties
name type description
searchFieldLabel string text on the filter textbox
disableCheckAll boolean disable the "check all" button
filter string the current value of the filter textbox
wrapFocus boolean whether focus wraps around the end and beginning of the list
multi boolean multi-select
activatable boolean color icons permanently on clicking
@action event fired before selection is made (find out: is this actually needed?)
@selected event fired after selection is made

TODO: search codebase for instances of filtered-list usage and add any properties/events/methods used that are not listed here.

  • propagate selected event for any changes on maybeValue
  • propagate ... event for any changes on ...
  • add screenshot tests
  • add storybook

Additional Information
This web-component is used pretty much everywhere in the software

Add documentation

Documentation still needs to be added and a deploy is also needed in the package.json

Lazy caching of search data

Similar to #8, SCD files can have very large numbers of ExtRefs and a debounce is insufficient to provide adequate performance.

I would like to see the oscd-filtered-list carry out lazy indexing and perhaps show a light coloured "progress of index" background in the search field.

I'm not sure from a technology point of view how to implement this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.