Commit 377cee61 authored by Jaden DIEFENBAUGH's avatar Jaden DIEFENBAUGH
Browse files

[toolchains] properly update all synchronization channel labels when renaming dataset blocks

parent 38ea1b96
Pipeline #20366 canceled with stages
in 4 minutes and 19 seconds
......@@ -300,6 +300,7 @@ export class ToolchainEditor extends React.PureComponent<Props, State> {
// changes a block's name given the set it belongs to, the old name, and the new name
updateBlockName = (set: BlockSet, oldName: string, newName: string) => {
// func to update from/to strings with old names to new names
const updateConn = (from, to): string[] => {
const fromSplit = from.split('.');
fromSplit[0] = fromSplit[0] === oldName ? newName : fromSplit[0];
......@@ -307,6 +308,8 @@ export class ToolchainEditor extends React.PureComponent<Props, State> {
toSplit[0] = toSplit[0] === oldName ? newName : toSplit[0];
return [fromSplit.join('.'), toSplit.join('.')];
};
// update the block & conn representation with the new names
const rep = {...this.state.cache.contents.representation};
rep.blocks = {...rep.blocks};
rep.blocks[newName] = rep.blocks[oldName];
......@@ -322,20 +325,26 @@ export class ToolchainEditor extends React.PureComponent<Props, State> {
})
.reduce((cs, c) => ({...cs, [c[0]]: c[1]}), {})
;
// update the channel colors
if(set === 'datasets'){
rep.channel_colors[newName] = rep.channel_colors[oldName];
delete rep.channel_colors[oldName];
}
// update blocks & connections
const newContents = {
...this.state.cache.contents,
[set]: this.state.cache.contents[set].map(s => s.name === oldName ? {...s, name: newName} : s),
// update the conns, both the names of the blocks and the channel
connections: this.state.cache.contents.connections.map(c => {
if(!c.from.includes(oldName) && !c.to.includes(oldName))
if(!c.from.includes(oldName) && !c.to.includes(oldName) && c.channel !== oldName)
return c;
const newChannel = c.channel === oldName ? newName : c.channel;
const updated = updateConn(c.from, c.to);
return {
...c,
channel: newChannel,
from: updated[0],
to: updated[1],
};
......@@ -343,6 +352,17 @@ export class ToolchainEditor extends React.PureComponent<Props, State> {
representation: rep,
};
// if the changed block is a dataset, update the synchronized_channel on all blocks using its old name
if(set === 'datasets'){
newContents['blocks'] = this.state.cache.contents.blocks
.map(s => s.synchronized_channel === oldName ? {...s, synchronized_channel: newName} : s)
;
newContents['analyzers'] = this.state.cache.contents.analyzers
.map(s => s.synchronized_channel === oldName ? {...s, synchronized_channel: newName} : s)
;
}
const newGroups = this.state.cache.extraContents.groups
.map(({ name, blocks }) => ({ name, blocks: blocks.map(n => n === oldName ? newName : n) }));
console.log(newName);
......
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 to comment