diff --git a/pkg/capi/l10n/en-us.yaml b/pkg/capi/l10n/en-us.yaml index fb4b057..63d9e00 100644 --- a/pkg/capi/l10n/en-us.yaml +++ b/pkg/capi/l10n/en-us.yaml @@ -1,3 +1,5 @@ +action: + createCluster: Create Cluster capi: installation: title: Rancher Turtles diff --git a/pkg/capi/models/cluster.x-k8s.io.clusterclass.js b/pkg/capi/models/cluster.x-k8s.io.clusterclass.js new file mode 100644 index 0000000..575623e --- /dev/null +++ b/pkg/capi/models/cluster.x-k8s.io.clusterclass.js @@ -0,0 +1,33 @@ +import SteveModel from '@shell/plugins/steve/steve-class'; +import { CAPI } from '@shell/config/types'; +import { BLANK_CLUSTER, QUERY_PARAMS } from '../types/capi'; + +export default class ClusterClass extends SteveModel { + get _availableActions() { + const out = super._availableActions; + + out.unshift({ + action: 'goToCreateCluster', + label: this.t('action.createCluster'), + icon: 'icon icon-plus', + enabled: true + }); + + return out; + } + + goToCreateCluster() { + const escapedID = escape(this.id); + const location = { + name: 'c-cluster-product-resource-create', + params: { + cluster: BLANK_CLUSTER, + product: 'manager', + resource: CAPI.CAPI_CLUSTER + }, + query: { [QUERY_PARAMS.CLASS]: escapedID } + }; + + this.currentRouter().push(location); + } +} diff --git a/pkg/capi/types/capi.ts b/pkg/capi/types/capi.ts index f75f6fe..761451b 100644 --- a/pkg/capi/types/capi.ts +++ b/pkg/capi/types/capi.ts @@ -1,5 +1,7 @@ export const CAPI_PRODUCT_NAME = 'capi-turtles'; +export const QUERY_PARAMS = { CLASS: 'class' }; + export const BLANK_CLUSTER = '_'; export const LABELS = { AUTO_IMPORT: 'cluster-api.cattle.io/rancher-auto-import' };