File tree Expand file tree Collapse file tree 4 files changed +78
-5
lines changed
components/panels/bulk-link Expand file tree Collapse file tree 4 files changed +78
-5
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @srl-labs/clab-ui" ,
3- "version" : " 0.0.5 " ,
3+ "version" : " 0.0.6 " ,
44 "private" : false ,
55 "type" : " module" ,
66 "main" : " src/index.ts" ,
77 "types" : " src/index.ts" ,
8+ "exports" : {
9+ "." : " ./src/index.ts" ,
10+ "./theme" : " ./src/theme/index.ts" ,
11+ "./explorer" : " ./src/explorer/index.ts" ,
12+ "./inspect" : " ./src/inspect/index.ts" ,
13+ "./core/parsing" : " ./src/core/parsing/index.ts" ,
14+ "./core/schema" : " ./src/core/schema/index.ts" ,
15+ "./core/types" : " ./src/core/types/index.ts" ,
16+ "./core/utilities" : " ./src/core/utilities/index.ts" ,
17+ "./core/*" : " ./src/core/*.ts" ,
18+ "./components/context-menu/ContextMenu" : " ./src/components/context-menu/ContextMenu.tsx" ,
19+ "./*" : " ./src/*"
20+ },
821 "publishConfig" : {
922 "registry" : " https://npm.pkg.github.com" ,
1023 "access" : " public"
Original file line number Diff line number Diff line change 22 * Utility functions for bulk link creation
33 * Uses React Flow nodes/edges arrays for graph queries.
44 */
5- import { FilterUtils } from "../../../../../../src/helpers /filterUtils" ;
6- import { isSpecialEndpointId } from "@srl-labs/clab-ui /core/utilities/LinkTypes" ;
7- import type { TopoNode , TopoEdge } from "@srl-labs/clab-ui /core/types/graph" ;
5+ import { FilterUtils } from "../../../utils /filterUtils" ;
6+ import { isSpecialEndpointId } from "../../.. /core/utilities/LinkTypes" ;
7+ import type { TopoNode , TopoEdge } from "../../.. /core/types/graph" ;
88import { hasEdgeBetween as hasEdgeBetweenUtil } from "../../../utils/graphQueryUtils" ;
99import { allocateEndpoint , type EndpointAllocator } from "../../../utils/endpointAllocator" ;
1010
Original file line number Diff line number Diff line change 1+ export class FilterUtils {
2+ static createFilter ( filterText : string ) {
3+ if ( ! filterText ) {
4+ return ( ) => true ;
5+ }
6+
7+ const regex = this . tryCreateRegExp ( filterText ) ;
8+ if ( regex ) {
9+ return ( value : string ) => regex . test ( value ) ;
10+ }
11+
12+ const searchText = filterText . toLowerCase ( ) ;
13+ return ( value : string ) => value . toLowerCase ( ) . includes ( searchText ) ;
14+ }
15+
16+ static tryCreateRegExp ( filterText : string , flags = "i" ) : RegExp | null {
17+ if ( ! filterText ) {
18+ return null ;
19+ }
20+
21+ const processedPattern = this . convertUserFriendlyPattern ( filterText ) ;
22+
23+ try {
24+ return new RegExp ( processedPattern , flags ) ;
25+ } catch {
26+ return null ;
27+ }
28+ }
29+
30+ private static convertUserFriendlyPattern ( pattern : string ) : string {
31+ if ( this . looksLikeRegex ( pattern ) ) {
32+ return pattern ;
33+ }
34+ const hasWildcards = / [ * ? # ] / . test ( pattern ) ;
35+
36+ let converted = pattern
37+ . replace ( / \* / g, ".*" )
38+ . replace ( / \? / g, "." )
39+ . replace ( / # / g, "\\d+" ) ;
40+
41+ if ( hasWildcards ) {
42+ converted = `^${ converted } $` ;
43+ }
44+
45+ return converted ;
46+ }
47+
48+ private static looksLikeRegex ( pattern : string ) : boolean {
49+ return (
50+ pattern . includes ( "\\" ) ||
51+ pattern . includes ( "[" ) ||
52+ pattern . includes ( "(" ) ||
53+ pattern . includes ( "|" ) ||
54+ pattern . includes ( "^" ) ||
55+ pattern . includes ( "$" ) ||
56+ pattern . includes ( ".*" ) ||
57+ pattern . includes ( ".+" )
58+ ) ;
59+ }
60+ }
You can’t perform that action at this time.
0 commit comments