Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Data Mapper): Add updateDragList for remove/add and fix custom value shown #6502

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type CommonProps = {
connections: ConnectionDictionary;
schemaType: SchemaType;
draggable: boolean;
updateListItems: (index: number, item?: TemplateItemProps) => void;
};

export type TemplateItemProps = { input: InputConnection; index: number };
Expand Down Expand Up @@ -52,24 +53,26 @@ export const InputList = (props: InputListProps) => {
commonProps,
dragHandleProps,
} = props;
const { functionKey, data, inputsFromManifest, connections, schemaType } = commonProps;
const { functionKey, data, inputsFromManifest, connections, schemaType, updateListItems } = commonProps;

const inputName = useMemo(() => getInputName(input, connections), [connections, input]);
const inputValue = useMemo(() => getInputValue(input), [input]);
const inputType = useMemo(() => getInputTypeFromNode(input), [input]);
const removeUnboundedInput = useCallback(() => {
const targetNodeReactFlowKey = functionKey;
updateListItems(index);
dispatch(
deleteConnectionFromFunctionMenu({
targetId: targetNodeReactFlowKey,
inputIndex: index,
})
);
}, [dispatch, functionKey, index]);
}, [dispatch, functionKey, index, updateListItems]);

const updateInput = useCallback(
(newValue: InputConnection) => {
const targetNodeReactFlowKey = functionKey;
updateListItems(index, { input: newValue, index });
dispatch(
setConnectionInput({
targetNode: data,
Expand All @@ -79,7 +82,7 @@ export const InputList = (props: InputListProps) => {
})
);
},
[data, dispatch, functionKey, index]
[data, dispatch, functionKey, index, updateListItems]
);

const validateAndCreateConnection = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { isSchemaNodeExtended } from '../../../utils';
import {
connectionDoesExist,
createCustomInputConnection,
createNewEmptyConnection,
isNodeConnection,
newConnectionWillHaveCircularLogic,
} from '../../../utils/Connection.Utils';
Expand All @@ -34,29 +35,6 @@ export const InputTabContents = (props: {
functionKey: string;
}) => {
const intl = useIntl();
const { func, functionKey } = props;
const containerRef = useRef<HTMLDivElement | null>(null);
const styles = useStyles();
const dispatch = useDispatch();
const connectionDictionary = useSelector((state: RootState) => state.dataMap.present.curDataMapOperation.dataMapConnections);
const sourceSchemaDictionary = useSelector((state: RootState) => state.dataMap.present.curDataMapOperation.flattenedSourceSchema);
const functionNodeDictionary = useSelector((state: RootState) => state.dataMap.present.curDataMapOperation.functionNodes);

const connections = useSelector((state: RootState) => state.dataMap.present.curDataMapOperation.dataMapConnections);

const inputsFromManifest = useMemo(() => func.inputs, [func.inputs]);
const functionConnection = useMemo(() => connections[functionKey], [connections, functionKey]);

const [listItems, setListItems] = useState<TemplateItemProps[]>(
Object.entries(functionConnection.inputs).map(
(input, index) =>
({
input: input[1],
index,
}) as TemplateItemProps
)
);

const resources = useMemo(
() => ({
ACCEPTED_TYPES: intl.formatMessage({
Expand All @@ -83,7 +61,31 @@ export const InputTabContents = (props: {
[intl]
);

const { func, functionKey } = props;
const containerRef = useRef<HTMLDivElement | null>(null);
const styles = useStyles();
const dispatch = useDispatch();
const connectionDictionary = useSelector((state: RootState) => state.dataMap.present.curDataMapOperation.dataMapConnections);
const sourceSchemaDictionary = useSelector((state: RootState) => state.dataMap.present.curDataMapOperation.flattenedSourceSchema);
const functionNodeDictionary = useSelector((state: RootState) => state.dataMap.present.curDataMapOperation.functionNodes);

const connections = useSelector((state: RootState) => state.dataMap.present.curDataMapOperation.dataMapConnections);

const inputsFromManifest = useMemo(() => func.inputs, [func.inputs]);
const functionConnection = useMemo(() => connections[functionKey], [connections, functionKey]);

const [listItems, setListItems] = useState<TemplateItemProps[]>(
Object.entries(functionConnection.inputs).map(
(input, index) =>
({
input: input[1],
index,
}) as TemplateItemProps
)
);

const addUnboundedInputSlot = useCallback(() => {
setListItems((prev) => [...prev, { input: createNewEmptyConnection(), index: prev.length }]);
dispatch(createInputSlotForUnboundedInput(functionKey));
}, [dispatch, functionKey]);

Expand All @@ -101,6 +103,23 @@ export const InputTabContents = (props: {
[dispatch, functionKey]
);

const update = useCallback(
(index: number, item?: TemplateItemProps) => {
if (item) {
if (listItems.length >= index) {
const updatedList = [...listItems];
updatedList[index] = item;
setListItems(updatedList);
} else {
setListItems([...listItems, { input: item.input, index: listItems.length }]);
}
} else {
setListItems((prev) => prev.filter((item) => item.index !== index));
}
},
[listItems, setListItems]
);

return (
<div>
{func.maxNumberOfInputs !== UnboundedInput ? (
Expand Down Expand Up @@ -225,6 +244,7 @@ export const InputTabContents = (props: {
connections: connections,
schemaType: SchemaType.Source,
draggable: true,
updateListItems: update,
}}
onMoveEnd={onDragMoveEnd}
itemKey={'index'}
Expand Down
2 changes: 1 addition & 1 deletion libs/data-mapper-v2/src/utils/Function.Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export const functionDropDownItemText = (key: string, node: FunctionData, connec
}

if (isCustomValueConnection(input)) {
return input;
return input.value;
}

if (input.node && isFunctionData(input.node)) {
Expand Down
Loading