@@ -24,17 +24,17 @@ interface IIndexAction {
2424
2525interface IDeleteAction {
2626 type : "delete" ;
27- payload : string ;
27+ payload : Array < string > ;
2828}
2929
3030interface IAddAction {
3131 type : "add" ;
32- payload : TestRun ;
32+ payload : Array < TestRun > ;
3333}
3434
3535interface IUpdateAction {
3636 type : "update" ;
37- payload : TestRun ;
37+ payload : Array < TestRun > ;
3838}
3939
4040interface IApproveAction {
@@ -107,19 +107,26 @@ function testRunReducer(state: State, action: IAction): State {
107107 case "delete" :
108108 return {
109109 ...state ,
110- testRuns : state . testRuns . filter ( ( p ) => p . id !== action . payload ) ,
110+ testRuns : state . testRuns . filter ( ( p ) => ! action . payload . includes ( p . id ) ) ,
111111 } ;
112112 case "add" :
113113 return {
114114 ...state ,
115- testRuns : [ ...state . testRuns , action . payload ] ,
115+ testRuns : [
116+ ...state . testRuns ,
117+ ...action . payload . filter (
118+ // remove duplicates
119+ ( i ) => ! state . testRuns . find ( ( tr ) => tr . id === i . id )
120+ ) ,
121+ ] ,
116122 } ;
117123 case "update" :
118124 return {
119125 ...state ,
120126 testRuns : state . testRuns . map ( ( t ) => {
121- if ( t . id === action . payload . id ) {
122- return action . payload ;
127+ const item = action . payload . find ( ( i ) => i . id === t . id ) ;
128+ if ( item ) {
129+ return item ;
123130 }
124131 return t ;
125132 } ) ,
@@ -172,36 +179,33 @@ async function getTestRunList(
172179 } ) ;
173180}
174181
175- async function deleteTestRun ( dispatch : Dispatch , id : string ) {
176- return testRunService . remove ( id ) . then ( ( testRun ) => {
177- dispatch ( { type : "delete" , payload : id } ) ;
178- return testRun ;
179- } ) ;
182+ async function deleteTestRun ( dispatch : Dispatch , ids : Array < string > ) {
183+ dispatch ( { type : "delete" , payload : ids } ) ;
180184}
181185
182- async function selectTestRun ( dispatch : Dispatch , id : string | undefined ) {
186+ async function selectTestRun ( dispatch : Dispatch , id ? : string ) {
183187 dispatch ( { type : "select" , payload : id } ) ;
184188}
185189
186- async function setTestRunIndex ( dispatch : Dispatch , index : string | undefined ) {
190+ async function setTestRunIndex ( dispatch : Dispatch , index ? : string ) {
187191 dispatch ( { type : "index" , payload : index } ) ;
188192}
189193
190- async function addTestRun ( dispatch : Dispatch , testRun : TestRun ) {
191- dispatch ( { type : "add" , payload : testRun } ) ;
194+ async function addTestRun ( dispatch : Dispatch , testRuns : Array < TestRun > ) {
195+ dispatch ( { type : "add" , payload : testRuns } ) ;
192196}
193197
194- async function updateTestRun ( dispatch : Dispatch , testRun : TestRun ) {
195- dispatch ( { type : "update" , payload : testRun } ) ;
198+ async function updateTestRun ( dispatch : Dispatch , testRuns : Array < TestRun > ) {
199+ dispatch ( { type : "update" , payload : testRuns } ) ;
196200}
197201
198202export {
199203 TestRunProvider ,
200204 useTestRunState ,
201205 useTestRunDispatch ,
202206 getTestRunList ,
203- deleteTestRun ,
204207 selectTestRun ,
205208 addTestRun ,
209+ deleteTestRun ,
206210 updateTestRun ,
207211} ;
0 commit comments