-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ayolab/fix-shortcircuit-parameters-layout
- Loading branch information
Showing
169 changed files
with
5,806 additions
and
3,548 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/components/custom-aggrid/custom-aggrid-filters/custom-aggrid-autocomplete-filter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
import React, { FunctionComponent, SyntheticEvent, useMemo } from 'react'; | ||
import { Autocomplete, TextField } from '@mui/material'; | ||
import { useIntl } from 'react-intl'; | ||
import { useCustomAggridFilter } from '../hooks/use-custom-aggrid-filter'; | ||
import { isStringOrNonEmptyArray } from '../custom-aggrid-header-utils'; | ||
import { CustomAggridFilterParams, FILTER_TEXT_COMPARATORS, FilterEnumsType } from '../custom-aggrid-header.type'; | ||
|
||
export interface CustomAggridAutocompleteFilterParams extends CustomAggridFilterParams { | ||
filterEnums?: FilterEnumsType; | ||
getEnumLabel?: (value: string) => string; // Used for translation of enum values in the filter | ||
} | ||
|
||
export const CustomAggridAutocompleteFilter: FunctionComponent<CustomAggridAutocompleteFilterParams> = ({ | ||
field, | ||
filterParams, | ||
filterEnums, | ||
getEnumLabel, | ||
}) => { | ||
const intl = useIntl(); | ||
const { selectedFilterData, handleChangeFilterValue } = useCustomAggridFilter(field, filterParams); | ||
|
||
const handleFilterAutoCompleteChange = (_: SyntheticEvent, data: string[]) => { | ||
handleChangeFilterValue({ value: data, type: FILTER_TEXT_COMPARATORS.EQUALS }); | ||
}; | ||
|
||
const filterOption = useMemo(() => filterEnums?.[field] ?? [], [field, filterEnums]); | ||
|
||
return ( | ||
<Autocomplete | ||
multiple | ||
value={Array.isArray(selectedFilterData) ? selectedFilterData : []} | ||
options={filterOption} | ||
getOptionLabel={getEnumLabel} | ||
onChange={handleFilterAutoCompleteChange} | ||
size="small" | ||
disableCloseOnSelect | ||
renderInput={(params) => ( | ||
<TextField | ||
{...params} | ||
placeholder={ | ||
!isStringOrNonEmptyArray(selectedFilterData) | ||
? intl.formatMessage({ | ||
id: 'filter.filterOoo', | ||
}) | ||
: '' | ||
} | ||
/> | ||
)} | ||
fullWidth | ||
/> | ||
); | ||
}; |
Oops, something went wrong.