1
1
import { EntityType , SchemaField } from '../../../../../../../types.generated' ;
2
2
import EntityRegistry from '../../../../../EntityRegistry' ;
3
3
4
+ function matchesTagsOrTerms ( field : SchemaField , filterText : string , entityRegistry : EntityRegistry ) {
5
+ return (
6
+ field . globalTags ?. tags ?. find ( ( tagAssociation ) =>
7
+ entityRegistry . getDisplayName ( EntityType . Tag , tagAssociation . tag ) . toLocaleLowerCase ( ) . includes ( filterText ) ,
8
+ ) ||
9
+ field . glossaryTerms ?. terms ?. find ( ( termAssociation ) =>
10
+ entityRegistry
11
+ . getDisplayName ( EntityType . GlossaryTerm , termAssociation . term )
12
+ . toLocaleLowerCase ( )
13
+ . includes ( filterText ) ,
14
+ )
15
+ ) ;
16
+ }
17
+
4
18
// returns list of fieldPaths for fields that have Terms or Tags matching the filterText
5
19
function getFilteredFieldPathsByMetadata ( editableSchemaMetadata : any , entityRegistry , filterText ) {
6
20
return (
7
21
editableSchemaMetadata ?. editableSchemaFieldInfo
8
- . filter ( ( fieldInfo ) => {
9
- return (
10
- fieldInfo . globalTags ?. tags . find ( ( tagAssociation ) =>
11
- entityRegistry
12
- . getDisplayName ( EntityType . Tag , tagAssociation . tag )
13
- . toLocaleLowerCase ( )
14
- . includes ( filterText ) ,
15
- ) ||
16
- fieldInfo . glossaryTerms ?. terms . find ( ( termAssociation ) =>
17
- entityRegistry
18
- . getDisplayName ( EntityType . GlossaryTerm , termAssociation . term )
19
- . toLocaleLowerCase ( )
20
- . includes ( filterText ) ,
21
- )
22
- ) ;
23
- } )
22
+ . filter ( ( fieldInfo ) => matchesTagsOrTerms ( fieldInfo , filterText , entityRegistry ) )
24
23
. map ( ( fieldInfo ) => fieldInfo . fieldPath ) || [ ]
25
24
) ;
26
25
}
27
26
28
- function shouldInclude (
29
- fieldName : string ,
30
- fullFieldPath : string ,
31
- filterText : string ,
32
- filteredFieldPathsByMetadata : any ,
33
- ) {
34
- return fieldName . toLocaleLowerCase ( ) . includes ( filterText ) || filteredFieldPathsByMetadata . includes ( fullFieldPath ) ;
27
+ function matchesEditableTagsOrTerms ( field : SchemaField , filteredFieldPathsByEditableMetadata : any ) {
28
+ return filteredFieldPathsByEditableMetadata . includes ( field . fieldPath ) ;
29
+ }
30
+
31
+ function matchesFieldName ( fieldName : string , filterText : string ) {
32
+ return fieldName . toLocaleLowerCase ( ) . includes ( filterText ) ;
35
33
}
36
34
37
35
export function filterSchemaRows (
@@ -44,7 +42,7 @@ export function filterSchemaRows(
44
42
if ( ! filterText ) return { filteredRows : rows , expandedRowsFromFilter : new Set ( ) } ;
45
43
const formattedFilterText = filterText . toLocaleLowerCase ( ) ;
46
44
47
- const filteredFieldPathsByMetadata = getFilteredFieldPathsByMetadata (
45
+ const filteredFieldPathsByEditableMetadata = getFilteredFieldPathsByMetadata (
48
46
editableSchemaMetadata ,
49
47
entityRegistry ,
50
48
formattedFilterText ,
@@ -53,12 +51,20 @@ export function filterSchemaRows(
53
51
const expandedRowsFromFilter = new Set ( ) ;
54
52
55
53
rows . forEach ( ( row ) => {
56
- if ( shouldInclude ( row . fieldPath , row . fieldPath , formattedFilterText , filteredFieldPathsByMetadata ) ) {
54
+ if (
55
+ matchesFieldName ( row . fieldPath , formattedFilterText ) ||
56
+ matchesEditableTagsOrTerms ( row , filteredFieldPathsByEditableMetadata ) ||
57
+ matchesTagsOrTerms ( row , formattedFilterText , entityRegistry ) // non-editable tags and terms
58
+ ) {
57
59
finalFieldPaths . add ( row . fieldPath ) ;
58
60
}
59
61
const splitFieldPath = row . fieldPath . split ( '.' ) ;
60
62
const fieldName = splitFieldPath . slice ( - 1 ) [ 0 ] ;
61
- if ( shouldInclude ( fieldName , row . fieldPath , formattedFilterText , filteredFieldPathsByMetadata ) ) {
63
+ if (
64
+ matchesFieldName ( fieldName , formattedFilterText ) ||
65
+ matchesEditableTagsOrTerms ( row , filteredFieldPathsByEditableMetadata ) ||
66
+ matchesTagsOrTerms ( row , formattedFilterText , entityRegistry )
67
+ ) {
62
68
// if we match specifically on this field (not just its parent), add and expand all parents
63
69
splitFieldPath . reduce ( ( previous , current ) => {
64
70
finalFieldPaths . add ( previous ) ;
0 commit comments