Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/pf3-component-mapper/src/form-fields/button.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import { Button } from 'patternfly-react';

export default (props) => <Button style={{ marginLeft: 3 }} { ...props } />;
const ButtonOverride = (props) => <Button style={{ marginLeft: 3 }} { ...props } />;

export default ButtonOverride;
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ FinalFormField.propTypes = {
description: PropTypes.string,
hideLabel: PropTypes.bool,
isVisible: PropTypes.bool,
noCheckboxLabel: PropTypes.bool,
};

const CheckboxGroupField = ({ options, ...rest }) =>
Expand Down
65 changes: 49 additions & 16 deletions packages/pf3-component-mapper/src/form-fields/layout-components.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import { layoutComponents } from '@data-driven-forms/react-form-renderer';
import { FormGroup, ButtonGroup, Icon, HelpBlock, Form } from 'patternfly-react';
import Button from './button';
Expand All @@ -12,25 +13,57 @@ const ArrayFieldWrapper = ({ children }) => (
</div>
);

const FormWapper = ({ children, ...props }) => <Form { ...props } >{ children }</Form>;

FormWapper.propTypes = {
children: PropTypes.oneOfType([ PropTypes.node, PropTypes.arrayOf(PropTypes.node) ]).isRequired,
};

const FormButton = ({ label, variant, children, ...props }) => <Button bsStyle={ variant } { ...props }>{ label || children }</Button>;

FormButton.propTypes = {
label: PropTypes.oneOfType([ PropTypes.string, PropTypes.node, PropTypes.arrayOf(PropTypes.node) ]),
variant: PropTypes.string,
children: PropTypes.oneOfType([ PropTypes.node, PropTypes.arrayOf(PropTypes.node) ]),
};

const ButtonGroupWrapper = ({ children, ...props }) => (
<ButtonGroup
className="pull-right"
style={{ display: 'inline-block' }}
{ ...props }
>
{ children }
</ButtonGroup>
);

ButtonGroupWrapper.propTypes = {
children: PropTypes.oneOfType([ PropTypes.node, PropTypes.arrayOf(PropTypes.node) ]).isRequired,
};

const TitleWrapper = ({ children }) => <h3>{ children }</h3>;

TitleWrapper.propTypes = {
children: PropTypes.oneOfType([ PropTypes.node, PropTypes.arrayOf(PropTypes.node) ]).isRequired,
};

const DescriptionWrapper = ({ children }) => <p>{ children }</p>;

DescriptionWrapper.propTypes = {
children: PropTypes.oneOfType([ PropTypes.node, PropTypes.arrayOf(PropTypes.node) ]).isRequired,
};

const layoutMapper = {
[layoutComponents.FORM_WRAPPER]: ({ children, ...props }) => <Form { ...props } >{ children }</Form>,
[layoutComponents.BUTTON]: ({ label, variant, children, ...props }) => <Button bsStyle={ variant } { ...props }>{ label || children }</Button>,
[layoutComponents.COL]: ({ children, xs, ...rest }) => <div key={ rest.key || rest.name }>{ children }</div>,
[layoutComponents.FORM_WRAPPER]: FormWapper,
[layoutComponents.BUTTON]: FormButton,
[layoutComponents.COL]: ({ children, xs, ...rest }) => <div key={ rest.key || rest.name }>{ children }</div>, // TO BE removed
[layoutComponents.FORM_GROUP]: FormGroup,
[layoutComponents.BUTTON_GROUP]: ({ children, ...props }) => (
<ButtonGroup
className="pull-right"
style={{ display: 'inline-block' }}
{ ...props }
>
{ children }
</ButtonGroup>
),
[layoutComponents.ICON]: props => <Icon { ...props } />,
[layoutComponents.ARRAY_FIELD_WRAPPER]: ArrayFieldWrapper,
[layoutComponents.BUTTON_GROUP]: ButtonGroupWrapper,
[layoutComponents.ICON]: props => <Icon { ...props } />, // TO BE removed
[layoutComponents.ARRAY_FIELD_WRAPPER]: ArrayFieldWrapper, // TO BE removed
[layoutComponents.HELP_BLOCK]: HelpBlock,
[layoutComponents.TITLE]: ({ children }) => <h3>{ children }</h3>,
[layoutComponents.DESCRIPTION]: ({ children }) => <p>{ children }</p>,
[layoutComponents.TITLE]: TitleWrapper,
[layoutComponents.DESCRIPTION]: DescriptionWrapper,
};

