Skip to content

Commit

Permalink
fix(setHeaders): Fix broken setHeaders processor
Browse files Browse the repository at this point in the history
After changing the way how `AutoForm` updates the node's models, nested
schemas, like the one used by `setHeader` no longer work as the key of
the property being changed is expressed using the `.` (dot) notation.

As an example: `headers.0.expression`

This means that we can't use the `key` as it is to set the values, as it
won't achieve the expected result.

The fix is to use `lodash/set` to navigate through the path and assign
the value in the right place.

fix: KaotoIO#727
  • Loading branch information
lordrip committed Jan 25, 2024
1 parent 0964ad5 commit 7f9ab67
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AutoField, AutoFields, AutoForm, ErrorsField } from '@kaoto-next/uniforms-patternfly';
import { CodeBlock, CodeBlockCode, Title } from '@patternfly/react-core';
import set from 'lodash.set';
import { FunctionComponent, useCallback, useContext, useEffect, useMemo, useRef } from 'react';
import { stringify } from 'yaml';
import { EntitiesContext } from '../../../providers/entities.provider';
Expand Down Expand Up @@ -52,13 +53,13 @@ export const CanvasForm: FunctionComponent<CanvasFormProps> = (props) => {
}, [props.selectedNode.data?.vizNode]);

const handleOnChangeIndividualProp = useCallback(
(key: string, value: unknown) => {
(path: string, value: unknown) => {
if (!props.selectedNode.data?.vizNode) {
return;
}

const newModel = props.selectedNode.data?.vizNode?.getComponentSchema()?.definition || {};
newModel[key] = value;
set(newModel, path, value);
props.selectedNode.data.vizNode.updateModel(newModel);
entitiesContext?.updateSourceCodeFromEntities();
},
Expand Down

0 comments on commit 7f9ab67

Please sign in to comment.