11import React , { useMemo , useState , useRef } from "react" ;
22import { useCellTypesQuery } from "common/queries/cellType" ;
3- import { DefaultAutocompleteOption , DropdownMenu } from "@czi-sds/components" ;
3+ import {
4+ DefaultAutocompleteOption ,
5+ DropdownMenu ,
6+ MenuItem ,
7+ } from "@czi-sds/components" ;
48import { AutocompleteValue } from "@mui/material" ;
5- import { useDispatch } from "react-redux" ;
9+ import { useDispatch , useSelector } from "react-redux" ;
10+ import { RootState } from "reducers" ;
611import { CellTypeInputDropdown } from "./style" ;
712
813export function CellTypeDropdown ( { cellType } : { cellType : string } ) {
14+ const { selectedCellTypes } = useSelector ( ( state : RootState ) => ( {
15+ selectedCellTypes : state . controls . chromatinSelectedCellTypes ,
16+ } ) ) ;
17+
918 const cellTypesQuery = useCellTypesQuery ( ) ;
1019 const cellTypes = useMemo (
1120 ( ) => cellTypesQuery . data ?? [ ] ,
@@ -19,10 +28,25 @@ export function CellTypeDropdown({ cellType }: { cellType: string }) {
1928 type Multiple = false ;
2029 type DisableClearable = false ;
2130 type FreeSolo = false ;
31+ const otherSelectedCellTypes = useMemo (
32+ ( ) => new Set ( selectedCellTypes . filter ( ( type ) => type !== cellType ) ) ,
33+ [ cellType , selectedCellTypes ]
34+ ) ;
2235
2336 const cellTypeOptions = useMemo (
24- ( ) => cellTypes . map < Option > ( ( name ) => ( { name } ) ) ,
25- [ cellTypes ]
37+ ( ) =>
38+ cellTypes . map < Option > ( ( name ) => ( {
39+ name,
40+ component : (
41+ < MenuItem
42+ selected = { cellType === name }
43+ disabled = { otherSelectedCellTypes . has ( name ) }
44+ >
45+ { name }
46+ </ MenuItem >
47+ ) ,
48+ } ) ) ,
49+ [ cellType , cellTypes , otherSelectedCellTypes ]
2650 ) ;
2751
2852 const activeOption = useMemo (
@@ -67,6 +91,14 @@ export function CellTypeDropdown({ cellType }: { cellType: string }) {
6791 setOpen ( false ) ;
6892 anchorElRef . current = null ;
6993
94+ if (
95+ ! value ||
96+ value . name === cellType ||
97+ otherSelectedCellTypes . has ( value . name )
98+ ) {
99+ return ;
100+ }
101+
70102 if ( value ) {
71103 dispatch ( {
72104 type : "toggle chromatin cell types" ,
0 commit comments