Skip to content

[DataGrid] Allows to customize variant of value input in filter panel #4826

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

Merged
merged 12 commits into from
Jun 24, 2022

Conversation

alexfauquette
Copy link
Member

@alexfauquette alexfauquette commented May 10, 2022

Fix #4822

The idea for know is to pass customization props to the filter input

Special case for Autocomplet input for which TextFields are not the root component

@alexfauquette alexfauquette self-assigned this May 10, 2022
@alexfauquette alexfauquette added the on hold There is a blocker, we need to wait label May 10, 2022
@mui-bot
Copy link

mui-bot commented May 10, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 260.7 466 395.4 380.98 74.201
Sort 100k rows ms 481 869.8 794.6 722.98 151.445
Select 100k rows ms 122.2 224.5 165.6 168.86 35.259
Deselect 100k rows ms 99.5 195.2 178.8 152.86 32.944

Generated by 🚫 dangerJS against 9f56639

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@alexfauquette alexfauquette marked this pull request as ready for review June 14, 2022 12:01
@alexfauquette alexfauquette added bug 🐛 Something doesn't work customization: css Design CSS customizability and removed on hold There is a blocker, we need to wait labels Jun 14, 2022
@DanailH DanailH self-requested a review June 14, 2022 14:22
@@ -476,6 +498,7 @@ const GridFilterForm = React.forwardRef<HTMLDivElement, GridFilterFormProps>(
applyValue={applyFilterChanges}
focusElementRef={valueRef}
{...currentOperator.InputComponentProps}
{...valueInputTextFieldProps}
Copy link
Member

@m4theushw m4theushw Jun 14, 2022

Choose a reason for hiding this comment

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

In theory, this could also be a breaking change. If the input component spreads the rest of the props to the root element, receiving an unexpected prop will cause a console error. What do you think of adding InputComponentProps and spreading it here? In v6, we kill valueInputProps and the FormControl surrounding it.

Instead of

<GridFilterPanel
  filterFormProps={{
    valueInputProps: { variant: 'outlined' },
  }}
/>

users will do

<GridFilterPanel
  filterFormProps={{
    InputComponentProps: { variant: 'outlined' },
  }}
/>

Copy link
Member Author

Choose a reason for hiding this comment

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

👍That was another option I had in mind

About the naming, what do you think of TextFieldProps instead of InputComponentProps to be more specific?

Copy link
Member

Choose a reason for hiding this comment

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

We can't know if the input component is a text field or not, it could be anything. The filter operator already has InputComponentProps. I was considering this name for consistency.

Copy link
Member Author

Choose a reason for hiding this comment

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

But variant is not part of the InputComponentProps.
The InputComponent will be a FilledInput, OutlinedInput or Input component depending on the variant prop value

Copy link
Member

Choose a reason for hiding this comment

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

My idea was to allow any prop in InputComponentProps, not restricting to only those from the text field variants. It's the role of the current input component to use the variant received.

As example, the input component of the operators of a singleSelect column is not a TextField, but an Autocomplete. We need to forward the prop to the element that can use it.

diff --git a/packages/grid/x-data-grid/src/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.tsx b/packages/grid/x-data-grid/src/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.tsx
index e757992be..d3fa254ca 100644
--- a/packages/grid/x-data-grid/src/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.tsx
+++ b/packages/grid/x-data-grid/src/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.tsx
@@ -24,7 +24,7 @@ const isOptionEqualToValue: GridFilterInputMultipleSingleSelectProps['isOptionEq
 const filter = createFilterOptions<any>();
 
 function GridFilterInputMultipleSingleSelect(props: GridFilterInputMultipleSingleSelectProps) {
-  const { item, applyValue, type, apiRef, focusElementRef, ...other } = props;
+  const { item, applyValue, type, apiRef, focusElementRef, variant = 'standard', ...other } = props;
   const id = useId();
 
   const resolvedColumn = item.columnField ? apiRef.current.getColumn(item.columnField) : null;
@@ -118,7 +118,7 @@ function GridFilterInputMultipleSingleSelect(props: GridFilterInputMultipleSingl
           }}
           inputRef={focusElementRef}
           type={'singleSelect'}
-          variant="standard"
+          variant={variant}
         />
       )}
       {...other}

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 21, 2022
@github-actions
Copy link

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

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 21, 2022
@@ -69,6 +69,10 @@ export default function CustomFilterPanelContent() {
size: 'small',
sx: { mt: 'auto' },
},
InputComponentProps: {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we can reflect FilterFormValueInput > currentOperator.InputComponent hierarchy in here?
I would expect something like this:

filterFormProps: {
  valueInputProps: {
    // will be passed to `FilterFormValueInput`
    // ...
    
    InputComponentProps: {
      // will be passed to `currentOperator.InputComponent`
    }
  }
}

Especially since InputComponentProps are only passed to value input, not to other inputs

Copy link
Member Author

Choose a reason for hiding this comment

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

done

import { GridFilterItem } from '../../../models/gridFilterItem';

export interface GridFilterInputValueProps {
export type GridFilterInputValueProps<T> = {
Copy link
Member

Choose a reason for hiding this comment

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

Can we type it better?

import type { GridApiCommon } from '../../../models/api/gridApiCommon';
import type { GridApiCommunity } from '../../../models/api/gridApiCommunity';

export type GridFilterInputValueProps<Api extends GridApiCommon = GridApiCommunity> = {
  // ...
  apiRef: React.MutableRefObject<Api>;

Maybe something like this?
The Api is optional, so no need for GridFilterInputValueProps<any> in other places
What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

If I get it correctly:

  • Api will includes all the properties of GridApiCommon
  • By default we set it to GridApiCommunity
  • It can be override by writing for example GridFilterInputValueProps<GridApiPro>

Copy link
Member

Choose a reason for hiding this comment

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

Correct

@github-actions
Copy link

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

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 21, 2022

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 22, 2022
@alexfauquette alexfauquette requested a review from m4theushw June 22, 2022 11:57
| 'multiple'
| 'color'
>,
GridFilterInputValueProps<GridApiCommon> {
Copy link
Member

Choose a reason for hiding this comment

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

Is GridApiCommon necessary here?

Copy link
Member Author

Choose a reason for hiding this comment

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

effectively it's not

@@ -220,6 +220,8 @@ const GridFilterForm = React.forwardRef<HTMLDivElement, GridFilterFormProps>(
const isBaseSelectNative = baseSelectProps.native ?? true;
const OptionComponent = isBaseSelectNative ? 'option' : MenuItem;

const { InputComponentProps, ...propagatedValueInputProps } = valueInputProps;
Copy link
Member

Choose a reason for hiding this comment

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

We never used "propagated", but "other" is already being used. Maybe prefix it.

Suggested change
const { InputComponentProps, ...propagatedValueInputProps } = valueInputProps;
const { InputComponentProps, ...valueInputPropsOther } = valueInputProps;

@alexfauquette alexfauquette merged commit 666f636 into mui:master Jun 24, 2022
@alexfauquette alexfauquette deleted the fix-4822 branch June 24, 2022 12:49
joserodolfofreitas pushed a commit to joserodolfofreitas/mui-x that referenced this pull request Jul 15, 2022
alexfauquette added a commit to alexfauquette/mui-x that referenced this pull request Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work customization: css Design CSS customizability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[data grid] Allow GridFilterPanel filterFormProps valueInputProps variant customization
4 participants