1
1
import { Icon } from '@iconify/react' ;
2
- import { useTheme } from '@mui/material' ;
2
+ import { Checkbox , useTheme } from '@mui/material' ;
3
3
import Box from '@mui/material/Box' ;
4
4
import IconButton from '@mui/material/IconButton' ;
5
5
import ListItemText from '@mui/material/ListItemText' ;
@@ -25,13 +25,32 @@ import { ConfirmDialog } from '../../common';
25
25
import ResourceTable from '../../common/Resource/ResourceTable' ;
26
26
import RecentClusters from './RecentClusters' ;
27
27
28
+ /**
29
+ * Gets the origin of a cluster.
30
+ *
31
+ * @param cluster
32
+ * @returns A description of where the cluster is picked up from: dynamic, in-cluster, or from a kubeconfig file.
33
+ */
34
+ function getOrigin ( cluster : Cluster ) : string {
35
+ if ( cluster . meta_data ?. source === 'kubeconfig' ) {
36
+ const kubeconfigPath = process . env . KUBECONFIG ?? '~/.kube/config' ;
37
+ return `Kubeconfig: ${ kubeconfigPath } ` ;
38
+ } else if ( cluster . meta_data ?. source === 'dynamic_cluster' ) {
39
+ return t ( 'translation|Plugin' ) ;
40
+ } else if ( cluster . meta_data ?. source === 'in_cluster' ) {
41
+ return t ( 'translation|In-cluster' ) ;
42
+ }
43
+ return 'Unknown' ;
44
+ }
45
+
28
46
function ContextMenu ( { cluster } : { cluster : Cluster } ) {
29
47
const { t } = useTranslation ( [ 'translation' ] ) ;
30
48
const history = useHistory ( ) ;
31
49
const dispatch = useDispatch ( ) ;
32
50
const [ anchorEl , setAnchorEl ] = React . useState < null | HTMLElement > ( null ) ;
33
51
const menuId = useId ( 'context-menu' ) ;
34
52
const [ openConfirmDialog , setOpenConfirmDialog ] = React . useState ( false ) ;
53
+ const [ openDeleteDynamicDialog , setOpenDeleteDynamicDialog ] = React . useState ( false ) ;
35
54
36
55
function removeCluster ( cluster : Cluster ) {
37
56
deleteCluster ( cluster . name || '' )
@@ -92,7 +111,8 @@ function ContextMenu({ cluster }: { cluster: Cluster }) {
92
111
>
93
112
< ListItemText > { t ( 'translation|Settings' ) } </ ListItemText >
94
113
</ MenuItem >
95
- { helpers . isElectron ( ) && cluster . meta_data ?. source === 'dynamic_cluster' && (
114
+
115
+ { helpers . isElectron ( ) && (
96
116
< MenuItem
97
117
onClick = { ( ) => {
98
118
setOpenConfirmDialog ( true ) ;
@@ -108,17 +128,52 @@ function ContextMenu({ cluster }: { cluster: Cluster }) {
108
128
open = { openConfirmDialog }
109
129
handleClose = { ( ) => setOpenConfirmDialog ( false ) }
110
130
onConfirm = { ( ) => {
111
- setOpenConfirmDialog ( false ) ;
112
- removeCluster ( cluster ) ;
131
+ if ( cluster . meta_data ?. source !== 'dynamic_cluster' ) {
132
+ setOpenDeleteDynamicDialog ( true ) ;
133
+ } else {
134
+ setOpenConfirmDialog ( false ) ;
135
+ removeCluster ( cluster ) ;
136
+ }
113
137
} }
114
138
title = { t ( 'translation|Delete Cluster' ) }
115
139
description = { t (
116
- 'translation|Are you sure you want to remove the cluster "{{ clusterName }}"?' ,
140
+ 'translation|Are you sure you want to remove the cluster "{{ clusterName }}"? from {{ source }} ' ,
117
141
{
118
142
clusterName : cluster . name ,
143
+ source : getOrigin ( cluster ) ,
119
144
}
120
145
) }
121
146
/>
147
+
148
+ < ConfirmDialog
149
+ open = { openDeleteDynamicDialog }
150
+ handleClose = { ( ) => setOpenDeleteDynamicDialog ( false ) }
151
+ onConfirm = { ( ) => {
152
+ setOpenDeleteDynamicDialog ( false ) ;
153
+ removeCluster ( cluster ) ;
154
+ } }
155
+ title = { t ( 'translation|Delete Cluster' ) }
156
+ description = {
157
+ < >
158
+ { t (
159
+ 'translation|The cluster "{{ clusterName }}" is not a dynamic cluster from Headlamp, this cluster will be deleted from {{ source }}.' ,
160
+ {
161
+ clusterName : cluster . name ,
162
+ source : getOrigin ( cluster ) ,
163
+ }
164
+ ) }
165
+
166
+ < >
167
+ < Typography > Accept</ Typography >
168
+ < Checkbox
169
+ checked = { false }
170
+ onChange = { ( ) => { } }
171
+ inputProps = { { 'aria-label' : 'primary checkbox' } }
172
+ />
173
+ </ >
174
+ </ >
175
+ }
176
+ />
122
177
</ >
123
178
) ;
124
179
}
@@ -239,24 +294,6 @@ function HomeComponent(props: HomeComponentProps) {
239
294
. sort ( ) ;
240
295
}
241
296
242
- /**
243
- * Gets the origin of a cluster.
244
- *
245
- * @param cluster
246
- * @returns A description of where the cluster is picked up from: dynamic, in-cluster, or from a kubeconfig file.
247
- */
248
- function getOrigin ( cluster : Cluster ) : string {
249
- if ( cluster . meta_data ?. source === 'kubeconfig' ) {
250
- const kubeconfigPath = process . env . KUBECONFIG ?? '~/.kube/config' ;
251
- return `Kubeconfig: ${ kubeconfigPath } ` ;
252
- } else if ( cluster . meta_data ?. source === 'dynamic_cluster' ) {
253
- return t ( 'translation|Plugin' ) ;
254
- } else if ( cluster . meta_data ?. source === 'in_cluster' ) {
255
- return t ( 'translation|In-cluster' ) ;
256
- }
257
- return 'Unknown' ;
258
- }
259
-
260
297
const memoizedComponent = React . useMemo (
261
298
( ) => (
262
299
< PageGrid >
0 commit comments