Skip to content

Commit 5f18610

Browse files
author
Shahak Yosef
committed
Merged PR 195262: Support empty advanced filters
Support empty advanced filters
1 parent 8384e27 commit 5f18610

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/models.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ export interface IAdvancedFilterCondition {
475475

476476
export interface IAdvancedFilter extends IFilter {
477477
logicalOperator: AdvancedFilterLogicalOperators;
478-
conditions: IAdvancedFilterCondition[];
478+
conditions?: IAdvancedFilterCondition[];
479479
}
480480

481481
export enum FilterType {
@@ -846,9 +846,6 @@ export class AdvancedFilter extends Filter {
846846
extractedConditions = (conditions as IAdvancedFilterCondition[]);
847847
}
848848

849-
if (extractedConditions.length === 0) {
850-
throw new Error(`conditions must be a non-empty array. You passed: ${conditions}`);
851-
}
852849
if (extractedConditions.length > 2) {
853850
throw new Error(`AdvancedFilters may not have more than two conditions. You passed: ${conditions.length}`);
854851
}

src/validators/models/filtersValidator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export class AdvancedFilterValidator extends FilterValidatorBase {
246246
},
247247
{
248248
field: "conditions",
249-
validators: [Validators.fieldRequiredValidator, Validators.filterConditionsValidator]
249+
validators: [Validators.filterConditionsValidator]
250250
},
251251
{
252252
field: "filterType",

test/models.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3159,6 +3159,28 @@ describe("Unit | Filters", () => {
31593159
expect(filter.toJSON()).toEqual(expectedFilter);
31603160
});
31613161

3162+
it("should output the correct json when toJSON is called for empty advanced filter", () => {
3163+
// Arrange
3164+
const expectedFilter: models.IAdvancedFilter = {
3165+
$schema: "http://powerbi.com/product/schema#advanced",
3166+
target: {
3167+
table: "a",
3168+
column: "b"
3169+
},
3170+
conditions: [],
3171+
logicalOperator: "And",
3172+
filterType: models.FilterType.Advanced
3173+
};
3174+
3175+
// Act
3176+
const filter = new models.AdvancedFilter(
3177+
expectedFilter.target as models.IFilterTarget,
3178+
expectedFilter.logicalOperator);
3179+
3180+
// Assert
3181+
expect(filter.toJSON()).toEqual(expectedFilter);
3182+
});
3183+
31623184
it("can be constructed using either array form or individual arguments", () => {
31633185
// Arrange
31643186
const expectedFilter: models.IAdvancedFilter = {

0 commit comments

Comments
 (0)