Skip to content

Commit

Permalink
disabled Serverless add actions is not displayed in topology menu
Browse files Browse the repository at this point in the history
  • Loading branch information
invincibleJai committed Nov 23, 2022
1 parent 7ad7c83 commit 874b13b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
38 changes: 34 additions & 4 deletions frontend/packages/knative-plugin/src/actions/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getCommonResourceActions } from '@console/app/src/actions/creators/comm
import { DeploymentActionFactory } from '@console/app/src/actions/creators/deployment-factory';
import { getHealthChecksAction } from '@console/app/src/actions/creators/health-checks-factory';
import { disabledActionsFilter } from '@console/dev-console/src/actions/add-resources';
import { getDisabledAddActions } from '@console/dev-console/src/utils/useAddActionExtensions';
import { Action } from '@console/dynamic-plugin-sdk';
import {
K8sResourceKind,
Expand All @@ -17,7 +18,14 @@ import { MoveConnectorAction } from '@console/topology/src/actions/edgeActions';
import { getModifyApplicationAction } from '@console/topology/src/actions/modify-application';
import { TYPE_APPLICATION_GROUP } from '@console/topology/src/const';
import { useKnativeEventingEnabled } from '../catalog/useEventSourceProvider';
import { EVENT_SINK_CATALOG_TYPE_ID, EVENT_SOURCE_CATALOG_TYPE_ID } from '../const';
import {
EVENTING_BROKER_ACTION_ID,
EVENTING_CHANNEL_ACTION_ID,
EVENT_SINK_ACTION_ID,
EVENT_SINK_CATALOG_TYPE_ID,
EVENT_SOURCE_ACTION_ID,
EVENT_SOURCE_CATALOG_TYPE_ID,
} from '../const';
import { RevisionModel, EventingBrokerModel, ServiceModel } from '../models';
import {
TYPE_EVENT_SOURCE,
Expand Down Expand Up @@ -143,6 +151,16 @@ export const useChannelActionProvider = (resource: K8sResourceKind) => {
return [actions, !inFlight, undefined];
};

const getEventingEnabledAddAction = () => {
const disabledAddActions = getDisabledAddActions();
return {
isEventSourceAddEnabled: !disabledAddActions?.includes(EVENT_SOURCE_ACTION_ID),
isEventSinkAddEnabled: !disabledAddActions?.includes(EVENT_SINK_ACTION_ID),
isChannelAddEnabled: !disabledAddActions?.includes(EVENTING_CHANNEL_ACTION_ID),
isBrokerAddEnabled: !disabledAddActions?.includes(EVENTING_BROKER_ACTION_ID),
};
};

export const useTopologyActionsProvider = ({
element,
connectorSource,
Expand All @@ -153,6 +171,12 @@ export const useTopologyActionsProvider = ({
const isEventSinkTypeEnabled = isCatalogTypeEnabled(EVENT_SINK_CATALOG_TYPE_ID);
const isEventSourceTypeEnabled = isCatalogTypeEnabled(EVENT_SOURCE_CATALOG_TYPE_ID);
const isEventingEnabled = useKnativeEventingEnabled();
const {
isEventSourceAddEnabled,
isEventSinkAddEnabled,
isChannelAddEnabled,
isBrokerAddEnabled,
} = getEventingEnabledAddAction();

const [namespace] = useActiveNamespace();
const actions = React.useMemo(() => {
Expand All @@ -163,14 +187,16 @@ export const useTopologyActionsProvider = ({
}
const path = application ? 'add-to-application' : 'add-to-project';
const addActions: Action[] = [];
if (isEventSinkTypeEnabled && isEventingEnabled) {
if (isEventSinkAddEnabled && isEventSinkTypeEnabled && isEventingEnabled) {
addActions.push(AddEventSinkAction(namespace, application, undefined, path));
}
if (isEventSourceTypeEnabled && isEventingEnabled) {
if (isEventSourceAddEnabled && isEventSourceTypeEnabled && isEventingEnabled) {
addActions.push(AddEventSourceAction(namespace, application, undefined, path));
}
if (isEventingEnabled) {
if (isEventingEnabled && isChannelAddEnabled) {
addActions.push(AddChannelAction(namespace, application, path));
}
if (isEventingEnabled && isBrokerAddEnabled) {
addActions.push(AddBrokerAction(namespace, application, path));
}
return addActions.filter(disabledActionsFilter);
Expand Down Expand Up @@ -226,7 +252,11 @@ export const useTopologyActionsProvider = ({
}, [
connectorSource,
element,
isBrokerAddEnabled,
isChannelAddEnabled,
isEventSinkAddEnabled,
isEventSinkTypeEnabled,
isEventSourceAddEnabled,
isEventSourceTypeEnabled,
isEventingEnabled,
namespace,
Expand Down
4 changes: 4 additions & 0 deletions frontend/packages/knative-plugin/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ export const EVENT_SOURCE_CATALOG_TYPE_ID = 'EventSource';
export const EVENT_SINK_CATALOG_TYPE_ID = 'EventSink';
export const FLAG_EVENT_SOURCE_PING = 'FLAG_EVENT_SOURCE_PING';
export const FLAG_KNATIVE_EVENTING_ENABLED = 'FLAG_KNATIVE_EVENTING_ENABLED';
export const EVENT_SOURCE_ACTION_ID = 'knative-event-source';
export const EVENT_SINK_ACTION_ID = 'knative-event-sink';
export const EVENTING_CHANNEL_ACTION_ID = 'knative-eventing-channel';
export const EVENTING_BROKER_ACTION_ID = 'knative-eventing-broker';

0 comments on commit 874b13b

Please sign in to comment.