Skip to content

Commit

Permalink
refactor: Autocomplete component in PlaygroundCodeFieldset (#8912)
Browse files Browse the repository at this point in the history
Custom context fields that have a list of allowed values, show values with autocomplete list
  • Loading branch information
Curis-lab authored Dec 4, 2024
1 parent 8fbf797 commit 50929c5
Showing 1 changed file with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
useTheme,
Autocomplete,
type SelectChangeEvent,
Checkbox,
} from '@mui/material';

import debounce from 'debounce';
Expand All @@ -31,6 +32,9 @@ import {
isStringOrStringArray,
normalizeCustomContextProperties,
} from '../../playground.utils';
import CheckBoxOutlineBlank from '@mui/icons-material/CheckBoxOutlineBlank';
import CheckBoxIcon from '@mui/icons-material/CheckBox';

interface IPlaygroundCodeFieldsetProps {
context: string | undefined;
setContext: Dispatch<SetStateAction<string | undefined>>;
Expand Down Expand Up @@ -155,7 +159,6 @@ export const PlaygroundCodeFieldset: VFC<IPlaygroundCodeFieldsetProps> = ({
const value = validDate
? parseDateValue(validDate.toISOString())
: parseDateValue(now.toISOString());

return (
<TextField
id='date'
Expand All @@ -181,23 +184,42 @@ export const PlaygroundCodeFieldset: VFC<IPlaygroundCodeFieldsetProps> = ({
);
if (foundField?.legalValues && foundField.legalValues.length > 0) {
const options = foundField.legalValues.map(({ value }) => value);

return (
<Autocomplete
disablePortal
limitTags={3}
id='context-legal-values'
freeSolo
filterSelectedOptions
multiple={true}
options={options}
disableCloseOnSelect
size='small'
value={resolveAutocompleteValue()}
onChange={changeContextValue}
options={options}
multiple={true}
getOptionLabel={(option) => option}
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%' }}
renderInput={(params: any) => (
renderInput={(params) => (
<TextField {...params} label='Value' />
)}
disableCloseOnSelect={false}
/>
);
}
Expand Down

0 comments on commit 50929c5

Please sign in to comment.