@@ -25,7 +25,14 @@ import { TestStatus } from "../types/testStatus";
2525import { useHistory , Prompt } from "react-router-dom" ;
2626import { IgnoreArea } from "../types/ignoreArea" ;
2727import { KonvaEventObject } from "konva/types/Node" ;
28- import { Close , Add , Delete , Save , WarningRounded , LayersClear } from "@material-ui/icons" ;
28+ import {
29+ Close ,
30+ Add ,
31+ Delete ,
32+ Save ,
33+ WarningRounded ,
34+ LayersClear ,
35+ } from "@material-ui/icons" ;
2936import { TestRunDetails } from "./TestRunDetails" ;
3037import useImage from "use-image" ;
3138import { routes } from "../constants" ;
@@ -35,6 +42,8 @@ import { CommentsPopper } from "./CommentsPopper";
3542import { useSnackbar } from "notistack" ;
3643import { ScaleActionsSpeedDial } from "./ZoomSpeedDial" ;
3744import { ApproveRejectButtons } from "./ApproveRejectButtons" ;
45+ import { head } from "lodash" ;
46+ import { invertIgnoreArea } from "../_helpers/ignoreArea.helper" ;
3847
3948const defaultStagePos = {
4049 x : 0 ,
@@ -79,7 +88,9 @@ const TestDetailsModal: React.FunctionComponent<{
7988 ) ;
8089
8190 const [ isDrawMode , setIsDrawMode ] = useState ( false ) ;
82- const [ valueOfIgnoreOrCompare , setValueOfIgnoreOrCompare ] = useState ( "Ignore Areas" ) ;
91+ const [ valueOfIgnoreOrCompare , setValueOfIgnoreOrCompare ] = useState (
92+ "Ignore Areas"
93+ ) ;
8394 const [ isDiffShown , setIsDiffShown ] = useState ( false ) ;
8495 const [ selectedRectId , setSelectedRectId ] = React . useState < string > ( ) ;
8596
@@ -105,10 +116,7 @@ const TestDetailsModal: React.FunctionComponent<{
105116 // update in test run
106117 testRunService . setIgnoreAreas ( testRun . id , ignoreAreas ) ,
107118 // update in variation
108- testVariationService . setIgnoreAreas (
109- testRun . testVariationId ,
110- ignoreAreas
111- ) ,
119+ testVariationService . setIgnoreAreas ( testRun . testVariationId , ignoreAreas ) ,
112120 ] )
113121 . then ( ( ) => {
114122 enqueueSnackbar ( successMessage , {
@@ -122,56 +130,21 @@ const TestDetailsModal: React.FunctionComponent<{
122130 ) ;
123131 } ;
124132
125- const isValidCompareArea = ( ) => {
126- if ( ignoreAreas . length === 1 ) {
127- return true ;
128- }
129- enqueueSnackbar ( "Select one and only one area to compare." , {
130- variant : "error" ,
131- } ) ;
132- return false ;
133- } ;
134-
135133 const saveIgnoreAreasOrCompareArea = ( ) => {
136134 if ( valueOfIgnoreOrCompare . includes ( "Ignore" ) ) {
137135 saveTestRun ( ignoreAreas , "Ignore areas are updated." ) ;
138- return ;
139- }
140- if ( isValidCompareArea ( ) ) {
141- const imageHeight = image ?. height ? image . height : 0 ;
142- const imageWidth = image ?. width ? image . width : 0 ;
143- const firstIgnoreArea = ignoreAreas [ 0 ] ;
144- let ignoreArea1 = Object . assign ( { } , firstIgnoreArea ) ;
145- ignoreArea1 . x = 0 ;
146- ignoreArea1 . y = 0 ;
147- ignoreArea1 . width = firstIgnoreArea . x ;
148- ignoreArea1 . height = imageHeight ;
149- ignoreArea1 . id = firstIgnoreArea . id + 1 ;
150-
151- let ignoreArea2 = Object . assign ( { } , firstIgnoreArea ) ;
152- ignoreArea2 . x = firstIgnoreArea . x ;
153- ignoreArea2 . y = 0 ;
154- ignoreArea2 . width = imageWidth ;
155- ignoreArea2 . height = firstIgnoreArea . y ;
156- ignoreArea2 . id = firstIgnoreArea . id + 2 ;
157-
158- let ignoreArea3 = Object . assign ( { } , firstIgnoreArea ) ;
159- ignoreArea3 . x = firstIgnoreArea . x + firstIgnoreArea . width ;
160- ignoreArea3 . y = firstIgnoreArea . y ;
161- ignoreArea3 . height = imageHeight ;
162- ignoreArea3 . width = imageWidth ;
163- ignoreArea3 . id = firstIgnoreArea . id + 3 ;
164-
165- let ignoreArea4 = Object . assign ( { } , firstIgnoreArea ) ;
166- ignoreArea4 . x = firstIgnoreArea . x ;
167- ignoreArea4 . y = firstIgnoreArea . y + firstIgnoreArea . height ;
168- ignoreArea4 . height = imageHeight ;
169- ignoreArea4 . width = firstIgnoreArea . width ;
170- ignoreArea4 . id = firstIgnoreArea . id + 4 ;
136+ } else {
137+ const invertedIgnoreAreas = invertIgnoreArea (
138+ image ! . width ,
139+ image ! . height ,
140+ head ( ignoreAreas )
141+ ) ;
171142
172- const newIgnoreArea = [ ignoreArea1 , ignoreArea2 , ignoreArea3 , ignoreArea4 ] ;
173- setIgnoreAreas ( newIgnoreArea ) ;
174- saveTestRun ( newIgnoreArea , "Selected area has been inverted to ignore areas and saved." ) ;
143+ setIgnoreAreas ( invertedIgnoreAreas ) ;
144+ saveTestRun (
145+ invertedIgnoreAreas ,
146+ "Selected area has been inverted to ignore areas and saved."
147+ ) ;
175148 }
176149 } ;
177150
@@ -199,9 +172,9 @@ const TestDetailsModal: React.FunctionComponent<{
199172 const fitStageToScreen = ( ) => {
200173 const scale = image
201174 ? Math . min (
202- stageWidth < image . width ? stageWidth / image . width : 1 ,
203- stageHeigth < image . height ? stageHeigth / image . height : 1
204- )
175+ stageWidth < image . width ? stageWidth / image . width : 1 ,
176+ stageHeigth < image . height ? stageHeigth / image . height : 1
177+ )
205178 : 1 ;
206179 setStageScale ( scale ) ;
207180 resetPositioin ( ) ;
@@ -267,10 +240,10 @@ const TestDetailsModal: React.FunctionComponent<{
267240 ) }
268241 { ( testRun . status === TestStatus . unresolved ||
269242 testRun . status === TestStatus . new ) && (
270- < Grid item >
271- < ApproveRejectButtons testRun = { testRun } />
272- </ Grid >
273- ) }
243+ < Grid item >
244+ < ApproveRejectButtons testRun = { testRun } />
245+ </ Grid >
246+ ) }
274247 < Grid item >
275248 < IconButton color = "inherit" onClick = { handleClose } >
276249 < Close />
@@ -308,7 +281,9 @@ const TestDetailsModal: React.FunctionComponent<{
308281 id = "area-select"
309282 labelId = "areaSelect"
310283 value = { valueOfIgnoreOrCompare }
311- onChange = { ( event ) => onIgnoreOrCompareSelectChange ( event . target . value as string ) }
284+ onChange = { ( event ) =>
285+ onIgnoreOrCompareSelectChange ( event . target . value as string )
286+ }
312287 >
313288 { [ "Ignore Areas" , "Compare Area" ] . map ( ( eachItem ) => (
314289 < MenuItem key = { eachItem } value = { eachItem } >
@@ -342,9 +317,7 @@ const TestDetailsModal: React.FunctionComponent<{
342317 < Grid item >
343318 < IconButton
344319 disabled = { ignoreAreas . length === 0 }
345- onClick = { ( ) =>
346- setIgnoreAreas ( [ ] )
347- }
320+ onClick = { ( ) => setIgnoreAreas ( [ ] ) }
348321 >
349322 < LayersClear />
350323 </ IconButton >
@@ -353,9 +326,7 @@ const TestDetailsModal: React.FunctionComponent<{
353326 < Grid item >
354327 < IconButton
355328 disabled = { isIgnoreAreasSaved ( ) }
356- onClick = { ( ) =>
357- saveIgnoreAreasOrCompareArea ( )
358- }
329+ onClick = { ( ) => saveIgnoreAreasOrCompareArea ( ) }
359330 >
360331 < Save />
361332 </ IconButton >
0 commit comments