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

fix(mui): transformMuiOperatorToCrudOperator return type #5937

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/ninety-pots-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@refinedev/mui": patch
---

fix: `transformMuiOperatorToCrudOperator` return type is wrong.

This PR fixes the return type of `transformMuiOperatorToCrudOperator` function. It has return type `Exclude<CrudOperators, "or">` but it also should exclude `and` operator to satisfy `LogicalFilter` type.
8 changes: 5 additions & 3 deletions packages/mui/src/definitions/dataGrid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const transformCrudSortingToSortModel = (

export const transformMuiOperatorToCrudOperator = (
operatorValue?: string,
): Exclude<CrudOperators, "or"> => {
): Exclude<CrudOperators, "or" | "and"> => {
if (!operatorValue) {
return "eq";
}
Expand Down Expand Up @@ -72,7 +72,7 @@ export const transformMuiOperatorToCrudOperator = (
case "isNotEmpty":
return "nnull";
default:
return operatorValue as Exclude<CrudOperators, "or">;
return operatorValue as Exclude<CrudOperators, "or" | "and">;
}
};

Expand All @@ -81,11 +81,13 @@ export const transformFilterModelToCrudFilters = ({
logicOperator,
}: GridFilterModel): CrudFilters => {
const filters = items.map(({ field, value, operator }) => {
return {
const filter: LogicalFilter = {
field: field,
value: ["isEmpty", "isNotEmpty"].includes(operator) ? true : value ?? "",
operator: transformMuiOperatorToCrudOperator(operator),
};

return filter;
});

if (logicOperator === GridLogicOperator.Or) {
Expand Down