diff --git a/conda/js/src/components/toolchain/InsertObjectModal.jsx b/conda/js/src/components/toolchain/InsertObjectModal.jsx index ca621feaa8e84c66ad9fe1f0dedd2d723272f0bf..0c08497a83411d0503719f0b1813ae0adaee5fbe 100644 --- a/conda/js/src/components/toolchain/InsertObjectModal.jsx +++ b/conda/js/src/components/toolchain/InsertObjectModal.jsx @@ -163,7 +163,6 @@ class InsertObjectModal extends React.PureComponent<Props, State> { } stringifyResultName = (obj: any) => { - console.log(obj); if(!obj) return ''; if(obj.set) diff --git a/conda/js/src/components/toolchain/ToolchainConnection.jsx b/conda/js/src/components/toolchain/ToolchainConnection.jsx index 98dc00c599d7f6b918b08c56fcbea8574d505f54..2340378ceb32d3486a03f95371cb96c2a4633ba0 100644 --- a/conda/js/src/components/toolchain/ToolchainConnection.jsx +++ b/conda/js/src/components/toolchain/ToolchainConnection.jsx @@ -55,7 +55,10 @@ class ToolchainConnection extends React.Component<Props> { return true; } } else if(key === 'connection'){ - if(nextProps[key].channel !== this.props[key].channel) + if(nextProps[key].channel !== this.props[key].channel + || nextProps[key].from !== this.props[key].from + || nextProps[key].to !== this.props[key].to + ) return true; } else if(nextProps[key] !== this.props[key]){ return true; diff --git a/conda/js/src/components/toolchain/ToolchainEditor.jsx b/conda/js/src/components/toolchain/ToolchainEditor.jsx index 2d2b80be47216e9bc0a129fc60afc38a17081f06..564d7c702c517ba1ba3e7aaae5403477a0659e89 100644 --- a/conda/js/src/components/toolchain/ToolchainEditor.jsx +++ b/conda/js/src/components/toolchain/ToolchainEditor.jsx @@ -111,6 +111,9 @@ const generateNewHistory = (state: State): History => { }; }; + +const generateConnectionRepresentations = (connections: ConnectionType[]) => Object.assign({}, ...connections.map(c => ({[`${ c.from }/${ c.to }`]: []}))); + export class ToolchainEditor extends React.PureComponent<Props, State> { constructor(props: Props) { super(props); @@ -262,7 +265,8 @@ export class ToolchainEditor extends React.PureComponent<Props, State> { const newBlocks = assignBlockChannels(this.state.cache.contents.blocks); const newAnalyzers = assignBlockChannels(this.state.cache.contents.analyzers); - const newRepConns = connectionData.map(c => `${ c.from }/${ c.to }`).reduce((o, name) => ({ ...o, [name]: []}), {}); + + const newRepConns = generateConnectionRepresentations(connectionData); this.setContents({ blocks: newBlocks, analyzers: newAnalyzers, @@ -453,14 +457,17 @@ export class ToolchainEditor extends React.PureComponent<Props, State> { } // adds new blocks at a certain location via an array of arrays of info about the new block(s) - // each array is info about a new block: + // it will also copy connections via looking for connections between copied blocks and copying them to the related new blocks + // Parameters: + // blockData: each array is info about a new block: // - the first string is the new name // - the BlockSet is the set to put the block in // - the numbers are the x & y coords of the new block - // - the last entry is an optional block object to copy from - // it will also copy connections via looking for connections between copied blocks - // and copying them to the related new blocks - addBlocks = (blockData: [string, BlockSet, number, number, ?BlockType][]) => { + // - last entry is an optional block object to copy from + // connections: + // if you are inserting blocks from different toolchains, give the new connections as the second arg! + // these new connections should already be updated to have the new syncd channel names + addBlocks = (blockData: [string, BlockSet, number, number, ?BlockType][], connections: ConnectionType[]) => { const newBlocks = blockData.map(d => this.generateNewBlockData(...d)); const sets = blockData.map(b => b[1]); @@ -477,33 +484,47 @@ export class ToolchainEditor extends React.PureComponent<Props, State> { } }; - const copyBlocks = blockData.filter(bd => bd.length === 5); - const newConnections: ConnectionType[] = [...this.state.cache.contents.connections].map(({ from, to, channel }) => { - const fromBlock = copyBlocks.find(bd => from.startsWith(`${ bd[4].name }.`)); - const toBlock = copyBlocks.find(bd => to.startsWith(`${ bd[4].name }.`)); - if(!fromBlock || !toBlock) - return false; - const newFromBlockData = newBlocks.find(b => b.block.name === fromBlock[0]); - if(!newFromBlockData) - return false; - else { - return { - from: from.replace(`${ fromBlock[4].name }.`, `${ fromBlock[0] }.`), - to: to.replace(`${ toBlock[4].name }.`, `${ toBlock[0] }.`), - channel: newFromBlockData.block.synchronized_channel || newFromBlockData.block.name, - }; - } - }) - .filter(c => c); const newContents = { blocks: [...this.state.cache.contents.blocks, ...newBlocks.filter((b, i) => sets[i] === 'blocks').map(b => b.block)], datasets: [...this.state.cache.contents.datasets, ...newBlocks.filter((b, i) => sets[i] === 'datasets').map(b => b.block)], analyzers: [...this.state.cache.contents.analyzers, ...newBlocks.filter((b, i) => sets[i] === 'analyzers').map(b => b.block)], representation: rep, - connections: [...this.state.cache.contents.connections, ...newConnections], + connections: this.state.cache.contents.connections, }; + // if the blocks werent copied from an external toolchain, + // check for connection info from the copied blocks and create new connections between the new blocks + if(!connections){ + const copyBlocks = blockData.filter(bd => bd.length > 4); + const newConnections: ConnectionType[] = [...this.state.cache.contents.connections].map(({ from, to, channel }) => { + const fromBlock = copyBlocks.find(bd => from.startsWith(`${ bd[4].name }.`)); + const toBlock = copyBlocks.find(bd => to.startsWith(`${ bd[4].name }.`)); + if(!fromBlock || !toBlock) + return false; + const newFromBlockData = newBlocks.find(b => b.block.name === fromBlock[0]); + if(!newFromBlockData) + return false; + else { + return { + from: from.replace(`${ fromBlock[4].name }.`, `${ fromBlock[0] }.`), + to: to.replace(`${ toBlock[4].name }.`, `${ toBlock[0] }.`), + channel: newFromBlockData.block.synchronized_channel || newFromBlockData.block.name, + }; + } + }) + .filter(c => c); + newContents.connections = [...this.state.cache.contents.connections, ...newConnections]; + const newRepConns = generateConnectionRepresentations(newConnections); + newContents.representation.connections = {...rep.connections, ...newRepConns}; + } else { + // add the new connections from the copied toolchain + const newConnections = connections; + newContents.connections = [...this.state.cache.contents.connections, ...newConnections]; + const newRepConns = generateConnectionRepresentations(newConnections); + newContents.representation.connections = {...rep.connections, ...newRepConns}; + } + this.setContents(newContents); } @@ -1156,9 +1177,7 @@ export class ToolchainEditor extends React.PureComponent<Props, State> { b[3] += y; } - this.addBlocks(newBlocksData); - if(newConnections) - this.createConnections(newConnections); + this.addBlocks(newBlocksData, newConnections); }} usedNames={this.getUsedNames()} />