This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor v2v, basicSettings and CreateVmDialog + fix bugs (#417)
- renamed basiceSettings -> vmSettings - updated enhancedK8sMethods
- Loading branch information
Showing
130 changed files
with
6,434 additions
and
5,710 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import { Col, ControlLabel, FormGroup, HelpBlock, FieldLevelHelp } from 'patternfly-react'; | ||
import { get } from 'lodash'; | ||
|
||
import { VALIDATION_INFO_TYPE } from '../../constants'; | ||
import { prefixedId } from '../../utils'; | ||
|
||
export const FormControlLabel = ({ isRequired, title, help }) => ( | ||
<React.Fragment> | ||
<ControlLabel className={isRequired ? 'required-pf' : null}>{title}</ControlLabel> | ||
{help && <FieldLevelHelp className="kubevirt-form-group__field-help" placement="right" content={help} />} | ||
</React.Fragment> | ||
); | ||
|
||
FormControlLabel.defaultProps = { | ||
isRequired: false, | ||
title: '', | ||
help: '', | ||
}; | ||
|
||
FormControlLabel.propTypes = { | ||
isRequired: PropTypes.bool, | ||
title: PropTypes.string, | ||
help: PropTypes.string, | ||
}; | ||
|
||
export const ValidationFormRow = ({ | ||
children, | ||
id, | ||
className, | ||
isHidden, | ||
validation, | ||
controlSize, | ||
labelSize, | ||
textPosition, | ||
...props | ||
}) => { | ||
if (isHidden) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<FormGroup | ||
id={prefixedId(id, 'id-form-row')} | ||
validationState={validation && validation.type !== VALIDATION_INFO_TYPE ? validation.type : null} | ||
className={classNames('kubevirt-form-group', className)} | ||
> | ||
<Col sm={labelSize} className={textPosition}> | ||
<FormControlLabel {...props} /> | ||
</Col> | ||
<Col sm={controlSize}>{children}</Col> | ||
</FormGroup> | ||
); | ||
}; | ||
|
||
ValidationFormRow.defaultProps = { | ||
...FormControlLabel.defaultProps, | ||
children: null, | ||
id: null, | ||
className: null, | ||
isHidden: false, | ||
validation: {}, | ||
controlSize: 5, | ||
labelSize: 3, | ||
textPosition: 'text-right', | ||
}; | ||
|
||
ValidationFormRow.propTypes = { | ||
...FormControlLabel.propTypes, | ||
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]), | ||
id: PropTypes.string, | ||
className: PropTypes.string, | ||
isHidden: PropTypes.bool, | ||
validation: PropTypes.object, | ||
controlSize: PropTypes.number, | ||
labelSize: PropTypes.number, | ||
textPosition: PropTypes.string, | ||
}; | ||
|
||
export const FormRow = ({ children, validation, ...props }) => { | ||
const validationMessage = get(validation, 'message', null); | ||
|
||
return ( | ||
<ValidationFormRow validation={validation} {...props}> | ||
{children} | ||
{validationMessage && <HelpBlock>{validationMessage}</HelpBlock>} | ||
</ValidationFormRow> | ||
); | ||
}; | ||
|
||
FormRow.defaultProps = ValidationFormRow.defaultProps; | ||
|
||
FormRow.propTypes = ValidationFormRow.propTypes; |
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,27 @@ | ||
import { FormRow, ValidationFormRow } from '../FormRow'; | ||
import { VALIDATION_ERROR_TYPE } from '../../../constants'; | ||
|
||
export default [ | ||
{ | ||
component: FormRow, | ||
name: 'FormRow', | ||
props: { | ||
id: '1', | ||
children: 'text', | ||
onChange: () => {}, | ||
}, | ||
}, | ||
{ | ||
component: ValidationFormRow, | ||
name: 'error ValidationFormRow', | ||
props: { | ||
id: '1', | ||
children: 'test', | ||
validation: { | ||
message: 'error validation', | ||
type: VALIDATION_ERROR_TYPE, | ||
}, | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import { FormRow, ValidationFormRow, FormControlLabel } from '../FormRow'; | ||
|
||
describe('<FormRow />', () => { | ||
it('renders FormRow correctly', () => { | ||
const component = shallow(<FormRow>test</FormRow>); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
it('renders ValidationFormRow correctly', () => { | ||
const component = shallow(<ValidationFormRow>test</ValidationFormRow>); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
it('renders FormControlLabel correctly', () => { | ||
const component = shallow(<FormControlLabel title="test" />); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); |
58 changes: 58 additions & 0 deletions
58
src/components/Form/tests/__snapshots__/FormRow.test.js.snap
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,58 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<FormRow /> renders FormControlLabel correctly 1`] = ` | ||
<Fragment> | ||
<ControlLabel | ||
bsClass="control-label" | ||
className={null} | ||
srOnly={false} | ||
> | ||
test | ||
</ControlLabel> | ||
</Fragment> | ||
`; | ||
|
||
exports[`<FormRow /> renders FormRow correctly 1`] = ` | ||
<ValidationFormRow | ||
className={null} | ||
controlSize={5} | ||
help="" | ||
id={null} | ||
isHidden={false} | ||
isRequired={false} | ||
labelSize={3} | ||
textPosition="text-right" | ||
title="" | ||
validation={Object {}} | ||
> | ||
test | ||
</ValidationFormRow> | ||
`; | ||
|
||
exports[`<FormRow /> renders ValidationFormRow correctly 1`] = ` | ||
<FormGroup | ||
bsClass="form-group" | ||
className="kubevirt-form-group" | ||
id={null} | ||
> | ||
<Col | ||
bsClass="col" | ||
className="text-right" | ||
componentClass="div" | ||
sm={3} | ||
> | ||
<FormControlLabel | ||
help="" | ||
isRequired={false} | ||
title="" | ||
/> | ||
</Col> | ||
<Col | ||
bsClass="col" | ||
componentClass="div" | ||
sm={5} | ||
> | ||
test | ||
</Col> | ||
</FormGroup> | ||
`; |
Oops, something went wrong.