@@ -414,6 +414,45 @@ function AssignPioreactors({ experiment, variant="text" }) {
414414 return differences ;
415415 }
416416
417+ function getAssignmentDeltaCounts ( delta ) {
418+ let assignedCount = 0 ;
419+ let unassignedCount = 0 ;
420+
421+ for ( const worker in delta ) {
422+ if ( delta [ worker ] . current && ! delta [ worker ] . initial ) {
423+ assignedCount += 1 ;
424+ } else {
425+ unassignedCount += 1 ;
426+ }
427+ }
428+
429+ return { assignedCount, unassignedCount } ;
430+ }
431+
432+ function getAssignmentDeltaLabel ( delta ) {
433+ const { assignedCount, unassignedCount } = getAssignmentDeltaCounts ( delta ) ;
434+ const labelParts = [ ] ;
435+ const totalCount = assignedCount + unassignedCount ;
436+
437+ if ( unassignedCount > 0 ) {
438+ labelParts . push ( `Unassign ${ unassignedCount } ` ) ;
439+ }
440+
441+ if ( assignedCount > 0 ) {
442+ labelParts . push ( `Assign ${ assignedCount } ` ) ;
443+ }
444+
445+ if ( labelParts . length === 0 ) {
446+ return "No changes" ;
447+ }
448+
449+ if ( assignedCount > 0 && unassignedCount > 0 ) {
450+ return `Update ${ totalCount } ` ;
451+ }
452+
453+ return labelParts . join ( ", " ) ;
454+ }
455+
417456 const updateAssignments = async ( ) => {
418457 const delta = compareObjects ( assigned , initialAssigned ) ;
419458 const promises = [ ] ;
@@ -480,6 +519,10 @@ function AssignPioreactors({ experiment, variant="text" }) {
480519 setSelectAll ( allSelected ? true : ( noneSelected ? false : null ) ) ;
481520 } , [ assigned , workers , experiment ] ) ;
482521
522+ const assignmentDelta = compareObjects ( assigned , initialAssigned ) ;
523+ const assignmentDeltaCount = Object . keys ( assignmentDelta ) . length ;
524+ const assignmentDeltaLabel = getAssignmentDeltaLabel ( assignmentDelta ) ;
525+
483526 return (
484527 < React . Fragment >
485528 < Button variant = { variant } style = { { textTransform : "none" } } onClick = { handleClickOpen } >
@@ -514,7 +557,7 @@ function AssignPioreactors({ experiment, variant="text" }) {
514557 < DialogContent >
515558 < p >
516559 Assign and unassign Pioreactors to experiment{ " " }
517- < Chip icon = { < PlayCircleOutlinedIcon /> } size = "small" label = { experiment } clickable component = { Link } onClick = { ( ) => selectExperiment ( experiment ) } data-experiment-name = { experiment } /> .
560+ < Chip icon = { < PlayCircleOutlinedIcon /> } size = "small" label = { experiment } /> .
518561 </ p >
519562 < FormControl sx = { { m : "auto" } } component = "fieldset" variant = "standard" >
520563 < FormLabel component = "legend" > Pioreactors</ FormLabel >
@@ -574,10 +617,10 @@ function AssignPioreactors({ experiment, variant="text" }) {
574617 < Button
575618 variant = "contained"
576619 onClick = { updateAssignments }
577- disabled = { Object . keys ( compareObjects ( assigned , initialAssigned ) ) . length === 0 }
620+ disabled = { true && assignmentDeltaCount === 0 }
578621 style = { { textTransform : "none" } }
579622 >
580- Update { Object . keys ( compareObjects ( assigned , initialAssigned ) ) . length }
623+ { assignmentDeltaLabel }
581624 </ Button >
582625 </ DialogActions >
583626 </ Dialog >
0 commit comments