Skip to content

Commit

Permalink
dropped support the fields according to the RFC
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Dec 9, 2024
1 parent c9bb60b commit b4e4d67
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 236 deletions.
16 changes: 1 addition & 15 deletions x-pack/plugins/stack_connectors/common/dynamic_config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@
* 2.0.
*/

export enum DisplayType {
TEXTBOX = 'textbox',
TEXTAREA = 'textarea',
NUMERIC = 'numeric',
TOGGLE = 'toggle',
DROPDOWN = 'dropdown',
CHECKABLE = 'checkable',
}

export interface SelectOption {
label: string;
value: string;
Expand Down Expand Up @@ -46,17 +37,12 @@ export interface Validation {
export interface ConfigProperties {
category?: string;
default_value: string | number | boolean | null;
depends_on: Dependency[];
display: DisplayType;
label: string;
options?: SelectOption[];
order?: number | null;
placeholder?: string;
required: boolean;
sensitive: boolean;
tooltip: string | null;
description: string | null;
type: FieldType;
ui_restrictions: string[];
validations: Validation[];
value: string | number | boolean | null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { createStartServicesMock } from '@kbn/triggers-actions-ui-plugin/public/common/lib/kibana/kibana_react.mock';
import { useProviders } from './providers/get_providers';
import { DisplayType, FieldType } from '../../../common/dynamic_config/types';
import { FieldType } from '../../../common/dynamic_config/types';

jest.mock('./providers/get_providers');

Expand Down Expand Up @@ -50,44 +50,37 @@ const providersSchemas = [
task_type: 'completion',
configuration: {
user: {
display: DisplayType.TEXTBOX,
label: 'User',
order: 1,
required: false,
sensitive: false,
tooltip: 'Specifies the user issuing the request.',
description: 'Specifies the user issuing the request.',
type: FieldType.STRING,
validations: [],
value: '',
ui_restrictions: [],
default_value: null,
depends_on: [],
},
},
},
],
configuration: {
api_key: {
display: DisplayType.TEXTBOX,
label: 'API Key',
order: 3,
required: true,
sensitive: true,
tooltip: `The OpenAI API authentication key. For more details about generating OpenAI API keys, refer to the https://platform.openai.com/account/api-keys.`,
description: `The OpenAI API authentication key. For more details about generating OpenAI API keys, refer to the https://platform.openai.com/account/api-keys.`,
type: FieldType.STRING,
validations: [],
value: null,
ui_restrictions: [],
default_value: null,
depends_on: [],
},
model_id: {
display: DisplayType.TEXTBOX,
label: 'Model ID',
order: 2,
required: true,
sensitive: false,
tooltip: 'The name of the model.',
description: 'The name of the model.',
type: FieldType.STRING,
validations: [],
value: null,
Expand All @@ -96,12 +89,11 @@ const providersSchemas = [
depends_on: [],
},
organization_id: {
display: DisplayType.TEXTBOX,
label: 'Organization ID',
order: 4,
required: false,
sensitive: false,
tooltip: '',
description: '',
type: FieldType.STRING,
validations: [],
value: null,
Expand All @@ -110,12 +102,11 @@ const providersSchemas = [
depends_on: [],
},
url: {
display: DisplayType.TEXTBOX,
label: 'URL',
order: 1,
required: true,
sensitive: false,
tooltip: '',
description: '',
type: FieldType.STRING,
validations: [],
value: null,
Expand All @@ -140,12 +131,11 @@ const providersSchemas = [
],
configuration: {
api_key: {
display: DisplayType.TEXTBOX,
label: 'API Key',
order: 1,
required: true,
sensitive: true,
tooltip: `API Key for the provider you're connecting to`,
description: `API Key for the provider you're connecting to`,
type: FieldType.STRING,
validations: [],
value: null,
Expand All @@ -154,12 +144,11 @@ const providersSchemas = [
depends_on: [],
},
model_id: {
display: DisplayType.TEXTBOX,
label: 'Model ID',
order: 2,
required: true,
sensitive: false,
tooltip: `ID of the LLM you're using`,
description: `ID of the LLM you're using`,
type: FieldType.STRING,
validations: [],
value: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,11 @@ import {
EuiFieldPassword,
EuiSwitch,
EuiTextArea,
EuiFlexGroup,
EuiFlexItem,
EuiIcon,
EuiFieldNumber,
EuiCheckableCard,
useGeneratedHtmlId,
EuiSpacer,
EuiSuperSelect,
EuiText,
} from '@elastic/eui';

import { isEmpty } from 'lodash/fp';
import { ConfigEntryView, DisplayType } from '../../../../common/dynamic_config/types';
import { ConfigEntryView, FieldType } from '../../../../common/dynamic_config/types';
import {
ensureBooleanType,
ensureCorrectTyping,
Expand All @@ -49,7 +41,7 @@ export const ConfigInputField: React.FC<ConfigInputFieldProps> = ({
validateAndSetConfigValue,
}) => {
// eslint-disable-next-line @typescript-eslint/naming-convention
const { isValid, placeholder, value, default_value, key } = configEntry;
const { isValid, value, default_value, key } = configEntry;
const [innerValue, setInnerValue] = useState(
!value || value.toString().length === 0 ? default_value : value
);
Expand All @@ -68,7 +60,6 @@ export const ConfigInputField: React.FC<ConfigInputFieldProps> = ({
setInnerValue(event.target.value);
validateAndSetConfigValue(event.target.value);
}}
placeholder={placeholder}
/>
);
};
Expand Down Expand Up @@ -104,7 +95,7 @@ export const ConfigInputTextArea: React.FC<ConfigInputFieldProps> = ({
validateAndSetConfigValue,
}) => {
// eslint-disable-next-line @typescript-eslint/naming-convention
const { isValid, placeholder, value, default_value, key } = configEntry;
const { isValid, value, default_value, key } = configEntry;
const [innerValue, setInnerValue] = useState(value ?? default_value);
useEffect(() => {
setInnerValue(value ?? default_value);
Expand All @@ -121,7 +112,6 @@ export const ConfigInputTextArea: React.FC<ConfigInputFieldProps> = ({
setInnerValue(event.target.value);
validateAndSetConfigValue(event.target.value);
}}
placeholder={placeholder}
/>
);
};
Expand All @@ -132,7 +122,7 @@ export const ConfigNumberField: React.FC<ConfigInputFieldProps> = ({
validateAndSetConfigValue,
}) => {
// eslint-disable-next-line @typescript-eslint/naming-convention
const { isValid, placeholder, value, default_value, key } = configEntry;
const { isValid, value, default_value, key } = configEntry;
const [innerValue, setInnerValue] = useState(value ?? default_value);
useEffect(() => {
setInnerValue(!value || value.toString().length === 0 ? default_value : value);
Expand All @@ -149,43 +139,10 @@ export const ConfigNumberField: React.FC<ConfigInputFieldProps> = ({
setInnerValue(newValue);
validateAndSetConfigValue(newValue);
}}
placeholder={placeholder}
/>
);
};

export const ConfigCheckableField: React.FC<ConfigInputFieldProps> = ({
configEntry,
validateAndSetConfigValue,
}) => {
const radioCardId = useGeneratedHtmlId({ prefix: 'radioCard' });
// eslint-disable-next-line @typescript-eslint/naming-convention
const { value, options, default_value } = configEntry;
const [innerValue, setInnerValue] = useState(value ?? default_value);
useEffect(() => {
setInnerValue(value ?? default_value);
}, [default_value, value]);
return (
<>
{options?.map((o) => (
<>
<EuiCheckableCard
id={radioCardId}
label={o.label}
value={innerValue as any}
checked={innerValue === o.value}
onChange={(event) => {
setInnerValue(o.value);
validateAndSetConfigValue(o.value);
}}
/>
<EuiSpacer size="s" />
</>
))}
</>
);
};

export const ConfigSensitiveTextArea: React.FC<ConfigInputFieldProps> = ({
isLoading,
configEntry,
Expand Down Expand Up @@ -230,44 +187,6 @@ export const ConfigInputPassword: React.FC<ConfigInputFieldProps> = ({
);
};

export const ConfigSelectField: React.FC<ConfigInputFieldProps> = ({
configEntry,
isLoading,
validateAndSetConfigValue,
}) => {
// eslint-disable-next-line @typescript-eslint/naming-convention
const { isValid, options, value, default_value } = configEntry;
const [innerValue, setInnerValue] = useState(value ?? default_value);
const optionsRes = options?.map((o) => ({
value: o.value,
inputDisplay: (
<EuiFlexGroup gutterSize="s" alignItems="center" responsive={false}>
{o.icon ? (
<EuiFlexItem grow={false}>
<EuiIcon color="subdued" style={{ lineHeight: 'inherit' }} type={o.icon} />
</EuiFlexItem>
) : null}
<EuiFlexItem grow={false}>
<EuiText>{o.label}</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
),
}));
return (
<EuiSuperSelect
fullWidth
isInvalid={!isValid}
disabled={isLoading}
options={optionsRes as any}
valueOfSelected={innerValue as any}
onChange={(newValue) => {
setInnerValue(newValue);
validateAndSetConfigValue(newValue);
}}
/>
);
};

export const ConnectorConfigurationField: React.FC<ConnectorConfigurationFieldProps> = ({
configEntry,
isLoading,
Expand All @@ -277,30 +196,10 @@ export const ConnectorConfigurationField: React.FC<ConnectorConfigurationFieldPr
setConfigValue(ensureCorrectTyping(configEntry.type, value));
};

const { key, display, sensitive } = configEntry;

switch (display) {
case DisplayType.DROPDOWN:
return (
<ConfigSelectField
key={key}
isLoading={isLoading}
configEntry={configEntry}
validateAndSetConfigValue={validateAndSetConfigValue}
/>
);

case DisplayType.CHECKABLE:
return (
<ConfigCheckableField
key={key}
isLoading={isLoading}
configEntry={configEntry}
validateAndSetConfigValue={validateAndSetConfigValue}
/>
);
const { key, type, sensitive } = configEntry;

case DisplayType.NUMERIC:
switch (type) {
case FieldType.INTEGER:
return (
<ConfigNumberField
key={key}
Expand All @@ -310,29 +209,7 @@ export const ConnectorConfigurationField: React.FC<ConnectorConfigurationFieldPr
/>
);

case DisplayType.TEXTAREA:
const textarea = (
<ConfigInputTextArea
key={sensitive ? key + '-sensitive-text-area' : key + 'text-area'}
isLoading={isLoading}
configEntry={configEntry}
validateAndSetConfigValue={validateAndSetConfigValue}
/>
);

return sensitive ? (
<>
<ConfigSensitiveTextArea
isLoading={isLoading}
configEntry={configEntry}
validateAndSetConfigValue={validateAndSetConfigValue}
/>
</>
) : (
textarea
);

case DisplayType.TOGGLE:
case FieldType.BOOLEAN:
return (
<ConfigSwitchField
isLoading={isLoading}
Expand Down
Loading

0 comments on commit b4e4d67

Please sign in to comment.