@@ -2,7 +2,6 @@ import { getGlobalTypes } from "./actions/types/GlobalTypes";
22import { getInstancesTypes } from "./actions/types/getInstancesTypes" ;
33import {
44 SELECTED_COLOR ,
5- DESELECTED_COLOR ,
65 TEMPLATE_COLOR ,
76 SKELETON ,
87 CYLINDERS ,
@@ -22,6 +21,7 @@ export const initialStateInstancesReducer = {
2221 error : false ,
2322 errorMessage : undefined ,
2423 cameraEvent : { } ,
24+ selectedInstancesCount : 1 ,
2525} ;
2626
2727const getMappedCanvasData = ( loadedInstances ) => {
@@ -74,7 +74,8 @@ const InstancesReducer = (state = initialStateInstancesReducer, response) => {
7474 newInstance . userSetColor = TEMPLATE_COLOR ;
7575 newInstance . stackInstance = true ;
7676 } else {
77- newInstance . color = DESELECTED_COLOR ;
77+ newInstance . color = getNextColor ( state . selectedInstancesCount ) ;
78+ newInstance . colorIndex = state . selectedInstancesCount ;
7879 }
7980
8081 let launchTemplate = state . launchTemplate ;
@@ -104,7 +105,7 @@ const InstancesReducer = (state = initialStateInstancesReducer, response) => {
104105 focused . color = SELECTED_COLOR ;
105106 loadedInstances ?. forEach ( ( i ) => {
106107 if ( i . metadata ?. Id !== focused . metadata ?. Id ) {
107- i . color = i . userSetColor || DESELECTED_COLOR ;
108+ i . color = i . userSetColor || getNextColor ( i . colorIndex || 0 ) ;
108109 i . selected = false ;
109110 }
110111 } ) ;
@@ -114,6 +115,7 @@ const InstancesReducer = (state = initialStateInstancesReducer, response) => {
114115 allLoadedInstances : loadedInstances ,
115116 launchTemplate : launchTemplate ,
116117 focusedInstance : focused ,
118+ selectedInstancesCount : newInstance . metadata ?. IsTemplate ? state . selectedInstancesCount : state . selectedInstancesCount + 1 ,
117119 event : {
118120 action : getInstancesTypes . ADD_INSTANCE ,
119121 id : response . payload . Id ,
@@ -324,6 +326,7 @@ const InstancesReducer = (state = initialStateInstancesReducer, response) => {
324326 } ) ;
325327 }
326328 case getInstancesTypes . SELECT_INSTANCE : {
329+ const selectedInstancesCount = state . selectedInstancesCount ;
327330 const allLoadedInstances = [ ...state . allLoadedInstances ] ;
328331 const findInstance = allLoadedInstances ?. find (
329332 ( i ) => i . metadata ?. Id === response . payload . id
@@ -334,12 +337,12 @@ const InstancesReducer = (state = initialStateInstancesReducer, response) => {
334337 findInstance . color = SELECTED_COLOR ;
335338 allLoadedInstances ?. forEach ( ( i ) => {
336339 if ( i . metadata ?. Id !== findInstance . metadata ?. Id ) {
337- i . color = i . userSetColor || DESELECTED_COLOR ;
340+ i . color = i . userSetColor || getNextColor ( i . colorIndex ) ;
338341 i . selected = false ;
339342 }
340343 } ) ;
341344 } else {
342- findInstance . color = findInstance . userSetColor || DESELECTED_COLOR ;
345+ findInstance . color = findInstance . userSetColor || getNextColor ( findInstance . colorIndex ) ;
343346 }
344347 }
345348
@@ -351,14 +354,19 @@ const InstancesReducer = (state = initialStateInstancesReducer, response) => {
351354 matchObject . selected = ! matchObject . selected ;
352355 if ( matchObject . selected ) matchObject . color = SELECTED_COLOR ;
353356 else {
354- matchObject . color = DESELECTED_COLOR ;
357+ const instance = allLoadedInstances . find ( i => i . metadata ?. Id === response . payload . id ) ;
358+ matchObject . color = getNextColor ( instance ?. colorIndex ) ;
355359 }
356360 }
357361
362+ // Only increment the counter if we're selecting a new instance
363+ const newCount = findInstance && ! findInstance . selected ? selectedInstancesCount + 1 : selectedInstancesCount ;
364+
358365 return Object . assign ( { } , state , {
359366 allLoadedInstances : allLoadedInstances ,
360367 threeDObjects : threeDObjects ,
361368 mappedCanvasData : getMappedCanvasData ( allLoadedInstances ) ,
369+ selectedInstancesCount : newCount ,
362370 event : {
363371 action : getInstancesTypes . UPDATE_INSTANCES ,
364372 id : response . payload . id ,
@@ -650,7 +658,7 @@ const InstancesReducer = (state = initialStateInstancesReducer, response) => {
650658 newInstance . color = { ...TEMPLATE_COLOR , a : 0.4 } ;
651659 } else {
652660 // For other instances, use next color from palette with opacity 0.3
653- newInstance . color = getNextColor ( 0.3 ) ;
661+ newInstance . color = getNextColor ( 0 , 0 .3) ;
654662 // Store original color with full opacity for potential skeleton use
655663 newInstance . fullOpacityColor = { ...newInstance . color , a : 1.0 } ;
656664 }
0 commit comments