1
1
import { MouseEventHandler , useCallback , useEffect , useMemo , useState } from 'react' ;
2
2
import ButtonWithToolTip from '../../../UI/ButtonWithToolTip' ;
3
3
import { appLabels , buttonCaptions , getDefaultSchemaExamples , tooltips } from '../../../../utils/Constants' ;
4
- import { Flex , Typography , useMediaQuery , Tag } from '@neo4j-ndl/react' ;
4
+ import { Flex , Typography , useMediaQuery } from '@neo4j-ndl/react' ;
5
5
import { useCredentials } from '../../../../context/UserCredentials' ;
6
6
import { useFileContext } from '../../../../context/UsersFiles' ;
7
7
import { OptionType , TupleType } from '../../../../types' ;
8
8
import { getNodeLabelsAndRelTypes } from '../../../../services/GetNodeLabelsRelTypes' ;
9
9
import { showNormalToast } from '../../../../utils/Toasts' ;
10
10
import { useHasSelections } from '../../../../hooks/useHasSelections' ;
11
- import { Hierarchy1Icon } from '@neo4j-ndl/react/icons ' ;
11
+ import PatternContainer from './PatternContainer ' ;
12
12
import SchemaViz from '../../../Graph/SchemaViz' ;
13
13
import GraphPattern from './GraphPattern' ;
14
14
import { updateLocalStorage , extractOptions } from '../../../../utils/Utils' ;
15
+ import SchemaSelectionDialog from '../../../UI/SchemaSelectionPopup' ;
15
16
16
17
export default function NewEntityExtractionSetting ( {
17
18
view,
@@ -61,9 +62,9 @@ export default function NewEntityExtractionSetting({
61
62
try {
62
63
const response = await getNodeLabelsAndRelTypes ( ) ;
63
64
setLoading ( false ) ;
64
- const schemaData : string [ ] = response . data . data ;
65
+ const schemaData : string [ ] = response . data . data . triplets ;
65
66
const schemaTuples : TupleType [ ] = schemaData . map ( ( item : string ) => {
66
- const matchResult = item . match ( / ( . * ?) - \[ : ( . * ? ) \] - > ( .* ) / ) ;
67
+ const matchResult = item . match ( / ^ ( . + ?) - ( [ A - Z _ ] + ) - > ( .+ ) $ / ) ;
67
68
if ( matchResult ) {
68
69
const [ source , rel , target ] = matchResult . slice ( 1 ) . map ( ( s ) => s . trim ( ) ) ;
69
70
return {
@@ -88,8 +89,14 @@ export default function NewEntityExtractionSetting({
88
89
89
90
const clickHandler : MouseEventHandler < HTMLButtonElement > = useCallback ( async ( ) => {
90
91
await getOptions ( ) ;
92
+ setSchemaPopupView ( 'loadExistingSchema' )
93
+ setOpenSchemaPopup ( true ) ;
91
94
} , [ nodeLabelOptions , relationshipTypeOptions ] ) ;
92
95
96
+ const onclosePopup = ( ) => {
97
+ setOpenSchemaPopup ( false ) ;
98
+ }
99
+
93
100
const handleClear = ( ) => {
94
101
setSelectedNodes ( [ ] ) ;
95
102
setSelectedRels ( [ ] ) ;
@@ -139,11 +146,6 @@ export default function NewEntityExtractionSetting({
139
146
updateLocalStorage ( userCredentials ! ! , 'selectedNodeLabels' , selectedRelPayload ) ;
140
147
setSelectedNodes ( nodeLabelOptions ) ;
141
148
setSelectedRels ( relationshipTypeOptions ) ;
142
-
143
- console . log ( 'Schema settings saved successfully:' , {
144
- nodes : selectedNodePayload ,
145
- rels : selectedRelPayload ,
146
- } ) ;
147
149
} ;
148
150
149
151
const handleSchemaView = ( ) => {
@@ -237,40 +239,12 @@ export default function NewEntityExtractionSetting({
237
239
>
238
240
</ GraphPattern >
239
241
{ pattern . length > 0 && (
240
- < div className = 'h-full' >
241
- < div className = 'flex align-self-center justify-center border' >
242
- < h5 > { appLabels . selectedPatterns } </ h5 >
243
- </ div >
244
- < div className = 'flex items-start gap-4 mt-4' >
245
- < div className = 'flex flex-wrap gap-2 patternContainer' >
246
- { pattern . map ( ( pattern ) => (
247
- < Tag
248
- key = { pattern }
249
- onRemove = { ( ) => handleRemovePattern ( pattern ) }
250
- isRemovable = { true }
251
- type = 'default'
252
- size = 'medium'
253
- className = { `rounded-full px-4 py-1 shadow-sm transition-all duration-300 ${ pattern === highlightPattern ? 'animate-highlight' : ''
254
- } `}
255
- >
256
- { pattern }
257
- </ Tag >
258
- ) ) }
259
- </ div >
260
- < div className = 'flex-shrink-0 items-end m-auto' >
261
- < ButtonWithToolTip
262
- label = { 'Graph Schema' }
263
- text = { tooltips . visualizeGraph }
264
- placement = 'top'
265
- fill = 'outlined'
266
- onClick = { handleSchemaView }
267
- className = 'ml-4'
268
- >
269
- < Hierarchy1Icon />
270
- </ ButtonWithToolTip >
271
- </ div >
272
- </ div >
273
- </ div >
242
+ < PatternContainer
243
+ pattern = { pattern }
244
+ handleRemove = { handleRemovePattern }
245
+ handleSchemaView = { handleSchemaView }
246
+ highlightPattern = { highlightPattern ?? '' }
247
+ > </ PatternContainer >
274
248
) }
275
249
< Flex className = 'mt-4! mb-2 flex! items-center' flexDirection = 'row' justifyContent = 'flex-end' >
276
250
< Flex flexDirection = 'row' gap = '4' >
@@ -354,6 +328,15 @@ export default function NewEntityExtractionSetting({
354
328
relationshipValues = { ( relationshipTypeOptions ) ?? [ ] }
355
329
/>
356
330
) }
331
+ {
332
+ openSchemaPopup && ( < SchemaSelectionDialog
333
+ open = { openSchemaPopup }
334
+ onClose = { onclosePopup }
335
+ pattern = { pattern }
336
+ handleRemove = { handleRemovePattern }
337
+ handleSchemaView = { handleSchemaView }
338
+ > </ SchemaSelectionDialog > )
339
+ }
357
340
</ div >
358
341
) ;
359
342
}
0 commit comments