44 * License, v. 2.0. If a copy of the MPL was not distributed with this
55 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
66 */
7- import React , { useMemo } from 'react' ;
7+ import React , { ChangeEvent , useEffect , useMemo } from 'react' ;
88import { Grid , IconButton , InputAdornment , TextField } from '@mui/material' ;
99import ClearIcon from '@mui/icons-material/Clear' ;
1010import { DisplayRounding } from '../display-rounding' ;
1111import { useIntl } from 'react-intl' ;
1212import { mergeSx , type MuiStyles } from '@gridsuite/commons-ui' ;
1313import { FILTER_DATA_TYPES } from './custom-aggrid-filter.type' ;
14+ import { useFilterSelector } from '../../../hooks/use-filter-selector' ;
15+ import { FilterParams } from '../../../types/custom-aggrid-types' ;
1416
1517const styles = {
1618 input : {
@@ -28,32 +30,56 @@ const styles = {
2830} as const satisfies MuiStyles ;
2931
3032interface CustomAggridTextFilterProps {
31- value : unknown ;
33+ colId : string ;
3234 onChange : ( event : React . ChangeEvent < HTMLInputElement > ) => void ;
3335 onClear : ( ) => void ;
3436 isNumberInput : boolean ;
3537 decimalAfterDot : number ;
38+ filterParams : FilterParams ;
3639}
3740
3841export const CustomAggridTextFilter : React . FC < CustomAggridTextFilterProps > = ( {
39- value ,
42+ colId ,
4043 onChange,
4144 onClear,
4245 isNumberInput,
46+ filterParams,
4347 decimalAfterDot = 0 ,
4448} ) => {
49+ const [ value , setValue ] = React . useState ( '' ) ;
4550 const intl = useIntl ( ) ;
4651
52+ const { filters } = useFilterSelector ( filterParams . type , filterParams . tab ) ;
53+
4754 const isRoundingDisplayed = useMemo ( ( ) => ! ! ( isNumberInput && value ) , [ isNumberInput , value ] ) ;
4855
56+ const handleChange = ( event : ChangeEvent < HTMLInputElement > ) => {
57+ const upperCaseValue = event . target . value . toUpperCase ( ) ;
58+ setValue ( upperCaseValue ) ;
59+ onChange ( event ) ;
60+ } ;
61+
62+ const handleClear = ( ) => {
63+ setValue ( '' ) ;
64+ onClear ( ) ;
65+ } ;
66+
67+ useEffect ( ( ) => {
68+ const filterObject = filters ?. find ( ( filter ) => filter . column === colId ) ;
69+ if ( filterObject ) {
70+ setValue ( String ( filterObject . value ) ) ;
71+ }
72+ // eslint-disable-next-line react-hooks/exhaustive-deps
73+ } , [ ] ) ;
74+
4975 return (
5076 < Grid container direction = "column" gap = { 0.2 } >
5177 < Grid item >
5278 < TextField
5379 size = { 'small' }
5480 fullWidth
5581 value = { value || '' }
56- onChange = { onChange }
82+ onChange = { handleChange }
5783 placeholder = { intl . formatMessage ( {
5884 id : 'filter.filterOoo' ,
5985 } ) }
@@ -64,7 +90,7 @@ export const CustomAggridTextFilter: React.FC<CustomAggridTextFilterProps> = ({
6490 InputProps = { {
6591 endAdornment : value ? (
6692 < InputAdornment position = "end" >
67- < IconButton aria-label = "clear filter" onClick = { onClear } edge = "end" size = "small" >
93+ < IconButton aria-label = "clear filter" onClick = { handleClear } edge = "end" size = "small" >
6894 < ClearIcon />
6995 </ IconButton >
7096 </ InputAdornment >
0 commit comments