Skip to content

Commit 58e8edf

Browse files
authored
[frontend] Filters components refacto to tsx (#13845)
1 parent 8faa891 commit 58e8edf

File tree

2 files changed

+44
-41
lines changed

2 files changed

+44
-41
lines changed

opencti-platform/opencti-front/src/private/components/common/lists/ListFiltersWithoutLocalStorage.jsx renamed to opencti-platform/opencti-front/src/private/components/common/lists/ListFiltersWithoutLocalStorage.tsx

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,18 @@ import { FilterListOutlined } from '@mui/icons-material';
44
import Popover from '@mui/material/Popover';
55
import Tooltip from '@mui/material/Tooltip';
66
import { RayEndArrow, RayStartArrow } from 'mdi-material-ui';
7-
import React from 'react';
8-
import makeStyles from '@mui/styles/makeStyles';
7+
import React, { ReactElement } from 'react';
98
import { useFormatter } from '../../../../components/i18n';
109

11-
// Deprecated - https://mui.com/system/styles/basics/
12-
// Do not use it for new code.
13-
const useStyles = makeStyles(() => ({
14-
filters: {
15-
float: 'left',
16-
margin: '-3px 0 0 -5px',
17-
},
18-
container: {
19-
width: 600,
20-
padding: 20,
21-
},
22-
}));
10+
interface ListFiltersWithoutLocalStorageProps {
11+
handleOpenFilters: (event: React.SyntheticEvent) => void;
12+
handleCloseFilters: () => void;
13+
open: boolean;
14+
anchorEl: Element | null;
15+
filterElement: ReactElement;
16+
variant?: string;
17+
type?: string;
18+
}
2319

2420
const ListFiltersWithoutLocalStorage = ({
2521
handleOpenFilters,
@@ -29,23 +25,24 @@ const ListFiltersWithoutLocalStorage = ({
2925
filterElement,
3026
variant,
3127
type,
32-
}) => {
28+
}: ListFiltersWithoutLocalStorageProps) => {
3329
const { t_i18n } = useFormatter();
34-
const classes = useStyles();
3530
let icon = <FilterListOutlined fontSize="medium" />;
3631
let tooltip = t_i18n('Filters');
37-
// let color = 'primary';
3832
if (type === 'from') {
3933
icon = <RayStartArrow fontSize="medium" />;
4034
tooltip = t_i18n('Dynamic source filters');
41-
// color = 'warning';
4235
} else if (type === 'to') {
4336
icon = <RayEndArrow fontSize="medium" />;
4437
tooltip = t_i18n('Dynamic target filters');
45-
// color = 'success';
4638
}
4739
return (
48-
<div className={classes.filters}>
40+
<div
41+
style={{
42+
float: 'left',
43+
margin: '-3px 0 0 -5px',
44+
}}
45+
>
4946
{variant === 'text' ? (
5047
<Tooltip title={tooltip}>
5148
<Button
@@ -68,7 +65,12 @@ const ListFiltersWithoutLocalStorage = ({
6865
</Tooltip>
6966
)}
7067
<Popover
71-
classes={{ paper: classes.container }}
68+
sx={{
69+
'& .MuiPaper-root': {
70+
width: 600,
71+
padding: 20,
72+
},
73+
}}
7274
open={open}
7375
anchorEl={anchorEl}
7476
onClose={handleCloseFilters}

opencti-platform/opencti-front/src/private/components/common/lists/SearchScopeElement.jsx renamed to opencti-platform/opencti-front/src/private/components/common/lists/SearchScopeElement.tsx

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
11
import InputAdornment from '@mui/material/InputAdornment';
22
import IconButton from '@common/button/IconButton';
33
import { PaletteOutlined } from '@mui/icons-material';
4-
import Popover from '@mui/material/Popover';
4+
import Popover, { PopoverProps } from '@mui/material/Popover';
55
import MenuList from '@mui/material/MenuList';
66
import MenuItem from '@mui/material/MenuItem';
77
import Checkbox from '@mui/material/Checkbox';
88
import ListItemText from '@mui/material/ListItemText';
99
import React, { useState } from 'react';
10-
import makeStyles from '@mui/styles/makeStyles';
1110
import { useFormatter } from '../../../../components/i18n';
1211
import useAttributes from '../../../../utils/hooks/useAttributes';
1312
import { 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

2422
const 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

Comments
 (0)