GEOLYTIX / xyz

An open source javascript framework for spatial data and application interfaces.
MIT License
86 stars 25 forks source link

Update docs and allow for numeric filter value. #1307

Closed dbauszus-glx closed 3 weeks ago

dbauszus-glx commented 3 weeks ago

The filter_in function should work on an array of numeric values.

eg.

{
  "field": "minutes",
  "type": "integer",
  "filter": {
    "type": "in",
    "searchbox": true
}

The searchbox function doesn't require a defaultSearch method which was used as a method to append the no search results.

The searchbox function should warn if no searchFunction is provided.

I split the add() and remove() methods from the pills(component) method for clarity.

Updated the docs for @module /ui/layers/filters, @function filter_in

@module /ui/elements/searchbox, @function searchbox

@module /ui/elements/pills, @function pills, @function add, @function remove

I found this hard to understand.

        filtered
        .filter(i => !pillComponent.pills.has(i)) // only those not selected already
        .map((i, j) => {
          if(j > 9) return; // show only 10 top matches
          searchbox.list.appendChild(mapp.utils.html.node`<li onclick=${e => {
            if(pillComponent.pills.has(i)) return;
            pillComponent.add(i);
          }}>${i}`);

I prefer to use named variables, where can be the index. Using i as value, and j as index was very hard to understand. I prefer to use filter separately eg (i<9) opposed to a condition in an array map/forEach method. I prefer to use forEach if nothing is returned from the method which is the point of the map method.

        filtered
          .filter(val => !pillComponent.pills.has(val)) // only those not selected already
          .filter((val, i) => i < 9)
          .forEach(val => {

            // Append li element to searchbox.list
            searchbox.list.append(mapp.utils.html.node`
              <li onclick=${() => {
                // Add pill not yet in pillComponent
                !pillComponent.pills.has(val) && pillComponent.add(val);
              }}>${val}`)
          });
sonarcloud[bot] commented 3 weeks ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud