-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(provider/cf): refactor create SG to use FormikFormField
Co-Authored-By: Stu Pollock <spollock@pivotal.io>
- Loading branch information
Jammy Louie
and
Stu Pollock
committed
Dec 17, 2018
1 parent
c92d463
commit 59cab80
Showing
16 changed files
with
1,067 additions
and
1,137 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
app/scripts/modules/cloudfoundry/src/common/cloudFoundry.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.cloud-foundry-radio-button { | ||
margin-left: 20px; | ||
padding-left: 20px; | ||
padding-right: 20px; | ||
} | ||
|
||
.cloud-foundry-input { | ||
margin-left: 15px; | ||
} | ||
|
||
.cloud-foundry-checkbox { | ||
input[type='checkbox'] { | ||
margin-left: -5px; | ||
margin-top: 9px; | ||
} | ||
} |
154 changes: 154 additions & 0 deletions
154
...ts/modules/cloudfoundry/src/deploymentStrategy/CloudFoundryDeploymentStrategySelector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import * as React from 'react'; | ||
import * as DOMPurify from 'dompurify'; | ||
import Select, { Option } from 'react-select'; | ||
import { defaultsDeep, unset } from 'lodash'; | ||
|
||
import { | ||
HelpField, | ||
IDeploymentStrategy, | ||
IDeploymentStrategyAdditionalFieldsProps, | ||
IServerGroupCommand, | ||
} from '@spinnaker/core'; | ||
|
||
import { IRedBlackCommand } from 'cloudfoundry/deploymentStrategy/strategies/redblack/redblack.strategy'; | ||
import { AdditionalFields } from 'cloudfoundry/deploymentStrategy/strategies/redblack/AdditionalFields'; | ||
|
||
export interface ICloudFoundryDeploymentStrategySelectorProps { | ||
command: IServerGroupCommand; | ||
onFieldChange: (key: string, value: any) => void; | ||
onStrategyChange: (command: IServerGroupCommand, strategy: IDeploymentStrategy) => void; | ||
} | ||
|
||
export interface ICloudFoundryDeploymentStrategySelectorState { | ||
strategies: IDeploymentStrategy[]; | ||
currentStrategy: string; | ||
AdditionalFieldsComponent: React.ComponentType<IDeploymentStrategyAdditionalFieldsProps>; | ||
} | ||
|
||
export class CloudFoundryDeploymentStrategySelector extends React.Component< | ||
ICloudFoundryDeploymentStrategySelectorProps, | ||
ICloudFoundryDeploymentStrategySelectorState | ||
> { | ||
public state: ICloudFoundryDeploymentStrategySelectorState = { | ||
strategies: [ | ||
{ | ||
label: 'None', | ||
description: 'Creates the next server group with no impact on existing server groups', | ||
key: '', | ||
}, | ||
{ | ||
label: 'Highlander', | ||
description: | ||
'Destroys <i>all</i> previous server groups in the cluster as soon as new server group passes health checks', | ||
key: 'highlander', | ||
}, | ||
{ | ||
label: 'Red/Black', | ||
description: | ||
'Disables <i>all</i> previous server groups in the cluster as soon as new server group passes health checks', | ||
key: 'redblack', | ||
additionalFields: ['maxRemainingAsgs'], | ||
AdditionalFieldsComponent: AdditionalFields, | ||
initializationMethod: (command: IRedBlackCommand) => { | ||
defaultsDeep(command, { | ||
rollback: { | ||
onFailure: false, | ||
}, | ||
maxRemainingAsgs: 2, | ||
delayBeforeDisableSec: 0, | ||
delayBeforeScaleDownSec: 0, | ||
scaleDown: false, | ||
}); | ||
}, | ||
}, | ||
], | ||
currentStrategy: null, | ||
AdditionalFieldsComponent: undefined, | ||
}; | ||
|
||
public selectStrategy(strategy: string): void { | ||
const { command, onStrategyChange } = this.props; | ||
const oldStrategy = this.state.strategies.find(s => s.key === this.state.currentStrategy); | ||
const newStrategy = this.state.strategies.find(s => s.key === strategy); | ||
|
||
if (oldStrategy && oldStrategy.additionalFields) { | ||
oldStrategy.additionalFields.forEach(field => { | ||
if (!newStrategy || !newStrategy.additionalFields || !newStrategy.additionalFields.includes(field)) { | ||
unset(command, field); | ||
} | ||
}); | ||
} | ||
|
||
let AdditionalFieldsComponent; | ||
if (newStrategy) { | ||
AdditionalFieldsComponent = newStrategy.AdditionalFieldsComponent; | ||
if (newStrategy.initializationMethod) { | ||
newStrategy.initializationMethod(command); | ||
} | ||
} | ||
command.strategy = strategy; | ||
if (onStrategyChange && newStrategy) { | ||
onStrategyChange(command, newStrategy); | ||
} | ||
this.setState({ currentStrategy: strategy, AdditionalFieldsComponent }); | ||
} | ||
|
||
public strategyChanged = (option: Option<IDeploymentStrategy>) => { | ||
this.selectStrategy(option.key); | ||
}; | ||
|
||
public componentDidMount() { | ||
this.selectStrategy(this.props.command.strategy); | ||
} | ||
|
||
public render() { | ||
const { command, onFieldChange } = this.props; | ||
const { AdditionalFieldsComponent, currentStrategy, strategies } = this.state; | ||
const hasAdditionalFields = Boolean(AdditionalFieldsComponent); | ||
if (strategies && strategies.length) { | ||
return ( | ||
<div> | ||
<div className="StandardFieldLayout flex-container-h baseline margin-between-lg"> | ||
<div className={`sm-label-right`} style={{ paddingLeft: '13px' }}> | ||
Strategy | ||
<HelpField id="core.serverGroup.strategy" /> | ||
</div> | ||
<div className="flex-grow"> | ||
<Select | ||
clearable={false} | ||
required={true} | ||
options={strategies} | ||
placeholder="None" | ||
valueKey="key" | ||
value={currentStrategy} | ||
optionRenderer={this.strategyOptionRenderer} | ||
valueRenderer={o => <>{o.label}</>} | ||
onChange={this.strategyChanged} | ||
/> | ||
</div> | ||
</div> | ||
{hasAdditionalFields && ( | ||
<div className="form-group col-md-9 col-md-offset-3" style={{ marginTop: '5px', float: 'right' }}> | ||
<AdditionalFieldsComponent command={command} onChange={onFieldChange} /> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private strategyOptionRenderer = (option: IDeploymentStrategy) => { | ||
return ( | ||
<div className="body-regular"> | ||
<strong> | ||
<span dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(option.label) }} /> | ||
</strong> | ||
<div> | ||
<span dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(option.description) }} /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
} |
70 changes: 0 additions & 70 deletions
70
app/scripts/modules/cloudfoundry/src/deploymentStrategy/DeploymentStrategySelector.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.