-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change muiGridFilterToGql fallback operator to 'and' (#2061)
MUI uses and per default, not or. --------- Co-authored-by: Denise Buder <[email protected]> Co-authored-by: Johannes Obermair <[email protected]> Co-authored-by: Niko Sams <[email protected]>
- Loading branch information
1 parent
5c1ab80
commit a8a098a
Showing
3 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@comet/admin": patch | ||
--- | ||
|
||
muiGridFilterToGql: change fallback operator to 'and' to match MUI default |
78 changes: 78 additions & 0 deletions
78
packages/admin/admin/src/dataGrid/muiGridFilterToGql.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { GridColDef, GridLinkOperator } from "@mui/x-data-grid"; | ||
import { GridFilterModel } from "@mui/x-data-grid/models/gridFilterModel"; | ||
|
||
import { muiGridFilterToGql } from "./muiGridFilterToGql"; | ||
|
||
const columns: GridColDef<{ tag: string }>[] = [{ field: "tag" }]; | ||
|
||
const mockedFilterModelAndOperator: GridFilterModel = { | ||
items: [ | ||
{ | ||
columnField: "tag", | ||
operatorValue: "contains", | ||
id: 1, | ||
value: "de", | ||
}, | ||
{ | ||
columnField: "tag", | ||
operatorValue: "contains", | ||
id: 2, | ||
value: "en", | ||
}, | ||
], | ||
linkOperator: GridLinkOperator.And, | ||
}; | ||
|
||
const mockedFilterModelOrOperator: GridFilterModel = { | ||
items: [ | ||
{ | ||
columnField: "tag", | ||
operatorValue: "contains", | ||
id: 1, | ||
value: "de", | ||
}, | ||
{ | ||
columnField: "tag", | ||
operatorValue: "contains", | ||
id: 2, | ||
value: "en", | ||
}, | ||
], | ||
linkOperator: GridLinkOperator.Or, | ||
}; | ||
const mockedFilterModelWithoutOperator: GridFilterModel = { | ||
items: [ | ||
{ | ||
columnField: "tag", | ||
operatorValue: "contains", | ||
id: 1, | ||
value: "de", | ||
}, | ||
{ | ||
columnField: "tag", | ||
operatorValue: "contains", | ||
id: 2, | ||
value: "en", | ||
}, | ||
], | ||
}; | ||
|
||
describe("muiGridFilterToGql", () => { | ||
it("should use correct and filter for specified and operator", () => { | ||
const result = muiGridFilterToGql(columns, mockedFilterModelAndOperator); | ||
|
||
expect(result).toEqual({ filter: { and: [{ tag: { contains: "de" } }, { tag: { contains: "en" } }] } }); | ||
}); | ||
|
||
it("should use correct or filter for specified or operator", () => { | ||
const result = muiGridFilterToGql(columns, mockedFilterModelOrOperator); | ||
|
||
expect(result).toEqual({ filter: { or: [{ tag: { contains: "de" } }, { tag: { contains: "en" } }] } }); | ||
}); | ||
|
||
it("should use correct and filter for no operator specified ", () => { | ||
const result = muiGridFilterToGql(columns, mockedFilterModelWithoutOperator); | ||
|
||
expect(result).toEqual({ filter: { and: [{ tag: { contains: "de" } }, { tag: { contains: "en" } }] } }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters