Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 21, 2025

Converts FilteringLogic enum from numeric values (0, 1) to string union type ('and', 'or'), following the pattern established in PR #15706 for GridPagingMode. This enables better type safety and clearer intent while maintaining full backwards compatibility.

Changes

Core Type Definition

  • filtering-expression.interface.ts: Converted enum to const object with string union type
    // Before
    export enum FilteringLogic {
        And,  // 0
        Or    // 1
    }
    
    // After
    export const FilteringLogic = {
        And: 'and',
        Or: 'or'
    } as const;
    export type FilteringLogic = (typeof FilteringLogic)[keyof typeof FilteringLogic];

State Persistence Migration

  • state-base.directive.ts: Added normalizeOperators() to convert legacy numeric values (0, 1) to string constants during state deserialization
  • Recursively processes entire filtering expression trees

Component Updates

  • grid-filtering.service.ts: Updated getOperatorAsString() and comparison methods
  • query-builder-tree.component.ts: Fixed initialOperator type from number to FilteringLogic
  • excel-style components: Added isOperatorSelected() helper methods to handle backwards-compatible comparisons
  • grid-filtering-row.component.ts: Added conversion logic for dropdown selections

Template Updates

  • Replaced direct numeric comparisons with helper methods that check both legacy and current values
  • Excel-style filtering templates (default, date expressions)
  • Grid filtering row template

Backwards Compatibility

Legacy code and state continue to work:

  • FilteringLogic.And and FilteringLogic.Or constants remain accessible
  • Old state files with numeric operators (0, 1) are automatically normalized
  • Runtime checks handle both numeric and string values during transition period
Original prompt

Problem Statement

Convert the FilteringLogic enum to a string union type similar to the approach used in PR #15706 for GridPagingMode. This conversion needs to maintain backwards compatibility for:

  1. State persistence/deserialization
  2. Remote filtering backend contracts
  3. Query Builder expressions
  4. Filtering expressions trees

Current Implementation

The FilteringLogic enum is currently defined in projects/igniteui-angular/core/src/data-operations/filtering-expression.interface.ts:

/* mustCoerceToInt */
export enum FilteringLogic {
    And,
    Or
}

This enum is used throughout:

  • IgxGridBaseDirective.filteringLogic property
  • FilteringExpressionsTree.operator property
  • IFilteringExpressionsTree.operator interface
  • ExpressionUI.beforeOperator and afterOperator properties
  • Filtering strategies and service logic
  • State persistence in state-base.directive.ts

Required 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:

  • Remove the /* mustCoerceToInt */ comment
  • Convert the enum to a const object with string values:
export const FilteringLogic = {
    And: 'and',
    Or: 'or'
} as const;
export type FilteringLogic = (typeof FilteringLogic)[keyof typeof FilteringLogic];

Note: 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'):

  • In projects/igniteui-angular/core/src/data-operations/filtering-strategy.ts: Update FilteringLogic.And and FilteringLogic.Or comparisons to use the new string values
  • In projects/igniteui-angular/grids/core/src/filtering/grid-filtering.service.ts: Update filtering logic comparisons
  • In projects/igniteui-angular/grids/core/src/filtering/excel-style/excel-style-default-expression.component.ts: Update any FilteringLogic usage
  • In any other files that compare against enum values

3. Add backwards compatibility for state persistence

In projects/igniteui-angular/grids/core/src/state-base.directive.ts, add logic in the createExpressionsTreeFromObject method or wherever filtering state is restored to handle both old enum values (0, 1) and new string values ('and', 'or'):

// Normalize operator to handle both old enum values and new string values
const normalizeOperator = (operator: any): FilteringLogic => {
    if (operator === 0 || operator === 'and') return 'and';
    if (operator === 1 || operator === 'or') return 'or';
    return operator; // fallback
};

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:

  • Update the default _filteringExpressionsTree initialization to use FilteringLogic.And (which will resolve to 'and')
  • Ensure any hardcoded operator values are updated

5. Update FilteringExpressionsTree constructor

In projects/igniteui-angular/core/src/data-operations/filtering-expressions-tree.ts:

  • Ensure the constructor properly handles the new FilteringLogic type
  • Update any default logic initialization

6. Search and update all numeric comparisons

Search for patterns like:

  • operator === 0operator === FilteringLogic.And or operator === 'and'
  • operator === 1operator === FilteringLogic.Or or operator === 'or'
  • FilteringLogic.And → should continue to work, but internal comparisons should use string values
  • FilteringLogic.Or → should continue to work, but internal comparisons should use string values

7. Remove enum imports where no longer needed

After conversion, remove unused enum imports similar to how GridPagingMode imports were removed in PR #15706.

Testing Requirements

Ensure that:

  1. Existing filtering functionality works with the new string union type
  2. State persistence can load old state with enum values (0, 1) and convert to new string values
  3. FilteringExpressionsTree objects created with both old and new values work correctly
  4. Query Builder and Excel-style filtering continue to work
  5. Remote filtering scenarios handle the conversion properly

Reference

Follow the same pattern as PR #15706 which converted GridPagingMode:

  • Changed from enum with numeric values to const object with string values
  • Updated all comparisons throughout the codebase
  • Removed unnecessary enum imports
  • Maintained the enum-like constant object for backwards compatibility

The key files changed in that PR were:

  • projects/igniteui-angular/grids/core/src/common/enums.ts (enum definition)
  • Various grid pipes and components (usage updates)
  • Test files (usage updates)

This pull request was created as a result of the following prompt from Copilot chat.

Problem Statement

Convert the FilteringLogic enum to a string union type similar to the approach used in PR #15706 for GridPagingMode. This conversion needs to maintain backwards compatibility for:

  1. State persistence/deserialization
  2. Remote filtering backend contracts
  3. Query Builder expressions
  4. Filtering expressions trees

Current Implementation

The FilteringLogic enum is currently defined in projects/igniteui-angular/core/src/data-operations/filtering-expression.interface.ts:

/* mustCoerceToInt */
export enum FilteringLogic {
    And,
    Or
}

This enum is used throughout:

  • IgxGridBaseDirective.filteringLogic property
  • FilteringExpressionsTree.operator property
  • IFilteringExpressionsTree.operator interface
  • ExpressionUI.beforeOperator and afterOperator properties
  • Filtering strategies and service logic
  • State persistence in state-base.directive.ts

Required 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:

  • Remove the /* mustCoerceToInt */ comment
  • Convert the enum to a const object with string values:
export const FilteringLogic = {
    And: 'and',
    Or: 'or'
} as const;
export type FilteringLogic = (typeof FilteringLogic)[keyof typeof FilteringLogic];

Note: 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'):

  • In projects/igniteui-angular/core/src/data-operations/filtering-strategy.ts: Update FilteringLogic.And and FilteringLogic.Or comparisons to use the new string values
  • In projects/igniteui-angular/grids/core/src/filtering/grid-filtering.service.ts: Update filtering logic comparisons
  • In projects/igniteui-angular/grids/core/src/filtering/excel-style/excel-style-default-expression.component.ts: Update any FilteringLogic usage
  • In any other files that compare against enum values

3. Add backwards compatibility for state persistence

In projects/igniteui-angular/grids/core/src/state-base.directive.ts, add logic in the createExpressionsTreeFromObject method or wherever filtering state is restored to handle both old enum values (0, 1) and new string values ('and', 'or'):

// Normalize operator to handle both old enum values and new string values
const normalizeOperator = (operator: any): FilteringLogic => {
    if (operator === 0 || operator === 'and') return 'and';
    if (operator === 1 || operator === 'or') return 'or';
    return operator; // fallback
};

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:

  • Update the default _filteringExpressionsTree initialization to use FilteringLogic.And (which will resolve to 'and')
  • Ensure any hardcoded operator values are updated

5. Update FilteringExpressionsTree constructor

In projects/igniteui-angular/core/src/data-operations/filtering-expressions-tree.ts:

  • Ensure the constructor properly handles the new FilteringLogic type
  • Update any default logic initialization

6. Search and update all numeric comparisons

Search for patterns like:

  • operator === 0operator === FilteringLogic.And or operator === 'and'
  • operator === 1operator === FilteringLogic.Or or operator === 'or'
  • FilteringLogic.And → should continue to work, but internal comparisons should use string values
  • FilteringLogic.Or → should continue to work, but internal comparisons should use string values

7. Remove enum imports where no longer needed

After conversion, remove unused enum imports similar to how GridPagingMode imports were removed in PR #15706.

Testing Requirements

Ensure that:

  1. Existing filtering functionality works with the new string union type
  2. State persistence can load old state with enum values (0, 1) and convert to new string values
  3. FilteringExpressionsTree objects created with both old and new values work correctly
  4. Query Builder and Excel-style filtering continue to work
  5. Remote filtering scenarios handle the conversion properly

Reference

Follow the same pattern as PR #15706 which converted GridPagingMode:

  • Changed from enum with numeric values to const object with string values
  • Updated all comparisons throughout the codebase
  • Removed unnecessary enum imports
  • Maintained the enum-like constant object for backwards compatibility

The key files changed in that PR were:

  • projects/igniteui-angular/grids/core/src/common/enums.ts (enum definition)
  • Various grid pipes and components (usage updates)
  • Test files (usage updates)

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Convert FilteringLogic enum to string union type Convert FilteringLogic enum to string union type Nov 21, 2025
Copilot AI requested a review from damyanpetev November 21, 2025 16:57
Copilot finished work on behalf of damyanpetev November 21, 2025 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants