@@ -12,14 +12,18 @@ import {
1212 Tooltip ,
1313 Select ,
1414 MenuItem ,
15+ LinearProgress ,
1516} from "@material-ui/core" ;
1617import { ToggleButton } from "@material-ui/lab" ;
1718import { useHotkeys } from "react-hotkeys-hook" ;
1819import { TestRun } from "../types" ;
19- import { testRunService , staticService } from "../services" ;
20+ import {
21+ testRunService ,
22+ staticService ,
23+ } from "../services" ;
2024import { TestStatus } from "../types/testStatus" ;
2125import { useHistory , Prompt } from "react-router-dom" ;
22- import { IgnoreArea } from "../types/ignoreArea" ;
26+ import { IgnoreArea , UpdateIgnoreAreaDto } from "../types/ignoreArea" ;
2327import { KonvaEventObject } from "konva/types/Node" ;
2428import {
2529 Close ,
@@ -28,6 +32,7 @@ import {
2832 Save ,
2933 WarningRounded ,
3034 LayersClear ,
35+ Collections ,
3136} from "@material-ui/icons" ;
3237import { TestRunDetails } from "./TestRunDetails" ;
3338import useImage from "use-image" ;
@@ -72,6 +77,7 @@ const TestDetailsModal: React.FunctionComponent<{
7277 const [ stagePos , setStagePos ] = React . useState ( defaultStagePos ) ;
7378 const [ stageInitPos , setStageInitPos ] = React . useState ( defaultStagePos ) ;
7479 const [ stageOffset , setStageOffset ] = React . useState ( defaultStagePos ) ;
80+ const [ processing , setProcessing ] = React . useState ( false ) ;
7581
7682 const [ image , imageStatus ] = useImage (
7783 staticService . getImage ( testRun . imageName )
@@ -167,9 +173,9 @@ const TestDetailsModal: React.FunctionComponent<{
167173 const fitStageToScreen = ( ) => {
168174 const scale = image
169175 ? Math . min (
170- stageWidth < image . width ? stageWidth / image . width : 1 ,
171- stageHeigth < image . height ? stageHeigth / image . height : 1
172- )
176+ stageWidth < image . width ? stageWidth / image . width : 1 ,
177+ stageHeigth < image . height ? stageHeigth / image . height : 1
178+ )
173179 : 1 ;
174180 setStageScale ( scale ) ;
175181 resetPositioin ( ) ;
@@ -180,6 +186,30 @@ const TestDetailsModal: React.FunctionComponent<{
180186 setStageOffset ( defaultStagePos ) ;
181187 } ;
182188
189+ const applyIgnoreArea = ( ) => {
190+ let newIgnoreArea = ignoreAreas . find ( ( area ) => selectedRectId ! === area . id ) ;
191+ if ( newIgnoreArea ) {
192+ setProcessing ( true ) ;
193+ testRunService . getList ( testRun . buildId ) . then (
194+ ( testRuns : TestRun [ ] ) => {
195+ let allIds = testRuns . map ( ( item ) => item . id ) ;
196+ let data : UpdateIgnoreAreaDto = { ids : allIds , ignoreAreas : [ newIgnoreArea ! ] } ;
197+ testRunService . addIgnoreAreas ( data ) . then ( ( ) => {
198+ setProcessing ( false ) ;
199+ setSelectedRectId ( undefined ) ;
200+ enqueueSnackbar ( "Ignore areas are updated in all images in this build." , {
201+ variant : "success" ,
202+ } ) ;
203+ } ) ;
204+ } ) . catch ( ( error ) => {
205+ enqueueSnackbar ( "There was an error : " + error , { variant : "error" } ) ;
206+ setProcessing ( false ) ;
207+ } ) ;
208+ } else {
209+ enqueueSnackbar ( "There was an error determining which ignore area to apply." , { variant : "error" } ) ;
210+ }
211+ } ;
212+
183213 React . useEffect ( ( ) => {
184214 setIgnoreAreas ( JSON . parse ( testRun . ignoreAreas ) ) ;
185215 } , [ testRun ] ) ;
@@ -235,10 +265,10 @@ const TestDetailsModal: React.FunctionComponent<{
235265 ) }
236266 { ( testRun . status === TestStatus . unresolved ||
237267 testRun . status === TestStatus . new ) && (
238- < Grid item >
239- < ApproveRejectButtons testRun = { testRun } />
240- </ Grid >
241- ) }
268+ < Grid item >
269+ < ApproveRejectButtons testRun = { testRun } />
270+ </ Grid >
271+ ) }
242272 < Grid item >
243273 < IconButton color = "inherit" onClick = { handleClose } >
244274 < Close />
@@ -247,6 +277,7 @@ const TestDetailsModal: React.FunctionComponent<{
247277 </ Grid >
248278 </ Toolbar >
249279 </ AppBar >
280+ { ( processing ) && < LinearProgress /> }
250281 < Box m = { 1 } >
251282 < Grid container alignItems = "center" >
252283 < Grid item xs = { 12 } >
@@ -318,6 +349,18 @@ const TestDetailsModal: React.FunctionComponent<{
318349 </ IconButton >
319350 </ Grid >
320351 </ Tooltip >
352+ < Tooltip title = "Apply selected ignore area to all images in this build." aria-label = "apply ignore area" >
353+ < Grid item >
354+ < IconButton
355+ disabled = { ! selectedRectId || ignoreAreas . length === 0 }
356+ onClick = { ( ) =>
357+ applyIgnoreArea ( )
358+ }
359+ >
360+ < Collections />
361+ </ IconButton >
362+ </ Grid >
363+ </ Tooltip >
321364 < Grid item >
322365 < IconButton
323366 disabled = { isIgnoreAreasSaved ( ) }
0 commit comments