@@ -33,8 +33,8 @@ function ContextMenu({ cluster }: { cluster: Cluster }) {
33
33
const menuId = useId ( 'context-menu' ) ;
34
34
const [ openConfirmDialog , setOpenConfirmDialog ] = React . useState ( false ) ;
35
35
36
- function removeCluster ( cluster : Cluster ) {
37
- deleteCluster ( cluster . name || '' )
36
+ function removeCluster ( cluster : Cluster , isDynamic : boolean = false ) {
37
+ deleteCluster ( cluster . name || '' , isDynamic )
38
38
. then ( config => {
39
39
dispatch ( setConfig ( config ) ) ;
40
40
} )
@@ -92,7 +92,7 @@ function ContextMenu({ cluster }: { cluster: Cluster }) {
92
92
>
93
93
< ListItemText > { t ( 'translation|Settings' ) } </ ListItemText >
94
94
</ MenuItem >
95
- { helpers . isElectron ( ) && cluster . meta_data ?. source === 'dynamic_cluster' && (
95
+ { helpers . isElectron ( ) && (
96
96
< MenuItem
97
97
onClick = { ( ) => {
98
98
setOpenConfirmDialog ( true ) ;
@@ -104,6 +104,26 @@ function ContextMenu({ cluster }: { cluster: Cluster }) {
104
104
) }
105
105
</ Menu >
106
106
107
+ < ConfirmDialog
108
+ open = { openConfirmDialog }
109
+ handleClose = { ( ) => setOpenConfirmDialog ( false ) }
110
+ onConfirm = { ( ) => {
111
+ setOpenConfirmDialog ( false ) ;
112
+ // to do: create a function that removes the cluster and also edits the kubeconfig
113
+ if ( cluster . meta_data ?. source === 'dynamic_cluster' ) {
114
+ removeCluster ( cluster , true ) ;
115
+ } else removeCluster ( cluster ) ;
116
+ } }
117
+ title = { t ( 'translation|Delete Cluster' ) }
118
+ description = { t (
119
+ 'translation|Are you sure you want to remove the cluster "{{ clusterName }}"? from "{{ clusterOrigin }}"' ,
120
+ {
121
+ clusterName : cluster . name ,
122
+ clusterOrigin : getOrigin ( cluster ) ,
123
+ }
124
+ ) }
125
+ />
126
+
107
127
< ConfirmDialog
108
128
open = { openConfirmDialog }
109
129
handleClose = { ( ) => setOpenConfirmDialog ( false ) }
@@ -113,9 +133,10 @@ function ContextMenu({ cluster }: { cluster: Cluster }) {
113
133
} }
114
134
title = { t ( 'translation|Delete Cluster' ) }
115
135
description = { t (
116
- 'translation|Are you sure you want to remove the cluster "{{ clusterName }}"?' ,
136
+ 'translation|Are you sure you want to remove the cluster "{{ clusterName }}"? from "{{ clusterOrigin }}" ' ,
117
137
{
118
138
clusterName : cluster . name ,
139
+ clusterOrigin : getOrigin ( cluster ) ,
119
140
}
120
141
) }
121
142
/>
@@ -162,6 +183,26 @@ function ClusterStatus({ error }: { error?: ApiError | null }) {
162
183
) ;
163
184
}
164
185
186
+ /**
187
+ * Gets the origin of a cluster.
188
+ *
189
+ * @param cluster
190
+ * @returns A description of where the cluster is picked up from: dynamic, in-cluster, or from a kubeconfig file.
191
+ */
192
+ function getOrigin ( cluster : Cluster ) : string {
193
+ const { t } = useTranslation ( [ 'translation' ] ) ;
194
+
195
+ if ( cluster . meta_data ?. source === 'kubeconfig' ) {
196
+ const kubeconfigPath = process . env . KUBECONFIG ?? '~/.kube/config' ;
197
+ return `Kubeconfig: ${ kubeconfigPath } ` ;
198
+ } else if ( cluster . meta_data ?. source === 'dynamic_cluster' ) {
199
+ return t ( 'translation|Plugin' ) ;
200
+ } else if ( cluster . meta_data ?. source === 'in_cluster' ) {
201
+ return t ( 'translation|In-cluster' ) ;
202
+ }
203
+ return 'Unknown' ;
204
+ }
205
+
165
206
export default function Home ( ) {
166
207
const history = useHistory ( ) ;
167
208
const clusters = useClustersConf ( ) || { } ;
@@ -239,24 +280,6 @@ function HomeComponent(props: HomeComponentProps) {
239
280
. sort ( ) ;
240
281
}
241
282
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
283
const memoizedComponent = React . useMemo (
261
284
( ) => (
262
285
< PageGrid >
0 commit comments