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

[DataGridPro] Fix header filters rendering issue for isEmpty and isNotEmpty filter operators #14493

Merged
merged 4 commits into from
Sep 17, 2024

Conversation

k-rajat19
Copy link
Contributor

Fixes #14490

@k-rajat19 k-rajat19 changed the title [data grid ] Use disabled InputComponent for isEmpty and isNotEmpty filter operators [data grid] Use disabled InputComponent for isEmpty and isNotEmpty filter operators Sep 5, 2024
@michelengelen michelengelen added component: data grid This is the name of the generic UI component, not the React module! feature: Filtering on header Related to the header filtering (Pro) feature labels Sep 5, 2024
Copy link
Member

@MBilalShafi MBilalShafi left a comment

Choose a reason for hiding this comment

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

Thank you for picking this up. 🙏

Copy link
Member

Choose a reason for hiding this comment

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

Instead of having to update the behavior in the filter panel:

Before
image

After
image

I'd rather keep the disabled input components in the header filter cell.

How about something like:

diff --git a/packages/x-data-grid-pro/src/components/headerFiltering/GridHeaderFilterCell.tsx b/packages/x-data-grid-pro/src/components/headerFiltering/GridHeaderFilterCell.tsx
index 1d22e8793..80ff6dfa2 100644
--- a/packages/x-data-grid-pro/src/components/headerFiltering/GridHeaderFilterCell.tsx
+++ b/packages/x-data-grid-pro/src/components/headerFiltering/GridHeaderFilterCell.tsx
@@ -18,6 +18,11 @@ import {
   gridFilterModelSelector,
   gridFilterableColumnLookupSelector,
   GridPinnedColumnPosition,
+  GridFilterInputValue,
+  GridFilterInputDate,
+  GridFilterInputBoolean,
+  GridColType,
+  GridFilterInputSingleSelect,
 } from '@mui/x-data-grid';
 import {
   GridStateColDef,
@@ -32,7 +37,6 @@ import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
 import { DataGridProProcessedProps } from '../../models/dataGridProProps';
 import { GridHeaderFilterMenuContainer } from './GridHeaderFilterMenuContainer';
 import { GridHeaderFilterClearButton } from './GridHeaderFilterClearButton';
-
 export interface GridRenderHeaderFilterProps extends GridHeaderFilterCellProps {
   inputRef: React.RefObject<unknown>;
 }
@@ -87,6 +91,19 @@ const dateSx = {
   [`& input[value=""]:not(:focus)`]: { color: 'transparent' },
 };
 
+const defaultInputComponents: {
+  [key in GridColType]: React.JSXElementConstructor<any> | null;
+} = {
+  string: GridFilterInputValue,
+  number: GridFilterInputValue,
+  date: GridFilterInputDate,
+  dateTime: GridFilterInputDate,
+  boolean: GridFilterInputBoolean,
+  singleSelect: GridFilterInputSingleSelect,
+  actions: null,
+  custom: null,
+};
+
 const GridHeaderFilterCell = React.forwardRef<HTMLDivElement, GridHeaderFilterCellProps>(
   (props, ref) => {
     const {
@@ -147,7 +164,9 @@ const GridHeaderFilterCell = React.forwardRef<HTMLDivElement, GridHeaderFilterCe
     );
 
     const InputComponent =
-      colDef.filterable || isFilterReadOnly ? currentOperator!.InputComponent : null;
+      colDef.filterable || isFilterReadOnly
+        ? (currentOperator.InputComponent ?? defaultInputComponents[colDef.type as GridColType])
+        : null;
 
     const applyFilterChanges = React.useCallback(
       (updatedItem: GridFilterItem) => {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shukriya for the review
this solution is much better than that I have proposed earlier
I missed checking that it is already working in v6
thanks again :)

@MBilalShafi MBilalShafi added the regression A bug, but worse label Sep 6, 2024
@k-rajat19 k-rajat19 changed the title [data grid] Use disabled InputComponent for isEmpty and isNotEmpty filter operators [DataGridPro] Fix header filters rendering issue for isEmpty and isNotEmpty filter operators Sep 6, 2024
@MBilalShafi
Copy link
Member

Hey @k-rajat19
Thank you again for this pull request!

Your changes seem to impact the commercially licensed code. For any changes of this nature, we require contributors to sign the MUI’s Contributor License Agreement (CLA). However, I can’t find a CLA signed that could cover these changes. Please follow the steps at https://mui-org.notion.site/CLA-Contributor-License-Agreement-92ece655b1584b10b00e4de9e67eedb0 to sign the document.

@MBilalShafi MBilalShafi added the CLA: required See https://www.notion.so/mui-org/CLA-Contributor-License-Agreement-92ece655b1584b10b00e4de9e67eedb0 label Sep 6, 2024
@k-rajat19
Copy link
Contributor Author

I've sent the email to team-legal@mui.com

@zannager zannager added CLA: signed See https://www.notion.so/mui-org/CLA-Contributor-License-Agreement-92ece655b1584b10b00e4de9e67eedb0 and removed CLA: required See https://www.notion.so/mui-org/CLA-Contributor-License-Agreement-92ece655b1584b10b00e4de9e67eedb0 labels Sep 6, 2024
@zannager
Copy link
Member

zannager commented Sep 6, 2024

@MBilalShafi, CLA signed, thanks.

@mui-bot
Copy link

mui-bot commented Sep 6, 2024

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

Generated by 🚫 dangerJS against 74d04b2

Copy link
Member

@MBilalShafi MBilalShafi left a comment

Choose a reason for hiding this comment

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

LGTM

@MBilalShafi MBilalShafi merged commit 0d35d62 into mui:master Sep 17, 2024
16 checks passed
@k-rajat19 k-rajat19 deleted the header-filter branch September 17, 2024 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA: signed See https://www.notion.so/mui-org/CLA-Contributor-License-Agreement-92ece655b1584b10b00e4de9e67eedb0 component: data grid This is the name of the generic UI component, not the React module! feature: Filtering on header Related to the header filtering (Pro) feature regression A bug, but worse
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[data grid] Header Filters empty / no UI once isEmpty or isNotEmpty is selected
5 participants