-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NIFI-13961 Allow camelCase search when filtering on component selecti…
- Loading branch information
1 parent
4198880
commit eb7c618
Showing
6 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...apps/nifi/src/app/ui/common/extension-creation/filter-predicate/camel-case.search.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { matchesCamelCaseSearch } from './camel-case.search'; | ||
|
||
describe('matchesCamelCaseSearch', () => { | ||
const value = 'org.apache.nifi.processors.standard.GenerateFlowFile'; | ||
|
||
it.each([ | ||
{ value, query: '', expectedResult: false }, | ||
{ value, query: value, expectedResult: true }, | ||
{ value, query: 'Generate', expectedResult: true }, | ||
{ value, query: 'GFlowFile', expectedResult: true }, | ||
{ value, query: 'GeFlF', expectedResult: true }, | ||
{ value, query: 'GFF', expectedResult: true }, | ||
{ value, query: 'RFlowFile', expectedResult: false } | ||
])('should return $expectedResult for matching $query against $value', ({ value, query, expectedResult }) => { | ||
expect(matchesCamelCaseSearch(value, query)).toBe(expectedResult); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
...tend/apps/nifi/src/app/ui/common/extension-creation/filter-predicate/camel-case.search.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export function matchesCamelCaseSearch(value: string, filter: string): boolean { | ||
const camelCaseMatches = filter.match(/[^A-Z]+|[A-Z][^A-Z]*/g); | ||
if (camelCaseMatches == null) { | ||
return false; | ||
} | ||
|
||
const joinedParts = camelCaseMatches.join('.*'); | ||
return new RegExp(joinedParts).test(value); | ||
} |
75 changes: 75 additions & 0 deletions
75
...ontend/apps/nifi/src/app/ui/common/extension-creation/filter-predicate/extensions.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { FilterPredicate } from './filter-predicate'; | ||
import { anyOf, onLowerCaseFilter } from './extensions'; | ||
|
||
describe('FilterPredicate extensions', () => { | ||
describe('onLowerCaseFilter', () => { | ||
let memoizedFilter: string | null = null; | ||
|
||
const mnemonicTautology: FilterPredicate<any> = (_, filter) => { | ||
memoizedFilter = filter; | ||
return true; | ||
}; | ||
|
||
it('should create function that is passed lowercase filter values as is', () => { | ||
const lowerCaseInput = 'hello'; | ||
|
||
const predicate = onLowerCaseFilter(mnemonicTautology); | ||
predicate('example', lowerCaseInput); | ||
|
||
expect(memoizedFilter).toEqual(lowerCaseInput); | ||
}); | ||
|
||
it('should create function that is passed non-lowercase filter values as lowercase values', () => { | ||
const nonLowerCaseInput = 'HelLO WoRlD'; | ||
const expectedPassedValue = 'hello world'; | ||
|
||
const predicate = onLowerCaseFilter(mnemonicTautology); | ||
predicate('example', nonLowerCaseInput); | ||
|
||
expect(memoizedFilter).toEqual(expectedPassedValue); | ||
}); | ||
}); | ||
|
||
describe('anyOf', () => { | ||
const tautology: FilterPredicate<any> = () => true; | ||
const contradiction: FilterPredicate<any> = () => false; | ||
|
||
it('should create a function that yields true, when any of the functions passed to it yield true', () => { | ||
const predicate = anyOf(contradiction, contradiction, tautology, contradiction); | ||
const result = predicate('data', 'filter'); | ||
|
||
expect(result).toEqual(true); | ||
}); | ||
|
||
it('should create a function that yields false, when all of the functions passed to it yield false', () => { | ||
const predicate = anyOf(contradiction, contradiction, contradiction, contradiction, contradiction); | ||
const result = predicate('data', 'filter'); | ||
|
||
expect(result).toEqual(false); | ||
}); | ||
|
||
it('should create a function that yields false, when no function is passed to it', () => { | ||
const predicate = anyOf(); | ||
const result = predicate('data', 'filter'); | ||
|
||
expect(result).toEqual(false); | ||
}); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
...in/frontend/apps/nifi/src/app/ui/common/extension-creation/filter-predicate/extensions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { FilterPredicate } from './filter-predicate'; | ||
|
||
export function anyOf<T>(...predicates: FilterPredicate<T>[]): FilterPredicate<T> { | ||
return (data: T, filter: string) => predicates.some((predicate) => predicate(data, filter)); | ||
} | ||
|
||
export function onLowerCaseFilter<T>(predicate: FilterPredicate<T>): FilterPredicate<T> { | ||
return (data: T, filter: string) => predicate(data, filter.toLowerCase()); | ||
} |
18 changes: 18 additions & 0 deletions
18
...ntend/apps/nifi/src/app/ui/common/extension-creation/filter-predicate/filter-predicate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export type FilterPredicate<T> = (data: T, filter: string) => boolean; |