File tree 2 files changed +16
-3
lines changed
2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,14 @@ describe('matchFilteringProperty', () => {
42
42
const property = matchFilteringProperty ( filteringProperties , ' Averange latency' ) ;
43
43
expect ( property ) . toBe ( null ) ;
44
44
} ) ;
45
+ test ( 'should prefer an exact match to non-exact' , ( ) => {
46
+ const properties : FilteringProperty [ ] = [
47
+ { key : 'Test' , propertyLabel : 'Test' , groupValuesLabel : '' } ,
48
+ { key : 'test' , propertyLabel : 'test' , groupValuesLabel : '' } ,
49
+ ] ;
50
+ const property = matchFilteringProperty ( properties , 'test' ) ;
51
+ expect ( property ) . toBe ( properties [ 1 ] ) ;
52
+ } ) ;
45
53
} ) ;
46
54
47
55
describe ( 'matchOperator' , ( ) => {
Original file line number Diff line number Diff line change @@ -8,13 +8,18 @@ export function matchFilteringProperty(
8
8
filteringProperties : readonly FilteringProperty [ ] ,
9
9
filteringText : string
10
10
) : null | FilteringProperty {
11
- filteringText = filteringText . toLowerCase ( ) ;
12
-
13
11
let maxLength = 0 ;
14
12
let matchedProperty : null | FilteringProperty = null ;
15
13
16
14
for ( const property of filteringProperties ) {
17
- if ( property . propertyLabel . length > maxLength && startsWith ( filteringText , property . propertyLabel . toLowerCase ( ) ) ) {
15
+ if ( property . propertyLabel === filteringText ) {
16
+ matchedProperty = property ;
17
+ break ;
18
+ }
19
+ if (
20
+ property . propertyLabel . length > maxLength &&
21
+ startsWith ( filteringText . toLowerCase ( ) , property . propertyLabel . toLowerCase ( ) )
22
+ ) {
18
23
maxLength = property . propertyLabel . length ;
19
24
matchedProperty = property ;
20
25
}
You can’t perform that action at this time.
0 commit comments