16
16
import { GroupVersionKind } from '@backstage-community/plugin-kiali-common/types' ;
17
17
import { Link } from '@backstage/core-components' ;
18
18
import { SubRouteRef } from '@backstage/core-plugin-api' ;
19
+ import { Drawer , IconButton } from '@material-ui/core' ;
20
+ import Close from '@material-ui/icons/Close' ;
19
21
import { default as React } from 'react' ;
22
+ import { AppDetailsDrawer } from '../components/Drawers/AppDetailsDrawer' ;
23
+ import { ServiceDetailsDrawer } from '../components/Drawers/ServiceDetailsDrawer' ;
24
+ import { WorkloadDetailsDrawer } from '../components/Drawers/WorkloadDetailsDrawer' ;
20
25
import { isMultiCluster } from '../config' ;
21
26
import {
22
27
appDetailRouteRef ,
@@ -68,6 +73,7 @@ interface BackstageLinkProps {
68
73
query ?: string ;
69
74
children ?: React . ReactNode ;
70
75
onClick ?: React . MouseEventHandler < HTMLAnchorElement > ;
76
+ useDrawer ?: boolean ; // New prop to control drawer behavior
71
77
}
72
78
73
79
/* const getRef = (type: string, entity?: boolean, root?: boolean) => {
@@ -82,29 +88,138 @@ interface BackstageLinkProps {
82
88
return backstageRoutesObject[type].ref;
83
89
};*/
84
90
91
+ // Component for drawer content
92
+ const DrawerContent = ( {
93
+ toggleDrawer,
94
+ type,
95
+ name,
96
+ namespace,
97
+ } : {
98
+ toggleDrawer : ( isOpen : boolean ) => void ;
99
+ type : string ;
100
+ name : string ;
101
+ namespace : string ;
102
+ } ) => {
103
+ return (
104
+ < div style = { { padding : '10px' , minWidth : '400px' } } data-test = "drawer" >
105
+ < div style = { { paddingBottom : '30px' } } >
106
+ < IconButton
107
+ key = "dismiss"
108
+ id = "close_drawer"
109
+ title = "Close the drawer"
110
+ onClick = { ( ) => toggleDrawer ( false ) }
111
+ color = "inherit"
112
+ style = { { right : '0' , position : 'absolute' , top : '5px' } }
113
+ >
114
+ < Close />
115
+ </ IconButton >
116
+ </ div >
117
+ < div />
118
+ < div >
119
+ { type === 'workloads' && (
120
+ < WorkloadDetailsDrawer namespace = { namespace } workload = { name } />
121
+ ) }
122
+ { type === 'services' && (
123
+ < ServiceDetailsDrawer namespace = { namespace } service = { name } />
124
+ ) }
125
+ { type === 'applications' && (
126
+ < AppDetailsDrawer namespace = { namespace } app = { name } />
127
+ ) }
128
+ </ div >
129
+ </ div >
130
+ ) ;
131
+ } ;
132
+
85
133
export const BackstageObjectLink = ( props : BackstageLinkProps ) => {
86
- const { name, type, query, cluster } = props ;
87
- /* const link: RouteFunc<routeRefParams> = useRouteRef(
88
- getRef(type, props.entity, props.root),
89
- );*/
90
- const to = '' ;
91
- /*
92
- if (!props.root) {
93
- const items: { [key: string]: string } = { namespace: '' };
134
+ const { name, type, query, cluster, namespace, objectGVK, useDrawer } = props ;
135
+ const [ isDrawerOpen , setIsDrawerOpen ] = React . useState ( false ) ;
94
136
95
- if (type && name) {
96
- items[backstageRoutesObject[type].id] = name;
97
- }
98
- if (objectType) {
99
- items.objectType = objectType;
137
+ // If useDrawer is true and we have the required props, show drawer behavior
138
+ if ( useDrawer && name && namespace && type && ! props . root ) {
139
+ return (
140
+ < >
141
+ < Link
142
+ to = "#"
143
+ component = "button"
144
+ onClick = { e => {
145
+ e . preventDefault ( ) ;
146
+ setIsDrawerOpen ( true ) ;
147
+ } }
148
+ data-test = { `${
149
+ type ? backstageRoutesObject [ type ] . id : ''
150
+ } -namespace-${ name } `}
151
+ style = { {
152
+ textDecoration : 'underline' ,
153
+ color : 'inherit' ,
154
+ background : 'none' ,
155
+ border : 'none' ,
156
+ cursor : 'pointer' ,
157
+ font : 'inherit' ,
158
+ } }
159
+ >
160
+ { props . children || name }
161
+ </ Link >
162
+ < Drawer
163
+ anchor = "right"
164
+ open = { isDrawerOpen }
165
+ onClose = { ( ) => setIsDrawerOpen ( false ) }
166
+ >
167
+ < DrawerContent
168
+ toggleDrawer = { setIsDrawerOpen }
169
+ type = { type }
170
+ name = { name }
171
+ namespace = { namespace }
172
+ />
173
+ </ Drawer >
174
+ </ >
175
+ ) ;
176
+ }
177
+
178
+ // Original link behavior
179
+ let to = '' ;
180
+
181
+ if ( ! props . root ) {
182
+ if ( type && name && namespace ) {
183
+ // Generate detail page URLs
184
+ switch ( type ) {
185
+ case 'workloads' :
186
+ to = `/workloads/${ namespace } /${ name } ` ;
187
+ break ;
188
+ case 'services' :
189
+ to = `/services/${ namespace } /${ name } ` ;
190
+ break ;
191
+ case 'applications' :
192
+ to = `/applications/${ namespace } /${ name } ` ;
193
+ break ;
194
+ case 'istio' :
195
+ if ( objectGVK ) {
196
+ to = `/istio/${ namespace } /${ objectGVK . Kind } /${ name } ` ;
197
+ }
198
+ break ;
199
+ default :
200
+ to = '' ;
201
+ }
100
202
}
101
- // link(items)
102
- to = link();
103
203
} else {
104
- to = link();
204
+ // Generate section URLs
205
+ switch ( type ) {
206
+ case 'workloads' :
207
+ to = '/workloads' ;
208
+ break ;
209
+ case 'services' :
210
+ to = '/services' ;
211
+ break ;
212
+ case 'applications' :
213
+ to = '/applications' ;
214
+ break ;
215
+ case 'istio' :
216
+ to = '/istio' ;
217
+ break ;
218
+ default :
219
+ to = '' ;
220
+ }
105
221
}
106
- console.log(to)
107
- */
222
+
108
223
const href = addQuery ( to , cluster , query ) ;
109
224
return (
110
225
< Link
0 commit comments