@@ -3,14 +3,12 @@ import CircularProgress from "@material-ui/core/CircularProgress"
3
3
import Link from "@material-ui/core/Link"
4
4
import { makeStyles } from "@material-ui/core/styles"
5
5
import Tooltip from "@material-ui/core/Tooltip"
6
- import ComputerIcon from "@material-ui/icons/Computer"
7
- import PublicOutlinedIcon from "@material-ui/icons/PublicOutlined"
8
- import LockOutlinedIcon from "@material-ui/icons/LockOutlined"
9
- import GroupOutlinedIcon from "@material-ui/icons/GroupOutlined"
10
6
import ErrorOutlineIcon from "@material-ui/icons/ErrorOutline"
11
- import { FC , PropsWithChildren } from "react"
7
+ import { FC } from "react"
12
8
import * as TypesGen from "../../api/typesGenerated"
13
9
import { generateRandomString } from "../../util/random"
10
+ import { BaseIcon } from "./BaseIcon"
11
+ import { ShareIcon } from "./ShareIcon"
14
12
15
13
export const Language = {
16
14
appTitle : ( appName : string , identifier : string ) : string =>
@@ -19,76 +17,50 @@ export const Language = {
19
17
20
18
export interface AppLinkProps {
21
19
appsHost ?: string
22
- username : TypesGen . User [ "username" ]
23
- workspaceName : TypesGen . Workspace [ "name" ]
24
- agentName : TypesGen . WorkspaceAgent [ "name" ]
25
- appName : TypesGen . WorkspaceApp [ "name" ]
26
- appIcon ?: TypesGen . WorkspaceApp [ "icon" ]
27
- appCommand ?: TypesGen . WorkspaceApp [ "command" ]
28
- appSubdomain : TypesGen . WorkspaceApp [ "subdomain" ]
29
- appSharingLevel : TypesGen . WorkspaceApp [ "sharing_level" ]
30
- health : TypesGen . WorkspaceApp [ "health" ]
20
+ workspace : TypesGen . Workspace
21
+ app : TypesGen . WorkspaceApp
22
+ agent : TypesGen . WorkspaceAgent
31
23
}
32
24
33
- export const AppLink : FC < PropsWithChildren < AppLinkProps > > = ( {
25
+ export const AppLink : FC < AppLinkProps > = ( {
34
26
appsHost,
35
- username,
36
- workspaceName,
37
- agentName,
38
- appName,
39
- appIcon,
40
- appCommand,
41
- appSubdomain,
42
- appSharingLevel,
43
- health,
27
+ app,
28
+ workspace,
29
+ agent,
44
30
} ) => {
45
31
const styles = useStyles ( )
32
+ const username = workspace . owner_name
46
33
47
34
// The backend redirects if the trailing slash isn't included, so we add it
48
35
// here to avoid extra roundtrips.
49
- let href = `/@${ username } /${ workspaceName } .${ agentName } /apps/ ${ encodeURIComponent (
50
- appName ,
51
- ) } /`
52
- if ( appCommand ) {
53
- href = `/@${ username } /${ workspaceName } .${ agentName } /terminal?command= ${ encodeURIComponent (
54
- appCommand ,
55
- ) } `
36
+ let href = `/@${ username } /${ workspace . name } .${
37
+ agent . name
38
+ } /apps/ ${ encodeURIComponent ( app . name ) } /`
39
+ if ( app . command ) {
40
+ href = `/@${ username } /${ workspace . name } .${
41
+ agent . name
42
+ } /terminal?command= ${ encodeURIComponent ( app . command ) } `
56
43
}
57
- if ( appsHost && appSubdomain ) {
58
- const subdomain = `${ appName } --${ agentName } --${ workspaceName } --${ username } `
44
+ if ( appsHost && app . subdomain ) {
45
+ const subdomain = `${ app . name } --${ agent . name } --${ workspace . name } --${ username } `
59
46
href = `${ window . location . protocol } //${ appsHost } /` . replace ( "*" , subdomain )
60
47
}
61
48
62
49
let canClick = true
63
- let icon = appIcon ? (
64
- < img alt = { `${ appName } Icon` } src = { appIcon } />
65
- ) : (
66
- < ComputerIcon />
67
- )
68
-
69
- let shareIcon = < LockOutlinedIcon />
70
- let shareTooltip = "Private, only accessible by you"
71
- if ( appSharingLevel === "authenticated" ) {
72
- shareIcon = < GroupOutlinedIcon />
73
- shareTooltip = "Shared with all authenticated users"
74
- }
75
- if ( appSharingLevel === "public" ) {
76
- shareIcon = < PublicOutlinedIcon />
77
- shareTooltip = "Shared publicly"
78
- }
50
+ let icon = < BaseIcon app = { app } />
79
51
80
52
let primaryTooltip = ""
81
- if ( health === "initializing" ) {
53
+ if ( app . health === "initializing" ) {
82
54
canClick = false
83
55
icon = < CircularProgress size = { 16 } />
84
56
primaryTooltip = "Initializing..."
85
57
}
86
- if ( health === "unhealthy" ) {
58
+ if ( app . health === "unhealthy" ) {
87
59
canClick = false
88
60
icon = < ErrorOutlineIcon className = { styles . unhealthyIcon } />
89
61
primaryTooltip = "Unhealthy"
90
62
}
91
- if ( ! appsHost && appSubdomain ) {
63
+ if ( ! appsHost && app . subdomain ) {
92
64
canClick = false
93
65
icon = < ErrorOutlineIcon className = { styles . notConfiguredIcon } />
94
66
primaryTooltip =
@@ -99,11 +71,11 @@ export const AppLink: FC<PropsWithChildren<AppLinkProps>> = ({
99
71
< Button
100
72
size = "small"
101
73
startIcon = { icon }
102
- endIcon = { < Tooltip title = { shareTooltip } > { shareIcon } </ Tooltip > }
74
+ endIcon = { < ShareIcon app = { app } / >}
103
75
className = { styles . button }
104
76
disabled = { ! canClick }
105
77
>
106
- < span className = { styles . appName } > { appName } </ span >
78
+ < span className = { styles . appName } > { app . name } </ span >
107
79
</ Button >
108
80
)
109
81
@@ -120,7 +92,7 @@ export const AppLink: FC<PropsWithChildren<AppLinkProps>> = ({
120
92
event . preventDefault ( )
121
93
window . open (
122
94
href ,
123
- Language . appTitle ( appName , generateRandomString ( 12 ) ) ,
95
+ Language . appTitle ( app . name , generateRandomString ( 12 ) ) ,
124
96
"width=900,height=600" ,
125
97
)
126
98
}
0 commit comments