@@ -14,7 +14,7 @@ interface IGetAction {
1414
1515interface ISelectAction {
1616 type : "select" ;
17- payload : Build ;
17+ payload : Build | null ;
1818}
1919
2020interface IDeleteAction {
@@ -71,11 +71,18 @@ const initialState: State = {
7171function buildReducer ( state : State , action : IAction ) : State {
7272 switch ( action . type ) {
7373 case "select" :
74- return {
75- ...state ,
76- selectedBuildId : action . payload . id ,
77- selectedBuild : action . payload ,
78- } ;
74+ if ( action . payload === null ) {
75+ return {
76+ ...state ,
77+ selectedBuild : null
78+ } ;
79+ } else {
80+ return {
81+ ...state ,
82+ selectedBuildId : action . payload . id ,
83+ selectedBuild : action . payload ,
84+ } ;
85+ }
7986 case "request" :
8087 return {
8188 ...state ,
@@ -173,10 +180,14 @@ async function stopBuild(dispatch: Dispatch, id: string) {
173180 } ) ;
174181}
175182
176- async function selectBuild ( dispatch : Dispatch , id : string ) {
177- return buildsService . getDetails ( id ) . then ( ( build ) => {
178- dispatch ( { type : "select" , payload : build } ) ;
179- } ) ;
183+ async function selectBuild ( dispatch : Dispatch , id : string | null ) {
184+ if ( id === null ) {
185+ dispatch ( { type : "select" , payload : null } ) ;
186+ } else {
187+ return buildsService . getDetails ( id ) . then ( ( build ) => {
188+ dispatch ( { type : "select" , payload : build } ) ;
189+ } ) ;
190+ }
180191}
181192
182193async function addBuild ( dispatch : Dispatch , build : Build ) {
0 commit comments