Skip to content

Commit

Permalink
refactor(cf): remove destination from the SG command model (spinnaker…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy Louie authored and jkschneider committed Apr 25, 2019
1 parent 62c2b51 commit 632538d
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class CloudfoundryCloneServerGroupStageConfig extends React.Component<
credentials: command.credentials,
capacity: command.capacity,
account: command.account,
destination: command.destination,
delayBeforeDisableSec: command.delayBeforeDisableSec,
freeFormDetails: command.freeFormDetails,
maxRemainingAsgs: command.maxRemainingAsgs,
Expand All @@ -40,6 +39,7 @@ export class CloudfoundryCloneServerGroupStageConfig extends React.Component<
target: command.target,
targetCluster: command.targetCluster,
manifest: command.manifest,
source: command.source,
});
this.setState({ buttonText: 'Edit clone configuration' });
};
Expand Down Expand Up @@ -80,10 +80,10 @@ export class CloudfoundryCloneServerGroupStageConfig extends React.Component<
</thead>
<tbody>
<tr>
<td>{stage.credentials}</td>
<td>{stage.region}</td>
<td>{stage.targetCluster}</td>
<td>{cloneTargets.filter(t => t.val === stage.target).map(t => t.label)}</td>
<td>{stage.source ? stage.source.account : ''}</td>
<td>{stage.source ? stage.source.region : ''}</td>
<td>{stage.source ? stage.source.targetCluster : ''}</td>
<td>{stage.source ? cloneTargets.filter(t => t.val === stage.source.target).map(t => t.label) : ''}</td>
</tr>
</tbody>
</table>
Expand All @@ -99,8 +99,8 @@ export class CloudfoundryCloneServerGroupStageConfig extends React.Component<
</thead>
<tbody>
<tr>
<td>{stage.account || ''}</td>
<td>{stage.destination ? stage.destination.region : ''}</td>
<td>{stage.credentials}</td>
<td>{stage.region}</td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface IFormikAccountRegionClusterSelectorProps {
cloudProvider: string;
clusterField?: string;
componentName?: string;
credentialsField?: string;
formik: FormikProps<ICloudFoundryCreateServerGroupCommand>;
}

Expand All @@ -31,6 +32,7 @@ export interface IFormikAccountRegionClusterSelectorState {
clusterField: string;
clusters: string[];
componentName: string;
credentialsField: string;
}

export class FormikAccountRegionClusterSelector extends React.Component<
Expand All @@ -41,19 +43,26 @@ export class FormikAccountRegionClusterSelector extends React.Component<

constructor(props: IFormikAccountRegionClusterSelectorProps) {
super(props);
const credentialsField = props.credentialsField || 'credentials';
const clusterField = props.clusterField || 'cluster';
this.state = {
availableRegions: [],
cloudProvider: props.cloudProvider,
clusterField: clusterField,
clusterField,
clusters: [],
componentName: props.componentName || '',
credentialsField,
};
}

