Convert FilteringLogic enum to string union type #16502
Draft
+95
−32
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.
Converts
FilteringLogicenum from numeric values (0, 1) to string union type ('and', 'or'), following the pattern established in PR #15706 forGridPagingMode. This enables better type safety and clearer intent while maintaining full backwards compatibility.Changes
Core Type Definition
State Persistence Migration
normalizeOperators()to convert legacy numeric values (0, 1) to string constants during state deserializationComponent Updates
getOperatorAsString()and comparison methodsinitialOperatortype fromnumbertoFilteringLogicisOperatorSelected()helper methods to handle backwards-compatible comparisonsTemplate Updates
Backwards Compatibility
Legacy code and state continue to work:
FilteringLogic.AndandFilteringLogic.Orconstants remain accessibleOriginal prompt
Problem Statement
Convert the
FilteringLogicenum to a string union type similar to the approach used in PR #15706 forGridPagingMode. This conversion needs to maintain backwards compatibility for:Current Implementation
The
FilteringLogicenum is currently defined inprojects/igniteui-angular/core/src/data-operations/filtering-expression.interface.ts:This enum is used throughout:
IgxGridBaseDirective.filteringLogicpropertyFilteringExpressionsTree.operatorpropertyIFilteringExpressionsTree.operatorinterfaceExpressionUI.beforeOperatorandafterOperatorpropertiesstate-base.directive.tsRequired Changes
1. Convert the enum to union type (similar to GridPagingMode in PR #15706)
In
projects/igniteui-angular/core/src/data-operations/filtering-expression.interface.ts:/* mustCoerceToInt */commentNote: Use capital case for the keys (And, Or) to maintain API compatibility, but lowercase for the values ('and', 'or').
2. Update usage throughout the codebase
Update all direct enum value comparisons (0, 1) to use string values ('and', 'or'):
projects/igniteui-angular/core/src/data-operations/filtering-strategy.ts: UpdateFilteringLogic.AndandFilteringLogic.Orcomparisons to use the new string valuesprojects/igniteui-angular/grids/core/src/filtering/grid-filtering.service.ts: Update filtering logic comparisonsprojects/igniteui-angular/grids/core/src/filtering/excel-style/excel-style-default-expression.component.ts: Update any FilteringLogic usage3. Add backwards compatibility for state persistence
In
projects/igniteui-angular/grids/core/src/state-base.directive.ts, add logic in thecreateExpressionsTreeFromObjectmethod or wherever filtering state is restored to handle both old enum values (0, 1) and new string values ('and', 'or'):Apply this normalization when restoring filtering state and advanced filtering state.
4. Update default values
In
projects/igniteui-angular/grids/grid/src/grid-base.directive.ts:_filteringExpressionsTreeinitialization to useFilteringLogic.And(which will resolve to 'and')5. Update FilteringExpressionsTree constructor
In
projects/igniteui-angular/core/src/data-operations/filtering-expressions-tree.ts:6. Search and update all numeric comparisons
Search for patterns like:
operator === 0→operator === FilteringLogic.Andoroperator === 'and'operator === 1→operator === FilteringLogic.Ororoperator === 'or'FilteringLogic.And→ should continue to work, but internal comparisons should use string valuesFilteringLogic.Or→ should continue to work, but internal comparisons should use string values7. Remove enum imports where no longer needed
After conversion, remove unused enum imports similar to how
GridPagingModeimports were removed in PR #15706.Testing Requirements
Ensure that:
Reference
Follow the same pattern as PR #15706 which converted
GridPagingMode:The key files changed in that PR were:
projects/igniteui-angular/grids/core/src/common/enums.ts(enum definition)This pull request was created as a result of the following prompt from Copilot chat.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.