Skip to content

Commit

Permalink
Added feature gate for CSV Actions in Installed Operators
Browse files Browse the repository at this point in the history
  • Loading branch information
bipuladh committed Mar 5, 2020
1 parent d98fd56 commit d047b3b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions frontend/packages/ceph-storage-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ const plugin: Plugin<ConsumedExtensions> = [
throw e;
});
},
disallowed: [OCS_INDEPENDENT_FLAG],
},
},
// Download External Cluster Metadata
Expand All @@ -238,6 +239,7 @@ const plugin: Plugin<ConsumedExtensions> = [
import(
'./components/converged-credentials/credentials' /* webpackChunkName: "ceph-storage-export-credentials" */
).then((m) => m.default({})),
disallowed: [OCS_INDEPENDENT_FLAG],
},
},
// Independent mode dashboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace ExtensionProperties {
apiGroup: string;
/** action callback */
callback: (kind: K8sResourceKindReference, obj: any) => () => any;
required?: string | string[];
disallowed?: string | string[];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ describe(OperandDetailsPage.displayName, () => {
<OperandDetailsPage.WrappedComponent
modelRef={referenceFor(testResourceInstance)}
match={match}
flags={{}}
/>,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { match } from 'react-router-dom';
import * as _ from 'lodash';
import { connect } from 'react-redux';
import { compose } from 'redux';
import * as classNames from 'classnames';
import { sortable } from '@patternfly/react-table';
import { Status, SuccessStatus } from '@console/shared';
Expand Down Expand Up @@ -54,6 +55,7 @@ import { SpecDescriptor } from './descriptors/spec';
import { StatusCapability, Descriptor } from './descriptors/types';
import { Resources } from './k8s-resource';
import { referenceForProvidedAPI, OperandLink } from './index';
import { FlagsObject, connectToFlags, WithFlagsProps } from '@console/internal/reducers/features';

const csvName = () =>
window.location.pathname
Expand All @@ -64,9 +66,10 @@ const csvName = () =>
allParts[i - 1] === ClusterServiceVersionModel.plural,
);

const getActions = (ref: K8sResourceKindReference) => {
const getActions = (ref: K8sResourceKindReference, flags: FlagsObject) => {
const actions = plugins.registry
.getClusterServiceVersionActions()
.filter((action) => plugins.registry.isExtensionInUse(action, flags))
.filter(
(action) =>
action.properties.kind === kindForReference(ref) &&
Expand Down Expand Up @@ -245,7 +248,9 @@ export const OperandStatusIconAndText: React.FunctionComponent<OperandStatusIcon
return iconAndText;
};

export const OperandTableRow: React.FC<OperandTableRowProps> = ({ obj, index, key, style }) => {
export const OperandTableRow = connectToFlags<OperandTableRowProps & WithFlagsProps>(
...plugins.registry.getGatingFlagNames([plugins.isClusterServiceVersionAction]),
)(({ obj, index, key, style, flags }) => {
return (
<TableRow id={obj.metadata.uid} index={index} trKey={key} style={style}>
<TableData className={tableColumnClasses[0]}>
Expand All @@ -271,16 +276,17 @@ export const OperandTableRow: React.FC<OperandTableRowProps> = ({ obj, index, ke
</TableData>
<TableData className={tableColumnClasses[6]}>
<ResourceKebab
actions={getActions(referenceFor(obj))}
actions={getActions(referenceFor(obj), flags)}
kind={referenceFor(obj)}
resource={obj}
/>
</TableData>
</TableRow>
);
};
});

export const OperandList: React.SFC<OperandListProps> = (props) => {
const Row = (rowProps: OperandTableRowProps) => <OperandTableRow {...rowProps} />;
const ensureKind = (data: K8sResourceKind[]) =>
data.map((obj) => {
if (obj.apiVersion && obj.kind) {
Expand All @@ -307,7 +313,7 @@ export const OperandList: React.SFC<OperandListProps> = (props) => {
EmptyMsg={EmptyMsg}
aria-label="Operands"
Header={OperandTableHeader}
Row={OperandTableRow}
Row={Row}
virtualize
/>
);
Expand Down Expand Up @@ -578,7 +584,12 @@ const ResourcesTab = (resourceProps) => (
<Resources {...resourceProps} clusterServiceVersion={resourceProps.csv} />
);

export const OperandDetailsPage = connectToPlural((props: OperandDetailsPageProps) => (
export const OperandDetailsPage = compose(
connectToFlags<OperandDetailsPageProps & WithFlagsProps>(
...plugins.registry.getGatingFlagNames([plugins.isClusterServiceVersionAction]),
),
connectToPlural,
)((props: OperandDetailsPageProps & WithFlagsProps) => (
<DetailsPage
match={props.match}
name={props.match.params.name}
Expand All @@ -593,7 +604,7 @@ export const OperandDetailsPage = connectToPlural((props: OperandDetailsPageProp
prop: 'csv',
},
]}
menuActions={getActions(props.modelRef)}
menuActions={getActions(props.modelRef, props.flags)}
breadcrumbsFor={() => [
{
name: 'Installed Operators',
Expand Down

0 comments on commit d047b3b

Please sign in to comment.