Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1806914: redirect to topology when resource created from dev-catalog #4459

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ export const CreateOperandForm: React.FC<CreateOperandFormProps> = ({
operandModel,
providedAPI,
namespace,
activePerspective,
onToggleEditMethod = _.noop,
}) => {
// Map providedAPI spec descriptors and openAPI spec properties to OperandField[] array
Expand Down Expand Up @@ -700,11 +701,13 @@ export const CreateOperandForm: React.FC<CreateOperandFormProps> = ({
k8sCreate(operandModel, formData.setIn(['metadata', 'namespace'], namespace).toJS())
.then(() =>
history.push(
`${resourcePathFromModel(
ClusterServiceVersionModel,
clusterServiceVersion.metadata.name,
namespace,
)}/${referenceForModel(operandModel)}`,
activePerspective === 'dev'
? '/topology'
: `${resourcePathFromModel(
ClusterServiceVersionModel,
clusterServiceVersion.metadata.name,
namespace,
)}/${referenceForModel(operandModel)}`,
),
)
.catch((err: { json: Status }) => {
Expand Down Expand Up @@ -1306,6 +1309,7 @@ export type CreateOperandFormProps = {
clusterServiceVersion: ClusterServiceVersionKind;
buffer?: K8sResourceKind;
namespace: string;
activePerspective: string;
};

export type CreateOperandYAMLProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { referenceForProvidedAPI } from '.';

import Spy = jasmine.Spy;

const activePerspective = 'admin';

describe(CreateOperand.displayName, () => {
let wrapper: ShallowWrapper<CreateOperandProps>;

Expand All @@ -34,6 +36,7 @@ describe(CreateOperand.displayName, () => {
};
wrapper = shallow(
<CreateOperand
activePerspective={activePerspective}
operandModel={testModel}
clusterServiceVersion={{ data: testClusterServiceVersion, loaded: true, loadError: null }}
customResourceDefinition={{ data: testCRD, loaded: true, loadError: null }}
Expand Down Expand Up @@ -132,6 +135,7 @@ describe(CreateOperandForm.displayName, () => {
beforeEach(() => {
wrapper = shallow(
<CreateOperandForm
activePerspective={activePerspective}
namespace="default"
operandModel={testModel}
providedAPI={testClusterServiceVersion.spec.customresourcedefinitions.owned[0]}
Expand Down Expand Up @@ -207,6 +211,7 @@ describe(CreateOperandYAML.displayName, () => {
beforeEach(() => {
wrapper = shallow(
<CreateOperandYAML
activePerspective={activePerspective}
operandModel={testModel}
providedAPI={testClusterServiceVersion.spec.customresourcedefinitions.owned[0]}
clusterServiceVersion={testClusterServiceVersion}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { ClusterServiceVersionModel } from '../models';
import { ClusterServiceVersionKind, CRDDescription, APIServiceDefinition } from '../types';
import { CreateOperandForm, OperandField } from './create-operand-form';
import { providedAPIsFor, referenceForProvidedAPI } from '.';
import { getActivePerspective } from '@console/internal/reducers/ui';

/**
* Component which wraps the YAML editor to ensure the templates are added from the `ClusterServiceVersion` annotations.
Expand All @@ -39,6 +40,7 @@ export const CreateOperandYAML: React.FC<CreateOperandYAMLProps> = ({
clusterServiceVersion,
match,
operandModel,
activePerspective,
onToggleEditMethod = _.noop,
}) => {
const template = React.useMemo(() => _.attempt(() => safeDump(buffer)), [buffer]);
Expand All @@ -57,9 +59,13 @@ export const CreateOperandYAML: React.FC<CreateOperandYAMLProps> = ({
};

const resourceObjPath = () =>
`${resourcePathFromModel(ClusterServiceVersionModel, match.params.appName, match.params.ns)}/${
match.params.plural
}`;
activePerspective === 'dev'
? '/topology'
: `${resourcePathFromModel(
ClusterServiceVersionModel,
match.params.appName,
match.params.ns,
)}/${match.params.plural}`;

const onSwitchToForm = React.useCallback(() => {
onToggleEditMethod(parsedYAML);
Expand Down Expand Up @@ -112,6 +118,7 @@ export const CreateOperand: React.FC<CreateOperandProps> = ({
loadError,
match,
operandModel,
activePerspective,
}) => {
const { data: csv } = clusterServiceVersion;
const csvAnnotations = _.get(csv, 'metadata.annotations', {});
Expand Down Expand Up @@ -155,6 +162,7 @@ export const CreateOperand: React.FC<CreateOperandProps> = ({
}
return method === 'yaml' ? (
<CreateOperandYAML
activePerspective={activePerspective}
match={match}
buffer={buffer || defaultSample}
operandModel={operandModel}
Expand All @@ -164,6 +172,7 @@ export const CreateOperand: React.FC<CreateOperandProps> = ({
/>
) : (
<CreateOperandForm
activePerspective={activePerspective}
namespace={match.params.ns}
operandModel={operandModel}
providedAPI={providedAPI}
Expand All @@ -184,6 +193,7 @@ export const CreateOperand: React.FC<CreateOperandProps> = ({
openAPI,
operandModel,
providedAPI,
activePerspective,
]);

return (
Expand All @@ -193,8 +203,9 @@ export const CreateOperand: React.FC<CreateOperandProps> = ({
);
};

const stateToProps = ({ k8s }: RootState, props: Omit<CreateOperandPageProps, 'operandModel'>) => ({
operandModel: k8s.getIn(['RESOURCES', 'models', props.match.params.plural]) as K8sKind,
const stateToProps = (state: RootState, props: Omit<CreateOperandPageProps, 'operandModel'>) => ({
operandModel: state.k8s.getIn(['RESOURCES', 'models', props.match.params.plural]) as K8sKind,
activePerspective: getActivePerspective(state),
});

export const CreateOperandPage = connect(stateToProps)((props: CreateOperandPageProps) => (
Expand Down Expand Up @@ -237,6 +248,7 @@ export type CreateOperandProps = {
loadError?: any;
clusterServiceVersion: FirehoseResult<ClusterServiceVersionKind>;
customResourceDefinition?: FirehoseResult<CustomResourceDefinitionKind>;
activePerspective: string;
};

export type CreateOperandFormProps = {
Expand All @@ -247,6 +259,7 @@ export type CreateOperandFormProps = {
clusterServiceVersion: ClusterServiceVersionKind;
buffer?: K8sResourceKind;
namespace: string;
activePerspective: string;
};

export type CreateOperandYAMLProps = {
Expand All @@ -256,6 +269,7 @@ export type CreateOperandYAMLProps = {
clusterServiceVersion: ClusterServiceVersionKind;
buffer?: K8sResourceKind;
match: RouterMatch<{ appName: string; ns: string; plural: K8sResourceKindReference }>;
activePerspective: string;
};

export type CreateOperandPageProps = {
Expand Down
20 changes: 13 additions & 7 deletions frontend/public/components/instantiate-template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {
TemplateInstanceKind,
TemplateParameter,
} from '../module/k8s';
import { getActivePerspective } from '../reducers/ui';
import { RootState } from '../redux';

const TemplateResourceDetails: React.FC<TemplateResourceDetailsProps> = ({ template }) => {
const resources = _.uniq(_.compact(_.map(template.objects, 'kind'))).sort();
Expand Down Expand Up @@ -112,8 +114,9 @@ const TemplateInfo: React.FC<TemplateInfoProps> = ({ template }) => {
};
TemplateInfo.displayName = 'TemplateInfo';

const stateToProps = ({ k8s }) => ({
models: k8s.getIn(['RESOURCES', 'models']),
const stateToProps = (state: RootState) => ({
models: state.k8s.getIn(['RESOURCES', 'models']),
activePerspective: getActivePerspective(state),
});

class TemplateForm_ extends React.Component<TemplateFormProps, TemplateFormState> {
Expand Down Expand Up @@ -209,11 +212,13 @@ class TemplateForm_ extends React.Component<TemplateFormProps, TemplateFormState
return this.createTemplateInstance(secret).then((instance: TemplateInstanceKind) => {
this.setState({ inProgress: false });
history.push(
resourcePathFromModel(
TemplateInstanceModel,
instance.metadata.name,
instance.metadata.namespace,
),
this.props.activePerspective === 'dev'
? `/topology`
: resourcePathFromModel(
TemplateInstanceModel,
instance.metadata.name,
instance.metadata.namespace,
),
);
});
})
Expand Down Expand Up @@ -362,6 +367,7 @@ type TemplateFormProps = {
obj: any;
preselectedNamespace: string;
models: any;
activePerspective: string;
};

type TemplateFormState = {
Expand Down