From 5c45f7dce0d117739fd33c428e228abb789e3cd1 Mon Sep 17 00:00:00 2001 From: Surat Das Date: Mon, 21 Jun 2021 15:05:04 -0700 Subject: [PATCH 1/3] Apply ignore area to all images from selected ignore area from details page. --- src/components/TestDetailsModal.tsx | 51 ++++++++++++++++++++++++++++- src/services/testRun.service.ts | 12 +++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/components/TestDetailsModal.tsx b/src/components/TestDetailsModal.tsx index 41b28e34..b938a39a 100644 --- a/src/components/TestDetailsModal.tsx +++ b/src/components/TestDetailsModal.tsx @@ -12,6 +12,7 @@ import { Tooltip, Select, MenuItem, + CircularProgress, } from "@material-ui/core"; import { ToggleButton } from "@material-ui/lab"; import { useHotkeys } from "react-hotkeys-hook"; @@ -32,6 +33,7 @@ import { Save, WarningRounded, LayersClear, + Collections, } from "@material-ui/icons"; import { TestRunDetails } from "./TestRunDetails"; import useImage from "use-image"; @@ -76,6 +78,7 @@ const TestDetailsModal: React.FunctionComponent<{ const [stagePos, setStagePos] = React.useState(defaultStagePos); const [stageInitPos, setStageInitPos] = React.useState(defaultStagePos); const [stageOffset, setStageOffset] = React.useState(defaultStagePos); + const [progress, setProgress] = React.useState(0); const [image, imageStatus] = useImage( staticService.getImage(testRun.imageName) @@ -156,6 +159,11 @@ const TestDetailsModal: React.FunctionComponent<{ } }; + const getIgnoreAreaForSelectionId = (idPassed: string) => { + let ignoreAreaToReturn = ignoreAreas.filter((area) => idPassed === area.id)[0]; + return ignoreAreaToReturn; + }; + const handleClose = () => { selectTestRun(testRunDispatch, undefined); }; @@ -185,6 +193,34 @@ const TestDetailsModal: React.FunctionComponent<{ setStageOffset(defaultStagePos); }; + const applyIgnoreArea = () => { + let newIgnoreArea = getIgnoreAreaForSelectionId(selectedRectId!); + let runningNumber = 0; + let index = 0; + testRunService.getList(testRun.buildId).then( + (allRows) => { + allRows.forEach( + async (eachRow) => { + let existingIgnoreArea = (await testRunService.getTestRunDetails(eachRow.id)).ignoreAreas.toString(); + //Add a running number to make id unique. + const newId = (Date.now() + (++runningNumber)).toString().slice(0, 13); + newIgnoreArea.id = newId; + let newIgnoreAreas: IgnoreArea[] = JSON.parse(existingIgnoreArea); + newIgnoreAreas.push(newIgnoreArea); + testRunService.setIgnoreAreas(eachRow.id, newIgnoreAreas); + // update in variation + testVariationService.setIgnoreAreas(testRun.testVariationId, ignoreAreas); + let valueToSet = Math.floor(++index * 100 / allRows.length); + setProgress(valueToSet); + }); + }); + setProgress(0); + setSelectedRectId(undefined); + enqueueSnackbar("Ignore areas are updated in all images in this build.", { + variant: "success", + }); + }; + React.useEffect(() => { setIgnoreAreas(JSON.parse(testRun.ignoreAreas)); }, [testRun]); @@ -252,6 +288,7 @@ const TestDetailsModal: React.FunctionComponent<{ + {(100 > progress && progress > 0) && } @@ -313,7 +350,7 @@ const TestDetailsModal: React.FunctionComponent<{ - + + + + + applyIgnoreArea() + } + > + + + + { + const requestOptions = { + method: "GET", + headers: authHeader(), + }; + + return fetch(`${API_URL}${ENDPOINT_URL}/${id}`, requestOptions).then( + handleResponse + ); +} + async function setComment(id: string, comment: string): Promise { const requestOptions = { method: "PUT", @@ -84,6 +95,7 @@ export const testRunService = { remove, approve, reject, + getTestRunDetails, setIgnoreAreas, setComment, }; From acf8dd19b2bc11f03fa80c3ef64a3627adde87e7 Mon Sep 17 00:00:00 2001 From: Surat Das Date: Thu, 1 Jul 2021 19:06:57 -0700 Subject: [PATCH 2/3] Modified code based on changes in master branch. --- src/components/TestDetailsModal.tsx | 59 +++++++++++++---------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/src/components/TestDetailsModal.tsx b/src/components/TestDetailsModal.tsx index 63b05721..1697a73a 100644 --- a/src/components/TestDetailsModal.tsx +++ b/src/components/TestDetailsModal.tsx @@ -12,15 +12,18 @@ import { Tooltip, Select, MenuItem, - CircularProgress, + LinearProgress, } from "@material-ui/core"; import { ToggleButton } from "@material-ui/lab"; import { useHotkeys } from "react-hotkeys-hook"; import { TestRun } from "../types"; -import { testRunService, staticService } from "../services"; +import { + testRunService, + staticService, +} from "../services"; import { TestStatus } from "../types/testStatus"; import { useHistory, Prompt } from "react-router-dom"; -import { IgnoreArea } from "../types/ignoreArea"; +import { IgnoreArea, UpdateIgnoreAreaDto } from "../types/ignoreArea"; import { KonvaEventObject } from "konva/types/Node"; import { Close, @@ -74,7 +77,7 @@ const TestDetailsModal: React.FunctionComponent<{ const [stagePos, setStagePos] = React.useState(defaultStagePos); const [stageInitPos, setStageInitPos] = React.useState(defaultStagePos); const [stageOffset, setStageOffset] = React.useState(defaultStagePos); - const [progress, setProgress] = React.useState(0); + const [processing, setProcessing] = React.useState(false); const [image, imageStatus] = useImage( staticService.getImage(testRun.imageName) @@ -175,9 +178,9 @@ const TestDetailsModal: React.FunctionComponent<{ const fitStageToScreen = () => { const scale = image ? Math.min( - stageWidth < image.width ? stageWidth / image.width : 1, - stageHeigth < image.height ? stageHeigth / image.height : 1 - ) + stageWidth < image.width ? stageWidth / image.width : 1, + stageHeigth < image.height ? stageHeigth / image.height : 1 + ) : 1; setStageScale(scale); resetPositioin(); @@ -189,31 +192,21 @@ const TestDetailsModal: React.FunctionComponent<{ }; const applyIgnoreArea = () => { + setProcessing(true); let newIgnoreArea = getIgnoreAreaForSelectionId(selectedRectId!); - let runningNumber = 0; - let index = 0; testRunService.getList(testRun.buildId).then( (allRows) => { - allRows.forEach( - async (eachRow) => { - let existingIgnoreArea = (await testRunService.getTestRunDetails(eachRow.id)).ignoreAreas.toString(); - //Add a running number to make id unique. - const newId = (Date.now() + (++runningNumber)).toString().slice(0, 13); - newIgnoreArea.id = newId; - let newIgnoreAreas: IgnoreArea[] = JSON.parse(existingIgnoreArea); - newIgnoreAreas.push(newIgnoreArea); - testRunService.setIgnoreAreas(eachRow.id, newIgnoreAreas); - // update in variation - testVariationService.setIgnoreAreas(testRun.testVariationId, ignoreAreas); - let valueToSet = Math.floor(++index * 100 / allRows.length); - setProgress(valueToSet); + let allIds: string[] = []; + allRows.forEach((value) => allIds.push(value.id)); + let data: UpdateIgnoreAreaDto = { ids: allIds, ignoreAreas: [newIgnoreArea] }; + testRunService.addIgnoreAreas(data).then(() => { + setProcessing(false); + setSelectedRectId(undefined); + enqueueSnackbar("Ignore areas are updated in all images in this build.", { + variant: "success", }); + }); }); - setProgress(0); - setSelectedRectId(undefined); - enqueueSnackbar("Ignore areas are updated in all images in this build.", { - variant: "success", - }); }; React.useEffect(() => { @@ -271,10 +264,10 @@ const TestDetailsModal: React.FunctionComponent<{ )} {(testRun.status === TestStatus.unresolved || testRun.status === TestStatus.new) && ( - - - - )} + + + + )} @@ -283,7 +276,7 @@ const TestDetailsModal: React.FunctionComponent<{ - {(100 > progress && progress > 0) && } + {(processing) && } @@ -345,7 +338,7 @@ const TestDetailsModal: React.FunctionComponent<{ - + Date: Fri, 2 Jul 2021 13:06:26 -0700 Subject: [PATCH 3/3] Implemented review comments. --- src/components/TestDetailsModal.tsx | 39 +++++++++++++++-------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/components/TestDetailsModal.tsx b/src/components/TestDetailsModal.tsx index 1697a73a..3cc2a2ec 100644 --- a/src/components/TestDetailsModal.tsx +++ b/src/components/TestDetailsModal.tsx @@ -157,11 +157,6 @@ const TestDetailsModal: React.FunctionComponent<{ } }; - const getIgnoreAreaForSelectionId = (idPassed: string) => { - let ignoreAreaToReturn = ignoreAreas.filter((area) => idPassed === area.id)[0]; - return ignoreAreaToReturn; - }; - const handleClose = () => { selectTestRun(testRunDispatch, undefined); }; @@ -192,21 +187,27 @@ const TestDetailsModal: React.FunctionComponent<{ }; const applyIgnoreArea = () => { - setProcessing(true); - let newIgnoreArea = getIgnoreAreaForSelectionId(selectedRectId!); - testRunService.getList(testRun.buildId).then( - (allRows) => { - let allIds: string[] = []; - allRows.forEach((value) => allIds.push(value.id)); - let data: UpdateIgnoreAreaDto = { ids: allIds, ignoreAreas: [newIgnoreArea] }; - testRunService.addIgnoreAreas(data).then(() => { - setProcessing(false); - setSelectedRectId(undefined); - enqueueSnackbar("Ignore areas are updated in all images in this build.", { - variant: "success", + let newIgnoreArea = ignoreAreas.find((area) => selectedRectId! === area.id); + if (newIgnoreArea) { + setProcessing(true); + testRunService.getList(testRun.buildId).then( + (testRuns: TestRun[]) => { + let allIds = testRuns.map((item) => item.id); + let data: UpdateIgnoreAreaDto = { ids: allIds, ignoreAreas: [newIgnoreArea!] }; + testRunService.addIgnoreAreas(data).then(() => { + setProcessing(false); + setSelectedRectId(undefined); + enqueueSnackbar("Ignore areas are updated in all images in this build.", { + variant: "success", + }); }); + }).catch((error) => { + enqueueSnackbar("There was an error : " + error, { variant: "error" }); + setProcessing(false); }); - }); + } else { + enqueueSnackbar("There was an error determining which ignore area to apply.", { variant: "error" }); + } }; React.useEffect(() => { @@ -276,7 +277,7 @@ const TestDetailsModal: React.FunctionComponent<{ - {(processing) && } + {(processing) && }