Skip to content

Commit

Permalink
redirect to topology when resource created from dev-catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil143 committed Feb 26, 2020
1 parent 7bac664 commit 8c2fcf1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
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 @@ -39,6 +39,7 @@ import { CreateYAML } from '@console/internal/components/create-yaml';
import { RadioGroup } from '@console/internal/components/radio';
import { ConfigureUpdateStrategy } from '@console/internal/components/modals/configure-update-strategy-modal';
import { ExpandCollapse } from '@console/internal/components/utils/expand-collapse';
import { getActivePerspective } from '@console/internal/reducers/ui';
import * as classNames from 'classnames';
import * as _ from 'lodash';
import { Helmet } from 'react-helmet';
Expand Down Expand Up @@ -232,6 +233,7 @@ const fieldsForOpenAPI = (openAPI: SwaggerDefinition): OperandField[] => {

export const CreateOperandForm: React.FC<CreateOperandFormProps> = ({
clusterServiceVersion,
activePerspective,
openAPI,
operandModel,
providedAPI,
Expand Down Expand Up @@ -428,19 +430,29 @@ export const CreateOperandForm: React.FC<CreateOperandFormProps> = ({
k8sCreate(operandModel, k8sObj)
.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 }) => {
setError(err.json.message);
});
}
},
[clusterServiceVersion.metadata.name, fields, formValues, k8sObj, namespace, operandModel],
[
clusterServiceVersion.metadata.name,
fields,
formValues,
k8sObj,
namespace,
operandModel,
activePerspective,
],
);

// TODO(alecmerdler): Move this into a single `<SpecDescriptorInput>` entry component in the `descriptors/` directory
Expand Down Expand Up @@ -1116,11 +1128,13 @@ export const CreateOperandYAML: React.FC<CreateOperandYAMLProps> = (props) => {
console.error('Error parsing example JSON from annotation. Falling back to default.');
}
const resourceObjPath = () =>
`${resourcePathFromModel(
ClusterServiceVersionModel,
props.match.params.appName,
props.match.params.ns,
)}/${props.match.params.plural}`;
props.activePerspective === 'dev'
? `/topology`
: `${resourcePathFromModel(
ClusterServiceVersionModel,
props.match.params.appName,
props.match.params.ns,
)}/${props.match.params.plural}`;

const onChange = React.useCallback(
(yaml) => {
Expand Down Expand Up @@ -1154,6 +1168,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 @@ -1242,6 +1257,7 @@ export const CreateOperand: React.FC<CreateOperandProps> = ({
<StatusBox loaded={loaded} loadError={loadError} data={clusterServiceVersion}>
{(method === 'form' && (
<CreateOperandForm
activePerspective={activePerspective}
namespace={match.params.ns}
operandModel={operandModel}
providedAPI={providedAPI}
Expand All @@ -1253,6 +1269,7 @@ export const CreateOperand: React.FC<CreateOperandProps> = ({
)) ||
(method === 'yaml' && (
<CreateOperandYAML
activePerspective={activePerspective}
match={match}
sample={sample}
operandModel={operandModel}
Expand All @@ -1266,8 +1283,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 @@ -1308,6 +1326,7 @@ export type CreateOperandProps = {
loadError?: any;
clusterServiceVersion: FirehoseResult<ClusterServiceVersionKind>;
customResourceDefinition?: FirehoseResult<CustomResourceDefinitionKind>;
activePerspective: string;
};

export type CreateOperandFormProps = {
Expand All @@ -1318,6 +1337,7 @@ export type CreateOperandFormProps = {
clusterServiceVersion: ClusterServiceVersionKind;
sample?: K8sResourceKind;
namespace: string;
activePerspective: string;
};

export type CreateOperandYAMLProps = {
Expand All @@ -1327,6 +1347,7 @@ export type CreateOperandYAMLProps = {
clusterServiceVersion: ClusterServiceVersionKind;
sample?: 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

0 comments on commit 8c2fcf1

Please sign in to comment.