Skip to content

Commit

Permalink
refactor(react-components): improve rule based styling applier (#4243)
Browse files Browse the repository at this point in the history
* apply styles at the end in a bulk for the same output

* refactor: use filterUndefined function and remove the necessity of verifying it again
  • Loading branch information
danpriori authored Feb 23, 2024
1 parent 2f1bba2 commit e948ebb
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions react-components/src/components/RuleBasedOutputs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { type CogniteCadModel, TreeIndexNodeCollection } from '@cognite/reveal';
import { type AssetMapping3D, type Asset } from '@cognite/sdk';
import { type FdmPropertyType } from '../Reveal3DResources/types';
import { filterUndefined } from '../../utilities/filterUndefined';

const checkStringExpressionStatement = (
asset: Asset,
Expand Down Expand Up @@ -168,7 +169,7 @@ export const generateRuleBasedOutputs = (

const ruleWithOutputs = ruleSet?.rulesWithOutputs;

ruleWithOutputs?.forEach((ruleWithOutput: { rule: Rule; outputs: RuleOutput[] }) => {
ruleWithOutputs?.forEach(async (ruleWithOutput: { rule: Rule; outputs: RuleOutput[] }) => {
const { rule, outputs } = ruleWithOutput;
// Starting Expression
const expression = rule.expression;
Expand All @@ -179,7 +180,7 @@ export const generateRuleBasedOutputs = (

if (outputSelected === undefined) return;

analyzeNodesAgainstExpression({
await analyzeNodesAgainstExpression({
model,
contextualizedAssetNodes,
assetMappings,
Expand All @@ -189,7 +190,7 @@ export const generateRuleBasedOutputs = (
});
};

const analyzeNodesAgainstExpression = ({
const analyzeNodesAgainstExpression = async ({
model,
contextualizedAssetNodes,
assetMappings,
Expand All @@ -201,8 +202,8 @@ const analyzeNodesAgainstExpression = ({
assetMappings: AssetMapping3D[];
expression: Expression;
outputSelected: ColorRuleOutput;
}): void => {
void Promise.all(
}): Promise<void> => {
const allTreeNodes = await Promise.all(
contextualizedAssetNodes.map(async (assetNode) => {
const finalGlobalOutputResult = traverseExpression(assetNode, [expression]);

Expand All @@ -212,12 +213,18 @@ const analyzeNodesAgainstExpression = ({
);

// get the 3d nodes linked to the asset and with treeindex and subtreeRange
const treeNodes: NodeAndRange[] = await getThreeDNodesFromAsset(nodesFromThisAsset, model);
const nodesAndRange: NodeAndRange[] = await getThreeDNodesFromAsset(
nodesFromThisAsset,
model
);

applyNodeStyles(treeNodes, outputSelected, model);
return nodesAndRange;
}
})
);

const filteredAllTreeNodes = filterUndefined(allTreeNodes.flat());
applyNodeStyles(filteredAllTreeNodes, outputSelected, model);
};

const getThreeDNodesFromAsset = async (
Expand Down

0 comments on commit e948ebb

Please sign in to comment.