refactor: Address review comments

This commit is contained in:
Sidharth Vinod 2023-12-07 11:27:48 +05:30
parent 65a08efa00
commit 867686fe34
No known key found for this signature in database
GPG Key ID: FB5CCD378D3907CD

View File

@ -56,7 +56,7 @@ export const lookUpDomId = function (id: string) {
* *
*/ */
export const addVertex = function ( export const addVertex = function (
_id: string, id: string,
textObj: FlowText, textObj: FlowText,
type: 'group', type: 'group',
style: string[], style: string[],
@ -64,18 +64,14 @@ export const addVertex = function (
dir: string, dir: string,
props = {} props = {}
) { ) {
if (!id || id.trim().length === 0) {
return;
}
let txt; let txt;
const id = _id;
if (id === undefined) {
return;
}
if (id.trim().length === 0) {
return;
}
if (vertices[id] === undefined) { if (vertices[id] === undefined) {
vertices[id] = { vertices[id] = {
id: id, id,
labelType: 'text', labelType: 'text',
domId: MERMAID_DOM_ID_PREFIX + id + '-' + vertexCounter, domId: MERMAID_DOM_ID_PREFIX + id + '-' + vertexCounter,
styles: [], styles: [],
@ -95,7 +91,7 @@ export const addVertex = function (
vertices[id].text = txt; vertices[id].text = txt;
} else { } else {
if (vertices[id].text === undefined) { if (vertices[id].text === undefined) {
vertices[id].text = _id; vertices[id].text = id;
} }
} }
if (type !== undefined) { if (type !== undefined) {
@ -255,24 +251,24 @@ export const setDirection = function (dir: string) {
* @param className - Class to add * @param className - Class to add
*/ */
export const setClass = function (ids: string, className: string) { export const setClass = function (ids: string, className: string) {
ids.split(',').forEach(function (_id) { for (const id of ids.split(',')) {
const id = _id; if (vertices[id]) {
if (vertices[id] !== undefined) {
vertices[id].classes.push(className); vertices[id].classes.push(className);
} }
if (subGraphLookup[id]) {
if (subGraphLookup[id] !== undefined) {
subGraphLookup[id].classes.push(className); subGraphLookup[id].classes.push(className);
} }
}); }
}; };
const setTooltip = function (ids: string, tooltip: string) { const setTooltip = function (ids: string, tooltip: string) {
ids.split(',').forEach(function (id) { if (!tooltip) {
if (tooltip !== undefined) { return;
tooltips[version === 'gen-1' ? lookUpDomId(id) : id] = sanitizeText(tooltip); }
tooltip = sanitizeText(tooltip);
for (const id of ids.split(',')) {
tooltips[version === 'gen-1' ? lookUpDomId(id) : id] = tooltip;
} }
});
}; };
const setClickFun = function (id: string, functionName: string, functionArgs: string) { const setClickFun = function (id: string, functionName: string, functionArgs: string) {
@ -491,10 +487,7 @@ export const addSubGraph = function (
return { nodeList, dir }; return { nodeList, dir };
} }
let nodeList: string[] = []; const { nodeList, dir } = uniq(list.flat());
const { nodeList: nl, dir } = uniq(list.flat());
nodeList = nl;
if (version === 'gen-1') { if (version === 'gen-1') {
for (let i = 0; i < nodeList.length; i++) { for (let i = 0; i < nodeList.length; i++) {
nodeList[i] = lookUpDomId(nodeList[i]); nodeList[i] = lookUpDomId(nodeList[i]);