Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lavocatt committed Oct 31, 2024
1 parent b8294e7 commit 48aac97
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
11 changes: 11 additions & 0 deletions console-extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
}
}
]
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
Expand Down
42 changes: 40 additions & 2 deletions src/k8s/customHooks.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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<Action[]>(() => {
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];
};

0 comments on commit 48aac97

Please sign in to comment.