-
Notifications
You must be signed in to change notification settings - Fork 327
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
Use AG Grid filter types #12072
Merged
+198
−23
Merged
Use AG Grid filter types #12072
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a08f09c
basic new filters working
marthasharkey 60125b9
Merge branch 'develop' into wip/mk/change-filter-types
marthasharkey 8b45b83
reduce repetition
marthasharkey 91199ee
add between filter
marthasharkey fbb0d0e
format
marthasharkey c08cedb
fix types
marthasharkey f4d54b9
fix date and between filters
marthasharkey 0598f6d
fix typo for Equal filter
marthasharkey 03abcaf
Merge branch 'develop' into wip/mk/change-filter-types
marthasharkey a5fdef9
initial changes for AND/OR
marthasharkey d3315ff
set to one filter condition for now
marthasharkey fb35bfc
Merge branch 'develop' into wip/mk/change-filter-types
marthasharkey 5d248eb
remove logs
marthasharkey 9df19db
remove unneeded import
marthasharkey f5c00fd
sort type
marthasharkey a2ceb14
Merge branch 'develop' into wip/mk/change-filter-types
marthasharkey 9cb8e2a
remove unused import
marthasharkey 75126a4
fix types
marthasharkey d35ab1c
run format
marthasharkey 13ce68d
use isNumeric function and simplify type repetition
marthasharkey 4b541e7
run format
marthasharkey b32631e
run format
marthasharkey 7d73899
run format
marthasharkey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -13,14 +13,48 @@ export type SortModel = { | |||||||||||||||||||||||
sortDirection: SortDirection | ||||||||||||||||||||||||
sortIndex: number | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
type FilterType = 'number' | 'date' | 'set' | ||||||||||||||||||||||||
type FilterAction = | ||||||||||||||||||||||||
| 'equals' | ||||||||||||||||||||||||
| 'notEqual' | ||||||||||||||||||||||||
| 'greaterThan' | ||||||||||||||||||||||||
| 'greaterThanOrEqual' | ||||||||||||||||||||||||
| 'lessThan' | ||||||||||||||||||||||||
| 'lessThanOrEqual' | ||||||||||||||||||||||||
| 'inRange' | ||||||||||||||||||||||||
| 'blank' | ||||||||||||||||||||||||
| 'notBlank' | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
export type GridFilterModel = { | ||||||||||||||||||||||||
columnName: string | ||||||||||||||||||||||||
filterType: FilterType | ||||||||||||||||||||||||
filter?: string | ||||||||||||||||||||||||
filterTo?: string | ||||||||||||||||||||||||
dateFrom?: string | ||||||||||||||||||||||||
dateTo?: string | ||||||||||||||||||||||||
values?: string[] | ||||||||||||||||||||||||
filterAction?: FilterAction | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
type FilterValueRange = { | ||||||||||||||||||||||||
toValue: string | ||||||||||||||||||||||||
fromValue: string | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
//The filter value can be a single value for comparisons such as 'equals' or 'greater than,' a list for 'is in' filtering, or two values that define a range. | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be a doc comment |
||||||||||||||||||||||||
type FilterValue = string | string[] | FilterValueRange | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
const actionMap = { | ||||||||||||||||||||||||
equals: '..Equal', | ||||||||||||||||||||||||
notEqual: '..Not_Equal', | ||||||||||||||||||||||||
greaterThan: '..Greater', | ||||||||||||||||||||||||
greaterThanOrEqual: '..Equal_Or_Greater', | ||||||||||||||||||||||||
lessThan: '..Less', | ||||||||||||||||||||||||
lessThanOrEqual: '..Equal_Or_Less', | ||||||||||||||||||||||||
inRange: '..Between', | ||||||||||||||||||||||||
blank: '..Is_Nothing', | ||||||||||||||||||||||||
notBlank: '..Not_Nothing', | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
export interface SortFilterNodesButtonOptions { | ||||||||||||||||||||||||
filterModel: ToValue<{ | ||||||||||||||||||||||||
[key: string]: { | ||||||||||||||||||||||||
values: any[] | ||||||||||||||||||||||||
filterType: string | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
}> | ||||||||||||||||||||||||
filterModel: ToValue<GridFilterModel[]> | ||||||||||||||||||||||||
sortModel: ToValue<SortModel[]> | ||||||||||||||||||||||||
isDisabled: ToValue<boolean> | ||||||||||||||||||||||||
isFilterSortNodeEnabled: ToValue<boolean> | ||||||||||||||||||||||||
|
@@ -65,6 +99,8 @@ function useSortFilterNodesButton({ | |||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
const filterPattern = computed(() => Pattern.parseExpression('__ (__ __)')!) | ||||||||||||||||||||||||
const filterBetweenPattern = computed(() => Pattern.parseExpression('__ (..Between __ __)')!) | ||||||||||||||||||||||||
const filterNothingPattern = computed(() => Pattern.parseExpression('__ __')!) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
function makeFilterPattern(module: Ast.MutableModule, columnName: string, items: string[]) { | ||||||||||||||||||||||||
if ( | ||||||||||||||||||||||||
|
@@ -97,6 +133,39 @@ function useSortFilterNodesButton({ | |||||||||||||||||||||||
]) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
function makeNumericFilterPattern( | ||||||||||||||||||||||||
module: Ast.MutableModule, | ||||||||||||||||||||||||
columnName: string, | ||||||||||||||||||||||||
item: string | FilterValueRange, | ||||||||||||||||||||||||
filterAction: FilterAction, | ||||||||||||||||||||||||
) { | ||||||||||||||||||||||||
const valueFormatter = getColumnValueToEnso(columnName) | ||||||||||||||||||||||||
if (filterAction === 'inRange' && typeof item === 'object') { | ||||||||||||||||||||||||
const filterToValue = valueFormatter(item.toValue, module) | ||||||||||||||||||||||||
const filterFromValue = valueFormatter(item.fromValue, module) | ||||||||||||||||||||||||
return filterBetweenPattern.value.instantiateCopied([ | ||||||||||||||||||||||||
Ast.TextLiteral.new(columnName), | ||||||||||||||||||||||||
filterFromValue as Expression | MutableExpression, | ||||||||||||||||||||||||
filterToValue as Expression | MutableExpression, | ||||||||||||||||||||||||
]) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
const filterValue = valueFormatter(item as string, module) | ||||||||||||||||||||||||
const action = actionMap[filterAction] | ||||||||||||||||||||||||
return filterPattern.value.instantiateCopied([ | ||||||||||||||||||||||||
Ast.TextLiteral.new(columnName), | ||||||||||||||||||||||||
Ast.parseExpression(action)!, | ||||||||||||||||||||||||
filterValue as Expression | MutableExpression, | ||||||||||||||||||||||||
]) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
function makeNothingFilterPattern(columnName: string, filterAction: FilterAction) { | ||||||||||||||||||||||||
const action = actionMap[filterAction] | ||||||||||||||||||||||||
return filterNothingPattern.value.instantiateCopied([ | ||||||||||||||||||||||||
Ast.TextLiteral.new(columnName), | ||||||||||||||||||||||||
Ast.parseExpression(action)!, | ||||||||||||||||||||||||
]) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
function getAstPatternSort() { | ||||||||||||||||||||||||
return Pattern.new<Ast.Expression>((ast) => | ||||||||||||||||||||||||
Ast.App.positional( | ||||||||||||||||||||||||
|
@@ -106,22 +175,62 @@ function useSortFilterNodesButton({ | |||||||||||||||||||||||
) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
function getAstPatternFilter(columnName: string, items: string[]) { | ||||||||||||||||||||||||
function getAstPatternFilter( | ||||||||||||||||||||||||
columnName: string, | ||||||||||||||||||||||||
items: string[] | string | FilterValue, | ||||||||||||||||||||||||
filterType: FilterType, | ||||||||||||||||||||||||
filterAction?: FilterAction, | ||||||||||||||||||||||||
) { | ||||||||||||||||||||||||
return Pattern.new<Ast.Expression>((ast) => | ||||||||||||||||||||||||
Ast.App.positional( | ||||||||||||||||||||||||
Ast.PropertyAccess.new(ast.module, ast, Ast.identifier('filter')!), | ||||||||||||||||||||||||
filterType === 'set' ? | ||||||||||||||||||||||||
makeFilterPattern(ast.module, columnName, items as string[]) | ||||||||||||||||||||||||
: makeNumericFilterPattern(ast.module, columnName, items as string | FilterValueRange, filterAction!), | ||||||||||||||||||||||||
), | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
function getAstNothingPatternFilter(columnName: string, filterAction: FilterAction) { | ||||||||||||||||||||||||
return Pattern.new<Ast.Expression>((ast) => | ||||||||||||||||||||||||
Ast.App.positional( | ||||||||||||||||||||||||
Ast.PropertyAccess.new(ast.module, ast, Ast.identifier('filter')!), | ||||||||||||||||||||||||
makeFilterPattern(ast.module, columnName, items), | ||||||||||||||||||||||||
makeNothingFilterPattern(columnName, filterAction), | ||||||||||||||||||||||||
), | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
function getAstPatternFilterAndSort(columnName: string, items: string[]) { | ||||||||||||||||||||||||
function getAstPatternFilterAndSort( | ||||||||||||||||||||||||
columnName: string, | ||||||||||||||||||||||||
items: string[] | string | FilterValueRange, | ||||||||||||||||||||||||
filterType: FilterType, | ||||||||||||||||||||||||
filterAction?: FilterAction, | ||||||||||||||||||||||||
) { | ||||||||||||||||||||||||
return Pattern.new<Ast.Expression>((ast) => | ||||||||||||||||||||||||
Ast.OprApp.new( | ||||||||||||||||||||||||
ast.module, | ||||||||||||||||||||||||
Ast.App.positional( | ||||||||||||||||||||||||
Ast.PropertyAccess.new(ast.module, ast, Ast.identifier('filter')!), | ||||||||||||||||||||||||
makeFilterPattern(ast.module, columnName, items), | ||||||||||||||||||||||||
filterType === 'set' ? | ||||||||||||||||||||||||
makeFilterPattern(ast.module, columnName, items as string[]) | ||||||||||||||||||||||||
: makeNumericFilterPattern(ast.module, columnName, items as string | FilterValueRange, filterAction!), | ||||||||||||||||||||||||
), | ||||||||||||||||||||||||
'.', | ||||||||||||||||||||||||
Ast.App.positional( | ||||||||||||||||||||||||
Ast.Ident.new(ast.module, Ast.identifier('sort')!), | ||||||||||||||||||||||||
makeSortPattern(ast.module), | ||||||||||||||||||||||||
), | ||||||||||||||||||||||||
), | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
function getAstNothingPatternFilterAndSort(columnName: string, filterAction: FilterAction) { | ||||||||||||||||||||||||
return Pattern.new<Ast.Expression>((ast) => | ||||||||||||||||||||||||
Ast.OprApp.new( | ||||||||||||||||||||||||
ast.module, | ||||||||||||||||||||||||
Ast.App.positional( | ||||||||||||||||||||||||
Ast.PropertyAccess.new(ast.module, ast, Ast.identifier('filter')!), | ||||||||||||||||||||||||
makeNothingFilterPattern(columnName, filterAction), | ||||||||||||||||||||||||
), | ||||||||||||||||||||||||
'.', | ||||||||||||||||||||||||
Ast.App.positional( | ||||||||||||||||||||||||
|
@@ -136,15 +245,44 @@ function useSortFilterNodesButton({ | |||||||||||||||||||||||
const patterns = new Array<Pattern>() | ||||||||||||||||||||||||
const filterModelValue = toValue(filterModel) | ||||||||||||||||||||||||
const sortModelValue = toValue(sortModel) | ||||||||||||||||||||||||
if (Object.keys(filterModelValue).length) { | ||||||||||||||||||||||||
for (const [columnName, columnFilter] of Object.entries(filterModelValue)) { | ||||||||||||||||||||||||
const items = columnFilter.values | ||||||||||||||||||||||||
const filterPatterns = | ||||||||||||||||||||||||
sortModelValue.length ? | ||||||||||||||||||||||||
getAstPatternFilterAndSort(columnName, items) | ||||||||||||||||||||||||
: getAstPatternFilter(columnName, items) | ||||||||||||||||||||||||
patterns.push(filterPatterns) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
if (filterModelValue.length) { | ||||||||||||||||||||||||
filterModelValue.map((filterModel: GridFilterModel) => { | ||||||||||||||||||||||||
const columnName = filterModel.columnName | ||||||||||||||||||||||||
const filterAction = filterModel.filterAction | ||||||||||||||||||||||||
const filterType = filterModel.filterType | ||||||||||||||||||||||||
if (filterAction === 'blank' || filterAction === 'notBlank') { | ||||||||||||||||||||||||
const filterPatterns = | ||||||||||||||||||||||||
sortModelValue.length ? | ||||||||||||||||||||||||
getAstNothingPatternFilterAndSort(columnName, filterAction) | ||||||||||||||||||||||||
: getAstNothingPatternFilter(columnName, filterAction) | ||||||||||||||||||||||||
patterns.push(filterPatterns) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
let value: FilterValue | ||||||||||||||||||||||||
switch (filterType) { | ||||||||||||||||||||||||
case 'number': | ||||||||||||||||||||||||
value = | ||||||||||||||||||||||||
filterAction === 'inRange' ? | ||||||||||||||||||||||||
{ toValue: filterModel.filterTo!, fromValue: filterModel.filter! } | ||||||||||||||||||||||||
: (filterModel.filter as FilterValue) | ||||||||||||||||||||||||
break | ||||||||||||||||||||||||
case 'date': | ||||||||||||||||||||||||
value = | ||||||||||||||||||||||||
filterAction === 'inRange' ? | ||||||||||||||||||||||||
{ toValue: filterModel.dateTo!, fromValue: filterModel.dateFrom! } | ||||||||||||||||||||||||
: (filterModel.dateFrom as FilterValue) | ||||||||||||||||||||||||
break | ||||||||||||||||||||||||
default: | ||||||||||||||||||||||||
value = filterModel.values as FilterValue | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
if (value) { | ||||||||||||||||||||||||
const filterPatterns = | ||||||||||||||||||||||||
sortModelValue.length ? | ||||||||||||||||||||||||
getAstPatternFilterAndSort(columnName, value, filterType, filterAction) | ||||||||||||||||||||||||
: getAstPatternFilter(columnName, value, filterType, filterAction) | ||||||||||||||||||||||||
patterns.push(filterPatterns) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
}) | ||||||||||||||||||||||||
} else if (sortModelValue.length) { | ||||||||||||||||||||||||
patterns.push(getAstPatternSort()) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could use
isNumericType