Commit 31c314b7 authored by Jaden DIEFENBAUGH's avatar Jaden DIEFENBAUGH
Browse files

[js][tc] reset blocks sync channel when it has no conns to it, #120

parent 1b0a4516
......@@ -39,7 +39,7 @@ import * as Selectors from '@store/selectors.js';
import type { FlattenedDatabaseEntry } from '@store/selectors';
import Block from './ToolchainBlock.jsx';
import type { BlockType, ConnectionType, BlockSet, Group, Contents } from '@helpers/toolchainTypes';
import type { NormalBlock, AnalyzerBlock, BlockType, ConnectionType, BlockSet, Group, Contents } from '@helpers/toolchainTypes';
import { connectionToId } from './ToolchainConnection.jsx';
import ValidSchemaBadge from '../ValidSchemaBadge.jsx';
import CacheInput from '../CacheInput.jsx';
......@@ -653,12 +653,27 @@ export class ToolchainEditor extends React.PureComponent<Props, State> {
.reduce((cs, [name, rep]) => ({...cs, [name]: rep}), {})
;
const newConns = this.props.data.contents.connections.filter(c => {
if(c.from === cn.from && c.to === cn.to)
return false;
return true;
});
// if the given block has no conns to it, the syncd channel should become ''
const removeInvalidChannels = (b: NormalBlock | AnalyzerBlock): NormalBlock | AnalyzerBlock => {
if(newConns.find(c => c.to.split('.')[0] == b.name))
return b;
return {
...b,
synchronized_channel: '',
};
};
const newContents = {
connections: this.props.data.contents.connections.filter(c => {
if(c.from === cn.from && c.to === cn.to)
return false;
return true;
}),
connections: newConns,
blocks: this.props.data.contents.blocks.map(b => removeInvalidChannels(b)),
analyzers: this.props.data.contents.analyzers.map(b => removeInvalidChannels(b)),
representation: rep,
};
......
......@@ -1028,5 +1028,37 @@ describe('<ToolchainEditor />', function() {
expect(data.contents.representation.connections).to.not.have.property('training_data.species/training_data.species');
expect(data.contents.connections.findIndex(c => c.from == conToDel.from && c.to == conToDel.to)).to.equal(-1);
});
it('Properly deletes conns between training_data & training_alg, and clears training_alg sync channel', async () => {
const conToDel = { from: 'training_data.species', to: 'training_alg.species', channel: 'training_data' };
const conToDel2 = { from: 'training_data.measurements', to: 'training_alg.measurements', channel: 'training_data' };
const tc = getValidObj(getIrisTc());
wrapper = mount(
<C
data={tc}
sets={sets}
protocols={protocols}
toolchains={state.toolchain}
databases={state.database}
normalAlgorithms={normalAlgorithms}
analyzerAlgorithms={analyzerAlgorithms}
saveFunc={saveFunc}
updateFunc={updateFunc}
/>
);
// change testing_alg.lda_machine to testing_alg.lda
expect(wrapper.exists('#training_data-species-training_alg-species')).to.equal(true);
expect(wrapper.exists('#training_data-measurements-training_alg-measurements')).to.equal(true);
wrapper.instance().handleConnectionContextMenu({}, { clicked: 'delete', connection: conToDel });
wrapper.update();
wrapper.instance().handleConnectionContextMenu({}, { clicked: 'delete', connection: conToDel2 });
wrapper.update();
expect(wrapper.exists('#training_data-species-training_alg-species')).to.equal(false);
expect(wrapper.exists('#training_data-measurements-training_alg-measurements')).to.equal(false);
const data = wrapper.props().data;
expect(data.contents.blocks.find(b => b.name == 'training_alg')).to.have.property('synchronized_channel', '');
});
});
});
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