Skip to content

Commit

Permalink
Find errors via object numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
GribovskyPavel committed Nov 14, 2023
1 parent 64399f1 commit a80337a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/common/components/layouts/pages/inspect/Inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function Inspect({ jobStatus, taskStatus, ruleSummaries, lockApp, unlockApp, onF
);
const initTree = useCallback(
tree => {
const ruleSummariesWithTreeIds = setRulesTreeIds(tree.name, ruleSummaries);
const ruleSummariesWithTreeIds = setRulesTreeIds(tree, ruleSummaries);
const treeWithRoleNames = getTreeRoleNames(tree, ruleSummariesWithTreeIds);
const ids = getTreeIds(tree);
setTreeData({ tree: treeWithRoleNames, ids: ids, ruleSummaries: ruleSummariesWithTreeIds });
Expand Down
42 changes: 28 additions & 14 deletions src/common/services/treeService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import _ from 'lodash';

const TREEPATH = '/StructTreeRoot';

const getContext = arr => {
let allContext = '';
_.map(arr, subArr => {
Expand All @@ -10,6 +12,20 @@ const getContext = arr => {
return allContext;
};

const getIdStringsFromContext = (treeName, context) => {
return context
.split(TREEPATH)[1]
.match(/\(\d+ \d+ \S+ \S+ \S+\)/g)
.filter((idStr, index) => {
if (index === 0) return !idStr.includes(treeName);
return true;
})
.map(id => {
const parsedId = id.slice(1, -1).split(' ');
return `${parsedId[0]}:${parsedId[1]}`;
});
};

const getStructureIds = arr => {
return Array.from(new Set(getContext(arr).match(/\(\d+ \d+ \S+ \S+ \S+\)/g)))
.filter(id => !id.includes('/'))
Expand Down Expand Up @@ -47,30 +63,28 @@ const getTreeIds = (node, ids = []) => {
return ids;
};

const setRulesTreeIds = (treeName, rules) => {
const TREEPATH = '/StructTreeRoot';
const setRulesTreeIds = (tree, rules) => {
return rules.map(({ checks }) => {
return checks.map(check => {
if (check.context.includes(TREEPATH)) {
const idStrings = check.context
.split(TREEPATH)[1]
.match(/[^/]+/g)
.filter((idStr, index) => {
if (index === 1) return !idStr.includes(treeName) && !idStr.includes('{');
return !idStr.includes('{');
});
const treeId = idStrings
.map(idStr => idStr.match(/\[\d+]/))
.join('')
.replaceAll('][', ':')
.slice(1, -1);
const idStrings = getIdStringsFromContext(tree.name, check.context);
const treeId = findIdByObjNumbers(tree, idStrings.reverse());
return { ...check, treeId: treeId };
}
return { ...check, treeId: null };
});
});
};

const findIdByObjNumbers = (node, pathArray) => {
if (!pathArray || !pathArray.length) return node.id;
const path = pathArray.pop();
const [num, gen] = path.split(':');
const nextNode = node.children.find(({ ref }) => ref.num === +num && ref.gen === +gen);
if (!nextNode) return null;
return findIdByObjNumbers(nextNode, pathArray);
};

const findNode = (arr, id) => {
let ruleIndex = null;
let checkIndex = null;
Expand Down

0 comments on commit a80337a

Please sign in to comment.