1- import React , { useEffect } from 'react' ;
1+ import React , { useEffect , useMemo , useCallback } from 'react' ;
22import Helmet from 'react-helmet' ;
33import Container from '@material-ui/core/Container' ;
44import Drawer from '@material-ui/core/Drawer' ;
@@ -91,7 +91,7 @@ function FamilyChartWithAnnotations() {
9191 // eslint-disable-next-line react-hooks/exhaustive-deps
9292 } , [ ] /* run only once */ ) ;
9393
94- function getActionMessage ( ) {
94+ function getActionMessage ( config , userAction , itemsHash ) {
9595 switch ( userAction . type ) {
9696 case UserActionType . ContextButtonClick : {
9797 const item = itemsHash [ userAction . itemId ] ;
@@ -110,11 +110,35 @@ function FamilyChartWithAnnotations() {
110110 }
111111 }
112112
113- const snackbarMessage = getActionMessage ( ) ;
113+ function getOptionsPanelConfig ( datasetNames , annotationConfig ) {
114+ return [ { title : "Family Samples" ,
115+ namespace : "datasets" ,
116+ options : [
117+ { optionType : "RadioBoxConfig" , name : "datasetName" , caption : "Names" , options : datasetNames , valueType : "string" } ,
118+ ]
119+ } ,
120+ FamilyLayoutOptions ,
121+ DefaultTemplateOptions ,
122+ ( annotationConfig !== undefined ? ConnectorAnnotationOptions : undefined ) ,
123+ GroupTitlesOptions ,
124+ MarkersOptions ,
125+ IntervalsOptions ,
126+ ConnectorsOptions ,
127+ LabelsOptions ,
128+ CalloutOptions ,
129+ InteractivityOptions ,
130+ RenderingOptions ,
131+ FrameOptions
132+ ] . filter ( items => items ) ;
133+ }
134+
135+ const snackbarMessage = useMemo ( ( ) => getActionMessage ( config , userAction , itemsHash ) , [ config , userAction , itemsHash ] ) ;
114136 const templateConfig = config . templates . find ( template => template . name === 'defaultTemplate' ) ;
115137 const contactTemplateConfig = config . templates . find ( template => template . name === 'contactTemplate' ) ;
116138 const miniTemplateConfig = config . templates . find ( template => template . name === 'miniTemplate' ) ;
117- const annotationConfig = config . annotations . find ( annotation => annotation . name === "usercontrolledconnector" ) || new primitives . orgdiagram . ConnectorAnnotationConfig ( { offset : 2 } ) ;
139+ const annotationConfig = config . annotations . find ( annotation => annotation . name === "usercontrolledconnector" ) ;
140+ const optionsPanelConfig = useMemo ( ( ) => getOptionsPanelConfig ( datasetNames , annotationConfig ) , [ datasetNames , annotationConfig ] ) ;
141+
118142 return (
119143 < >
120144 < Helmet >
@@ -282,24 +306,7 @@ function FamilyChartWithAnnotations() {
282306 </ div >
283307 < Divider />
284308 < OptionsPanel
285- optionsPanelConfig = { [ { title : "Family Samples" ,
286- namespace : "datasets" ,
287- options : [
288- { optionType : "RadioBoxConfig" , name : "datasetName" , caption : "Names" , options : datasetNames , valueType : "string" } ,
289- ]
290- } ,
291- FamilyLayoutOptions ,
292- DefaultTemplateOptions ,
293- ConnectorAnnotationOptions ,
294- GroupTitlesOptions ,
295- MarkersOptions ,
296- IntervalsOptions ,
297- ConnectorsOptions ,
298- LabelsOptions ,
299- CalloutOptions ,
300- InteractivityOptions ,
301- RenderingOptions ,
302- FrameOptions ] }
309+ optionsPanelConfig = { optionsPanelConfig }
303310 config = { config }
304311 defaultTemplate = { templateConfig }
305312 annotation = { annotationConfig }
0 commit comments