@@ -16,9 +16,8 @@ import * as FluentIcons from "@fluentui/react-icons";
16
16
import { useContext , useEffect , useState } from "react" ;
17
17
import { SchemaDesignerContext } from "../schemaDesignerStateProvider" ;
18
18
import { locConstants } from "../../../common/locConstants" ;
19
- import { Edge , Node , useReactFlow } from "@xyflow/react" ;
20
- import { SchemaDesigner } from "../../../../sharedInterfaces/schemaDesigner" ;
21
- import { flowUtils } from "../schemaDesignerUtils" ;
19
+ import { useReactFlow } from "@xyflow/react" ;
20
+ import eventBus from "../schemaDesignerEvents" ;
22
21
23
22
export function FilterTablesButton ( ) {
24
23
const context = useContext ( SchemaDesignerContext ) ;
@@ -33,27 +32,17 @@ export function FilterTablesButton() {
33
32
const [ isFilterMenuOpen , setIsFilterMenuOpen ] = useState ( false ) ;
34
33
35
34
function loadTables ( ) {
36
- const schema = flowUtils . extractSchemaModel (
37
- reactFlow . getNodes ( ) as Node < SchemaDesigner . Table > [ ] ,
38
- reactFlow . getEdges ( ) as Edge < SchemaDesigner . ForeignKey > [ ] ,
39
- ) ;
40
-
41
- if ( ! schema ) {
42
- return ;
35
+ // Update the selected tables based on the current nodes
36
+ const nodes = reactFlow . getNodes ( ) ;
37
+ const tableNames = nodes
38
+ . filter ( ( node ) => node . hidden !== true )
39
+ . map ( ( node ) => `${ node . data . schema } .${ node . data . name } ` ) ;
40
+ if ( nodes . length === tableNames . length ) {
41
+ setSelectedTables ( [ ] ) ;
42
+ } else {
43
+ setSelectedTables ( tableNames ) ;
43
44
}
44
- const tableNames = schema . tables . map ( ( table ) => `${ table . schema } .${ table . name } ` ) ;
45
- // bring selected tables to the top
46
- tableNames . sort ( ( a , b ) => {
47
- const aSelected = selectedTables . includes ( a ) ;
48
- const bSelected = selectedTables . includes ( b ) ;
49
- if ( aSelected && ! bSelected ) {
50
- return - 1 ;
51
- }
52
- if ( ! aSelected && bSelected ) {
53
- return 1 ;
54
- }
55
- return a . localeCompare ( b ) ;
56
- } ) ;
45
+ setFilterText ( "" ) ;
57
46
}
58
47
59
48
useEffect ( ( ) => {
@@ -83,6 +72,14 @@ export function FilterTablesButton() {
83
72
} ) ;
84
73
} , [ selectedTables ] ) ;
85
74
75
+ useEffect ( ( ) => {
76
+ eventBus . on ( "getScript" , ( ) =>
77
+ requestAnimationFrame ( ( ) => {
78
+ loadTables ( ) ;
79
+ } ) ,
80
+ ) ;
81
+ } , [ ] ) ;
82
+
86
83
// Function to highlight text based on search
87
84
const highlightText = ( text : string , searchText : string ) => {
88
85
if ( ! searchText || searchText . trim ( ) === "" ) {
@@ -212,6 +209,13 @@ export function FilterTablesButton() {
212
209
style = { { } }
213
210
onClick = { ( ) => {
214
211
setSelectedTables ( [ ] ) ;
212
+ const nodes = reactFlow . getNodes ( ) ;
213
+ nodes . forEach ( ( node ) => {
214
+ reactFlow . updateNode ( node . id , {
215
+ ...node ,
216
+ hidden : false ,
217
+ } ) ;
218
+ } ) ;
215
219
} }
216
220
appearance = "subtle"
217
221
icon = { < FluentIcons . DismissRegular /> } >
0 commit comments