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

dropdown_pills added to elements; #1284

Merged
merged 6 commits into from
May 29, 2024
Merged

Conversation

cityremade
Copy link
Member

Now filter[in] supports multi select with values as pills; Config inside in-filter: "dropdown_pills": true

Now filter[in] supports multi select with values as pills;
Config inside in-filter: "dropdown_pills": true
@cityremade cityremade added the Feature New feature requests or changes to the behaviour or look of existing application features. label May 24, 2024
@cityremade cityremade added this to the UI Elements milestone May 24, 2024
@cityremade cityremade self-assigned this May 24, 2024
@cityremade cityremade linked an issue May 24, 2024 that may be closed by this pull request
@dbauszus-glx
Copy link
Member

The duplicate code issue has been resolved in 20d3b48

Inside the filter.mjs I add pills to be dropdown_pills, ie. true || false/undefined

  if (filter.dropdown || filter.dropdown_pills) {

    const dropdown = mapp.ui.elements.dropdown({
      pills: filter.dropdown_pills,
      multi: true,
      placeholder: 'Select Multiple',
      entries: filter[filter.type].map(val => ({
        title: val,
        option: val,
        selected: chkSet.has(val)
      })),
      callback: async (e, options) => {

        if (!options.length) {

          // Remove empty array filter.
          delete layer.filter.current[filter.field]
        } else {

          // Set filter values array from options.
          Object.assign(layer.filter.current, {
            [filter.field]: {
              [filter.type]: options
            }
          })
        }

        applyFilter(layer)
      }
    })

    return mapp.utils.html.node`<div class="filter">${dropdown}`
  }

In the dropdown.mjs I add the pills element to params.pills if true.

  params.pills &&= mapp.ui.elements.pills({
    pills: [...params.selectedTitles],
    addCallback: (val, _pills) => {
      params.callback?.(null, [..._pills]);
    },
    removeCallback: (val, _pills) => {

      // deselect value in the list
      const item = ul.find(li => li.title === val);
      item.classList.remove('selected');
      params.selectedTitles.delete(item.title);
      params.selectedOptions.delete(item.dataset.option);
      params.callback?.(null, [..._pills]);
    }
  });

A dropdown pills by definition will always be a dropdown multi and I made the mistake of introducing the dropdown_multi element before thinking this through which leaves us now with this technical debt module.

export default (params) => {

  console.warn('mapp.ui.elements.dropdown should be used with the multi flag')

  params.multi = true

  return mapp.ui.elements.dropdown(params)
}

@cityremade cityremade marked this pull request as ready for review May 24, 2024 15:10
@dbauszus-glx
Copy link
Member

dbauszus-glx commented May 24, 2024

I've added a maxHeight param for dropdowns.

This is set to 300 for filter.
image

Copy link
Member

@dbauszus-glx dbauszus-glx left a comment

Choose a reason for hiding this comment

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

this works as expected for me.

@AlexanderGeere
Copy link
Contributor

AlexanderGeere commented May 27, 2024

Should these work when an in filter is applied to an integer field?

I put an example in bugs_testing/filter/filter.json

The pills dont get removed when you click the x.

I assume because 1 !== "1" .

@dbauszus-glx dbauszus-glx self-requested a review May 28, 2024 08:47
Copy link

sonarcloud bot commented May 28, 2024

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

@dbauszus-glx
Copy link
Member

@AlexanderGeere this should now be fixed by adding and checking on the data-value attribute instead of the title.

@dbauszus-glx dbauszus-glx merged commit 968bc44 into GEOLYTIX:main May 29, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature requests or changes to the behaviour or look of existing application features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

array input element [mapp.ui.elements.arrayInput()]
5 participants