mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-10 01:16:39 +02:00
refactor: Autocomplete component in PlaygroundCodeFieldset (#8912)
Custom context fields that have a list of allowed values, show values with autocomplete list
This commit is contained in:
parent
8fbf7976e6
commit
50929c5e4a
@ -19,6 +19,7 @@ import {
|
|||||||
useTheme,
|
useTheme,
|
||||||
Autocomplete,
|
Autocomplete,
|
||||||
type SelectChangeEvent,
|
type SelectChangeEvent,
|
||||||
|
Checkbox,
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
|
|
||||||
import debounce from 'debounce';
|
import debounce from 'debounce';
|
||||||
@ -31,6 +32,9 @@ import {
|
|||||||
isStringOrStringArray,
|
isStringOrStringArray,
|
||||||
normalizeCustomContextProperties,
|
normalizeCustomContextProperties,
|
||||||
} from '../../playground.utils';
|
} from '../../playground.utils';
|
||||||
|
import CheckBoxOutlineBlank from '@mui/icons-material/CheckBoxOutlineBlank';
|
||||||
|
import CheckBoxIcon from '@mui/icons-material/CheckBox';
|
||||||
|
|
||||||
interface IPlaygroundCodeFieldsetProps {
|
interface IPlaygroundCodeFieldsetProps {
|
||||||
context: string | undefined;
|
context: string | undefined;
|
||||||
setContext: Dispatch<SetStateAction<string | undefined>>;
|
setContext: Dispatch<SetStateAction<string | undefined>>;
|
||||||
@ -155,7 +159,6 @@ export const PlaygroundCodeFieldset: VFC<IPlaygroundCodeFieldsetProps> = ({
|
|||||||
const value = validDate
|
const value = validDate
|
||||||
? parseDateValue(validDate.toISOString())
|
? parseDateValue(validDate.toISOString())
|
||||||
: parseDateValue(now.toISOString());
|
: parseDateValue(now.toISOString());
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TextField
|
<TextField
|
||||||
id='date'
|
id='date'
|
||||||
@ -181,23 +184,42 @@ export const PlaygroundCodeFieldset: VFC<IPlaygroundCodeFieldsetProps> = ({
|
|||||||
);
|
);
|
||||||
if (foundField?.legalValues && foundField.legalValues.length > 0) {
|
if (foundField?.legalValues && foundField.legalValues.length > 0) {
|
||||||
const options = foundField.legalValues.map(({ value }) => value);
|
const options = foundField.legalValues.map(({ value }) => value);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
disablePortal
|
disablePortal
|
||||||
limitTags={3}
|
limitTags={3}
|
||||||
id='context-legal-values'
|
id='context-legal-values'
|
||||||
freeSolo
|
multiple={true}
|
||||||
filterSelectedOptions
|
options={options}
|
||||||
|
disableCloseOnSelect
|
||||||
size='small'
|
size='small'
|
||||||
value={resolveAutocompleteValue()}
|
value={resolveAutocompleteValue()}
|
||||||
onChange={changeContextValue}
|
onChange={changeContextValue}
|
||||||
options={options}
|
getOptionLabel={(option) => option}
|
||||||
multiple={true}
|
renderOption={(props, option, { selected }) => {
|
||||||
|
return (
|
||||||
|
<li {...props}>
|
||||||
|
<Checkbox
|
||||||
|
icon={
|
||||||
|
<CheckBoxOutlineBlank fontSize='small' />
|
||||||
|
}
|
||||||
|
checkedIcon={
|
||||||
|
<CheckBoxIcon fontSize='small' />
|
||||||
|
}
|
||||||
|
sx={(theme) => ({
|
||||||
|
marginRight: theme.spacing(0.5),
|
||||||
|
})}
|
||||||
|
checked={selected}
|
||||||
|
/>
|
||||||
|
{option}
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
}}
|
||||||
sx={{ width: 370, maxWidth: '100%' }}
|
sx={{ width: 370, maxWidth: '100%' }}
|
||||||
renderInput={(params: any) => (
|
renderInput={(params) => (
|
||||||
<TextField {...params} label='Value' />
|
<TextField {...params} label='Value' />
|
||||||
)}
|
)}
|
||||||
disableCloseOnSelect={false}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user