export default layoutMapper;
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react';
import RequiredLabel from './required-label';
import { Checkbox, Col, FormGroup, ControlLabel } from 'patternfly-react';
import PropTypes from 'prop-types';
import { Checkbox, FormGroup, ControlLabel } from 'patternfly-react';
import { composeValidators } from '@data-driven-forms/react-form-renderer';

import RequiredLabel from './required-label';

const MultipleChoiceList = ({ validate, FieldProvider, ...props }) => (
<FieldProvider { ...props } validate={ composeValidators(props.validate || []) }>
{ ({
Expand Down Expand Up @@ -56,4 +58,10 @@ const MultipleChoiceList = ({ validate, FieldProvider, ...props }) => (
</FieldProvider>
);

MultipleChoiceList.propTypes = {
validate: PropTypes.func,
FieldProvider: PropTypes.oneOfType([ PropTypes.node, PropTypes.func ]),
name: PropTypes.string.isRequired,
};

export default MultipleChoiceList;
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ exports[`<Wizard /> should render Wizard correctly 1`] = `
<div
className="wizard-pf-footer modal-footer"
>
<_default
<ButtonOverride
color="secondary"
onClick={[MockFunction]}
style={
Expand Down Expand Up @@ -184,8 +184,8 @@ exports[`<Wizard /> should render Wizard correctly 1`] = `
Cancel
</button>
</Button>
</_default>
<_default
</ButtonOverride>
<ButtonOverride
disabled={true}
onClick={[Function]}
type="button"
Expand Down Expand Up @@ -234,7 +234,7 @@ exports[`<Wizard /> should render Wizard correctly 1`] = `
Back
</button>
</Button>
</_default>
</ButtonOverride>
<SimpleNext
FieldProvider={[Function]}
buttonLabels={
Expand All @@ -253,7 +253,7 @@ exports[`<Wizard /> should render Wizard correctly 1`] = `
submit={[Function]}
valid={true}
>
<_default
<ButtonOverride
bsStyle="primary"
onClick={[Function]}
type="button"
Expand Down Expand Up @@ -299,7 +299,7 @@ exports[`<Wizard /> should render Wizard correctly 1`] = `
</Icon>
</button>
</Button>
</_default>
</ButtonOverride>
</SimpleNext>
</div>
</ModalFooter>
Expand Down Expand Up @@ -469,7 +469,7 @@ exports[`<Wizard /> should render Wizard with conditional steps correctly 1`] =
<div
className="wizard-pf-footer modal-footer"
>
<_default
<ButtonOverride
color="secondary"
onClick={[MockFunction]}
style={
Expand Down Expand Up @@ -512,8 +512,8 @@ exports[`<Wizard /> should render Wizard with conditional steps correctly 1`] =
Cancel
</button>
</Button>
</_default>
<_default
</ButtonOverride>
<ButtonOverride
disabled={true}
onClick={[Function]}
type="button"
Expand Down Expand Up @@ -562,7 +562,7 @@ exports[`<Wizard /> should render Wizard with conditional steps correctly 1`] =
Back
</button>
</Button>
</_default>
</ButtonOverride>
<ConditionalNext
FieldProvider={[Function]}
buttonLabels={
Expand Down Expand Up @@ -612,7 +612,7 @@ exports[`<Wizard /> should render Wizard with conditional steps correctly 1`] =
submit={[Function]}
valid={true}
>
<_default
<ButtonOverride
bsStyle="primary"
onClick={[Function]}
type="button"
Expand Down Expand Up @@ -658,7 +658,7 @@ exports[`<Wizard /> should render Wizard with conditional steps correctly 1`] =
</Icon>
</button>
</Button>
</_default>
</ButtonOverride>
</SimpleNext>
</MockFieldProvider>
</ConditionalNext>
Expand Down Expand Up @@ -915,7 +915,7 @@ exports[`<Wizard /> should render Wizard with stepsInfo correctly 1`] = `
<div
className="wizard-pf-footer modal-footer"
>
<_default
<ButtonOverride
color="secondary"
onClick={[MockFunction]}
style={
Expand Down Expand Up @@ -958,8 +958,8 @@ exports[`<Wizard /> should render Wizard with stepsInfo correctly 1`] = `
Cancel
</button>
</Button>
</_default>
<_default
</ButtonOverride>
<ButtonOverride
disabled={true}
onClick={[Function]}
type="button"
Expand Down Expand Up @@ -1008,7 +1008,7 @@ exports[`<Wizard /> should render Wizard with stepsInfo correctly 1`] = `
Back
</button>
</Button>
</_default>
</ButtonOverride>
<SimpleNext
FieldProvider={[Function]}
buttonLabels={
Expand All @@ -1027,7 +1027,7 @@ exports[`<Wizard /> should render Wizard with stepsInfo correctly 1`] = `
submit={[Function]}
valid={true}
>
<_default
<ButtonOverride
bsStyle="primary"
onClick={[Function]}
type="button"
Expand Down Expand Up @@ -1073,7 +1073,7 @@ exports[`<Wizard /> should render Wizard with stepsInfo correctly 1`] = `
</Icon>
</button>
</Button>
</_default>
</ButtonOverride>
</SimpleNext>
</div>
</ModalFooter>
Expand Down Expand Up @@ -1245,7 +1245,7 @@ exports[`<Wizard /> should render Wizard with title correctly 1`] = `
<div
className="wizard-pf-footer modal-footer"
>
<_default
<ButtonOverride
color="secondary"
onClick={[MockFunction]}
style={
Expand Down Expand Up @@ -1288,8 +1288,8 @@ exports[`<Wizard /> should render Wizard with title correctly 1`] = `
Cancel
</button>
</Button>
</_default>
<_default
</ButtonOverride>
<ButtonOverride
disabled={true}
onClick={[Function]}
type="button"
Expand Down Expand Up @@ -1338,7 +1338,7 @@ exports[`<Wizard /> should render Wizard with title correctly 1`] = `
Back
</button>
</Button>
</_default>
</ButtonOverride>
<SimpleNext
FieldProvider={[Function]}
buttonLabels={
Expand All @@ -1357,7 +1357,7 @@ exports[`<Wizard /> should render Wizard with title correctly 1`] = `
submit={[Function]}
valid={true}
>
<_default
<ButtonOverride
bsStyle="primary"
onClick={[Function]}
type="button"
Expand Down Expand Up @@ -1403,7 +1403,7 @@ exports[`<Wizard /> should render Wizard with title correctly 1`] = `
</Icon>
</button>
</Button>
</_default>
</ButtonOverride>
</SimpleNext>
</div>
</ModalFooter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { composeValidators } from '@data-driven-forms/react-form-renderer';
const propTypes = {
validate: PropTypes.oneOfType([ PropTypes.array, PropTypes.func ]),
FieldProvider: PropTypes.oneOfType([ PropTypes.node, PropTypes.func ]),
name: PropTypes.string.isRequired,
};

const MultipleChoiceList = ({ validate, FieldProvider, ...props }) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ Select.defaultProps = {
loadingMessage: 'Loading...',
};

const DataDrivenSelect = ({ input, multi, ...props }) => (
const DataDrivenSelect = ({ multi, ...props }) => (
<Select
{ ...input }
hideSelectedOptions={ false }
isMulti={ multi }
{ ...props }
Expand All @@ -120,10 +119,8 @@ const DataDrivenSelect = ({ input, multi, ...props }) => (
);

DataDrivenSelect.propTypes = {
input: PropTypes.shape({
value: PropTypes.any,
onChange: PropTypes.func,
}).isRequired,
value: PropTypes.any,
onChange: PropTypes.func,
multi: PropTypes.bool,
placeholder: PropTypes.string,
};
Expand Down
3 changes: 3 additions & 0 deletions packages/pf4-component-mapper/src/form-fields/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ FormTabs.propTypes = {
formOptions: PropTypes.shape({
renderForm: PropTypes.func.isRequired,
}).isRequired,
dataType: PropTypes.any,
FieldProvider: PropTypes.any,
validate: PropTypes.any,
};

export default FormTabs;
8 changes: 3 additions & 5 deletions packages/pf4-component-mapper/src/tests/select/select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,9 @@ describe('<Select />', () => {
const props = {
multi: true,
options: [{ label: 'a', value: 1 }, { label: 'b', value: 2 }],
input: {
name: 'foo',
onChange: Function,
value: [ 1, 2 ],
},
name: 'foo',
onChange: Function,
value: [ 1, 2 ],
};
const wrapper = mount(<DataDrivenSelect { ...props }/>);
const mappedProps = wrapper.find(Select).props();
Expand Down