Skip to content

Commit

Permalink
fix auto-import action when cluster has no labels (#28)
Browse files Browse the repository at this point in the history
Co-authored-by: Evgeniya Vashkevich <evgeniya.vashkevich@suse.com>
  • Loading branch information
mantis-toboggan-md and eva-vashkevich committed Jan 27, 2024
1 parent 76afa65 commit 3045090
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
56 changes: 28 additions & 28 deletions pkg/capi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions pkg/capi/util/auto-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3045090

Please sign in to comment.