Merge pull request #775 from automatisch/fix-autocomplete-search

fix(ControlledAutocomplete): use option value as option key
This commit is contained in:
Ömer Faruk Aydın
2022-12-04 22:51:56 +01:00
committed by GitHub
4 changed files with 30 additions and 3 deletions

View File

@@ -1,7 +1,8 @@
import * as React from 'react'; import * as React from 'react';
import FormHelperText from '@mui/material/FormHelperText';
import { Controller, useFormContext } from 'react-hook-form'; import { Controller, useFormContext } from 'react-hook-form';
import FormHelperText from '@mui/material/FormHelperText';
import Autocomplete, { AutocompleteProps } from '@mui/material/Autocomplete'; import Autocomplete, { AutocompleteProps } from '@mui/material/Autocomplete';
import Typography from '@mui/material/Typography';
import type { IFieldDropdownOption } from '@automatisch/types'; import type { IFieldDropdownOption } from '@automatisch/types';
interface ControlledAutocompleteProps interface ControlledAutocompleteProps
@@ -9,6 +10,7 @@ interface ControlledAutocompleteProps
shouldUnregister?: boolean; shouldUnregister?: boolean;
name: string; name: string;
required?: boolean; required?: boolean;
showOptionValue?: boolean;
description?: string; description?: string;
dependsOn?: string[]; dependsOn?: string[];
} }
@@ -31,6 +33,7 @@ function ControlledAutocomplete(
description, description,
options = [], options = [],
dependsOn = [], dependsOn = [],
showOptionValue,
...autocompleteProps ...autocompleteProps
} = props; } = props;
@@ -96,6 +99,19 @@ function ControlledAutocomplete(
}} }}
ref={ref} ref={ref}
data-test={`${name}-autocomplete`} data-test={`${name}-autocomplete`}
renderOption={(optionProps, option) => (
<li
{...optionProps}
key={option.value.toString()}
style={{ flexDirection: 'column', alignItems: 'start' }}
>
<Typography>{option.label}</Typography>
{showOptionValue && (
<Typography variant="caption">{option.value}</Typography>
)}
</li>
)}
/> />
<FormHelperText <FormHelperText

View File

@@ -116,7 +116,7 @@ export default function Editor(props: EditorProps): React.ReactElement {
gap={1} gap={1}
> >
{flow?.steps?.map((step, index, steps) => ( {flow?.steps?.map((step, index, steps) => (
<React.Fragment key={`${step}-${index}`}> <React.Fragment key={`${step.id}-${index}`}>
<FlowStep <FlowStep
key={step.id} key={step.id}
step={step} step={step}

View File

@@ -94,6 +94,7 @@ function FlowSubstep(props: FlowSubstepProps): React.ReactElement {
namePrefix="parameters" namePrefix="parameters"
stepId={step.id} stepId={step.id}
disabled={editorContext.readOnly} disabled={editorContext.readOnly}
showOptionValue={true}
/> />
))} ))}
</Stack> </Stack>

View File

@@ -14,6 +14,7 @@ type InputCreatorProps = {
namePrefix?: string; namePrefix?: string;
stepId?: string; stepId?: string;
disabled?: boolean; disabled?: boolean;
showOptionValue?: boolean;
}; };
type RawOption = { type RawOption = {
@@ -27,7 +28,15 @@ const optionGenerator = (options: RawOption[]): IFieldDropdownOption[] =>
export default function InputCreator( export default function InputCreator(
props: InputCreatorProps props: InputCreatorProps
): React.ReactElement { ): React.ReactElement {
const { onChange, onBlur, schema, namePrefix, stepId, disabled } = props; const {
onChange,
onBlur,
schema,
namePrefix,
stepId,
disabled,
showOptionValue,
} = props;
const { const {
key: name, key: name,
@@ -62,6 +71,7 @@ export default function InputCreator(
description={description} description={description}
loading={loading} loading={loading}
disabled={disabled} disabled={disabled}
showOptionValue={showOptionValue}
/> />
); );
} }