11import InputAdornment from '@mui/material/InputAdornment' ;
22import IconButton from '@common/button/IconButton' ;
33import { PaletteOutlined } from '@mui/icons-material' ;
4- import Popover from '@mui/material/Popover' ;
4+ import Popover , { PopoverProps } from '@mui/material/Popover' ;
55import MenuList from '@mui/material/MenuList' ;
66import MenuItem from '@mui/material/MenuItem' ;
77import Checkbox from '@mui/material/Checkbox' ;
88import ListItemText from '@mui/material/ListItemText' ;
99import React , { useState } from 'react' ;
10- import makeStyles from '@mui/styles/makeStyles' ;
1110import { useFormatter } from '../../../../components/i18n' ;
1211import useAttributes from '../../../../utils/hooks/useAttributes' ;
1312import { displayEntityTypeForTranslation } from '../../../../utils/String' ;
1413
15- // Deprecated - https://mui.com/system/styles/basics/
16- // Do not use it for new code.
17- const useStyles = makeStyles ( {
18- container2 : {
19- width : 300 ,
20- padding : 0 ,
21- } ,
22- } ) ;
14+ interface SearchScopeElementProps {
15+ name : string ;
16+ disabled ?: boolean ;
17+ searchScope : Record < string , string [ ] > ;
18+ setSearchScope : React . Dispatch < React . SetStateAction < Record < string , string [ ] > > > ;
19+ availableRelationFilterTypes ?: Record < string , string [ ] > ;
20+ }
2321
2422const SearchScopeElement = ( {
2523 name,
2624 disabled = false ,
2725 searchScope,
2826 setSearchScope,
2927 availableRelationFilterTypes,
30- } ) => {
28+ } : SearchScopeElementProps ) => {
3129 const { t_i18n } = useFormatter ( ) ;
32- const classes = useStyles ( ) ;
33- const [ anchorElSearchScope , setAnchorElSearchScope ] = useState ( ) ;
30+ const [ anchorElSearchScope , setAnchorElSearchScope ] = useState < PopoverProps [ 'anchorEl' ] > ( ) ;
3431 const { stixCoreObjectTypes : entityTypes } = useAttributes ( ) ;
3532 if ( name === 'contextEntityId' ) {
3633 entityTypes . push ( 'User' ) ;
@@ -48,9 +45,9 @@ const SearchScopeElement = ({
4845 } ;
4946 } )
5047 . sort ( ( a , b ) => a . label . localeCompare ( b . label ) ) ;
51- const handleOpenSearchScope = ( event ) => setAnchorElSearchScope ( event . currentTarget ) ;
48+ const handleOpenSearchScope = ( event : React . SyntheticEvent ) => setAnchorElSearchScope ( event . currentTarget ) ;
5249 const handleCloseSearchScope = ( ) => setAnchorElSearchScope ( undefined ) ;
53- const handleToggleSearchScope = ( key , value ) => {
50+ const handleToggleSearchScope = ( key : string , value : string ) => {
5451 setSearchScope ( ( c ) => ( {
5552 ...c ,
5653 [ key ] : ( searchScope [ key ] || [ ] ) . includes ( value )
@@ -59,18 +56,22 @@ const SearchScopeElement = ({
5956 } ) ) ;
6057 } ;
6158
62- let color = searchScope [ name ] && searchScope [ name ] . length > 0
59+ const color = searchScope [ name ] && searchScope [ name ] . length > 0
6360 ? 'secondary'
6461 : 'primary' ;
65- if ( disabled ) color = undefined ;
6662
6763 return (
6864 < InputAdornment position = "end" style = { { position : 'absolute' , right : 5 } } >
69- < IconButton disabled = { disabled } onClick = { handleOpenSearchScope } size = "small" edge = "end" >
70- < PaletteOutlined fontSize = "small" color = { color } />
65+ < IconButton disabled = { disabled } onClick = { handleOpenSearchScope } size = "small" >
66+ < PaletteOutlined fontSize = "small" color = { disabled ? undefined : color } />
7167 </ IconButton >
7268 < Popover
73- classes = { { paper : classes . container2 } }
69+ sx = { {
70+ '& .MuiPaper-root' : {
71+ width : 300 ,
72+ padding : 0 ,
73+ } ,
74+ } }
7475 open = { Boolean ( anchorElSearchScope ) }
7576 anchorEl = { anchorElSearchScope }
7677 onClose = { ( ) => handleCloseSearchScope ( ) }
0 commit comments