-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(kubernetes): convert scale manifest stage to react (#10151)
Co-authored-by: Matt Gogerly <6519811+mattgogerly@users.noreply.github.com>
- Loading branch information
1 parent
45bf17d
commit 269b738
Showing
11 changed files
with
167 additions
and
106 deletions.
There are no files selected for viewing
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
43 changes: 43 additions & 0 deletions
43
packages/kubernetes/src/manifest/scale/ScaleSettingsForm.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,43 @@ | ||
import React, { useState } from 'react'; | ||
import { NumberInput, StageConfigField } from '@spinnaker/core'; | ||
import type { IScaleCommand } from './scale.controller'; | ||
|
||
export interface IScaleSettingsFormProps { | ||
options: IScaleCommand; | ||
onChange(options: IScaleCommand): void; | ||
} | ||
|
||
export interface IScaleSettingsFormState { | ||
options: IScaleCommand; | ||
} | ||
|
||
export function ScaleSettingsForm({ options, onChange }: IScaleSettingsFormProps) { | ||
const [state, setState] = useState<IScaleSettingsFormState>({ | ||
options: options, | ||
}); | ||
|
||
const updateReplicas = (newReplicas: number) => { | ||
state.options.replicas = newReplicas; | ||
if (onChange) { | ||
onChange(state.options); | ||
} | ||
setState({ options: state.options }); | ||
}; | ||
|
||
return ( | ||
<div className="form-horizontal"> | ||
<StageConfigField label="Replicas" fieldColumns={4} groupClassName="form-group form-inline"> | ||
<div className="input-group"> | ||
<NumberInput | ||
inputClassName="input-sm highlight-pristine" | ||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => { | ||
updateReplicas(e.target.valueAsNumber); | ||
}} | ||
value={options.replicas} | ||
min={0} | ||
/> | ||
</div> | ||
</StageConfigField> | ||
</div> | ||
); | ||
} |
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
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
26 changes: 4 additions & 22 deletions
26
packages/kubernetes/src/manifest/scale/scaleSettingsForm.component.ts
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 |
---|---|---|
@@ -1,29 +1,11 @@ | ||
import type { IComponentOptions } from 'angular'; | ||
import { module } from 'angular'; | ||
|
||
const kubernetesScaleManifestSettingsFormComponent: IComponentOptions = { | ||
bindings: { settings: '=' }, | ||
controllerAs: 'ctrl', | ||
template: ` | ||
<div class="form-horizontal"> | ||
<div class="form-group form-inline"> | ||
<div class="col-md-3 sm-label-right"> | ||
Replicas | ||
</div> | ||
<div class="col-md-4"> | ||
<input type="text" | ||
class="form-control input-sm highlight-pristine" | ||
ng-model="ctrl.settings.replicas" | ||
min="0"/> | ||
</div> | ||
</div> | ||
</div> | ||
`, | ||
}; | ||
import { react2angular } from 'react2angular'; | ||
import { withErrorBoundary } from '@spinnaker/core'; | ||
import { ScaleSettingsForm } from './ScaleSettingsForm'; | ||
|
||
export const KUBERNETES_SCALE_MANIFEST_SETTINGS_FORM = | ||
'spinnaker.kubernetes.v2.kubernetes.manifest.scale.settingsForm.component'; | ||
module(KUBERNETES_SCALE_MANIFEST_SETTINGS_FORM, []).component( | ||
'kubernetesScaleManifestSettingsForm', | ||
kubernetesScaleManifestSettingsFormComponent, | ||
react2angular(withErrorBoundary(ScaleSettingsForm, 'kubernetesScaleManifestSettingsForm'), ['options', 'onChange']), | ||
); |
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
38 changes: 38 additions & 0 deletions
38
packages/kubernetes/src/pipelines/stages/scaleManifest/ScaleManifestConfig.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,38 @@ | ||
import { defaults } from 'lodash'; | ||
import React, { useEffect } from 'react'; | ||
|
||
import type { IFormikStageConfigInjectedProps, IStageConfigProps } from '@spinnaker/core'; | ||
import { FormikStageConfig } from '@spinnaker/core'; | ||
|
||
import { ScaleManifestStageForm } from './ScaleManifestStageForm'; | ||
|
||
export function ScaleManifestStageConfig({ | ||
application, | ||
pipeline, | ||
stage, | ||
updateStage, | ||
stageFieldUpdated, | ||
}: IStageConfigProps) { | ||
useEffect(() => { | ||
defaults(stage, { | ||
app: application.name, | ||
cloudProvider: 'kubernetes', | ||
}); | ||
|
||
if (stage.isNew) { | ||
stage.replicas = 0; | ||
} | ||
}, []); | ||
|
||
return ( | ||
<FormikStageConfig | ||
application={application} | ||
pipeline={pipeline} | ||
stage={stage} | ||
onChange={updateStage} | ||
render={(props: IFormikStageConfigInjectedProps) => ( | ||
<ScaleManifestStageForm {...props} stageFieldUpdated={stageFieldUpdated} /> | ||
)} | ||
/> | ||
); | ||
} |
46 changes: 46 additions & 0 deletions
46
packages/kubernetes/src/pipelines/stages/scaleManifest/ScaleManifestStageForm.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,46 @@ | ||
import React from 'react'; | ||
|
||
import type { IFormikStageConfigInjectedProps } from '@spinnaker/core'; | ||
|
||
import type { IScaleCommand } from '../../../manifest'; | ||
import { ScaleSettingsForm } from '../../../manifest/scale/ScaleSettingsForm'; | ||
import type { IManifestSelector } from '../../../manifest/selector/IManifestSelector'; | ||
import { SelectorMode } from '../../../manifest/selector/IManifestSelector'; | ||
import { ManifestSelector } from '../../../manifest/selector/ManifestSelector'; | ||
|
||
interface IScaleManifestStageConfigFormProps { | ||
stageFieldUpdated: () => void; | ||
} | ||
|
||
export function ScaleManifestStageForm({ | ||
application, | ||
formik, | ||
stageFieldUpdated, | ||
}: IScaleManifestStageConfigFormProps & IFormikStageConfigInjectedProps) { | ||
const stage = formik.values; | ||
|
||
const onManifestSelectorChange = () => { | ||
stageFieldUpdated(); | ||
}; | ||
|
||
const onScaleSettingsFormChange = () => { | ||
stageFieldUpdated(); | ||
}; | ||
|
||
return ( | ||
<div className="form-horizontal"> | ||
<h4>Manifest</h4> | ||
<div className="horizontal-rule" /> | ||
<ManifestSelector | ||
application={application} | ||
selector={(stage as unknown) as IManifestSelector} | ||
modes={[SelectorMode.Static, SelectorMode.Dynamic]} | ||
onChange={onManifestSelectorChange} | ||
includeSpinnakerKinds={null} | ||
/> | ||
<h4>Settings</h4> | ||
<div className="horizontal-rule" /> | ||
<ScaleSettingsForm options={(stage as unknown) as IScaleCommand} onChange={onScaleSettingsFormChange} /> | ||
</div> | ||
); | ||
} |
32 changes: 0 additions & 32 deletions
32
packages/kubernetes/src/pipelines/stages/scaleManifest/scaleManifestConfig.controller.ts
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
packages/kubernetes/src/pipelines/stages/scaleManifest/scaleManifestConfig.html
This file was deleted.
Oops, something went wrong.
42 changes: 15 additions & 27 deletions
42
packages/kubernetes/src/pipelines/stages/scaleManifest/scaleManifestStage.ts
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 |
---|---|---|
@@ -1,33 +1,21 @@ | ||
import { module } from 'angular'; | ||
|
||
import type { IStage } from '@spinnaker/core'; | ||
import { ExecutionDetailsTasks, Registry } from '@spinnaker/core'; | ||
|
||
import { manifestExecutionDetails } from '../ManifestExecutionDetails'; | ||
import { KUBERNETES_SCALE_MANIFEST_SETTINGS_FORM } from '../../../manifest/scale/scaleSettingsForm.component'; | ||
import { KubernetesV2ScaleManifestConfigCtrl } from './scaleManifestConfig.controller'; | ||
import { ScaleManifestStageConfig } from './ScaleManifestConfig'; | ||
import { manifestSelectorValidators } from '../validators/manifestSelectorValidators'; | ||
|
||
export const KUBERNETES_SCALE_MANIFEST_STAGE = 'spinnaker.kubernetes.v2.pipeline.stage.scaleManifestStage'; | ||
const STAGE_NAME = 'Scale (Manifest)'; | ||
const STAGE_KEY = 'scaleManifest'; | ||
|
||
module(KUBERNETES_SCALE_MANIFEST_STAGE, [KUBERNETES_SCALE_MANIFEST_SETTINGS_FORM]) | ||
.config(() => { | ||
Registry.pipeline.registerStage({ | ||
label: 'Scale (Manifest)', | ||
description: 'Scale a Kubernetes object created from a manifest.', | ||
key: STAGE_KEY, | ||
cloudProvider: 'kubernetes', | ||
templateUrl: require('./scaleManifestConfig.html'), | ||
controller: 'KubernetesV2ScaleManifestConfigCtrl', | ||
controllerAs: 'ctrl', | ||
executionDetailsSections: [manifestExecutionDetails(STAGE_KEY), ExecutionDetailsTasks], | ||
accountExtractor: (stage: IStage): string[] => (stage.account ? [stage.account] : []), | ||
configAccountExtractor: (stage: any): string[] => (stage.account ? [stage.account] : []), | ||
validators: [ | ||
{ type: 'requiredField', fieldName: 'location', fieldLabel: 'Namespace' }, | ||
{ type: 'requiredField', fieldName: 'account', fieldLabel: 'Account' }, | ||
{ type: 'requiredField', fieldName: 'replicas', fieldLabel: 'Replicas' }, | ||
], | ||
}); | ||
}) | ||
.controller('KubernetesV2ScaleManifestConfigCtrl', KubernetesV2ScaleManifestConfigCtrl); | ||
Registry.pipeline.registerStage({ | ||
label: STAGE_NAME, | ||
description: 'Scale a Kubernetes object created from a manifest.', | ||
key: STAGE_KEY, | ||
cloudProvider: 'kubernetes', | ||
component: ScaleManifestStageConfig, | ||
executionDetailsSections: [manifestExecutionDetails(STAGE_KEY), ExecutionDetailsTasks], | ||
validators: [ | ||
...manifestSelectorValidators(STAGE_NAME), | ||
{ type: 'requiredField', fieldName: 'replicas', fieldLabel: 'Replicas' }, | ||
], | ||
}); |