@@ -9,7 +9,9 @@ import Visibility from '@material-ui/icons/Visibility';
99import ColorLens from '@material-ui/icons/ColorLens' ;
1010import Shuffle from '@material-ui/icons/Shuffle' ;
1111import { ChromePicker } from 'react-color' ;
12+ import { useDispatch , useSelector } from 'react-redux' ;
1213import { experimentLabelColor } from '../../theme' ;
14+ import { changeInstanceColor } from '../../redux/actions/general' ;
1315
1416const useStyles = makeStyles ( ( theme ) => ( {
1517 networkItem : {
@@ -35,14 +37,26 @@ const useStyles = makeStyles((theme) => ({
3537
3638const ControlPanelTreeItem = ( props ) => {
3739 const classes = useStyles ( ) ;
40+ const dispatch = useDispatch ( ) ;
3841 const [ showColorPicker , setShowColorPicker ] = React . useState ( false ) ;
3942 const [ isHoveredOver , setIsHoveredOver ] = React . useState ( false ) ;
4043 const [ color , setColor ] = React . useState ( '#ff0000' ) ;
44+ const instances = useSelector ( ( state ) => state . general . instances ) ;
4145
4246 const handleColorSelection = ( color , event , nodeId ) => {
47+ const newInstances = instances . filter ( ( instance ) => ! ( instance . instancePath . startsWith ( nodeId ) ) ) ;
48+ newInstances . push ( {
49+ instancePath : nodeId ,
50+ color : {
51+ r : color . rgb . r / 255 ,
52+ g : color . rgb . g / 255 ,
53+ b : color . rgb . b / 255 ,
54+ a : color . rgb . a ,
55+ } ,
56+ } ) ;
57+ dispatch ( changeInstanceColor ( newInstances ) ) ;
58+ console . log ( color ) ;
4359 setColor ( color . hex ) ;
44- event . preventDefault ( ) ;
45- event . stopPropagation ( ) ;
4660 } ;
4761
4862 const generateRandomColor = ( ) => {
0 commit comments