split table into measurements and records, add units to value display
This commit is contained in:
@@ -22,6 +22,43 @@ function mergeDefinition(nodeData, defs) {
|
||||
};
|
||||
}
|
||||
|
||||
function getSocketType(inputDef) {
|
||||
if (!inputDef) return null;
|
||||
const [type] = Array.isArray(inputDef) ? inputDef : [inputDef];
|
||||
return Array.isArray(type) ? type[0] : type;
|
||||
}
|
||||
|
||||
function getInputType(definition, inputName) {
|
||||
const required = definition?.input?.required || {};
|
||||
const optional = definition?.input?.optional || {};
|
||||
return getSocketType(required[inputName] ?? optional[inputName]);
|
||||
}
|
||||
|
||||
function remapLegacyHandle(handleId, kind, nodeData) {
|
||||
if (typeof handleId !== 'string') return handleId;
|
||||
|
||||
const parts = handleId.split('::');
|
||||
if (parts.length !== 3 || parts[2] !== 'TABLE') return handleId;
|
||||
|
||||
if (kind === 'source' && parts[0] === 'output') {
|
||||
const outputSlot = Number.parseInt(parts[1], 10);
|
||||
const outputType = nodeData?.definition?.output?.[outputSlot];
|
||||
if (typeof outputType === 'string' && outputType !== 'TABLE') {
|
||||
return `output::${outputSlot}::${outputType}`;
|
||||
}
|
||||
return handleId;
|
||||
}
|
||||
|
||||
if (kind === 'target' && parts[0] === 'input') {
|
||||
const inputType = getInputType(nodeData?.definition, parts[1]);
|
||||
if (typeof inputType === 'string' && inputType !== 'TABLE') {
|
||||
return `input::${parts[1]}::${inputType}`;
|
||||
}
|
||||
}
|
||||
|
||||
return handleId;
|
||||
}
|
||||
|
||||
export function hydrateWorkflowState(data, defs = {}) {
|
||||
const loadedNodes = Array.isArray(data?.nodes) ? data.nodes : [];
|
||||
const loadedEdges = Array.isArray(data?.edges) ? data.edges : [];
|
||||
@@ -43,11 +80,19 @@ export function hydrateWorkflowState(data, defs = {}) {
|
||||
},
|
||||
}));
|
||||
|
||||
const nodeById = new Map(nodes.map((node) => [String(node.id), node.data]));
|
||||
|
||||
const edges = loadedEdges.map((edge) => ({
|
||||
...edge,
|
||||
sourceHandle: remapLegacyHandle(edge.sourceHandle, 'source', nodeById.get(String(edge.source))),
|
||||
targetHandle: remapLegacyHandle(edge.targetHandle, 'target', nodeById.get(String(edge.target))),
|
||||
}));
|
||||
|
||||
const nextNodeId = Math.max(0, ...loadedNodes.map((node) => parseInt(node.id, 10) || 0)) + 1;
|
||||
|
||||
return {
|
||||
nodes,
|
||||
edges: loadedEdges,
|
||||
edges,
|
||||
nextNodeId,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user