@@ -40,27 +40,6 @@ const moreBuildsAvailable = (
40
40
return event . data . latest_build . updated_at !== latestBuildInTimeline . updated_at
41
41
}
42
42
43
- const updateWorkspaceStatus = (
44
- status : TypesGen . WorkspaceStatus ,
45
- workspace ?: TypesGen . Workspace ,
46
- ) => {
47
- if ( ! workspace ) {
48
- throw new Error ( "Workspace not defined" )
49
- }
50
-
51
- return {
52
- ...workspace ,
53
- latest_build : {
54
- ...workspace . latest_build ,
55
- status,
56
- } ,
57
- }
58
- }
59
-
60
- const isUpdated = ( newDateStr : string , oldDateStr : string ) : boolean => {
61
- return new Date ( oldDateStr ) . getTime ( ) - new Date ( newDateStr ) . getTime ( ) > 0
62
- }
63
-
64
43
const Language = {
65
44
getTemplateWarning :
66
45
"Error updating workspace: latest template could not be fetched." ,
@@ -273,7 +252,6 @@ export const workspaceMachine = createMachine(
273
252
on : {
274
253
REFRESH_WORKSPACE : {
275
254
actions : [ "refreshWorkspace" ] ,
276
- cond : "hasUpdates" ,
277
255
} ,
278
256
EVENT_SOURCE_ERROR : {
279
257
target : "error" ,
@@ -347,7 +325,7 @@ export const workspaceMachine = createMachine(
347
325
} ,
348
326
} ,
349
327
requestingStart : {
350
- entry : [ "clearBuildError" , "updateStatusToStarting" ] ,
328
+ entry : "clearBuildError" ,
351
329
invoke : {
352
330
src : "startWorkspace" ,
353
331
id : "startWorkspace" ,
@@ -366,7 +344,7 @@ export const workspaceMachine = createMachine(
366
344
} ,
367
345
} ,
368
346
requestingStop : {
369
- entry : [ "clearBuildError" , "updateStatusToStopping" ] ,
347
+ entry : "clearBuildError" ,
370
348
invoke : {
371
349
src : "stopWorkspace" ,
372
350
id : "stopWorkspace" ,
@@ -385,7 +363,7 @@ export const workspaceMachine = createMachine(
385
363
} ,
386
364
} ,
387
365
requestingDelete : {
388
- entry : [ "clearBuildError" , "updateStatusToDeleting" ] ,
366
+ entry : "clearBuildError" ,
389
367
invoke : {
390
368
src : "deleteWorkspace" ,
391
369
id : "deleteWorkspace" ,
@@ -404,11 +382,7 @@ export const workspaceMachine = createMachine(
404
382
} ,
405
383
} ,
406
384
requestingCancel : {
407
- entry : [
408
- "clearCancellationMessage" ,
409
- "clearCancellationError" ,
410
- "updateStatusToCanceling" ,
411
- ] ,
385
+ entry : [ "clearCancellationMessage" , "clearCancellationError" ] ,
412
386
invoke : {
413
387
src : "cancelWorkspace" ,
414
388
id : "cancelWorkspace" ,
@@ -456,7 +430,9 @@ export const workspaceMachine = createMachine(
456
430
on : {
457
431
REFRESH_TIMELINE : {
458
432
target : "#workspaceState.ready.timeline.gettingBuilds" ,
459
- cond : "moreBuildsAvailable" ,
433
+ cond : {
434
+ type : "moreBuildsAvailable" ,
435
+ } ,
460
436
} ,
461
437
} ,
462
438
} ,
@@ -623,46 +599,9 @@ export const workspaceMachine = createMachine(
623
599
} ) ,
624
600
{ to : "scheduleBannerMachine" } ,
625
601
) ,
626
- // Optimistically updates. So when the user clicks on stop, we can show
627
- // the "stopping" state right away without having to wait 0.5s ~ 2s to
628
- // display the visual feedback to the user.
629
- updateStatusToStarting : assign ( {
630
- workspace : ( { workspace } ) =>
631
- updateWorkspaceStatus ( "starting" , workspace ) ,
632
- } ) ,
633
- updateStatusToStopping : assign ( {
634
- workspace : ( { workspace } ) =>
635
- updateWorkspaceStatus ( "stopping" , workspace ) ,
636
- } ) ,
637
- updateStatusToDeleting : assign ( {
638
- workspace : ( { workspace } ) =>
639
- updateWorkspaceStatus ( "deleting" , workspace ) ,
640
- } ) ,
641
- updateStatusToCanceling : assign ( {
642
- workspace : ( { workspace } ) =>
643
- updateWorkspaceStatus ( "canceling" , workspace ) ,
644
- } ) ,
645
602
} ,
646
603
guards : {
647
604
moreBuildsAvailable,
648
- // We only want to update the workspace when there are changes to it to
649
- // avoid re-renderings and allow optimistically updates to improve the UI.
650
- // When updating the workspace every second, the optimistic updates that
651
- // were applied before get lost since it will be rewrite.
652
- hasUpdates : ( { workspace } , event : { data : TypesGen . Workspace } ) => {
653
- if ( ! workspace ) {
654
- throw new Error ( "Workspace not defined" )
655
- }
656
- const isWorkspaceUpdated = isUpdated (
657
- event . data . updated_at ,
658
- workspace . updated_at ,
659
- )
660
- const isBuildUpdated = isUpdated (
661
- event . data . latest_build . updated_at ,
662
- workspace . latest_build . updated_at ,
663
- )
664
- return isWorkspaceUpdated || isBuildUpdated
665
- } ,
666
605
} ,
667
606
services : {
668
607
getWorkspace : async ( _ , event ) => {
0 commit comments