From 71eaf0790f4794476504b9346503d2142f9af0f1 Mon Sep 17 00:00:00 2001 From: Tyler Ohlsen Date: Fri, 15 Nov 2024 12:14:26 -0800 Subject: [PATCH] Set default array accessors to bracket notation Signed-off-by: Tyler Ohlsen --- .../processor_inputs/ml_processor_inputs.tsx | 6 +++--- public/utils/utils.ts | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/public/pages/workflow_detail/workflow_inputs/processor_inputs/ml_processor_inputs.tsx b/public/pages/workflow_detail/workflow_inputs/processor_inputs/ml_processor_inputs.tsx index e12e4dd9..654eedc8 100644 --- a/public/pages/workflow_detail/workflow_inputs/processor_inputs/ml_processor_inputs.tsx +++ b/public/pages/workflow_detail/workflow_inputs/processor_inputs/ml_processor_inputs.tsx @@ -24,7 +24,6 @@ import { IConfigField, PROCESSOR_CONTEXT, WorkflowConfig, - JSONPATH_ROOT_SELECTOR, WorkflowFormValues, ModelInterface, IndexMappings, @@ -41,6 +40,7 @@ import { } from './modals'; import { AppState, getMappings, useAppDispatch } from '../../../../store'; import { + convertArrayAccessorsToBracketNotation, formikToPartialPipeline, getDataSourceId, parseModelInputs, @@ -186,7 +186,7 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) { setDocFields( docObjKeys.map((key) => { return { - label: key, + label: convertArrayAccessorsToBracketNotation(key), }; }) ); @@ -202,7 +202,7 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) { setQueryFields( queryObjKeys.map((key) => { return { - label: key, + label: convertArrayAccessorsToBracketNotation(key), }; }) ); diff --git a/public/utils/utils.ts b/public/utils/utils.ts index 30bff43b..ff86cfaf 100644 --- a/public/utils/utils.ts +++ b/public/utils/utils.ts @@ -473,3 +473,11 @@ export const getErrorMessageForStepType = ( return ''; } }; + +export function convertArrayAccessorsToBracketNotation(path: string): string { + return path.split('.').reduce((prevValue, curValue, idx) => { + return isNaN(parseInt(curValue)) + ? prevValue + '.' + curValue + : prevValue + `[${curValue}]`; + }); +}