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

List of filtered values should show the formatted numeric value not the source data #10756

Merged
merged 14 commits into from Feb 9, 2024

Conversation

jansiegel
Copy link
Member

@jansiegel jansiegel commented Jan 29, 2024

Context

This PR:

  • Adds a new modifyFiltersMultiSelectValue hook
  • Makes the filters' multi-selection module utilize the new hook to render the entry list
  • Utilizes the modifyFiltersMultiSelectValue to display the rendered values for the numeric-typed cells

How has this been tested?

Added new test cases.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature or improvement (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Additional language file or change to the existing one (translations)

Related issue(s):

  1. handsontable/dev-handsontable#1267

Affected project(s):

  • handsontable
  • @handsontable/angular
  • @handsontable/react
  • @handsontable/vue
  • @handsontable/vue3

Checklist:

- Implement a new `getDisplayValuesAtCol` method
- Make the filters' multi selection module utilize the newly created method
- Set the new `displayValue` prop in the numeric renderer
@jansiegel jansiegel self-assigned this Jan 29, 2024
jansiegel and others added 3 commits February 1, 2024 09:25
- Resolve issues with the `displayValue`s being out of sync with the filtered-out data
- Make the filter by value component use the source data for the comparing and filtering data, and the `displayValue` properties just in the UI
- Remove async logic from a test
Copy link

github-actions bot commented Feb 1, 2024

Launch the local version of documentation by running:

npm run docs:review 8f6a5f51261db15b47798bdc4b9b55224139948a

@jansiegel jansiegel requested a review from budnix February 2, 2024 10:00
@jansiegel jansiegel marked this pull request as ready for review February 2, 2024 10:00
Copy link
Member

@budnix budnix left a comment

Choose a reason for hiding this comment

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

I'm not convinced about that displayValue option. I know that the purpose of this task is to add support for modifying filter values only for numeric values, but with this shape, it isn't very clear.
The question that comes to my mind or limitation that I found:

  • The value can not be changed in the cells function. The displayValue property is always overwritten in the numeric renderer;
  • When the displayValue property does not exist, the Filters plugin generates one by calling the numeric renderer by itself. So what is this option for? Kind of read-only and for numeric columns only?
  • Maybe a better idea would be creating renderers for Filters. The same goes for cells. For example, filtersRenderer option, or so?

@jansiegel
Copy link
Member Author

I went through several approaches to this task, but I'll take any suggestions. As for the questions:

  • The value can not be changed in the cells function. The displayValue property is always overwritten in the numeric renderer;

Yes. The spec requires the multi-selection component in the Filters dropdown to display the same value that's being rendered in the cells. As we cannot know what the renderer with generate, there's no way to assign this value before it's triggered.

  • When the displayValue property does not exist, the Filters plugin generates one by calling the numeric renderer by itself. So what is this option for? Kind of read-only and for numeric columns only?

I had to add this logic because the Filters dropdown display all unique values in the table, and the renderers are run just for the visible part of the dataset. Without this logic, some of the values were being displayed in their "source" form, and some in the "rendered" form.

  • Maybe a better idea would be creating renderers for Filters. The same goes for cells. For example, filtersRenderer option, or so?

We can do that, but according the the spec, in this case the filtersRenderer should be exact same as the regular renderer (and for the other cell types the filtersRenderer should return the cell's source value...?)

@budnix
Copy link
Member

budnix commented Feb 7, 2024

Maybe I'd suggest adding a new hook for the MultipleSelect component of the Filters plugin. Let's name it modifyFiltersMultipleSelectValue hook, for example. This hook would be responsible only for modifying the values presented by that component. There would be one hook for all cell types.

Now, depending on the feature needs you can pass as many arguments as you wish. Usage example:

modifyFiltersMultipleSelectValue(sourceValue, cellType, cellProperties) => {
  let newValue = sourceValue;

  if (cellType === 'numeric') {
    if (isNumeric(newValue)) { // HERE I'd copy the logic from the renderer, or I can suggest moving it to a separate helper
      const numericFormat = cellProperties.numericFormat;
      const cellCulture = numericFormat && numericFormat.culture || '-';
      const cellFormatPattern = numericFormat && numericFormat.pattern;
      const className = cellProperties.className || '';
      const classArr = className.length ? className.split(' ') : [];

      if (typeof cellCulture !== 'undefined' && !numbro.languages()[cellCulture]) {
        const shortTag = cellCulture.replace('-', '');
        const langData = numbro.allLanguages ? numbro.allLanguages[cellCulture] : numbro[shortTag];

        if (langData) {
          numbro.registerLanguage(langData);
        }
      }

      numbro.setLanguage(cellCulture);

      newValue = numbro(newValue).format(cellFormatPattern || '0');
    } 
  }
  // PLACE FOR OTHER CELL TYPES

  return newValue;
}

jansiegel and others added 4 commits February 8, 2024 15:17
- Add the `modifyFiltersMultipleSelectValue` plugin hook
- Split the `numericRenderer` logic into two methods to use the value-generating one in the Filters plugin
Co-authored-by: Krzysztof Budnik <571316+budnix@users.noreply.github.com>
@jansiegel jansiegel requested a review from budnix February 8, 2024 14:50
Copy link
Member

@budnix budnix left a comment

Choose a reason for hiding this comment

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

It looks good. I left one comment with suggestions to be considered. And I wonder, would it be possible to pass a complete cellMeta object as a second argument? It would be better for the user not to have to figure out a new data structure. They already know/use cellMeta objects in other hooks or methods.

handsontable/src/plugins/filters/component/value.js Outdated Show resolved Hide resolved
@budnix
Copy link
Member

budnix commented Feb 9, 2024

Ah, and I almost forgot. Can you add a TypeScript definition for modifyFiltersMultiSelectValue hook? 😄

@jansiegel jansiegel merged commit d255844 into develop Feb 9, 2024
22 checks passed
@jansiegel jansiegel deleted the feature/dev-issue-1267 branch February 9, 2024 11:03
@jansiegel jansiegel mentioned this pull request Feb 9, 2024
12 tasks
@evanSe evanSe changed the title Display the numeric renderer's output in the Filters' multi-selection module. Display the numeric renderer’s output in the Filters’ multi-selection module. #10756 Mar 4, 2024
@evanSe evanSe changed the title Display the numeric renderer’s output in the Filters’ multi-selection module. #10756 Display the numeric renderer’s output in the Filters’ multi-selection module Mar 4, 2024
@evanSe evanSe changed the title Display the numeric renderer’s output in the Filters’ multi-selection module Show formatted numeric values in Filters Mar 4, 2024
@evanSe evanSe changed the title Show formatted numeric values in Filters List of filtered values should show the rendered numeric value not the source data Mar 4, 2024
@evanSe evanSe changed the title List of filtered values should show the rendered numeric value not the source data List of filtered values should show the formatted numeric value not the source data Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants