Commit 5c7d2a8b authored by Jaden DIEFENBAUGH's avatar Jaden DIEFENBAUGH

[js][db] now shows info alert when there are >=2 protocols w same template name and diff contents

parent 35e17cbe
Pipeline #22659 passed with stages
in 36 minutes and 41 seconds
......@@ -164,6 +164,65 @@ export class DatabaseEditor extends React.Component<Props, State> {
}));
};
// if the protocol template name has any uses with a different protocol makeup,
// returns the info on all other uses
validateProtocolTemplate = (protocol: Protocol): null | React.Node => {
const tName = protocol.template;
const prots = this.props.protocols.filter(p => p.template === tName);
// basically a hashmap of all the different protocols using this template name
// if theres more than one, theres at least two different protocols using the same template name!
const diffTemplateMap: {[string]: {name: string, database: string}[]} = {};
prots.forEach(prot => {
const p = copyObj(prot);
const pInfo = {
name: p.name,
database: p.database,
};
delete p['name'];
delete p['database'];
const json = JSON.stringify(p);
if(Object.keys(diffTemplateMap).includes(json)){
diffTemplateMap[json].push(pInfo);
} else {
diffTemplateMap[json] = [ pInfo ];
}
});
const tMapData = Object.entries(diffTemplateMap);
if(tMapData.length > 1){
// theres >=2 protocols using the same template name but with different contents
// get the currently active protocol
const prot = copyObj(protocol);
delete prot['name'];
delete prot['database'];
const pStr = JSON.stringify(prot);
// print out the protocols that are using the same template name but diff contents
const TemplateAlert = <Alert color='secondary'>
<p>
There are protocols using the same template name but with different contents:
</p>
<ul>
{
tMapData
// only protocols with different contents
.filter(([k, pData]) => k !== pStr)
// get all the protocols of all the different contents
.reduce((ps, [k, pData]) => [...ps, ...pData], [])
.map(({ name, database }, i) => <li key={i}>{`${ name } (${ database })`}</li>)
}
</ul>
</Alert>;
return TemplateAlert;
} else {
// valid template useage throughout all dbs
return null;
}
}
renderProtocol = (index: number, protocol: Protocol) => (
<Container className='protocol'>
<FormGroup row>
......@@ -198,6 +257,13 @@ export class DatabaseEditor extends React.Component<Props, State> {
/>
</Col>
</FormGroup>
{
// show an alert about protocol template usage
this.validateProtocolTemplate(protocol)
}
<Row className='protocolSets'>
<Col className='d-flex align-items-center mb-2'>
<h3 className='mb-0 mr-2'>
......
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