@@ -2,24 +2,53 @@ import Box from "@material-ui/core/Box"
2
2
import Typography from "@material-ui/core/Typography"
3
3
import React from "react"
4
4
import { Link } from "react-router-dom"
5
- import { WorkspaceProps } from "../Workspace/Workspace"
5
+ import { WorkspaceStatus } from "../Workspace/Workspace"
6
6
import CloudCircleIcon from "@material-ui/icons/CloudCircle"
7
7
import { TitleIconSize } from "../../theme/constants"
8
8
import { makeStyles } from "@material-ui/core/styles"
9
9
import { WorkspaceSection } from "../WorkspaceSection/WorkspaceSection"
10
10
import { Stack } from "../Stack/Stack"
11
11
import Button from "@material-ui/core/Button"
12
12
import Divider from "@material-ui/core/Divider"
13
+ import * as Types from "../../api/types"
14
+
15
+ const Language = {
16
+ stop : "Stop" ,
17
+ start : "Start" ,
18
+ update : "Update" ,
19
+ settings : "Settings"
20
+ }
21
+ export interface WorkspaceStatusBarProps {
22
+ organization : Types . Organization
23
+ workspace : Types . Workspace
24
+ template : Types . Template
25
+ status : WorkspaceStatus
26
+ handleUpdate : ( ) => void
27
+ handleToggle : ( ) => void
28
+ }
13
29
14
30
/**
15
31
* Component for the header at the top of the workspace page
16
32
*/
17
- export const WorkspaceStatusBar : React . FC < WorkspaceProps > = ( { organization, template, workspace } ) => {
33
+ export const WorkspaceStatusBar : React . FC < WorkspaceStatusBarProps > = ( { organization, template, workspace, status , handleUpdate , handleToggle } ) => {
18
34
const styles = useStyles ( )
19
35
20
36
const templateLink = `/templates/${ organization . name } /${ template . name } `
21
- const action = "Start" // TODO don't let me merge this
22
- const outOfDate = false // TODO
37
+ const statusToAction : Record < WorkspaceStatus , string > = {
38
+ started : Language . stop ,
39
+ stopping : Language . stop ,
40
+ stopped : Language . start ,
41
+ starting : Language . start ,
42
+ }
43
+ // Cannot start or stop in the middle of starting or stopping
44
+ const statusToDisabled : Record < WorkspaceStatus , boolean > = {
45
+ started : false ,
46
+ stopping : true ,
47
+ stopped : false ,
48
+ starting : true
49
+ }
50
+ const action = statusToAction [ status ]
51
+ const actionDisabled = statusToDisabled [ status ]
23
52
24
53
return (
25
54
< WorkspaceSection >
@@ -37,12 +66,12 @@ export const WorkspaceStatusBar: React.FC<WorkspaceProps> = ({ organization, tem
37
66
</ div >
38
67
</ div >
39
68
< div className = { styles . horizontal } >
40
- < Button color = "primary" > { action } </ Button >
41
- { outOfDate &&
42
- < Button color = "primary" > Update </ Button >
69
+ < Button onClick = { handleToggle } disabled = { actionDisabled } color = "primary" > { action } </ Button >
70
+ { workspace . outdated &&
71
+ < Button onClick = { handleUpdate } color = "primary" > { Language . update } </ Button >
43
72
}
44
73
< Divider orientation = "vertical" flexItem />
45
- < Link className = { styles . link } to = { `workspaces/${ workspace . id } /edit` } > Settings </ Link >
74
+ < Link className = { styles . link } to = { `workspaces/${ workspace . id } /edit` } > { Language . settings } </ Link >
46
75
</ div >
47
76
</ div >
48
77
</ Stack >
0 commit comments