Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5007 from rohitkrai03/helm-rollback
Add support for Helm release rollback
- Loading branch information
Showing
22 changed files
with
454 additions
and
84 deletions.
There are no files selected for viewing
70 changes: 18 additions & 52 deletions
70
frontend/packages/console-shared/src/components/formik-fields/RadioButtonField.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
4 changes: 2 additions & 2 deletions
4
...nents/formik-fields/RadioButtonField.scss → ...onents/formik-fields/RadioGroupField.scss
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,11 +1,11 @@ | ||
.odc-radio-button { | ||
.ocs-radio-group-field { | ||
padding-left: var(--pf-global--spacer--sm); | ||
|
||
input[type='radio'] { | ||
margin-top: 0; | ||
} | ||
|
||
&__children { | ||
padding: var(--pf-global--spacer--md) 0 var(--pf-global--spacer--md) 1.8rem; | ||
padding: var(--pf-global--spacer--md) 0; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
frontend/packages/console-shared/src/components/formik-fields/RadioGroupField.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,59 @@ | ||
import * as React from 'react'; | ||
import { useField } from 'formik'; | ||
import { FormGroup } from '@patternfly/react-core'; | ||
import { RadioGroupFieldProps } from './field-types'; | ||
import { getFieldId } from './field-utils'; | ||
import RadioButtonField from './RadioButtonField'; | ||
import './RadioGroupField.scss'; | ||
|
||
const RadioGroupField: React.FC<RadioGroupFieldProps> = ({ | ||
label, | ||
options, | ||
helpText, | ||
required, | ||
...props | ||
}) => { | ||
const [field, { touched, error }] = useField(props.name); | ||
const fieldId = getFieldId(props.name, 'radiogroup'); | ||
const isValid = !(touched && error); | ||
const errorMessage = !isValid ? error : ''; | ||
return ( | ||
<FormGroup | ||
className="ocs-radio-group-field" | ||
fieldId={fieldId} | ||
helperText={helpText} | ||
helperTextInvalid={errorMessage} | ||
isValid={isValid} | ||
isRequired={required} | ||
label={label} | ||
> | ||
{options.map((option) => { | ||
const activeChild = field.value === option.value && option.activeChildren; | ||
const staticChild = option.children; | ||
|
||
const description = (activeChild || staticChild) && ( | ||
<div className="ocs-radio-group-field__children"> | ||
{staticChild} | ||
{activeChild} | ||
</div> | ||
); | ||
|
||
return ( | ||
<React.Fragment key={option.value}> | ||
<RadioButtonField | ||
{...field} | ||
{...props} | ||
value={option.value} | ||
label={option.label} | ||
isDisabled={option.isDisabled} | ||
aria-describedby={`${fieldId}-helper`} | ||
description={description} | ||
/> | ||
</React.Fragment> | ||
); | ||
})} | ||
</FormGroup> | ||
); | ||
}; | ||
|
||
export default RadioGroupField; |
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
2 changes: 1 addition & 1 deletion
2
frontend/packages/console-shared/src/components/formik-fields/field-utils.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,3 +1,3 @@ | ||
export const getFieldId = (fieldName: string, fieldType: string) => { | ||
return `form-${fieldType}-${fieldName.replace(/\./g, '-')}-field`; | ||
return `form-${fieldType}-${fieldName?.replace(/\./g, '-')}-field`; | ||
}; |
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
87 changes: 87 additions & 0 deletions
87
frontend/packages/dev-console/src/components/helm/HelmReleaseRollbackPage.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,87 @@ | ||
import * as React from 'react'; | ||
import Helmet from 'react-helmet'; | ||
import { Formik } from 'formik'; | ||
import { RouteComponentProps } from 'react-router'; | ||
import { PageBody } from '@console/shared'; | ||
import { coFetchJSON } from '@console/internal/co-fetch'; | ||
import { PageHeading, history } from '@console/internal/components/utils'; | ||
|
||
import { HelmRelease } from './helm-types'; | ||
import NamespacedPage, { NamespacedPageVariants } from '../NamespacedPage'; | ||
import HelmReleaseRollbackForm from './form/HelmReleaseRollbackForm'; | ||
|
||
type HelmReleaseRollbackPageProps = RouteComponentProps<{ | ||
ns?: string; | ||
releaseName?: string; | ||
}>; | ||
|
||
type HelmRollbackFormData = { | ||
revision: number; | ||
}; | ||
|
||
const HelmReleaseRollbackPage: React.FC<HelmReleaseRollbackPageProps> = ({ match }) => { | ||
const { releaseName, ns: namespace } = match.params; | ||
const [releaseHistory, setReleaseHistory] = React.useState<HelmRelease[]>(null); | ||
|
||
React.useEffect(() => { | ||
let ignore = false; | ||
|
||
const fetchReleaseHistory = async () => { | ||
let res: HelmRelease[]; | ||
try { | ||
res = await coFetchJSON(`/api/helm/release/history?ns=${namespace}&name=${releaseName}`); | ||
} catch {} // eslint-disable-line no-empty | ||
if (ignore) return; | ||
|
||
res?.length > 0 && setReleaseHistory(res); | ||
}; | ||
|
||
fetchReleaseHistory(); | ||
|
||
return () => { | ||
ignore = true; | ||
}; | ||
}, [namespace, releaseName]); | ||
|
||
const initialValues: HelmRollbackFormData = { | ||
revision: -1, | ||
}; | ||
|
||
const handleSubmit = (values, actions) => { | ||
actions.setStatus({ isSubmitting: true }); | ||
const payload = { | ||
namespace, | ||
name: releaseName, | ||
version: values.revision, | ||
}; | ||
|
||
coFetchJSON | ||
.put('/api/helm/release', payload) | ||
.then(() => { | ||
actions.setStatus({ isSubmitting: false }); | ||
history.push(`/helm-releases/ns/${namespace}`); | ||
}) | ||
.catch((err) => { | ||
actions.setSubmitting(false); | ||
actions.setStatus({ submitError: err.message }); | ||
}); | ||
}; | ||
|
||
return ( | ||
<NamespacedPage variant={NamespacedPageVariants.light} disabled hideApplications> | ||
<Helmet> | ||
<title>Rollback Helm Release</title> | ||
</Helmet> | ||
<PageHeading title="Rollback Helm Release"> | ||
Select the version to rollback <strong>{releaseName}</strong> to, from the table below: | ||
</PageHeading> | ||
<PageBody> | ||
<Formik initialValues={initialValues} onSubmit={handleSubmit} onReset={history.goBack}> | ||
{(props) => <HelmReleaseRollbackForm {...props} releaseHistory={releaseHistory} />} | ||
</Formik> | ||
</PageBody> | ||
</NamespacedPage> | ||
); | ||
}; | ||
|
||
export default HelmReleaseRollbackPage; |
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
Oops, something went wrong.