Skip to content

Commit 32e0ee2

Browse files
authored
Merge pull request #396 from rvsia/rebaseVol4
[V2] Rebase master > V2 vol. 4
2 parents c0b9ca9 + e361765 commit 32e0ee2

File tree

14 files changed

+752
-88
lines changed

14 files changed

+752
-88
lines changed

packages/common/src/form-template.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,18 @@ export const FormControls = ({
4343
const { submitting, pristine, validating } = formSpyProps;
4444

4545
const buttons = {
46-
submit: <Button key="form-submit" type="submit" variant="primary" disabled={submitting || validating || disableSubmit} label={submitLabel} />,
47-
reset: canReset ? <Button key="form-reset" type="button" disabled={pristine} onClick={onReset} label={resetLabel} /> : null,
48-
cancel: onCancel ? <Button key="form-cancel" type="button" onClick={onCancel} label={cancelLabel} /> : null
46+
submit: (
47+
<Button
48+
key="form-submit"
49+
type="submit"
50+
variant="primary"
51+
buttonType="submit"
52+
disabled={submitting || validating || disableSubmit}
53+
label={submitLabel}
54+
/>
55+
),
56+
reset: canReset ? <Button key="form-reset" type="button" buttonType="reset" disabled={pristine} onClick={onReset} label={resetLabel} /> : null,
57+
cancel: onCancel ? <Button key="form-cancel" type="button" buttonType="cancel" onClick={onCancel} label={cancelLabel} /> : null
4958
};
5059

5160
return <ButtonGroup className={buttonClassName}>{completeButtons(buttonOrder).map((button) => buttons[button])}</ButtonGroup>;

packages/mui-component-mapper/src/files/form-template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const Title = ({ children }) => (
2020
</Grid>
2121
);
2222
const ButtonGroup = ({ children }) => <div style={{ display: 'flex', justifyContent: 'flex-end' }}>{children}</div>;
23-
const Button = ({ label, variant, children, ...props }) => (
23+
const Button = ({ label, variant, children, buttonType, ...props }) => (
2424
<MUIButton color={variant} variant="contained" {...props}>
2525
{label || children}
2626
</MUIButton>

packages/pf3-component-mapper/src/files/form-template.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ FormWrapper.propTypes = {
1010
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]).isRequired
1111
};
1212

13-
export const Button = ({ label, variant, children, ...props }) => (
13+
export const Button = ({ label, variant, children, buttonType, ...props }) => (
1414
<PF3Button bsStyle={variant} {...props}>
1515
{label || children}
1616
</PF3Button>
@@ -19,7 +19,8 @@ export const Button = ({ label, variant, children, ...props }) => (
1919
Button.propTypes = {
2020
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
2121
variant: PropTypes.string,
22-
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)])
22+
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
23+
buttonType: PropTypes.string
2324
};
2425

2526
export const ButtonGroup = ({ children, className, ...props }) => (

packages/pf4-component-mapper/src/files/form-template.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { Button as PF4Button, ActionGroup, Form, TextContent, Text, TextVariants
77

88
import './form-template.scss';
99

10-
export const Button = ({ label, bsStyle, children, disabled, ...props }) => (
11-
<PF4Button variant={bsStyle || 'secondary'} isDisabled={disabled} {...props}>
10+
export const Button = ({ label, bsStyle, children, disabled, buttonType, ...props }) => (
11+
<PF4Button variant={buttonType === 'cancel' ? 'link' : bsStyle || 'secondary'} isDisabled={disabled} {...props}>
1212
{label}
1313
{children}
1414
</PF4Button>
@@ -18,7 +18,8 @@ Button.propTypes = {
1818
label: PropTypes.string.isRequired,
1919
bsStyle: PropTypes.string,
2020
disabled: PropTypes.bool,
21-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
21+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
22+
buttonType: PropTypes.string
2223
};
2324

2425
export const ButtonGroup = ({ children, ...props }) => <ActionGroup {...props}>{children}</ActionGroup>;

packages/pf4-component-mapper/src/tests/__snapshots__/form-template-common.test.js.snap

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ exports[`FormTemplate PF4 Common should add missing buttons if not defined in bu
135135
className="pf-c-form__actions"
136136
>
137137
<Button
138+
buttonType="submit"
138139
key="form-submit"
139140
label="Submit"
140141
type="submit"
@@ -184,6 +185,7 @@ exports[`FormTemplate PF4 Common should add missing buttons if not defined in bu
184185
</Component>
185186
</Button>
186187
<Button
188+
buttonType="reset"
187189
disabled={true}
188190
key="form-reset"
189191
label="Reset"
@@ -240,6 +242,7 @@ exports[`FormTemplate PF4 Common should add missing buttons if not defined in bu
240242
</Component>
241243
</Button>
242244
<Button
245+
buttonType="cancel"
243246
key="form-cancel"
244247
label="Cancel"
245248
onClick={[MockFunction]}
@@ -248,7 +251,7 @@ exports[`FormTemplate PF4 Common should add missing buttons if not defined in bu
248251
<Component
249252
onClick={[MockFunction]}
250253
type="button"
251-
variant="secondary"
254+
variant="link"
252255
>
253256
<ComponentWithOuia
254257
component={[Function]}
@@ -261,7 +264,7 @@ exports[`FormTemplate PF4 Common should add missing buttons if not defined in bu
261264
"isDisabled": undefined,
262265
"onClick": [MockFunction],
263266
"type": "button",
264-
"variant": "secondary",
267+
"variant": "link",
265268
}
266269
}
267270
consumerContext={null}
@@ -275,12 +278,12 @@ exports[`FormTemplate PF4 Common should add missing buttons if not defined in bu
275278
}
276279
}
277280
type="button"
278-
variant="secondary"
281+
variant="link"
279282
>
280283
<button
281284
aria-disabled={null}
282285
aria-label={null}
283-
className="pf-c-button pf-m-secondary"
286+
className="pf-c-button pf-m-link"
284287
disabled={false}
285288
onClick={[MockFunction]}
286289
tabIndex={null}
@@ -443,6 +446,7 @@ exports[`FormTemplate PF4 Common should render all controls and with default lab
443446
className="pf-c-form__actions"
444447
>
445448
<Button
449+
buttonType="submit"
446450
key="form-submit"
447451
label="Submit"
448452
type="submit"
@@ -492,6 +496,7 @@ exports[`FormTemplate PF4 Common should render all controls and with default lab
492496
</Component>
493497
</Button>
494498
<Button
499+
buttonType="cancel"
495500
key="form-cancel"
496501
label="Cancel"
497502
onClick={[MockFunction]}
@@ -500,7 +505,7 @@ exports[`FormTemplate PF4 Common should render all controls and with default lab
500505
<Component
501506
onClick={[MockFunction]}
502507
type="button"
503-
variant="secondary"
508+
variant="link"
504509
>
505510
<ComponentWithOuia
506511
component={[Function]}
@@ -513,7 +518,7 @@ exports[`FormTemplate PF4 Common should render all controls and with default lab
513518
"isDisabled": undefined,
514519
"onClick": [MockFunction],
515520
"type": "button",
516-
"variant": "secondary",
521+
"variant": "link",
517522
}
518523
}
519524
consumerContext={null}
@@ -527,12 +532,12 @@ exports[`FormTemplate PF4 Common should render all controls and with default lab
527532
}
528533
}
529534
type="button"
530-
variant="secondary"
535+
variant="link"
531536
>
532537
<button
533538
aria-disabled={null}
534539
aria-label={null}
535-
className="pf-c-button pf-m-secondary"
540+
className="pf-c-button pf-m-link"
536541
disabled={false}
537542
onClick={[MockFunction]}
538543
tabIndex={null}
@@ -713,6 +718,7 @@ exports[`FormTemplate PF4 Common should render buttons in correct order 1`] = `
713718
className="pf-c-form__actions"
714719
>
715720
<Button
721+
buttonType="cancel"
716722
key="form-cancel"
717723
label="Cancel"
718724
onClick={[MockFunction]}
@@ -721,7 +727,7 @@ exports[`FormTemplate PF4 Common should render buttons in correct order 1`] = `
721727
<Component
722728
onClick={[MockFunction]}
723729
type="button"
724-
variant="secondary"
730+
variant="link"
725731
>
726732
<ComponentWithOuia
727733
component={[Function]}
@@ -734,7 +740,7 @@ exports[`FormTemplate PF4 Common should render buttons in correct order 1`] = `
734740
"isDisabled": undefined,
735741
"onClick": [MockFunction],
736742
"type": "button",
737-
"variant": "secondary",
743+
"variant": "link",
738744
}
739745
}
740746
consumerContext={null}
@@ -748,12 +754,12 @@ exports[`FormTemplate PF4 Common should render buttons in correct order 1`] = `
748754
}
749755
}
750756
type="button"
751-
variant="secondary"
757+
variant="link"
752758
>
753759
<button
754760
aria-disabled={null}
755761
aria-label={null}
756-
className="pf-c-button pf-m-secondary"
762+
className="pf-c-button pf-m-link"
757763
disabled={false}
758764
onClick={[MockFunction]}
759765
tabIndex={null}
@@ -766,6 +772,7 @@ exports[`FormTemplate PF4 Common should render buttons in correct order 1`] = `
766772
</Component>
767773
</Button>
768774
<Button
775+
buttonType="submit"
769776
key="form-submit"
770777
label="Submit"
771778
type="submit"
@@ -815,6 +822,7 @@ exports[`FormTemplate PF4 Common should render buttons in correct order 1`] = `
815822
</Component>
816823
</Button>
817824
<Button
825+
buttonType="reset"
818826
disabled={true}
819827
key="form-reset"
820828
label="Reset"
@@ -1022,6 +1030,7 @@ exports[`FormTemplate PF4 Common should render only submit button 1`] = `
10221030
className="pf-c-form__actions"
10231031
>
10241032
<Button
1033+
buttonType="submit"
10251034
key="form-submit"
10261035
label="Submit"
10271036
type="submit"

packages/react-form-renderer/src/files/default-schema-validator.js

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,51 +24,67 @@ const checkCondition = (condition, fieldName) => {
2424
return condition.forEach((item) => checkCondition(item, fieldName));
2525
}
2626

27+
if (condition.hasOwnProperty('and') && !Array.isArray(condition.and)) {
28+
throw new DefaultSchemaError(`
29+
Error occured in field definition with "name" property: "${fieldName}".
30+
'and' property in a field condition must be an array! Received: ${typeof condition.and}.
31+
`);
32+
}
33+
34+
if (condition.hasOwnProperty('or') && !Array.isArray(condition.and)) {
35+
throw new DefaultSchemaError(`
36+
Error occured in field definition with "name" property: "${fieldName}".
37+
'or' propery in a field condition must be an array! Received: ${typeof condition.and}.
38+
`);
39+
}
40+
2741
if (typeof condition !== 'object') {
2842
throw new DefaultSchemaError(`
2943
Error occured in field definition with name: "${fieldName}".
3044
Field condition must be an object, received ${Array.isArray(condition) ? 'array' : typeof condition}!
3145
`);
3246
}
3347

34-
if (!condition.hasOwnProperty('when')) {
35-
throw new DefaultSchemaError(`
48+
if (!condition.hasOwnProperty('and') && !condition.hasOwnProperty('or') && !condition.hasOwnProperty('not')) {
49+
if (!condition.hasOwnProperty('when')) {
50+
throw new DefaultSchemaError(`
3651
Error occured in field definition with "name" property: "${fieldName}".
3752
Field condition must have "when" property! Properties received: [${Object.keys(condition)}].
3853
`);
39-
}
54+
}
4055

41-
if (!(typeof condition.when === 'string' || Array.isArray(condition.when))) {
42-
throw new DefaultSchemaError(`
56+
if (!(typeof condition.when === 'string' || Array.isArray(condition.when))) {
57+
throw new DefaultSchemaError(`
4358
Error occured in field definition with name: "${fieldName}".
4459
Field condition property "when" must be oof type "string", ${typeof condition.when} received!].
4560
`);
46-
}
61+
}
4762

48-
if (
49-
!condition.hasOwnProperty('is') &&
50-
!condition.hasOwnProperty('isEmpty') &&
51-
!condition.hasOwnProperty('isNotEmpty') &&
52-
!condition.hasOwnProperty('pattern')
53-
) {
54-
throw new DefaultSchemaError(`
63+
if (
64+
!condition.hasOwnProperty('is') &&
65+
!condition.hasOwnProperty('isEmpty') &&
66+
!condition.hasOwnProperty('isNotEmpty') &&
67+
!condition.hasOwnProperty('pattern')
68+
) {
69+
throw new DefaultSchemaError(`
5570
Error occured in field definition with name: "${fieldName}".
5671
Field condition must have one of "is", "isEmpty", "isNotEmpty", "pattern" property! Properties received: [${Object.keys(condition)}].
5772
`);
58-
}
73+
}
5974

60-
if (condition.hasOwnProperty('notMatch') && !condition.hasOwnProperty('pattern') && !condition.hasOwnProperty('is')) {
61-
throw new DefaultSchemaError(`
75+
if (condition.hasOwnProperty('notMatch') && !condition.hasOwnProperty('pattern') && !condition.hasOwnProperty('is')) {
76+
throw new DefaultSchemaError(`
6277
Error occured in field definition with name: "${fieldName}".
6378
Field condition must have "pattern" or "is" property when "notMatch" is set! Properties received: [${Object.keys(condition)}].
6479
`);
65-
}
80+
}
6681

67-
if (condition.hasOwnProperty('pattern') && !(condition.pattern instanceof RegExp) && typeof condition.pattern !== 'string') {
68-
throw new DefaultSchemaError(`
82+
if (condition.hasOwnProperty('pattern') && !(condition.pattern instanceof RegExp) && typeof condition.pattern !== 'string') {
83+
throw new DefaultSchemaError(`
6984
Error occured in field definition with name: "${fieldName}".
7085
Field condition must have "pattern" of instance "RegExp" or "string"! Instance received: [${condition.pattern.constructor.name}].
7186
`);
87+
}
7288
}
7389
};
7490

0 commit comments

Comments
 (0)