Skip to content

Commit

Permalink
Add standalone form state for advanced transform modals (opensearch-p…
Browse files Browse the repository at this point in the history
…roject#456)

Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler authored Oct 31, 2024
1 parent dc07e49 commit 500e671
Show file tree
Hide file tree
Showing 5 changed files with 947 additions and 727 deletions.
14 changes: 14 additions & 0 deletions common/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ export type RequestFormValues = {
};
export type RequestSchema = WorkflowSchema;

// Form / schema interfaces for the input transform sub-form
export type InputTransformFormValues = {
input_map: MapArrayFormValue;
one_to_one: ConfigFieldValue;
};
export type InputTransformSchema = WorkflowSchema;

// Form / schema interfaces for the output transform sub-form
export type OutputTransformFormValues = {
output_map: MapArrayFormValue;
full_response_path: ConfigFieldValue;
};
export type OutputTransformSchema = WorkflowSchema;

/**
********** WORKSPACE TYPES/INTERFACES **********
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ import {
import { Field, FieldProps, getIn, useFormikContext } from 'formik';
import {
EMPTY_MAP_ENTRY,
IConfigField,
MapArrayFormValue,
MapEntry,
WorkflowFormValues,
} from '../../../../../common';
import { MapField } from './map_field';

interface MapArrayFieldProps {
field: IConfigField;
fieldPath: string; // the full path in string-form to the field (e.g., 'ingest.enrich.processors.text_embedding_processor.inputField')
helpText?: string;
keyTitle?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
PROCESSOR_CONTEXT,
WorkflowConfig,
JSONPATH_ROOT_SELECTOR,
ML_INFERENCE_DOCS_LINK,
WorkflowFormValues,
ModelInterface,
IndexMappings,
Expand Down Expand Up @@ -75,15 +74,9 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
) as IConfigField;
const modelFieldPath = `${props.baseConfigPath}.${props.config.id}.${modelField.id}`;
const modelIdFieldPath = `${modelFieldPath}.id`;
const inputMapField = props.config.fields.find(
(field) => field.id === 'input_map'
) as IConfigField;
const inputMapFieldPath = `${props.baseConfigPath}.${props.config.id}.${inputMapField.id}`;
const inputMapFieldPath = `${props.baseConfigPath}.${props.config.id}.input_map`;
const inputMapValue = getIn(values, inputMapFieldPath);
const outputMapField = props.config.fields.find(
(field) => field.id === 'output_map'
) as IConfigField;
const outputMapFieldPath = `${props.baseConfigPath}.${props.config.id}.${outputMapField.id}`;
const outputMapFieldPath = `${props.baseConfigPath}.${props.config.id}.output_map`;
const outputMapValue = getIn(values, outputMapFieldPath);
const fullResponsePath = getIn(
values,
Expand Down Expand Up @@ -250,7 +243,6 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
config={props.config}
baseConfigPath={props.baseConfigPath}
context={props.context}
inputMapField={inputMapField}
inputMapFieldPath={inputMapFieldPath}
modelInterface={modelInterface}
valueOptions={
Expand All @@ -269,7 +261,6 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
config={props.config}
baseConfigPath={props.baseConfigPath}
context={props.context}
outputMapField={outputMapField}
outputMapFieldPath={outputMapFieldPath}
modelInterface={modelInterface}
onClose={() => setIsOutputTransformModalOpen(false)}
Expand Down Expand Up @@ -365,7 +356,6 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
</EuiFlexGroup>
<EuiSpacer size="s" />
<MapArrayField
field={inputMapField}
fieldPath={inputMapFieldPath}
helpText={`An array specifying how to map fields from the ingested document to the model’s input. Dot notation is used by default. To explicitly use JSONPath, please ensure to prepend with the
root object selector "${JSONPATH_ROOT_SELECTOR}"`}
Expand Down Expand Up @@ -422,7 +412,6 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
</EuiFlexGroup>
<EuiSpacer size="s" />
<MapArrayField
field={outputMapField}
fieldPath={outputMapFieldPath}
helpText={`An array specifying how to map the model’s output to new document fields. Dot notation is used by default. To explicitly use JSONPath, please ensure to prepend with the
root object selector "${JSONPATH_ROOT_SELECTOR}"`}
Expand Down
Loading

0 comments on commit 500e671

Please sign in to comment.