diff --git a/console-extensions.json b/console-extensions.json index caf9125a..1ff0a665 100644 --- a/console-extensions.json +++ b/console-extensions.json @@ -84,5 +84,16 @@ }, "component": { "$codeRef": "AddBrokerContainer.AddBrokerPage" } } + }, + { + "type": "console.action/provider", + "properties": { + "model": { + "group": "broker.amq.io", + "version": "v1beta1", + "kind": "ActiveMQArtemis" + }, + "provider": { "$codeRef": "CustomHooks.useProvideActiveMQArtemisActions" } + } } ] diff --git a/package.json b/package.json index 9ba8f212..f76ab170 100644 --- a/package.json +++ b/package.json @@ -115,7 +115,8 @@ "UpdateBrokerContainer": "./brokers/update-broker/UpdateBroker.container", "BrokerDetailsContainer": "./brokers/broker-details/BrokerDetails.container", "AddressesContainer": "./addresses/Addresses/Address.container", - "AddressDetailsContainer": "./addresses/Address-details/AddressDetails.container" + "AddressDetailsContainer": "./addresses/Address-details/AddressDetails.container", + "CustomHooks": "./k8s/customHooks.ts" }, "dependencies": { "@console/pluginAPI": "*" diff --git a/src/k8s/customHooks.ts b/src/k8s/customHooks.ts index 352d113c..794c699a 100644 --- a/src/k8s/customHooks.ts +++ b/src/k8s/customHooks.ts @@ -1,5 +1,12 @@ -import { k8sGet, useK8sModel } from '@openshift-console/dynamic-plugin-sdk'; -import { useState } from 'react'; +import { + Action, + ExtensionHook, + NodeKind, + k8sGet, + useDeleteModal, + useK8sModel, +} from '@openshift-console/dynamic-plugin-sdk'; +import { useMemo, useState } from 'react'; import { AMQBrokerModel, IngressDomainModel } from './models'; import { BrokerCR, Ingress } from './types'; @@ -104,3 +111,34 @@ export const useHasCertManager = (): { } return { hasCertManager: hasCertManager, isLoading: loading, error: error }; }; + +export const useProvideActiveMQArtemisActions: ExtensionHook< + Action[], + NodeKind +> = (obj) => { + const [kindObj, inFlight] = useK8sModel({ + group: 'broker.amq.io', + version: 'v1beta1', + kind: 'ActiveMQArtemis', + }); + const deleteModal = useDeleteModal(obj); + const nodeActions = useMemo(() => { + const actions: Action[] = []; + actions.push({ + id: `delete-resource`, + label: 'Delete Broker', + cta: () => deleteModal(), + accessReview: { + group: kindObj.apiGroup, + resource: kindObj.plural, + name: obj.metadata.name, + namespace: obj.metadata.namespace, + verb: 'delete', + }, + }); + + return actions; + }, [obj, deleteModal, kindObj]); + + return [nodeActions, !inFlight, undefined]; +};