Merged PR 195262: Support empty advanced filters
Support empty advanced filters
This commit is contained in:
Родитель
8384e27527
Коммит
5f18610ae1
|
@ -475,7 +475,7 @@ export interface IAdvancedFilterCondition {
|
|||
|
||||
export interface IAdvancedFilter extends IFilter {
|
||||
logicalOperator: AdvancedFilterLogicalOperators;
|
||||
conditions: IAdvancedFilterCondition[];
|
||||
conditions?: IAdvancedFilterCondition[];
|
||||
}
|
||||
|
||||
export enum FilterType {
|
||||
|
@ -846,9 +846,6 @@ export class AdvancedFilter extends Filter {
|
|||
extractedConditions = (conditions as IAdvancedFilterCondition[]);
|
||||
}
|
||||
|
||||
if (extractedConditions.length === 0) {
|
||||
throw new Error(`conditions must be a non-empty array. You passed: ${conditions}`);
|
||||
}
|
||||
if (extractedConditions.length > 2) {
|
||||
throw new Error(`AdvancedFilters may not have more than two conditions. You passed: ${conditions.length}`);
|
||||
}
|
||||
|
|
|
@ -246,7 +246,7 @@ export class AdvancedFilterValidator extends FilterValidatorBase {
|
|||
},
|
||||
{
|
||||
field: "conditions",
|
||||
validators: [Validators.fieldRequiredValidator, Validators.filterConditionsValidator]
|
||||
validators: [Validators.filterConditionsValidator]
|
||||
},
|
||||
{
|
||||
field: "filterType",
|
||||
|
|
|
@ -3159,6 +3159,28 @@ describe("Unit | Filters", () => {
|
|||
expect(filter.toJSON()).toEqual(expectedFilter);
|
||||
});
|
||||
|
||||
it("should output the correct json when toJSON is called for empty advanced filter", () => {
|
||||
// Arrange
|
||||
const expectedFilter: models.IAdvancedFilter = {
|
||||
$schema: "http://powerbi.com/product/schema#advanced",
|
||||
target: {
|
||||
table: "a",
|
||||
column: "b"
|
||||
},
|
||||
conditions: [],
|
||||
logicalOperator: "And",
|
||||
filterType: models.FilterType.Advanced
|
||||
};
|
||||
|
||||
// Act
|
||||
const filter = new models.AdvancedFilter(
|
||||
expectedFilter.target as models.IFilterTarget,
|
||||
expectedFilter.logicalOperator);
|
||||
|
||||
// Assert
|
||||
expect(filter.toJSON()).toEqual(expectedFilter);
|
||||
});
|
||||
|
||||
it("can be constructed using either array form or individual arguments", () => {
|
||||
// Arrange
|
||||
const expectedFilter: models.IAdvancedFilter = {
|
||||
|
|
Загрузка…
Ссылка в новой задаче