GEOLYTIX / xyz

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

Group Class List Not Applied unless on the first infoj entry / Empty Group #1327

Open simon-leech opened 2 weeks ago

simon-leech commented 2 weeks ago

Issue Template

Description

  1. When using an infoj group and applying groupClassList this is only applied if the first infoj entry contains it. Example below the group will be collapsed. Move the groupClassList to the "field": "a" entry and it will be expanded.
    {
    "infoj": [
        {
            "field": "a",
            "group": "Test"
        },
        {
            "field": "b",
            "group": "Test",
            "groupClassList": "expanded"
        }
    ]
    }
  2. When using an infoj group but all the values in the group are null, an empty group is created. This shouldn't be created if no data to display as its a group of nothing in the infoj.

Type of Issue

Please delete options that are not relevant, and select all options that apply.

dbauszus-glx commented 1 week ago

This should be fairly easy to fix.

The expanded classlist is only assigned if a group does not exist. The classList should be added after if (!groups[entry.group]) {} instead.

function entryGroup(entry) {

  if (!entry.group) return;

  // Create new group
  if (!groups[entry.group]) {

    if (entry.expanded) {

      // Add to the string as this can have other classes.
      entry.groupClassList += ' expanded'
    }

    groups[entry.group] = entry.listview.appendChild(
      mapp.ui.elements.drawer({
        class: `group ${entry.groupClassList && 'expanded' || ''}`,
        header: mapp.utils.html`
          <h3>${entry.group}</h3>
          <div class="mask-icon expander"></div>`,
      }))
  }

  // The group will replace the entry listview to which elements will be appended.
  entry.listview = groups[entry.group]
}