@@ -56,6 +56,19 @@ type ResourceRow = {
5656 conditionSyncedMessage : string ;
5757} ;
5858
59+ /**
60+ * Checks if a resource is managed by Flux based on the kustomize.toolkit.fluxcd.io/name label
61+ */
62+ const isResourceFluxManaged = ( item : ManagedResourceItem | undefined ) : boolean => {
63+ if ( ! item ) return false ;
64+
65+ const fluxLabelValue = ( item ?. metadata ?. labels as unknown as Record < string , unknown > | undefined ) ?. [
66+ 'kustomize.toolkit.fluxcd.io/name'
67+ ] ;
68+
69+ return fluxLabelValue != null && ( typeof fluxLabelValue !== 'string' || fluxLabelValue . trim ( ) !== '' ) ;
70+ } ;
71+
5972export function ManagedResources ( ) {
6073 const { t } = useTranslation ( ) ;
6174 const toast = useToast ( ) ;
@@ -169,11 +182,7 @@ export function ManagedResources() {
169182 disableFilters : true ,
170183 Cell : ( { row } ) => {
171184 const { original } = row ;
172- const fluxLabelValue = (
173- original ?. item ?. metadata ?. labels as unknown as Record < string , unknown > | undefined
174- ) ?. [ 'kustomize.toolkit.fluxcd.io/name' ] ;
175- const isFluxManaged =
176- typeof fluxLabelValue === 'string' ? fluxLabelValue . trim ( ) !== '' : fluxLabelValue != null ;
185+ const isFluxManaged = isResourceFluxManaged ( original ?. item ) ;
177186 return original ?. item ? (
178187 < YamlViewButton
179188 variant = "resource"
@@ -207,11 +216,7 @@ export function ManagedResources() {
207216 const item = original ?. item ;
208217 if ( ! item ) return undefined ;
209218
210- const fluxLabelValue = ( item ?. metadata ?. labels as unknown as Record < string , unknown > | undefined ) ?. [
211- 'kustomize.toolkit.fluxcd.io/name'
212- ] ;
213- const isFluxManaged =
214- typeof fluxLabelValue === 'string' ? fluxLabelValue . trim ( ) !== '' : fluxLabelValue != null ;
219+ const isFluxManaged = isResourceFluxManaged ( item ) ;
215220
216221 const actions : ActionItem < ManagedResourceItem > [ ] = [
217222 {
0 commit comments