mui-x icon indicating copy to clipboard operation
mui-x copied to clipboard

[DataGrid] Improve clarity of numeric filter operator labels

Open kenanyusuf opened this issue 1 year ago • 5 comments

Replace numeric symbol operators with descriptive text labels. Improves the clarity of the operator options, and brings them inline with header filter labels.

Screenshot 2024-09-16 at 11 47 32

Addresses point made here: https://github.com/mui/mui-x/pull/14489#discussion_r1746674067

kenanyusuf avatar Sep 16 '24 10:09 kenanyusuf

Localization writing tips :writing_hand:

Seems you are updating localization :earth_africa: files.

Thank you for contributing to the localization! :tada: To make your PR perfect, here is a list of elements to check: :heavy_check_mark:

  • [ ] Verify if the PR title respects the release format. Here are two examples (depending if you update or add a locale file)

    [l10n] Improve Swedish (sv-SE) locale [l10n] Add Danish (da-DK) locale

  • [ ] Update the documentation of supported locales by running pnpm l10n
  • [ ] Clean files with pnpm prettier.

Deploy preview: https://deploy-preview-14638--material-ui-x.netlify.app/

Generated by :no_entry_sign: dangerJS against c79b37f335747ce3490372fe5123f1ed57f61f9a

mui-bot avatar Sep 16 '24 10:09 mui-bot

@romgrk to clarify, do you mean instead of updating filterOperator=, where the label is displayed, use the filerOperatorEquals translation key that already exists?

If that is what you mean, I tried it and found that the translation key is coupled to the value in gridNumericOperators.ts We transform the operator value here to create the translation key.

I don't particularly like this, it feels like magic and isn't type-safe. It would probably be better to have an extra key in the operator object for a translation key:

{
  value: '=',
+ labelTranslationKey: 'filerOperatorEquals',
  getApplyFilterFn: (filterItem) => {
    if (filterItem.value == null || Number.isNaN(filterItem.value)) {
      return null;
    }

    return (value): boolean => {
      return parseNumericValue(value) === filterItem.value;
    };
  },
  InputComponent: GridFilterInputValue,
  InputComponentProps: { type: 'number' },
}

What do you think?

kenanyusuf avatar Sep 18 '24 10:09 kenanyusuf

How about renaming the text labels to replace the operator labels? filterOperatorEquals -> filterOperator= I just want to avoid having duplicate translations for the same text.

romgrk avatar Sep 18 '24 10:09 romgrk

@romgrk I agree that we don't want duplicates.

filterOperatorEquals -> filterOperator=

We would have the same problem with this example.

We would have to update the equals string operator value to = to use the translation, but this would be a breaking change to the filter model. This would no longer work:

  filterModel={{
    items: [{ field: 'someString', operator: 'equals', value: 'some value' }],
                                              ^ it now expects `=`
  }} 

kenanyusuf avatar Sep 18 '24 10:09 kenanyusuf

This pull request has conflicts, please resolve those before we can evaluate the pull request.

github-actions[bot] avatar Nov 01 '24 23:11 github-actions[bot]