11import { useCallback , useEffect , useMemo , useState } from 'react' ;
2- import {
3- CalmArchitectureSchema ,
4- CalmNodeSchema ,
5- CalmRelationshipSchema ,
6- } from '@finos/calm-models/types' ;
2+ import { CalmArchitectureSchema , CalmNodeSchema , CalmRelationshipSchema } from '@finos/calm-models/types' ;
73import { useDropzone } from 'react-dropzone' ;
84import { ReactFlowVisualizer } from '../reactflow/ReactFlowVisualizer.js' ;
95import { PatternVisualizer } from '../reactflow/PatternVisualizer.js' ;
106import { Sidebar } from '../sidebar/Sidebar.js' ;
117import { MetadataPanel } from '../reactflow/MetadataPanel.js' ;
128import { toSidebarNodeData , toSidebarEdgeData } from '../reactflow/utils/patternClickHandlers.js' ;
13- import { THEME } from '../reactflow/theme.js' ;
149import type { DrawerProps , SelectedItem , Flow , Control } from '../../contracts/contracts.js' ;
1510
1611/**
@@ -21,8 +16,7 @@ function isPatternData(data: unknown): boolean {
2116 if ( ! data || typeof data !== 'object' ) return false ;
2217 const obj = data as Record < string , unknown > ;
2318 const props = obj [ 'properties' ] as Record < string , unknown > | undefined ;
24- return ! ! ( props ?. [ 'nodes' ] && typeof props [ 'nodes' ] === 'object' &&
25- ( props [ 'nodes' ] as Record < string , unknown > ) [ 'prefixItems' ] ) ;
19+ return ! ! ( props ?. [ 'nodes' ] && typeof props [ 'nodes' ] === 'object' && ( props [ 'nodes' ] as Record < string , unknown > ) [ 'prefixItems' ] ) ;
2620}
2721
2822/**
@@ -37,7 +31,6 @@ export function Drawer({ data }: DrawerProps) {
3731 const [ patternInstance , setPatternInstance ] = useState < Record < string , unknown > | undefined > ( undefined ) ;
3832 const [ fileInstance , setFileInstance ] = useState < Record < string , unknown > | undefined > ( undefined ) ;
3933 const [ selectedItem , setSelectedItem ] = useState < SelectedItem > ( null ) ;
40- const [ title , setTitle ] = useState < string > ( '' ) ;
4134 // Default to collapsed as per user request
4235 const [ isMetadataCollapsed , setIsMetadataCollapsed ] = useState ( true ) ;
4336 // Height of the metadata panel when expanded (in pixels)
@@ -48,24 +41,17 @@ export function Drawer({ data }: DrawerProps) {
4841 const fileText = await acceptedFiles [ 0 ] . text ( ) ;
4942 const parsed = JSON . parse ( fileText ) ;
5043 setFileInstance ( parsed ) ;
51- setTitle ( acceptedFiles [ 0 ] . name ) ;
5244 }
5345 } , [ ] ) ;
5446
5547 const { getRootProps, getInputProps, isDragActive } = useDropzone ( { onDrop } ) ;
5648
5749 useEffect ( ( ) => {
5850 const source = fileInstance ?? data ?. data ;
59- const isPattern = ! ! source && (
60- isPatternData ( source ) || ( ! fileInstance && data ?. calmType === 'Patterns' )
61- ) ;
51+ const isPattern = ! ! source && ( isPatternData ( source ) || ( ! fileInstance && data ?. calmType === 'Patterns' ) ) ;
6252
6353 setPatternInstance ( isPattern ? ( source as Record < string , unknown > ) : undefined ) ;
6454 setCALMInstance ( isPattern ? undefined : ( source as CalmArchitectureSchema | undefined ) ) ;
65-
66- if ( data ?. name && data ?. id && data ?. version ) {
67- setTitle ( `${ data . name } /${ data . id } /${ data . version } ` ) ;
68- }
6955 } , [ fileInstance , data ] ) ;
7056
7157 // Extract flows from CALM data
@@ -76,7 +62,9 @@ export function Drawer({ data }: DrawerProps) {
7662
7763 // Extract controls from CALM data (from root, nodes, and relationships)
7864 const controls = useMemo ( ( ) : Record < string , Control > => {
79- const calmData = calmInstance as CalmArchitectureSchema & { controls ?: Record < string , Control > } ;
65+ const calmData = calmInstance as CalmArchitectureSchema & {
66+ controls ?: Record < string , Control > ;
67+ } ;
8068 if ( ! calmData ) return { } ;
8169
8270 const rootControls : Record < string , Control > = calmData . controls || { } ;
@@ -147,20 +135,26 @@ export function Drawer({ data }: DrawerProps) {
147135 } , [ ] ) ;
148136
149137 // Handle transition click from flows panel - highlight the relationship
150- const handleTransitionClick = useCallback ( ( relationshipId : string ) => {
151- const relationship = calmInstance ?. relationships ?. find ( ( r ) => r [ 'unique-id' ] === relationshipId ) ;
152- if ( relationship ) {
153- handleEdgeClick ( relationship ) ;
154- }
155- } , [ calmInstance , handleEdgeClick ] ) ;
138+ const handleTransitionClick = useCallback (
139+ ( relationshipId : string ) => {
140+ const relationship = calmInstance ?. relationships ?. find ( ( r ) => r [ 'unique-id' ] === relationshipId ) ;
141+ if ( relationship ) {
142+ handleEdgeClick ( relationship ) ;
143+ }
144+ } ,
145+ [ calmInstance , handleEdgeClick ]
146+ ) ;
156147
157148 // Handle node click from controls panel
158- const handleControlNodeClick = useCallback ( ( nodeId : string ) => {
159- const node = calmInstance ?. nodes ?. find ( ( n ) => n [ 'unique-id' ] === nodeId ) ;
160- if ( node ) {
161- handleNodeClick ( node ) ;
162- }
163- } , [ calmInstance , handleNodeClick ] ) ;
149+ const handleControlNodeClick = useCallback (
150+ ( nodeId : string ) => {
151+ const node = calmInstance ?. nodes ?. find ( ( n ) => n [ 'unique-id' ] === nodeId ) ;
152+ if ( node ) {
153+ handleNodeClick ( node ) ;
154+ }
155+ } ,
156+ [ calmInstance , handleNodeClick ]
157+ ) ;
164158
165159 return (
166160 < div { ...getRootProps ( ) } className = "flex-1 flex overflow-hidden h-full" >
@@ -176,28 +170,11 @@ export function Drawer({ data }: DrawerProps) {
176170 < div className = "drawer-content h-full flex flex-col" >
177171 { hasContent ? (
178172 < >
179- { title && (
180- < div
181- style = { {
182- padding : '8px 16px' ,
183- borderBottom : `1px solid ${ THEME . colors . border } ` ,
184- backgroundColor : THEME . colors . backgroundSecondary ,
185- fontSize : '14px' ,
186- fontWeight : 500 ,
187- color : THEME . colors . foreground ,
188- flexShrink : 0 ,
189- } }
190- >
191- { title }
192- </ div >
193- ) }
194173 < div
195174 style = { {
196175 flex : 1 ,
197176 minHeight : 0 ,
198- ...( hasMetadata && ! isMetadataCollapsed
199- ? { height : `calc(100% - ${ metadataPanelHeight } px)` }
200- : { } ) ,
177+ ...( hasMetadata && ! isMetadataCollapsed ? { height : `calc(100% - ${ metadataPanelHeight } px)` } : { } ) ,
201178 } }
202179 >
203180 { patternInstance ? (
0 commit comments