11import React from "react" ;
2- import { Typography , IconButton , Tooltip } from "@material-ui/core" ;
3- import { BaseComponentProps , RowModel } from "@material-ui/data-grid" ;
2+ import { Typography , IconButton , Tooltip , LinearProgress } from "@material-ui/core" ;
3+ import { BaseComponentProps , InternalRowsState , RowModel } from "@material-ui/data-grid" ;
44import { BaseModal } from "../BaseModal" ;
55import { useSnackbar } from "notistack" ;
6- import { Delete , ThumbDown , ThumbUp } from "@material-ui/icons" ;
6+ import { Delete , LayersClear , ThumbDown , ThumbUp } from "@material-ui/icons" ;
77import { testRunService } from "../../services" ;
88import { TestStatus } from "../../types" ;
9+ import { IgnoreArea } from "../../types/ignoreArea" ;
910
1011export const BulkOperation : React . FunctionComponent < BaseComponentProps > = (
1112 props : BaseComponentProps
@@ -14,9 +15,12 @@ export const BulkOperation: React.FunctionComponent<BaseComponentProps> = (
1415 const [ approveDialogOpen , setApproveDialogOpen ] = React . useState ( false ) ;
1516 const [ rejectDialogOpen , setRejectDialogOpen ] = React . useState ( false ) ;
1617 const [ deleteDialogOpen , setDeleteDialogOpen ] = React . useState ( false ) ;
18+ const [ clearIgnoreDialogOpen , setClearIgnoreDialogOpen ] = React . useState ( false ) ;
19+ const [ isProcessing , setIsProcessing ] = React . useState ( false ) ;
1720
18- const rows : Record < React . ReactText , boolean > = props . state . selection ;
19- const count = Object . keys ( rows ) . length ;
21+ const allRows : InternalRowsState = props . state . rows ;
22+ const selectedRows : Record < React . ReactText , boolean > = props . state . selection ;
23+ const count = Object . keys ( selectedRows ) . length ;
2024
2125 const toggleApproveDialogOpen = ( ) => {
2226 setApproveDialogOpen ( ! approveDialogOpen ) ;
@@ -27,21 +31,30 @@ export const BulkOperation: React.FunctionComponent<BaseComponentProps> = (
2731 const toggleDeleteDialogOpen = ( ) => {
2832 setDeleteDialogOpen ( ! deleteDialogOpen ) ;
2933 } ;
34+ const toggleClearIgnoreDialogOpen = ( ) => {
35+ setClearIgnoreDialogOpen ( ! clearIgnoreDialogOpen ) ;
36+ } ;
3037
3138 const getTitle = ( ) => {
39+ if ( clearIgnoreDialogOpen ) {
40+ return "Clear Ignore Area For Selected Items" ;
41+ }
3242 return submitButtonText ( ) + " Test Runs" ;
3343 } ;
3444
3545 const submitButtonText = ( ) : string => {
36- if ( deleteDialogOpen ) {
37- return "Delete" ;
38- }
3946 if ( approveDialogOpen ) {
4047 return "Approve" ;
4148 }
4249 if ( rejectDialogOpen ) {
4350 return "Reject" ;
4451 }
52+ if ( deleteDialogOpen ) {
53+ return "Delete" ;
54+ }
55+ if ( clearIgnoreDialogOpen ) {
56+ return "Clear" ;
57+ }
4558 return "" ;
4659 } ;
4760
@@ -55,6 +68,9 @@ export const BulkOperation: React.FunctionComponent<BaseComponentProps> = (
5568 if ( rejectDialogOpen ) {
5669 return toggleRejectDialogOpen ( ) ;
5770 }
71+ if ( clearIgnoreDialogOpen ) {
72+ return toggleClearIgnoreDialogOpen ( ) ;
73+ }
5874 } ;
5975
6076 const isRowEligibleForApproveOrReject = ( id : string ) => {
@@ -72,6 +88,9 @@ export const BulkOperation: React.FunctionComponent<BaseComponentProps> = (
7288 if ( isRowEligibleForApproveOrReject ( id ) ) {
7389 processApproveReject ( id ) ;
7490 }
91+ if ( clearIgnoreDialogOpen ) {
92+ testRunService . setIgnoreAreas ( id , [ ] ) ;
93+ }
7594 } ;
7695
7796 const processApproveReject = ( id : string ) => {
@@ -90,6 +109,9 @@ export const BulkOperation: React.FunctionComponent<BaseComponentProps> = (
90109 if ( approveDialogOpen ) {
91110 return toggleApproveDialogOpen ( ) ;
92111 }
112+ if ( clearIgnoreDialogOpen ) {
113+ return toggleClearIgnoreDialogOpen ( ) ;
114+ }
93115 return toggleRejectDialogOpen ( ) ;
94116 } ;
95117
@@ -116,27 +138,37 @@ export const BulkOperation: React.FunctionComponent<BaseComponentProps> = (
116138 </ IconButton >
117139 </ span >
118140 </ Tooltip >
141+ < Tooltip
142+ title = "Clear ignore areas for selected rows."
143+ aria-label = "clear ignore area"
144+ >
145+ < span >
146+ < IconButton
147+ disabled = { count === 0 }
148+ onClick = { toggleClearIgnoreDialogOpen }
149+ >
150+ < LayersClear />
151+ </ IconButton >
152+ </ span >
153+ </ Tooltip >
119154
120155 < BaseModal
121- open = { deleteDialogOpen || approveDialogOpen || rejectDialogOpen }
156+ open = { deleteDialogOpen || approveDialogOpen || rejectDialogOpen || clearIgnoreDialogOpen }
122157 title = { getTitle ( ) }
123158 submitButtonText = { submitButtonText ( ) }
124159 onCancel = { dismissDialog }
125160 content = {
126- < Typography > { `Are you sure you want to ${ submitButtonText ( ) . toLowerCase ( ) } ${ count } items?` } </ Typography >
161+ < Typography >
162+ { `Are you sure you want to ${ submitButtonText ( ) . toLowerCase ( ) } ${ count } items?` }
163+ </ Typography >
127164 }
128165 onSubmit = { ( ) => {
129- enqueueSnackbar (
130- "Wait for the confirmation message until operation is completed." ,
131- {
132- variant : "info" ,
133- }
134- ) ;
135-
166+ setIsProcessing ( true ) ;
136167 Promise . all (
137- Object . keys ( rows ) . map ( ( id : string ) => processAction ( id ) )
168+ Object . keys ( selectedRows ) . map ( ( id : string ) => processAction ( id ) )
138169 )
139170 . then ( ( ) => {
171+ setIsProcessing ( false ) ;
140172 enqueueSnackbar ( `${ count } test runs processed.` , {
141173 variant : "success" ,
142174 } ) ;
@@ -149,6 +181,7 @@ export const BulkOperation: React.FunctionComponent<BaseComponentProps> = (
149181 closeModal ( ) ;
150182 } }
151183 />
184+ { isProcessing && < LinearProgress /> }
152185 </ >
153186 ) ;
154187} ;
0 commit comments