Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
refactor v2v, basicSettings and CreateVmDialog + fix bugs
Browse files Browse the repository at this point in the history
- renamed basiceSettings -> vmSettings
- updated enhancedK8sMethods
  • Loading branch information
suomiy committed Apr 27, 2019
1 parent 128947e commit 6804d8d
Show file tree
Hide file tree
Showing 131 changed files with 6,436 additions and 5,710 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@
"patternfly-react": "2.x",
"prettier": "1.x",
"prop-types": "15.x",
"redux": "3.x",
"react": "16.x",
"react-cosmos": "4.7.x",
"react-cosmos-test": "4.7.x",
"react-dom": "16.x",
"react-redux": "5.x",
"react-router-dom": "4.x",
"require-all": "3.x",
"sass-loader": "7.x",
Expand Down
6 changes: 2 additions & 4 deletions sass/components/Wizard/create-vm-wizard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
min-height: 100px;
}

.kubevirt-create-vm-wizard__import-vmware-passwordcheck-button-section {
margin-top: 10px; /* More compact, higher-level sections are 15px */
display: inline-flex;
width: 100%;
.kubevirt-create-vm-wizard__import-vmware-password {
margin-bottom: 10px; /* More compact, higher-level sections are 15px */
}

.kubevirt-create-vm-wizard__import-vmware-passwordcheck-button {
Expand Down
8 changes: 4 additions & 4 deletions src/components/Form/Dropdown.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import { isObject } from 'lodash';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { ButtonGroup, DropdownButton, MenuItem, noop, Tooltip, OverlayTrigger } from 'patternfly-react';

export const Dropdown = ({ id, value, disabled, onChange, choices, className, withTooltips }) => {
const title = typeof value === 'object' ? value.name || value.id : value;
const title = isObject(value) ? value.name || value.id : value;
return (
<ButtonGroup justified key={id}>
<DropdownButton
Expand All @@ -16,9 +17,8 @@ export const Dropdown = ({ id, value, disabled, onChange, choices, className, wi
onSelect={onChange}
>
{choices.map(choice => {
const isObject = typeof choice === 'object';
const key = isObject ? choice.id || choice.name : choice;
const val = isObject ? choice.name : choice;
const key = isObject(choice) ? choice.id || choice.name : choice;
const val = isObject(choice) ? choice.name : choice;

const content = (
<MenuItem key={key} eventKey={choice}>
Expand Down
95 changes: 95 additions & 0 deletions src/components/Form/FormRow.js
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;
27 changes: 27 additions & 0 deletions src/components/Form/fixtures/FormRow.fixture.js
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: () => {},
},
},
];
19 changes: 19 additions & 0 deletions src/components/Form/tests/FormRow.test.js
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 src/components/Form/tests/__snapshots__/FormRow.test.js.snap
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>
`;
Loading

0 comments on commit 6804d8d

Please sign in to comment.