Skip to content

Commit

Permalink
Set default array accessors to bracket notation
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler committed Nov 15, 2024
1 parent 01c4f35 commit 71eaf07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
IConfigField,
PROCESSOR_CONTEXT,
WorkflowConfig,
JSONPATH_ROOT_SELECTOR,
WorkflowFormValues,
ModelInterface,
IndexMappings,
Expand All @@ -41,6 +40,7 @@ import {
} from './modals';
import { AppState, getMappings, useAppDispatch } from '../../../../store';
import {
convertArrayAccessorsToBracketNotation,
formikToPartialPipeline,
getDataSourceId,
parseModelInputs,
Expand Down Expand Up @@ -186,7 +186,7 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
setDocFields(
docObjKeys.map((key) => {
return {
label: key,
label: convertArrayAccessorsToBracketNotation(key),
};
})
);
Expand All @@ -202,7 +202,7 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
setQueryFields(
queryObjKeys.map((key) => {
return {
label: key,
label: convertArrayAccessorsToBracketNotation(key),
};
})
);
Expand Down
8 changes: 8 additions & 0 deletions public/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}]`;
});
}

0 comments on commit 71eaf07

Please sign in to comment.