Commit 9347e9e4 authored by jasonych99's avatar jasonych99
Browse files

lint javascript

parent b774dc60
import React from 'react';
import { SVGContent, DescriptionContent } from './SectionReaction';
import _ from 'lodash';
import { SVGContent } from './SectionReaction';
import QuillViewer from '../QuillViewer';
import { digit } from '../utils/MathUtils';
import { rmOpsRedundantSpaceBreak, frontBreak } from '../utils/quillFormat';
import ArrayUtils from '../utils/ArrayUtils';
import { Alphabet } from '../utils/ElementUtils';
import _ from 'lodash';
const onlyBlank = (target) => {
if (target.length === 0) return true;
......@@ -60,96 +60,107 @@ const boldXX = () => {
return { attributes: { bold: "true" }, insert: "xx" };
}
const ProductsInfo = ({products = []}) => {
const ProductsInfo = ({ products = [] }) => {
let content = [];
products.forEach( (p, i) => {
products.forEach((p) => {
let ea = [];
const m = p.molecule;
p.elemental_compositions.forEach(ec => {
if(ec.description === "By molecule formula") {
p.elemental_compositions.forEach((ec) => {
if (ec.description === 'By molecule formula') {
for (let [k, v] of Object.entries(ec.data)) {
ea = [...ea, `${k}, ${v}`];
}
}
return null;
});
ea = ea.filter(r => r != null).join("; ");
const cas = p.xref && p.xref.cas ? p.xref.cas.value : "- ";
const pFormula = `Formula: ${m.sum_formular}; `;
const pCAS = `CAS: ${cas}; `;
const pSmiles = `Smiles: ${m.cano_smiles}; `;
const pInCHI = `InCHI: ${m.inchikey}; `;
const pMMass = `Molecular Mass: ${digit(m.molecular_weight, 4)}; `;
const pEMass = `Exact Mass: ${digit(m.exact_molecular_weight, 4)}; `;
const pEA = `EA: ${ea}.`;
content = [...content, { insert: "Name: " }, deltaSampleMoleculeName(p),
{ insert: "; " },
{ insert: pFormula + pCAS + pSmiles +
pInCHI + pMMass + pEMass + pEA },
{ insert: "\n" } ];
ea = ea.filter(r => r != null).join('; ');
const cas = p.xref && p.xref.cas ? p.xref.cas.value : '- ';
const pFormula = `Formula: ${m.sum_formular}; `;
const pCAS = `CAS: ${cas}; `;
const pSmiles = `Smiles: ${m.cano_smiles}; `;
const pInCHI = `InCHI: ${m.inchikey}; `;
const pMMass = `Molecular Mass: ${digit(m.molecular_weight, 4)}; `;
const pEMass = `Exact Mass: ${digit(m.exact_molecular_weight, 4)}; `;
const pEA = `EA: ${ea}.`;
content = [...content,
{ insert: 'Name: ' },
deltaSampleMoleculeName(p),
{ insert: '; ' },
{ insert: pFormula + pCAS + pSmiles + pInCHI + pMMass + pEMass + pEA },
{ insert: '\n' },
];
});
content = content.slice(0,-1);
return <QuillViewer value={{ops: content}} />
}
content = content.slice(0, -1);
return <QuillViewer value={{ ops: content }} />;
};
const stAndReContent = (el, prev_counter, prev_content) => {
let counter = prev_counter;
let content = prev_content;
[...el.starting_materials, ...el.reactants].forEach(el => {
const stAndReContent = (el, prevCounter, prevContent) => {
let counter = prevCounter;
let content = prevContent;
[...el.starting_materials, ...el.reactants].forEach((elm) => {
counter += 1;
content = [...content,
{ insert: `{${Alphabet(counter)}|` },
boldXX(),
{ insert: "} " },
deltaSampleMoleculeName(el),
{ insert: ` (${el.amount_g} g, ${digit(el.amount_mol * 1000, 4)} mmol, ${digit(el.equivalent, 2)} equiv.); ` }];
{ insert: `{${Alphabet(counter)}|` },
boldXX(),
{ insert: '} ' },
deltaSampleMoleculeName(elm),
{ insert: ` (${elm.amount_g} g, ${digit(elm.amount_mol * 1000, 4)} mmol, ${digit(elm.equivalent, 2)} equiv.); ` }];
});
return { counter: counter, content: content };
}
return { counter, content };
};
const solventsContent = (el, prev_counter, prev_content) => {
let counter = prev_counter;
let content = prev_content;
el.solvents.forEach(el => {
const solventsContent = (el, prevCounter, prevContent) => {
let counter = prevCounter;
let content = prevContent;
el.solvents.forEach((elm) => {
counter += 1;
content = [...content,
{ insert: `{${Alphabet(counter)}` },
{ insert: "} " },
deltaSampleMoleculeName(el),
{ insert: ` (${digit(el.amount_l * 1000, 2)} mL); ` }];
{ insert: `{${Alphabet(counter)}` },
{ insert: '} ' },
deltaSampleMoleculeName(elm),
{ insert: ` (${digit(elm.amount_l * 1000, 2)} mL); ` }];
});
return { counter: counter, content: content };
}
return { counter, content };
};
const porductsContent = (el, prev_counter, prev_content) => {
let counter = prev_counter;
let content = prev_content;
content = [...content, { insert: "Yield: " }];
el.products.forEach(p => {
const porductsContent = (el, prevCounter, prevContent) => {
let counter = prevCounter;
let content = prevContent;
content = [...content, { insert: 'Yield: ' }];
el.products.forEach((p) => {
counter += 1;
const m = p.molecule;
content = [...content,
{ insert: `{${Alphabet(counter)}|` },
boldXX(),
{ insert: "} " },
{ insert: ` = ${digit(p.equivalent * 100, 0)}%` },
{ insert: ` (${p.amount_g} g, ${digit(p.amount_mol * 1000, 4)} mmol)` },
{ insert: "; " }];
{ insert: `{${Alphabet(counter)}|` },
boldXX(),
{ insert: '} ' },
{ insert: ` = ${digit(p.equivalent * 100, 0)}%` },
{ insert: ` (${p.amount_g} g, ${digit(p.amount_mol * 1000, 4)} mmol)` },
{ insert: '; ' }];
});
content = content.slice(0,-1);
content = [...content, { insert: "." }];
return { counter: counter, content: content };
}
content = content.slice(0, -1);
content = [...content, { insert: '.' }];
return { counter, content };
};
const materailsContent = (el) => {
let counter = 0;
let content = [];
const counter = 0;
const content = [];
const stAndRe = stAndReContent(el, counter, content);
const solvCon = solventsContent(el, stAndRe.counter, stAndRe.content);
const prodCon = porductsContent(el, solvCon.counter, solvCon.content);
return prodCon.content;
}
};
const tlcContent = (el) => {
let content = [];
if (el.tlc_solvents) {
content = [{ attributes: { italic: 'true' }, insert: 'R' },
{ attributes: { script: 'sub', italic: 'true' }, insert: 'f' },
{ insert: ` = ${el.rf_value} (${el.tlc_solvents}).` }];
}
return content;
};
const obsvTlcContent = (el) => {
let content = [];
......@@ -157,17 +168,7 @@ const obsvTlcContent = (el) => {
content = rmOpsRedundantSpaceBreak(content);
if (onlyBlank(content)) return [];
return frontBreak(content);
}
const tlcContent = (el) => {
let content = [];
if(el.tlc_solvents) {
content = [{ attributes: { italic: "true" }, insert: "R"},
{ attributes: { script: "sub", italic: "true" }, insert: "f"},
{ insert: ` = ${el.rf_value} (${el.tlc_solvents}).`}]
}
return content;
}
};
const rmHeadSpace = (content) => {
let els = content;
......@@ -198,9 +199,7 @@ const rmTailSpace = (content) => {
return els;
};
const opsTailWithSymbol = (els, symbol) => {
return [...els, { insert: symbol }];
};
const opsTailWithSymbol = (els, symbol) => [...els, { insert: symbol }];
const endingSymbol = (content, symbol) => {
if (onlyBlank(content)) return [];
......@@ -215,9 +214,9 @@ const endingSymbol = (content, symbol) => {
const analysesContent = (products) => {
let content = [];
products.map((p) => {
products.forEach((p) => {
const sortAnalyses = ArrayUtils.sortArrByIndex(p.analyses);
return sortAnalyses.map((a) => {
sortAnalyses.forEach((a) => {
const data = a && a.extended_metadata
&& a.extended_metadata.report
&& a.extended_metadata.report === 'true'
......@@ -233,67 +232,62 @@ const analysesContent = (products) => {
};
const dangContent = (el) => {
if(el.dangerous_products.length === 0) return [];
let content = [{ attributes: { bold: "true" }, insert: "Attention! "},
{ insert: "The reaction includes the use of dangerous " +
"chemicals, which have the following " +
"classification: " }];
el.dangerous_products.forEach( d => {
content = [...content, { insert: d }, { insert: ", " }];
if (el.dangerous_products.length === 0) return [];
let content = [{ attributes: { bold: 'true' }, insert: 'Attention! ' },
{ insert: 'The reaction includes the use of dangerous ' +
'chemicals, which have the following ' +
'classification: ' }];
el.dangerous_products.forEach((d) => {
content = [...content, { insert: d }, { insert: ', ' }];
});
content = content.slice(0,-1);
content = content.slice(0, -1);
content = rmOpsRedundantSpaceBreak(content);
return content;
}
};
const DangerBlock = ({el}) => {
const DangerBlock = ({ el }) => {
const block = dangContent(el);
return block.length > 0 ? <QuillViewer value={{ops: block}} /> : null;
return block.length > 0 ? <QuillViewer value={{ ops: block }} /> : null;
};
const ContentBlock = ({el}) => {
const synName = synNameContent(el);
const desc = descContent(el);
const materials = materailsContent(el);
const obsvTlc = obsvTlcContent(el);
const analyses = analysesContent(el.products);
const block = [...synName, ...desc, ...materials,
...obsvTlc, ...analyses];
return <QuillViewer value={{ops: block}} />
}
const descContent = (el) => {
if(el.role !== "single") return [];
if (el.role !== 'single') return [];
let block = rmOpsRedundantSpaceBreak(el.description.ops);
block = [{ insert: "\n"}, ...block, { insert: "\n"}];
block = [{ insert: '\n' }, ...block, { insert: '\n' }];
return block;
}
};
const synNameContent = (el) => {
return [{ insert: `${el.name}: ` }];
}
const synNameContent = el => [{ insert: `${el.name}: ` }];
const SynthesisRow = ({el, counter, configs}) => {
return (
<div>
<Title el={el} counter={counter} />
<SVGContent
show={true}
svgPath={el.svgPath}
products={el.products}
isProductOnly={!configs.Showallchemi}
/>
<ProductsInfo products={el.products} />
<ContentBlock el={el} />
<DangerBlock el={el} />
</div>
);
}
const ContentBlock = ({ el }) => {
const synName = synNameContent(el);
const desc = descContent(el);
const materials = materailsContent(el);
const obsvTlc = obsvTlcContent(el);
const analyses = analysesContent(el.products);
const block = [...synName, ...desc, ...materials, ...obsvTlc, ...analyses];
return <QuillViewer value={{ ops: block }} />;
};
const SectionSiSynthesis = ({selectedObjs, configs}) => {
const SynthesisRow = ({ el, counter, configs }) => (
<div>
<Title el={el} counter={counter} />
<SVGContent
show
svgPath={el.svgPath}
products={el.products}
isProductOnly={!configs.Showallchemi}
/>
<ProductsInfo products={el.products} />
<ContentBlock el={el} />
<DangerBlock el={el} />
</div>
);
const SectionSiSynthesis = ({ selectedObjs, configs }) => {
let counter = 0;
const contents = selectedObjs.map( obj => {
if(obj.type === 'reaction' && obj.role !== 'gp') {
const contents = selectedObjs.map((obj) => {
if (obj.type === 'reaction' && obj.role !== 'gp') {
counter += 1;
return (
<SynthesisRow
......@@ -305,13 +299,14 @@ const SectionSiSynthesis = ({selectedObjs, configs}) => {
/>
);
}
});
return null;
}).filter(r => r !== null);
return (
<div>
{contents}
</div>
);
}
};
export default SectionSiSynthesis;
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