1
1
import Button from "@material-ui/core/Button"
2
- import DeleteOutlined from "@material-ui/icons/DeleteOutlined"
3
2
import AddCircleOutline from "@material-ui/icons/AddCircleOutline"
4
- import SettingsOutlined from "@material-ui/icons/SettingsOutlined"
5
- import CodeOutlined from "@material-ui/icons/CodeOutlined"
6
3
import { AuthorizationResponse , Template } from "api/typesGenerated"
7
4
import { Avatar } from "components/Avatar/Avatar"
8
5
import { Maybe } from "components/Conditionals/Maybe"
@@ -13,10 +10,13 @@ import {
13
10
PageHeaderSubtitle ,
14
11
} from "components/PageHeader/PageHeader"
15
12
import { Stack } from "components/Stack/Stack"
16
- import { FC } from "react"
13
+ import { FC , useState } from "react"
17
14
import { Link as RouterLink } from "react-router-dom"
18
15
import { useDeleteTemplate } from "./deleteTemplate"
19
16
import { Margins } from "components/Margins/Margins"
17
+ import MoreVertOutlined from "@material-ui/icons/MoreVertOutlined"
18
+ import Menu from "@material-ui/core/Menu"
19
+ import MenuItem from "@material-ui/core/MenuItem"
20
20
21
21
const Language = {
22
22
editButton : "Edit" ,
@@ -26,31 +26,60 @@ const Language = {
26
26
deleteButton : "Delete" ,
27
27
}
28
28
29
- const TemplateSettingsButton : FC < { templateName : string } > = ( {
29
+ const TemplateMenu : FC < { templateName : string ; onDelete : ( ) => void } > = ( {
30
30
templateName,
31
- } ) => (
32
- < Button
33
- variant = "outlined"
34
- component = { RouterLink }
35
- to = { `/templates/${ templateName } /settings` }
36
- startIcon = { < SettingsOutlined /> }
37
- >
38
- { Language . settingsButton }
39
- </ Button >
40
- )
31
+ onDelete,
32
+ } ) => {
33
+ const [ anchorEl , setAnchorEl ] = useState < HTMLButtonElement | null > ( null )
41
34
42
- const TemplateVariablesButton : FC < { templateName : string } > = ( {
43
- templateName,
44
- } ) => (
45
- < Button
46
- variant = "outlined"
47
- component = { RouterLink }
48
- to = { `/templates/${ templateName } /variables` }
49
- startIcon = { < CodeOutlined /> }
50
- >
51
- { Language . variablesButton }
52
- </ Button >
53
- )
35
+ const handleClose = ( ) => {
36
+ setAnchorEl ( null )
37
+ }
38
+
39
+ return (
40
+ < div >
41
+ < Button
42
+ variant = "outlined"
43
+ aria-controls = "template-options"
44
+ aria-haspopup = "true"
45
+ onClick = { ( e ) => setAnchorEl ( e . currentTarget ) }
46
+ >
47
+ < MoreVertOutlined />
48
+ </ Button >
49
+
50
+ < Menu
51
+ id = "template-options"
52
+ anchorEl = { anchorEl }
53
+ keepMounted
54
+ open = { Boolean ( anchorEl ) }
55
+ onClose = { handleClose }
56
+ >
57
+ < MenuItem
58
+ onClick = { handleClose }
59
+ component = { RouterLink }
60
+ to = { `/templates/${ templateName } /settings` }
61
+ >
62
+ { Language . settingsButton }
63
+ </ MenuItem >
64
+ < MenuItem
65
+ component = { RouterLink }
66
+ to = { `/templates/${ templateName } /variables` }
67
+ onClick = { handleClose }
68
+ >
69
+ { Language . variablesButton }
70
+ </ MenuItem >
71
+ < MenuItem
72
+ onClick = { ( ) => {
73
+ onDelete ( )
74
+ handleClose ( )
75
+ } }
76
+ >
77
+ { Language . deleteButton }
78
+ </ MenuItem >
79
+ </ Menu >
80
+ </ div >
81
+ )
82
+ }
54
83
55
84
const CreateWorkspaceButton : FC < {
56
85
templateName : string
@@ -65,12 +94,6 @@ const CreateWorkspaceButton: FC<{
65
94
</ Button >
66
95
)
67
96
68
- const DeleteTemplateButton : FC < { onClick : ( ) => void } > = ( { onClick } ) => (
69
- < Button variant = "outlined" startIcon = { < DeleteOutlined /> } onClick = { onClick } >
70
- { Language . deleteButton }
71
- </ Button >
72
- )
73
-
74
97
export type TemplatePageHeaderProps = {
75
98
template : Template
76
99
permissions : AuthorizationResponse
@@ -90,14 +113,13 @@ export const TemplatePageHeader: FC<TemplatePageHeaderProps> = ({
90
113
< PageHeader
91
114
actions = {
92
115
< >
116
+ < CreateWorkspaceButton templateName = { template . name } />
93
117
< Maybe condition = { permissions . canUpdateTemplate } >
94
- < DeleteTemplateButton
95
- onClick = { deleteTemplate . openDeleteConfirmation }
118
+ < TemplateMenu
119
+ templateName = { template . name }
120
+ onDelete = { deleteTemplate . openDeleteConfirmation }
96
121
/>
97
- < TemplateSettingsButton templateName = { template . name } />
98
- < TemplateVariablesButton templateName = { template . name } />
99
122
</ Maybe >
100
- < CreateWorkspaceButton templateName = { template . name } />
101
123
</ >
102
124
}
103
125
>
0 commit comments