-
Notifications
You must be signed in to change notification settings - Fork 2
/
PropertyCategoryLabelFilterer.ts
63 lines (53 loc) · 1.92 KB
/
PropertyCategoryLabelFilterer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module PropertyGrid
*/
import { countMatchesInString } from "../../../common/countMatchesInString";
import type { PropertyCategory } from "../../PropertyDataProvider";
import type { PropertyDataFilterResult } from "./PropertyDataFiltererBase";
import {
FilteredType,
PropertyCategoryDataFiltererBase,
} from "./PropertyDataFiltererBase";
/**
* PropertyData filterer which matches on PropertyCategory's label.
* @public
*/
export class PropertyCategoryLabelFilterer extends PropertyCategoryDataFiltererBase {
private _filterText: string = "";
public constructor(filterText: string = "") {
super();
this._filterText = filterText.toLowerCase().trim();
}
public get filterText(): string {
return this._filterText;
}
public set filterText(value: string) {
const lowerValue = value.toLowerCase().trim();
if (lowerValue !== this.filterText) {
this._filterText = lowerValue;
this.onFilterChanged.raiseEvent();
}
}
public get isActive() {
return this.filterText !== "";
}
public async categoryMatchesFilter(
node: PropertyCategory
): Promise<PropertyDataFilterResult> {
if (!this.isActive) return { matchesFilter: true };
const displayLabel = node.label.toLowerCase();
const matchesCount = countMatchesInString(displayLabel, this.filterText);
if (matchesCount === 0) return { matchesFilter: false };
return {
matchesFilter: true,
shouldExpandNodeParents: true,
shouldForceIncludeDescendants: true,
matchesCount,
filteredTypes: [FilteredType.Category],
};
}
}