diff --git a/pkg/capi/index.ts b/pkg/capi/index.ts index 34b60d5..a59ba5d 100644 --- a/pkg/capi/index.ts +++ b/pkg/capi/index.ts @@ -38,36 +38,36 @@ export default function(plugin: IPlugin): void { ); // add enable auto-import action to namespace table - // plugin.addAction(ActionLocation.TABLE, - // { path: [{ urlPath: '/c/local/explorer/projectsnamespaces', exact: true }, { urlPath: 'cluster.x-k8s.io.cluster', endsWith: true }] }, - // { - // labelKey: 'capi.autoImport.enableAction', - // icon: 'icon-plus', - // enabled(target: any) { - // return target.metadata.labels[LABELS.AUTO_IMPORT] !== 'true'; - // }, - // invoke(opts, resources = []) { - // resources.forEach((ns) => { - // toggleAutoImport(ns); - // }); - // } - // }); + plugin.addAction(ActionLocation.TABLE, + { path: [{ urlPath: '/c/local/explorer/projectsnamespaces', exact: true }, { urlPath: 'cluster.x-k8s.io.cluster', endsWith: true }] }, + { + labelKey: 'capi.autoImport.enableAction', + icon: 'icon-plus', + enabled(target: any) { + return target?.metadata?.labels?.[LABELS.AUTO_IMPORT] !== 'true'; + }, + invoke(opts, resources = []) { + resources.forEach((ns) => { + toggleAutoImport(ns); + }); + } + }); // add disable auto-import action to namespace table - // plugin.addAction(ActionLocation.TABLE, - // { path: [{ urlPath: '/c/local/explorer/projectsnamespaces', exact: true }, { urlPath: 'cluster.x-k8s.io.cluster', endsWith: true }] }, - // { - // labelKey: 'capi.autoImport.disableAction', - // icon: 'icon-minus', - // enabled(target: any) { - // return target.metadata.labels[LABELS.AUTO_IMPORT] === 'true'; - // }, - // invoke(opts, resources = []) { - // resources.forEach((ns) => { - // toggleAutoImport(ns); - // }); - // } - // }); + plugin.addAction(ActionLocation.TABLE, + { path: [{ urlPath: '/c/local/explorer/projectsnamespaces', exact: true }, { urlPath: 'cluster.x-k8s.io.cluster', endsWith: true }] }, + { + labelKey: 'capi.autoImport.disableAction', + icon: 'icon-minus', + enabled(target: any) { + return target?.metadata?.labels?.[LABELS.AUTO_IMPORT] === 'true'; + }, + invoke(opts, resources = []) { + resources.forEach((ns) => { + toggleAutoImport(ns); + }); + } + }); // add column to namespace table plugin.addTableColumn( diff --git a/pkg/capi/util/auto-import.ts b/pkg/capi/util/auto-import.ts index 32bd069..546d8b6 100644 --- a/pkg/capi/util/auto-import.ts +++ b/pkg/capi/util/auto-import.ts @@ -4,6 +4,9 @@ export default function(resource: any) { if (resource?.metadata?.labels?.[LABELS.AUTO_IMPORT] === 'true') { delete resource.metadata.labels[LABELS.AUTO_IMPORT]; } else { + if (!resource.metadata.labels) { + resource.metadata.labels = {}; + } resource.metadata.labels[LABELS.AUTO_IMPORT] = 'true'; } try {