Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Connector and Data Plane auto complete rendering properly with arrows #1466

Merged
merged 5 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/forms/renderers/AutoCompleteInputWithStartAdornment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { AutocompleteRenderInputParams, Box, Input } from '@mui/material';
import { ReactNode } from 'react';

interface Props {
textFieldProps: AutocompleteRenderInputParams;
startAdornment: ReactNode | null;
}

function AutoCompleteInputWithStartAdornment({
startAdornment: icon,
textFieldProps,
}: Props) {
if (icon) {
textFieldProps.InputProps.startAdornment = (
<Box style={{ paddingRight: 5 }}>{icon}</Box>
);
}

return (
<Input
{...textFieldProps.InputProps}
inputProps={textFieldProps.inputProps}
fullWidth={textFieldProps.fullWidth}
disabled={textFieldProps.disabled}
/>
);
}

export default AutoCompleteInputWithStartAdornment;
33 changes: 16 additions & 17 deletions src/forms/renderers/ConnectorSelect/AutoComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import {
AutocompleteRenderOptionState,
FilterOptionsState,
} from '@mui/material';
import ConnectorInput from 'forms/renderers/ConnectorSelect/Input';
import ConnectorIcon from 'components/connectors/ConnectorIcon';
import ConnectorOption from 'forms/renderers/ConnectorSelect/Option';
import merge from 'lodash/merge';
import React, { ReactNode, useMemo } from 'react';
import AutoCompleteInputWithStartAdornment from '../AutoCompleteInputWithStartAdornment';

export interface WithOptionLabel {
getOptionLabel?(option: EnumOption): string;
Expand All @@ -61,22 +61,19 @@ export const ConnectorAutoComplete = (
className,
id,
enabled,
uischema,
path,
options,
config,
handleChange,
getOptionLabel,
filterOptions,
} = props;

const appliedUiSchemaOptions = merge({}, config, uischema.options);
const [inputValue, setInputValue] = React.useState('');
const currentOption = useMemo(
() =>
options?.find((option) => {
return areOptionsEqual(option.value, data);
}) ?? null,
}) ?? undefined,
[data, options]
);

Expand All @@ -87,6 +84,7 @@ export const ConnectorAutoComplete = (
className={className}
id={id}
disabled={!enabled}
disableClearable
value={currentOption}
inputValue={inputValue}
onChange={(_event: any, newValue: EnumOption | null) => {
Expand All @@ -103,17 +101,18 @@ export const ConnectorAutoComplete = (
marginTop: 2,
}}
filterOptions={filterOptions}
renderInput={({ inputProps, InputProps }) => {
return (
<ConnectorInput
inputProps={inputProps}
InputProps={InputProps}
appliedUiSchemaOptions={appliedUiSchemaOptions}
enabled={enabled}
currentOption={currentOption}
/>
);
}}
renderInput={(textFieldProps) => (
<AutoCompleteInputWithStartAdornment
textFieldProps={textFieldProps}
startAdornment={
currentOption ? (
<ConnectorIcon
iconPath={currentOption.value.iconPath}
/>
) : null
}
/>
)}
renderOption={(renderOptionProps, option) => {
return (
<ConnectorOption
Expand Down
52 changes: 0 additions & 52 deletions src/forms/renderers/ConnectorSelect/Input.tsx

This file was deleted.

36 changes: 19 additions & 17 deletions src/forms/renderers/DataPlaneSelector/AutoComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import {
MenuList,
Typography,
} from '@mui/material';
import merge from 'lodash/merge';
import DataPlaneIcon from 'components/shared/Entity/DataPlaneIcon';
import React, { ReactNode, useMemo } from 'react';
import { useIntl } from 'react-intl';
import DataPlaneInput from './Input';
import AutoCompleteInputWithStartAdornment from '../AutoCompleteInputWithStartAdornment';
import Option from './Option';

export interface WithOptionLabel {
Expand All @@ -61,23 +61,20 @@ export const DataPlaneAutoComplete = ({
className,
id,
enabled,
uischema,
path,
options,
config,
handleChange,
getOptionLabel,
filterOptions,
}: EnumCellProps & WithClassname & WithOptionLabel) => {
const intl = useIntl();

const appliedUiSchemaOptions = merge({}, config, uischema.options);
const [inputValue, setInputValue] = React.useState('');
const currentOption = useMemo(
() =>
options?.find((option) => {
return areOptionsEqual(option.value, data);
}) ?? null,
}) ?? undefined,
[data, options]
);

Expand All @@ -87,6 +84,7 @@ export const DataPlaneAutoComplete = ({
className={className}
clearOnBlur
disabled={!enabled}
disableClearable
filterOptions={filterOptions}
fullWidth
getOptionLabel={getOptionLabel ?? ((option) => option.label)}
Expand Down Expand Up @@ -118,17 +116,21 @@ export const DataPlaneAutoComplete = ({
<MenuList style={{ padding: 0 }}>{children}</MenuList>
</li>
)}
renderInput={({ inputProps, InputProps }) => {
return (
<DataPlaneInput
inputProps={inputProps}
InputProps={InputProps}
appliedUiSchemaOptions={appliedUiSchemaOptions}
enabled={enabled}
currentOption={currentOption}
/>
);
}}
renderInput={(textFieldProps) => (
<AutoCompleteInputWithStartAdornment
textFieldProps={textFieldProps}
startAdornment={
currentOption ? (
<DataPlaneIcon
provider={
currentOption.value.dataPlaneName.provider
}
scope={currentOption.value.scope}
/>
) : null
}
/>
)}
renderOption={(renderOptionProps, option) => {
return (
<Option
Expand Down
53 changes: 0 additions & 53 deletions src/forms/renderers/DataPlaneSelector/Input.tsx

This file was deleted.