public componentDidMount(): void {
const { componentName, formik } = this.props;
const credentials = get(formik.values, componentName ? `${componentName}.credentials` : 'credentials', undefined);
const { credentialsField } = this.state;
const credentials = get(
formik.values,
componentName ? `${componentName}.${credentialsField}` : `${credentialsField}`,
undefined,
);
const region = get(formik.values, componentName ? `${componentName}.region` : 'region', undefined);
this.setRegionList(credentials);
this.setClusterList(credentials, [region]);
Expand Down Expand Up @@ -94,18 +103,23 @@ export class FormikAccountRegionClusterSelector extends React.Component<

public regionChanged = (region: string): void => {
const { componentName, formik } = this.props;
const credentials = get(formik.values, componentName ? `${componentName}.credentials` : 'credentials', undefined);
const { credentialsField } = this.state;
const credentials = get(
formik.values,
componentName ? `${componentName}.${credentialsField}` : `${credentialsField}`,
undefined,
);
this.setClusterList(credentials, [region]);
};

public render() {
const { accounts } = this.props;
const { availableRegions, clusters, clusterField, componentName } = this.state;
const { credentialsField, availableRegions, clusters, clusterField, componentName } = this.state;
return (
<div className="col-md-9">
<div className="sp-margin-m-bottom">
<FormikFormField
name={componentName ? `${componentName}.credentials` : 'credentials'}
name={componentName ? `${componentName}.${credentialsField}` : `${credentialsField}`}
label="Account"
fastField={false}
input={props => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class CloudFoundryServerGroupCommandBuilder {
mode = 'clone',
): IPromise<ICloudFoundryCreateServerGroupCommand> {
return this.buildNewServerGroupCommand(app, { mode }).then(command => {
command.credentials = serverGroup.account;
command.credentials = '';
command.manifest = {
direct: {
memory: serverGroup.memory ? serverGroup.memory + 'M' : '1024M',
Expand All @@ -82,9 +82,14 @@ export class CloudFoundryServerGroupCommandBuilder {
healthCheckType: 'port',
},
};
command.region = serverGroup.region;
command.region = '';
command.stack = serverGroup.stack;
command.freeFormDetails = serverGroup.detail;
command.source = {
asgName: serverGroup.name,
region: serverGroup.region,
account: serverGroup.account,
};
return command;
});
}
Expand Down Expand Up @@ -150,7 +155,6 @@ export class CloudFoundryServerGroupCommandBuilder {
command.credentials = stage.credentials;
command.capacity = stage.capacity;
command.account = stage.account;
command.destination = stage.destination;
command.delayBeforeDisableSec = stage.delayBeforeDisableSec;
command.freeFormDetails = stage.freeFormDetails || command.freeFormDetails;
command.maxRemainingAsgs = stage.maxRemainingAsgs;
Expand All @@ -161,6 +165,7 @@ export class CloudFoundryServerGroupCommandBuilder {
command.target = stage.target;
command.targetCluster = stage.targetCluster;
command.manifest = stage.manifest || command.manifest;
command.source = stage.source;

command.viewState = {
...command.viewState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ICloudFoundryEnvVar } from 'cloudfoundry/domain';
export interface ICloudFoundryCreateServerGroupCommand extends IServerGroupCommand {
// clone server group model
account?: string;
destination?: ICloudFoundryDestination;
source?: ICloudFoundrySource;
rollback?: boolean;
target?: string;
Expand Down Expand Up @@ -35,10 +34,7 @@ export interface ICloudFoundrySource {
asgName: string;
region: string;
account: string;
}

export interface ICloudFoundryDestination {
region: string;
targetCluster?: string;
}

export interface ICloudFoundryManifestDirectSource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ export class CloudFoundryCreateServerGroupModal extends React.Component<
this.props.closeModal && this.props.closeModal(command);
} else if (command.viewState.mode === 'clone') {
this.state.taskMonitor.submit(() =>
ReactInjector.serverGroupWriter.cloneServerGroup(
{ destination: { region: command.region, account: command.credentials }, ...command },
this.props.application,
),
ReactInjector.serverGroupWriter.cloneServerGroup(command, this.props.application),
);
} else {
this.state.taskMonitor.submit(() =>
Expand All @@ -114,7 +111,7 @@ export class CloudFoundryCreateServerGroupModal extends React.Component<

public render(): React.ReactElement<CloudFoundryCreateServerGroupModal> {
const { loading, pipeline, isClone, requiresTemplateSelection, stage, taskMonitor } = this.state;
const { application, command, dismissModal, title, isSourceConstant, serverGroup } = this.props;
const { application, command, dismissModal, title, isSourceConstant } = this.props;

if (requiresTemplateSelection) {
return (
Expand Down Expand Up @@ -142,9 +139,7 @@ export class CloudFoundryCreateServerGroupModal extends React.Component<
label="Basic Settings"
wizard={wizard}
order={nextIdx()}
render={({ innerRef }) => (
<CloudFoundryServerGroupBasicSettings ref={innerRef} formik={formik} isClone={isClone} />
)}
render={({ innerRef }) => <CloudFoundryServerGroupBasicSettings ref={innerRef} formik={formik} />}
/>

{isClone && isSourceConstant && (
Expand All @@ -156,7 +151,7 @@ export class CloudFoundryCreateServerGroupModal extends React.Component<
<CloudFoundryServerGroupConstantArtifactSettings
ref={innerRef}
formik={formik}
serverGroup={serverGroup}
source={command.source}
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,47 @@
import * as React from 'react';

import { ICloudFoundryCreateServerGroupCommand } from 'cloudfoundry/serverGroup/configure/serverGroupConfigurationModel.cf';
import { ICloudFoundryServerGroup } from 'cloudfoundry/domain';
import { FormikProps } from 'formik';

import {
ICloudFoundryCreateServerGroupCommand,
ICloudFoundrySource,
} from 'cloudfoundry/serverGroup/configure/serverGroupConfigurationModel.cf';

export interface ICloudFoundryCloneServerGroupProps {
formik: FormikProps<ICloudFoundryCreateServerGroupCommand>;
serverGroup: ICloudFoundryServerGroup;
source: ICloudFoundrySource;
}

export class CloudFoundryServerGroupConstantArtifactSettings extends React.Component<
ICloudFoundryCloneServerGroupProps
> {
constructor(props: ICloudFoundryCloneServerGroupProps) {
super(props);
const { serverGroup } = props;

this.props.formik.values.source = {
account: serverGroup.account,
asgName: serverGroup.name,
region: serverGroup.region,
};
const { source } = props;
this.props.formik.setFieldValue('source', source);
}

public render(): JSX.Element {
const { serverGroup } = this.props;
const { source } = this.props;

return (
<div>
<div className="form-group row">
<label className="col-md-3 col-form-label sm-label-right">Account</label>
<div className="col-md-7">
<input className="form-control" type="text" id="cluster" value={serverGroup.account} readOnly={true} />
<input className="form-control" type="text" id="cluster" value={source.account} readOnly={true} />
</div>
</div>
<div className="form-group row">
<label className="col-md-3 col-form-label sm-label-right">Region</label>
<div className="col-md-7">
<input className="form-control" type="text" id="cluster" value={serverGroup.region} readOnly={true} />
</div>
</div>
<div className="form-group row">
<label className="col-md-3 col-form-label sm-label-right">Cluster</label>
<div className="col-md-7">
<input className="form-control" type="text" id="cluster" value={serverGroup.cluster} readOnly={true} />
<input className="form-control" type="text" id="cluster" value={source.region} readOnly={true} />
</div>
</div>
<div className="form-group row">
<label className="col-md-3 col-form-label sm-label-right">Server Group</label>
<div className="col-md-7">
<input className="form-control" type="text" id="cluster" value={serverGroup.name} readOnly={true} />
<input className="form-control" type="text" id="cluster" value={source.asgName} readOnly={true} />
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import 'cloudfoundry/common/cloudFoundry.less';

export interface ICloudFoundryServerGroupBasicSettingsProps {
formik: FormikProps<ICloudFoundryCreateServerGroupCommand>;
isClone: boolean;
}

export interface ICloudFoundryServerGroupLocationSettingsState {
Expand Down Expand Up @@ -57,13 +56,11 @@ export class CloudFoundryServerGroupBasicSettings

private accountChanged = (): void => {
this.updateRegionList();
const regionField = this.props.isClone ? 'destination.region' : 'region';
this.props.formik.setFieldValue(regionField, '');
this.props.formik.setFieldValue('region', '');
};

private updateRegionList = (): void => {
const accountField = this.props.isClone ? 'account' : 'credentials';
const credentials = get(this.props.formik.values, accountField, undefined);
const credentials = get(this.props.formik.values, 'credentials', undefined);
if (credentials) {
Observable.fromPromise(AccountService.getRegionsForAccount(credentials))
.takeUntil(this.destroy$)
Expand All @@ -80,17 +77,15 @@ export class CloudFoundryServerGroupBasicSettings
};

public render(): JSX.Element {
const { formik, isClone } = this.props;
const { formik } = this.props;
const { accounts, regions } = this.state;
const { values } = formik;
const accountField = isClone ? 'account' : 'credentials';
const regionField = isClone ? 'destination.region' : 'region';
return (
<div className="form-group">
<div className="col-md-11">
<div className="sp-margin-m-bottom">
<FormikFormField
name={accountField}
name="credentials"
label="Account"
fastField={false}
input={props => (
Expand All @@ -107,7 +102,7 @@ export class CloudFoundryServerGroupBasicSettings
</div>
<div className="sp-margin-m-bottom">
<FormikFormField
name={regionField}
name="region"
label="Region"
fastField={false}
input={props => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ export class CloudFoundryServerGroupCloneSettings
return (
<div className="form-group">
<FormikAccountRegionClusterSelector
componentName={'source'}
accounts={accounts}
application={application}
cloudProvider={'cloudfoundry'}
clusterField={'targetCluster'}
credentialsField={'account'}
formik={formik}
/>
<div className="col-md-9">
Expand Down

0 comments on commit 632538d

Please sign in to comment.