From cc172e8a690903d8b394d04684a2ec0250b0bb7f Mon Sep 17 00:00:00 2001 From: Pauline Didier Date: Tue, 19 Nov 2024 15:26:01 +0100 Subject: [PATCH 1/3] fix: :bug: select reviewer rules based on affectedType --- core/src/validation/engine.spec.ts | 38 ++++++++++++++++++++++++++++++ core/src/validation/engine.ts | 8 +++++++ 2 files changed, 46 insertions(+) diff --git a/core/src/validation/engine.spec.ts b/core/src/validation/engine.spec.ts index 97377dfb..30bf4a01 100644 --- a/core/src/validation/engine.spec.ts +++ b/core/src/validation/engine.spec.ts @@ -143,4 +143,42 @@ describe("ValidationEngine", () => { expect(resultList.length).toBe(1); expect(resultList[0].ruleName).toBe("should be selected"); }); + + it("should select appropriate component rules based on affectedType", async () => { + validationEngine.register([ + { + type: "component", + name: "should apply to all components", + affectedType: [], + test: async ({ component }) => { + return false; + }, + messageTrue: "should never be true", + messageFalse: "Yep, it applied to all components", + }, + { + type: "component", + name: "should apply to external entity only", + affectedType: ["ee"], + test: async ({ component }) => { + return false; + }, + messageTrue: "should never be true", + messageFalse: "Yep, it applied to external entity only", + }, + ]); + + const modelId = await createSampleModel(dal); + const resultList = await validationEngine.getResults(modelId); + const applyAllResult = resultList.filter((r) => { + return r.ruleName === "should apply to all components"; + }); + const applyEEOnlyResult = resultList.filter((r) => { + return r.ruleName === "should apply to external entity only"; + }); + + expect(applyAllResult.length).toBe(2); + expect(applyEEOnlyResult.length).toBe(1); + expect(applyEEOnlyResult[0].elementName).toBe("omegalul"); + }); }); diff --git a/core/src/validation/engine.ts b/core/src/validation/engine.ts index f3846536..45ed23fe 100644 --- a/core/src/validation/engine.ts +++ b/core/src/validation/engine.ts @@ -180,6 +180,14 @@ export class ValidationEngine extends EventEmitter { } } } + + // Skip the rule if the component type is not in the affectedType array + if (rule.affectedType.length > 0) { + if (!rule.affectedType.includes(component.type)) { + continue; + } + } + try { const testResult = await rule.test({ ...ruleArgs, From 793f42310f7bf00e9543743e4d8122f690c9ca97 Mon Sep 17 00:00:00 2001 From: Pauline Didier Date: Wed, 20 Nov 2024 10:23:36 +0100 Subject: [PATCH 2/3] fix: :bug: fix blocked tabs with dataflows --- app/src/components/model/panels/bottom/BottomPanel.js | 10 ++++++---- .../model/panels/bottom/BottomTabsHeader.js | 11 +++-------- .../components/model/panels/bottom/ValidationTab.js | 11 +++++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/src/components/model/panels/bottom/BottomPanel.js b/app/src/components/model/panels/bottom/BottomPanel.js index 3ebf6a58..8188b6d2 100644 --- a/app/src/components/model/panels/bottom/BottomPanel.js +++ b/app/src/components/model/panels/bottom/BottomPanel.js @@ -6,6 +6,7 @@ import { useState, useEffect } from "react"; import { useModelID } from "../../hooks/useModelID"; import { useSelectedComponent } from "../../hooks/useSelectedComponent"; import { useValidateQuery } from "../../../../api/gram/validation"; +import { COMPONENT_TYPE } from "../../board/constants"; export function BottomPanel() { const modelId = useModelID(); @@ -57,16 +58,15 @@ export function BottomPanel() { } useEffect(() => { - if (!selectedComponent) { + if (!selectedComponent && tab === TAB.SELECTED_COMPONENT) { setTab(0); - } else { - setTab(2); } - }, [selectedComponent]); + }, [selectedComponent, tab]); if (bottomPanelCollapsed) { return <>; } + return ( {!isLoading && ( @@ -77,12 +77,14 @@ export function BottomPanel() { allLength={allNegativeResults.length} modelLength={modelResults.length} selectedLength={selectedResults.length} + selectedComponent={selectedComponent} /> )} diff --git a/app/src/components/model/panels/bottom/BottomTabsHeader.js b/app/src/components/model/panels/bottom/BottomTabsHeader.js index aa2c61ad..7c177872 100644 --- a/app/src/components/model/panels/bottom/BottomTabsHeader.js +++ b/app/src/components/model/panels/bottom/BottomTabsHeader.js @@ -1,5 +1,4 @@ import { Paper, Grow, Tab, Tabs, Badge, Typography, Box } from "@mui/material"; -import { useSelectedComponent } from "../../hooks/useSelectedComponent"; export const TAB = { ALL: 0, @@ -32,12 +31,8 @@ export function BottomTabsHeader({ allLength, modelLength, selectedLength, + selectedComponent, }) { - const selected = useSelectedComponent(); - - // This fixes an annoying MUI console error when you deselect a component - const tabHck = !selected && tab === TAB.COMPONENT ? TAB.SYSTEM : tab; - return ( setTab(v)} textColor="inherit" variant="fullWidth" @@ -97,7 +92,7 @@ export function BottomTabsHeader({ } value={TAB.MODEL} /> - {selected && ( + {selectedComponent && ( Date: Wed, 20 Nov 2024 10:46:40 +0100 Subject: [PATCH 3/3] feat: :sparkles: add review score to bottom panel --- .../model/panels/bottom/BottomPanel.js | 8 +++++++- .../model/panels/bottom/BottomTabsHeader.js | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/src/components/model/panels/bottom/BottomPanel.js b/app/src/components/model/panels/bottom/BottomPanel.js index 8188b6d2..b468253c 100644 --- a/app/src/components/model/panels/bottom/BottomPanel.js +++ b/app/src/components/model/panels/bottom/BottomPanel.js @@ -6,7 +6,6 @@ import { useState, useEffect } from "react"; import { useModelID } from "../../hooks/useModelID"; import { useSelectedComponent } from "../../hooks/useSelectedComponent"; import { useValidateQuery } from "../../../../api/gram/validation"; -import { COMPONENT_TYPE } from "../../board/constants"; export function BottomPanel() { const modelId = useModelID(); @@ -40,6 +39,12 @@ export function BottomPanel() { : []; } + const passedResults = validationResults.filter((result) => result.testResult); + const successRatio = + validationResults.length === 0 + ? 0 + : Number((passedResults.length / validationResults.length).toFixed(2)); + if (tab === 0) { // TAB.ALL filteredResults = allNegativeResults; @@ -78,6 +83,7 @@ export function BottomPanel() { modelLength={modelResults.length} selectedLength={selectedResults.length} selectedComponent={selectedComponent} + successRatio={successRatio} /> = 0.75) { + return "success"; + } else if (ratio >= 0.5) { + return "warning"; + } + return "error"; +} + export function BottomTabsHeader({ tab, setTab, @@ -32,6 +41,7 @@ export function BottomTabsHeader({ modelLength, selectedLength, selectedComponent, + successRatio, }) { return ( @@ -39,6 +49,7 @@ export function BottomTabsHeader({ sx={{ mx: 3, display: "flex", + gap: 1, justifyContent: "center", alignItems: "center", }} @@ -46,6 +57,12 @@ export function BottomTabsHeader({ QUALITY CHECK +