Commit 2272899b by YeYuheng Committed by GitHub

fix: preserve two-column table workflow inputs (#7051)

parent 9bb91d9b
...@@ -322,7 +322,7 @@ export const getReferenceVariableValue = ({ ...@@ -322,7 +322,7 @@ export const getReferenceVariableValue = ({
if ( if (
Array.isArray(value) && Array.isArray(value) &&
value.length > 0 && value.length > 0 &&
value.every((item) => isValidReferenceValueFormat(item)) value.every((item) => isValidReferenceValueFormat(item, nodesMap))
) { ) {
return value return value
.map<any>((val) => { .map<any>((val) => {
......
...@@ -408,8 +408,20 @@ export const formatEditorVariablePickerIcon = ( ...@@ -408,8 +408,20 @@ export const formatEditorVariablePickerIcon = (
}; };
// Check the value is a valid reference value format: [variableId, outputId] // Check the value is a valid reference value format: [variableId, outputId]
export const isValidReferenceValueFormat = (value: any): value is ReferenceItemValueType => { export const isValidReferenceValueFormat = (
return Array.isArray(value) && value.length === 2 && typeof value[0] === 'string'; value: any,
nodesMap?: Record<string, Pick<StoreNodeItemType, 'nodeId'>> | Map<string, Pick<StoreNodeItemType, 'nodeId'>>
): value is ReferenceItemValueType => {
if (!(Array.isArray(value) && value.length === 2 && typeof value[0] === 'string')) {
return false;
}
if (!nodesMap) return true;
const sourceNodeId = value[0];
if (sourceNodeId === VARIABLE_NODE_ID) return true;
return nodesMap instanceof Map ? nodesMap.has(sourceNodeId) : !!nodesMap[sourceNodeId];
}; };
/* /*
Check whether the value([variableId, outputId]) value is a valid reference value: Check whether the value([variableId, outputId]) value is a valid reference value:
......
...@@ -1265,6 +1265,22 @@ describe('getReferenceVariableValue', () => { ...@@ -1265,6 +1265,22 @@ describe('getReferenceVariableValue', () => {
expect(result).toBe('plain string'); expect(result).toBe('plain string');
}); });
it('should keep two-column table data as a two-dimensional array', () => {
const tableData = [
['指标', '金额(元)'],
['资产总额(期末余额)', '22,701,764,055.63'],
['负债总额(期末余额)', '4,809,415,705.17']
];
const result = getReferenceVariableValue({
value: tableData,
nodesMap: {},
variables: {}
});
expect(result).toEqual(tableData);
});
it('should handle array with single reference', () => { it('should handle array with single reference', () => {
const nodesMap: Record<string, RuntimeNodeItemType> = { const nodesMap: Record<string, RuntimeNodeItemType> = {
node1: { node1: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment