diff --git a/common/constants.ts b/common/constants.ts index eb950f43..96d60493 100644 --- a/common/constants.ts +++ b/common/constants.ts @@ -470,10 +470,10 @@ export enum TRANSFORM_CONTEXT { OUTPUT = 'output', } export enum TRANSFORM_TYPE { - STRING = 'string', - FIELD = 'field', - EXPRESSION = 'expression', - TEMPLATE = 'template', + STRING = 'String', + FIELD = 'Field', + EXPRESSION = 'Expression', + TEMPLATE = 'Template', } export const START_FROM_SCRATCH_WORKFLOW_NAME = 'Start From Scratch'; export const DEFAULT_NEW_WORKFLOW_NAME = 'new_workflow'; @@ -503,7 +503,7 @@ export const EMPTY_MAP_ENTRY = { key: '', value: '' } as MapEntry; export const EMPTY_INPUT_MAP_ENTRY = { key: '', value: { - transformType: TRANSFORM_TYPE.FIELD, + transformType: '' as TRANSFORM_TYPE, value: '', }, } as InputMapEntry; diff --git a/common/interfaces.ts b/common/interfaces.ts index acd36db7..f288d3cb 100644 --- a/common/interfaces.ts +++ b/common/interfaces.ts @@ -37,20 +37,9 @@ export type ConfigFieldType = | 'mapArray' | 'boolean' | 'number' - | 'transform' - | 'transformArray'; + | 'inputMapArray'; -export type ConfigFieldTransformValue = { - transformType: TRANSFORM_TYPE; - value: string; -}; -export type ConfigFieldTransformArrayValue = ConfigFieldTransformValue[]; - -export type ConfigFieldValue = - | string - | ConfigFieldTransformValue - | ConfigFieldTransformArrayValue - | {}; +export type ConfigFieldValue = string | {}; export interface IConfigField { type: ConfigFieldType; @@ -113,9 +102,14 @@ export type MapFormValue = MapEntry[]; export type MapArrayFormValue = MapFormValue[]; +export type Transform = { + transformType: TRANSFORM_TYPE; + value: string; +}; + export type InputMapEntry = { key: string; - value: ConfigFieldTransformValue; + value: Transform; }; export type InputMapFormValue = InputMapEntry[]; diff --git a/public/configs/ml_processor.ts b/public/configs/ml_processor.ts index 83254d2d..e6022a23 100644 --- a/public/configs/ml_processor.ts +++ b/public/configs/ml_processor.ts @@ -22,7 +22,7 @@ export abstract class MLProcessor extends Processor { }, { id: 'input_map', - type: 'transformArray', + type: 'inputMapArray', }, { id: 'output_map', diff --git a/public/pages/workflow_detail/workflow_inputs/input_fields/map_field.tsx b/public/pages/workflow_detail/workflow_inputs/input_fields/map_field.tsx index 784823dd..e1795e36 100644 --- a/public/pages/workflow_detail/workflow_inputs/input_fields/map_field.tsx +++ b/public/pages/workflow_detail/workflow_inputs/input_fields/map_field.tsx @@ -185,6 +185,7 @@ export function MapField(props: MapFieldProps) { placeholder={ props.keyPlaceholder || 'Input' } + allowCreate={true} /> ) : ( ) : ( ); } diff --git a/public/pages/workflow_detail/workflow_inputs/processor_inputs/ml_processor_inputs/ml_processor_inputs.tsx b/public/pages/workflow_detail/workflow_inputs/processor_inputs/ml_processor_inputs/ml_processor_inputs.tsx index 74476d93..a9bec8a8 100644 --- a/public/pages/workflow_detail/workflow_inputs/processor_inputs/ml_processor_inputs/ml_processor_inputs.tsx +++ b/public/pages/workflow_detail/workflow_inputs/processor_inputs/ml_processor_inputs/ml_processor_inputs.tsx @@ -18,6 +18,7 @@ import { EuiText, EuiToolTip, EuiSmallButton, + EuiIconTip, } from '@elastic/eui'; import { IProcessorConfig, @@ -31,11 +32,10 @@ import { MapArrayFormValue, MapEntry, MapFormValue, + EMPTY_INPUT_MAP_ENTRY, } from '../../../../../../common'; import { ModelField } from '../../input_fields'; import { - TRANSFORM_TYPE, - InputMapEntry, InputMapFormValue, InputMapArrayFormValue, } from '../../../../../../common'; @@ -142,15 +142,9 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) { const newModelInterface = models[modelId]?.interface; setModelInterface(newModelInterface); const modelInputsAsForm = [ - parseModelInputs(newModelInterface).map((modelInput) => { - return { - key: modelInput.label, - value: { - transformType: TRANSFORM_TYPE.FIELD, - value: '', - }, - } as InputMapEntry; - }) as InputMapFormValue, + parseModelInputs(newModelInterface).map( + (modelInput) => EMPTY_INPUT_MAP_ENTRY + ) as InputMapFormValue, ] as InputMapArrayFormValue; const modelOutputsAsForm = [ parseModelOutputs(newModelInterface).map((modelOutput) => { @@ -369,10 +363,29 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) { )} - {`Inputs`} + + + Inputs + + + + + { + return { + label: type, + }; +}); /** * Base component to configure ML inputs. @@ -75,7 +78,6 @@ export function ModelInputs(props: ModelInputsProps) { ) as IConfigField; const modelFieldPath = `${props.baseConfigPath}.${props.config.id}.${modelField.id}`; // Assuming no more than one set of input map entries. - // TODO: confirm the above. const inputMapFieldPath = `${props.baseConfigPath}.${props.config.id}.input_map.0`; // model interface state @@ -177,7 +179,7 @@ export function ModelInputs(props: ModelInputsProps) { { key: '', value: { - transformType: TRANSFORM_TYPE.FIELD, + transformType: '' as TRANSFORM_TYPE, value: '', }, } as InputMapEntry, @@ -198,26 +200,12 @@ export function ModelInputs(props: ModelInputsProps) { } // Defining constants for the key/value text vars, typically dependent on the different processor contexts. - const keyTitle = 'Name'; const keyPlaceholder = 'Name'; const keyOptions = parseModelInputs(modelInterface); - const valueTitle = - props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST - ? 'Query field' - : 'Document field'; const valuePlaceholder = props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST ? 'Specify a query field' : 'Define a document field'; - const valueHelpText = `Specify a ${ - props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST ? 'query' : 'document' - } field or define JSONPath to transform the ${ - props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST ? 'query' : 'document' - } to map to a model input field.${ - props.context === PROCESSOR_CONTEXT.SEARCH_RESPONSE - ? ` Or, if you'd like to include data from the the original query request, prefix your mapping with "${REQUEST_PREFIX}" or "${REQUEST_PREFIX_WITH_JSONPATH_ROOT_SELECTOR}" - for example, "_request.query.match.my_field"` - : '' - }`; const valueOptions = props.context === PROCESSOR_CONTEXT.INGEST ? docFields @@ -256,23 +244,26 @@ export function ModelInputs(props: ModelInputsProps) { - {keyTitle} + {`Name`} - + - {valueTitle} + {`Input type`} + + + + - + + Value + @@ -317,6 +308,7 @@ export function ModelInputs(props: ModelInputsProps) { fieldPath={`${inputMapFieldPath}.${idx}.key`} options={keyOptions as any[]} placeholder={keyPlaceholder} + allowCreate={true} /> ) : ( + + + + + <> @@ -349,6 +351,7 @@ export function ModelInputs(props: ModelInputsProps) { placeholder={ valuePlaceholder || 'Output' } + allowCreate={true} /> ) : (