orc-shared 5.10.0-dev.1 → 5.10.0-dev.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/AppFrame/Preferences.js +46 -45
- package/dist/components/ColumnWrapper.js +28 -5
- package/dist/components/DropMenu/Menu.js +79 -45
- package/dist/components/DropMenu/index.js +34 -29
- package/dist/components/Form/Combination.js +45 -16
- package/dist/components/Form/Field.js +57 -38
- package/dist/components/Form/FieldElements.js +0 -11
- package/dist/components/Form/Fieldset.js +47 -19
- package/dist/components/Form/Form.js +22 -9
- package/dist/components/Form/FormElement.js +40 -7
- package/dist/components/Form/Inputs/Button.js +63 -18
- package/dist/components/Form/Inputs/ReadOnly.js +50 -27
- package/dist/components/Form/Inputs/Selector.js +81 -0
- package/dist/components/Form/Inputs/Text.js +20 -37
- package/dist/components/Form/Inputs/Toggles.js +39 -40
- package/dist/components/Form/Inputs/index.js +2 -13
- package/dist/components/MaterialUI/DataDisplay/PredefinedElements/Placeholder.js +31 -11
- package/dist/components/MaterialUI/DataDisplay/Table.js +83 -18
- package/dist/components/MaterialUI/DataDisplay/TableProps.js +5 -1
- package/dist/components/MaterialUI/Inputs/Select.js +2 -0
- package/dist/components/MaterialUI/Inputs/SelectProps.js +2 -0
- package/dist/components/MaterialUI/Inputs/Switch.js +17 -1
- package/dist/components/MaterialUI/Inputs/SwitchProps.js +2 -0
- package/dist/components/MaterialUI/muiThemes.js +2 -1
- package/dist/constants.js +2 -1
- package/dist/hocs/withScrollBox.js +27 -12
- package/dist/hooks/useInMemoryPaging.js +139 -0
- package/dist/hooks/useMultipleFieldEditState.js +12 -3
- package/dist/selectors/locale.js +1 -0
- package/dist/selectors/metadata.js +16 -1
- package/dist/utils/ListHelper.js +271 -0
- package/dist/utils/comparisonHelper.js +176 -0
- package/dist/utils/propertyBagHelper.js +3 -1
- package/package.json +1 -1
- package/src/components/AppFrame/AppFrame.test.js +6 -19
- package/src/components/AppFrame/Preferences.js +30 -29
- package/src/components/AppFrame/Preferences.test.js +108 -206
- package/src/components/AppFrame/Topbar.test.js +3 -10
- package/src/components/ColumnWrapper.js +18 -9
- package/src/components/DropMenu/DropMenu.test.js +185 -224
- package/src/components/DropMenu/Menu.js +73 -80
- package/src/components/DropMenu/Menu.test.js +35 -86
- package/src/components/DropMenu/index.js +19 -15
- package/src/components/Form/Combination.js +35 -28
- package/src/components/Form/Combination.test.js +6 -19
- package/src/components/Form/Field.js +53 -66
- package/src/components/Form/Field.test.js +29 -51
- package/src/components/Form/FieldElements.js +0 -14
- package/src/components/Form/FieldElements.test.js +104 -111
- package/src/components/Form/Fieldset.js +42 -37
- package/src/components/Form/Fieldset.test.js +14 -7
- package/src/components/Form/Form.js +11 -7
- package/src/components/Form/Form.test.js +75 -56
- package/src/components/Form/FormElement.js +24 -16
- package/src/components/Form/InputField.test.js +24 -30
- package/src/components/Form/Inputs/Button.js +58 -14
- package/src/components/Form/Inputs/Button.test.js +32 -7
- package/src/components/Form/Inputs/Inputs.test.js +0 -7
- package/src/components/Form/Inputs/ReadOnly.js +34 -28
- package/src/components/Form/Inputs/ReadOnly.test.js +45 -7
- package/src/components/Form/Inputs/Selector.js +22 -0
- package/src/components/Form/Inputs/Selector.test.js +105 -0
- package/src/components/Form/Inputs/Text.js +15 -44
- package/src/components/Form/Inputs/Text.test.js +20 -29
- package/src/components/Form/Inputs/Toggles.js +27 -26
- package/src/components/Form/Inputs/Toggles.test.js +22 -28
- package/src/components/Form/Inputs/index.js +4 -15
- package/src/components/MaterialUI/DataDisplay/PredefinedElements/Placeholder.js +32 -6
- package/src/components/MaterialUI/DataDisplay/PredefinedElements/Placeholder.test.js +3 -1
- package/src/components/MaterialUI/DataDisplay/Table.js +165 -114
- package/src/components/MaterialUI/DataDisplay/Table.test.js +246 -1
- package/src/components/MaterialUI/DataDisplay/TableProps.js +4 -0
- package/src/components/MaterialUI/DataDisplay/TableProps.test.js +2 -0
- package/src/components/MaterialUI/Inputs/Select.js +2 -0
- package/src/components/MaterialUI/Inputs/SelectProps.js +2 -0
- package/src/components/MaterialUI/Inputs/SelectProps.test.js +2 -0
- package/src/components/MaterialUI/Inputs/Switch.js +22 -1
- package/src/components/MaterialUI/Inputs/Switch.test.js +23 -0
- package/src/components/MaterialUI/Inputs/SwitchProps.js +2 -0
- package/src/components/MaterialUI/Inputs/SwitchProps.test.js +2 -0
- package/src/components/MaterialUI/muiThemes.js +1 -0
- package/src/components/Navigation/Bar.test.js +92 -87
- package/src/constants.js +1 -0
- package/src/hocs/withScrollBox.js +32 -19
- package/src/hocs/withScrollBox.test.js +15 -3
- package/src/hooks/useInMemoryPaging.js +85 -0
- package/src/hooks/useInMemoryPaging.test.js +551 -0
- package/src/hooks/useMultipleFieldEditState.js +11 -4
- package/src/hooks/useMultipleFieldEditState.test.js +49 -1
- package/src/selectors/locale.js +1 -1
- package/src/selectors/metadata.js +18 -1
- package/src/selectors/metadata.test.js +104 -0
- package/src/utils/ListHelper.js +203 -0
- package/src/utils/ListHelper.test.js +710 -0
- package/src/utils/comparisonHelper.js +124 -0
- package/src/utils/comparisonHelper.test.js +324 -0
- package/src/utils/propertyBagHelper.js +2 -0
- package/src/utils/propertyBagHelper.test.js +6 -0
- package/dist/components/Form/FieldList.js +0 -270
- package/dist/components/Form/Inputs/FieldButtons.js +0 -66
- package/dist/components/Form/Inputs/Number.js +0 -117
- package/dist/components/Form/Inputs/SmallButton.js +0 -91
- package/dist/components/Form/Inputs/Time.js +0 -86
- package/dist/components/Form/Inputs/Translation.js +0 -169
- package/src/components/Form/FieldList.js +0 -210
- package/src/components/Form/FieldList.test.js +0 -558
- package/src/components/Form/Inputs/FieldButtons.js +0 -90
- package/src/components/Form/Inputs/Number.js +0 -60
- package/src/components/Form/Inputs/Number.test.js +0 -435
- package/src/components/Form/Inputs/SmallButton.js +0 -37
- package/src/components/Form/Inputs/SmallButton.test.js +0 -65
- package/src/components/Form/Inputs/Time.js +0 -32
- package/src/components/Form/Inputs/Time.test.js +0 -41
- package/src/components/Form/Inputs/Translation.js +0 -93
- package/src/components/Form/Inputs/Translation.test.js +0 -204
|
@@ -3,10 +3,11 @@ import Immutable from "immutable";
|
|
|
3
3
|
import { Provider } from "react-redux";
|
|
4
4
|
import { IntlProvider } from "react-intl";
|
|
5
5
|
import { mount } from "unexpected-reaction";
|
|
6
|
+
import { StylesProvider } from "@material-ui/core";
|
|
7
|
+
import { generateClassName } from "../../utils/testUtils";
|
|
6
8
|
import { FormContext } from "./Form";
|
|
7
9
|
import Fieldset from "./Fieldset";
|
|
8
10
|
import Combination from "./Combination";
|
|
9
|
-
import FieldList from "./FieldList";
|
|
10
11
|
import InputField from "./InputField";
|
|
11
12
|
import FieldElements from "./FieldElements";
|
|
12
13
|
|
|
@@ -28,112 +29,100 @@ describe("FieldElements", () => {
|
|
|
28
29
|
};
|
|
29
30
|
});
|
|
30
31
|
|
|
31
|
-
it("renders a list of field elements, handling fieldsets, combination fields
|
|
32
|
+
it("renders a list of field elements, handling fieldsets, combination fields", () =>
|
|
32
33
|
expect(
|
|
33
34
|
mount(
|
|
34
35
|
<Provider store={store}>
|
|
35
|
-
<
|
|
36
|
-
<
|
|
37
|
-
<
|
|
38
|
-
fields={[
|
|
39
|
-
{
|
|
40
|
-
type: "ReadOnly",
|
|
41
|
-
name: "thing",
|
|
42
|
-
someProp: 12.5,
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
type: "Fieldset",
|
|
46
|
-
label: "A field set",
|
|
47
|
-
fields: [
|
|
48
|
-
{
|
|
49
|
-
type: "NumberInput",
|
|
50
|
-
name: "stuff",
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
type: "Combination",
|
|
56
|
-
name: "combo",
|
|
57
|
-
label: "Combined fields",
|
|
58
|
-
proportions: ["300px", 100],
|
|
59
|
-
fields: [
|
|
60
|
-
{ type: "CheckboxInput", name: "item" },
|
|
61
|
-
{ type: "EmailInput", name: "otheritem" },
|
|
62
|
-
],
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
type: "List",
|
|
66
|
-
name: "list",
|
|
67
|
-
rowCount: 15,
|
|
68
|
-
someProp: "Is this way",
|
|
69
|
-
rowField: { name: "listStuff", type: "TextInput" },
|
|
70
|
-
},
|
|
71
|
-
]}
|
|
72
|
-
getUpdater={getUpdater}
|
|
73
|
-
/>
|
|
74
|
-
</FormContext.Provider>
|
|
75
|
-
</IntlProvider>
|
|
76
|
-
</Provider>,
|
|
77
|
-
).childNodes,
|
|
78
|
-
"to satisfy",
|
|
79
|
-
[
|
|
80
|
-
<Provider store={store}>
|
|
81
|
-
<IntlProvider locale="en">
|
|
82
|
-
<FormContext.Provider value={{ values }}>
|
|
83
|
-
<InputField
|
|
84
|
-
key="thing"
|
|
85
|
-
name="thing"
|
|
86
|
-
type="ReadOnly"
|
|
87
|
-
update={expect.it("when called", "to equal", "thing")}
|
|
88
|
-
someProp={12.5}
|
|
89
|
-
/>
|
|
90
|
-
</FormContext.Provider>
|
|
91
|
-
</IntlProvider>
|
|
92
|
-
</Provider>,
|
|
93
|
-
<Provider store={store}>
|
|
94
|
-
<IntlProvider locale="en">
|
|
95
|
-
<FormContext.Provider value={{ values }}>
|
|
96
|
-
<Fieldset label="A field set">
|
|
36
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
37
|
+
<IntlProvider locale="en">
|
|
38
|
+
<FormContext.Provider value={{ values }}>
|
|
97
39
|
<FieldElements
|
|
98
40
|
fields={[
|
|
99
41
|
{
|
|
100
|
-
type: "
|
|
101
|
-
name: "
|
|
42
|
+
type: "ReadOnly",
|
|
43
|
+
name: "thing",
|
|
44
|
+
someProp: 12.5,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: "Fieldset",
|
|
48
|
+
label: {
|
|
49
|
+
id: "fieldset",
|
|
50
|
+
defaultMessage: "A field set",
|
|
51
|
+
},
|
|
52
|
+
fields: [
|
|
53
|
+
{
|
|
54
|
+
type: "NumberInput",
|
|
55
|
+
name: "stuff",
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: "Combination",
|
|
61
|
+
name: "combo",
|
|
62
|
+
label: {
|
|
63
|
+
id: "CombinedFields",
|
|
64
|
+
defaultMessage: "Combined fields",
|
|
65
|
+
},
|
|
66
|
+
proportions: ["300px", 100],
|
|
67
|
+
fields: [{ type: "CheckboxInput", name: "item" }],
|
|
102
68
|
},
|
|
103
69
|
]}
|
|
104
70
|
getUpdater={getUpdater}
|
|
105
71
|
/>
|
|
106
|
-
</
|
|
107
|
-
</
|
|
108
|
-
</
|
|
72
|
+
</FormContext.Provider>
|
|
73
|
+
</IntlProvider>
|
|
74
|
+
</StylesProvider>
|
|
109
75
|
</Provider>,
|
|
76
|
+
).childNodes,
|
|
77
|
+
"to satisfy",
|
|
78
|
+
[
|
|
110
79
|
<Provider store={store}>
|
|
111
|
-
<
|
|
112
|
-
<
|
|
113
|
-
<
|
|
114
|
-
<
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
80
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
81
|
+
<IntlProvider locale="en">
|
|
82
|
+
<FormContext.Provider value={{ values }}>
|
|
83
|
+
<InputField
|
|
84
|
+
key="thing"
|
|
85
|
+
name="thing"
|
|
86
|
+
type="ReadOnly"
|
|
87
|
+
update={expect.it("when called", "to equal", "thing")}
|
|
88
|
+
someProp={12.5}
|
|
120
89
|
/>
|
|
121
|
-
</
|
|
122
|
-
</
|
|
123
|
-
</
|
|
90
|
+
</FormContext.Provider>
|
|
91
|
+
</IntlProvider>
|
|
92
|
+
</StylesProvider>
|
|
124
93
|
</Provider>,
|
|
125
94
|
<Provider store={store}>
|
|
126
|
-
<
|
|
127
|
-
<
|
|
128
|
-
<
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
95
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
96
|
+
<IntlProvider locale="en">
|
|
97
|
+
<FormContext.Provider value={{ values }}>
|
|
98
|
+
<Fieldset label={{ id: "FieldSet", defaultMessage: "A field set" }}>
|
|
99
|
+
<FieldElements
|
|
100
|
+
fields={[
|
|
101
|
+
{
|
|
102
|
+
type: "NumberInput",
|
|
103
|
+
name: "stuff",
|
|
104
|
+
},
|
|
105
|
+
]}
|
|
106
|
+
getUpdater={getUpdater}
|
|
107
|
+
/>
|
|
108
|
+
</Fieldset>
|
|
109
|
+
</FormContext.Provider>
|
|
110
|
+
</IntlProvider>
|
|
111
|
+
</StylesProvider>
|
|
112
|
+
</Provider>,
|
|
113
|
+
<Provider store={store}>
|
|
114
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
115
|
+
<IntlProvider locale="en">
|
|
116
|
+
<FormContext.Provider value={{ values }}>
|
|
117
|
+
<Combination
|
|
118
|
+
label={{ id: "CombinedFields", defaultMessage: "Combined fields" }}
|
|
119
|
+
proportions={["300px", 100]}
|
|
120
|
+
>
|
|
121
|
+
<FieldElements fields={[{ type: "CheckboxInput", name: "item" }]} getUpdater={getUpdater} />
|
|
122
|
+
</Combination>
|
|
123
|
+
</FormContext.Provider>
|
|
124
|
+
</IntlProvider>
|
|
125
|
+
</StylesProvider>
|
|
137
126
|
</Provider>,
|
|
138
127
|
],
|
|
139
128
|
));
|
|
@@ -141,29 +130,33 @@ describe("FieldElements", () => {
|
|
|
141
130
|
it("handles absent update function and values", () =>
|
|
142
131
|
expect(
|
|
143
132
|
<Provider store={store}>
|
|
144
|
-
<
|
|
145
|
-
<
|
|
146
|
-
<
|
|
147
|
-
|
|
148
|
-
{
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
133
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
134
|
+
<IntlProvider locale="en">
|
|
135
|
+
<FormContext.Provider value={{ values }}>
|
|
136
|
+
<FieldElements
|
|
137
|
+
fields={[
|
|
138
|
+
{
|
|
139
|
+
type: "ReadOnly",
|
|
140
|
+
name: "thing",
|
|
141
|
+
},
|
|
142
|
+
]}
|
|
143
|
+
/>
|
|
144
|
+
</FormContext.Provider>
|
|
145
|
+
</IntlProvider>
|
|
146
|
+
</StylesProvider>
|
|
156
147
|
</Provider>,
|
|
157
148
|
"when mounted",
|
|
158
149
|
"to satisfy",
|
|
159
150
|
<Provider store={store}>
|
|
160
|
-
<
|
|
161
|
-
<
|
|
162
|
-
<
|
|
163
|
-
<
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
151
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
152
|
+
<IntlProvider locale="en">
|
|
153
|
+
<FormContext.Provider value={{ values }}>
|
|
154
|
+
<React.Fragment>
|
|
155
|
+
<InputField name="thing" update={undefined} value={undefined} type="ReadOnly" />
|
|
156
|
+
</React.Fragment>
|
|
157
|
+
</FormContext.Provider>
|
|
158
|
+
</IntlProvider>
|
|
159
|
+
</StylesProvider>
|
|
167
160
|
</Provider>,
|
|
168
161
|
));
|
|
169
162
|
});
|
|
@@ -1,42 +1,47 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import Text from "../Text";
|
|
2
|
+
import { makeStyles } from "@material-ui/core/styles";
|
|
3
|
+
import { FormattedMessage } from "react-intl";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
5
|
+
const useStyles = makeStyles(theme => ({
|
|
6
|
+
fieldsetBox: {
|
|
7
|
+
position: "relative",
|
|
8
|
+
boxSizing: "border-box",
|
|
9
|
+
display: "flex",
|
|
10
|
+
alignSelf: "stretch",
|
|
11
|
+
flexDirection: "column",
|
|
12
|
+
flexWrap: "wrap",
|
|
13
|
+
border: `1px solid ${theme.palette.grey.borders}`,
|
|
14
|
+
borderRadius: 5,
|
|
15
|
+
marginTop: 45,
|
|
16
|
+
marginLeft: 0,
|
|
17
|
+
marginBottom: 0,
|
|
18
|
+
padding: 20,
|
|
19
|
+
paddingTop: 0,
|
|
20
|
+
backgroundColor: "#fafafa",
|
|
21
|
+
},
|
|
22
|
+
legend: {
|
|
23
|
+
position: "absolute",
|
|
24
|
+
top: "-2em",
|
|
25
|
+
left: -4,
|
|
26
|
+
fontFamily: theme.typography.button.fontFamily,
|
|
27
|
+
fontStyle: "italic",
|
|
28
|
+
fontSize: 13,
|
|
29
|
+
textTransform: "uppercase",
|
|
30
|
+
color: theme.palette.primary.main,
|
|
31
|
+
},
|
|
32
|
+
}));
|
|
32
33
|
|
|
33
|
-
const Fieldset = ({ label, children }) =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
const Fieldset = ({ label, children }) => {
|
|
35
|
+
const classes = useStyles();
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<fieldset className={classes.fieldsetBox}>
|
|
39
|
+
<legend className={classes.legend}>
|
|
40
|
+
<FormattedMessage {...label} />
|
|
41
|
+
</legend>
|
|
42
|
+
{children}
|
|
43
|
+
</fieldset>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
41
46
|
|
|
42
47
|
export default Fieldset;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Provider } from "react-redux";
|
|
3
|
-
import
|
|
3
|
+
import { IntlProvider } from "react-intl";
|
|
4
|
+
import Fieldset from "./Fieldset";
|
|
5
|
+
import { extractMessages } from "../../utils/testUtils";
|
|
6
|
+
import sharedMessages from "../../sharedMessages";
|
|
7
|
+
|
|
8
|
+
const messages = extractMessages(sharedMessages);
|
|
4
9
|
|
|
5
10
|
describe("Fieldset", () => {
|
|
6
11
|
it("works", () =>
|
|
@@ -12,15 +17,17 @@ describe("Fieldset", () => {
|
|
|
12
17
|
getState: () => ({}),
|
|
13
18
|
}}
|
|
14
19
|
>
|
|
15
|
-
<
|
|
16
|
-
<
|
|
17
|
-
|
|
20
|
+
<IntlProvider locale="en" messages={messages}>
|
|
21
|
+
<Fieldset label={{ id: "fieldset.label", defaultMessage: "A field set" }}>
|
|
22
|
+
<div id="child" />
|
|
23
|
+
</Fieldset>
|
|
24
|
+
</IntlProvider>
|
|
18
25
|
</Provider>,
|
|
19
26
|
"when mounted",
|
|
20
27
|
"to satisfy",
|
|
21
|
-
<
|
|
22
|
-
<
|
|
28
|
+
<fieldset>
|
|
29
|
+
<legend>A field set</legend>
|
|
23
30
|
<div id="child" />
|
|
24
|
-
</
|
|
31
|
+
</fieldset>,
|
|
25
32
|
));
|
|
26
33
|
});
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import React, { createContext } from "react";
|
|
2
|
-
import
|
|
2
|
+
import { makeStyles } from "@material-ui/core/styles";
|
|
3
3
|
import pt from "prop-types";
|
|
4
4
|
import withScrollBox from "../../hocs/withScrollBox";
|
|
5
5
|
import Form from "./FormElement";
|
|
6
6
|
import FieldElements from "./FieldElements";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
const useStyles = makeStyles(() => ({
|
|
9
|
+
wrapper: {
|
|
10
|
+
display: "flex",
|
|
11
|
+
marginBottom: 20,
|
|
12
|
+
},
|
|
13
|
+
}));
|
|
12
14
|
|
|
13
15
|
const splitFields = (fields, cols) => {
|
|
14
16
|
if (cols <= 1) return [fields];
|
|
@@ -27,8 +29,10 @@ export const FormContext = createContext();
|
|
|
27
29
|
FormContext.displayName = "FormContext";
|
|
28
30
|
|
|
29
31
|
export const FormPage = ({ formName, cols = [1, 1, 1], getUpdater, fields, values, wide }) => {
|
|
32
|
+
const classes = useStyles();
|
|
30
33
|
let colSpans = wide ? [] : cols;
|
|
31
34
|
const colFields = splitFields(fields, colSpans.length);
|
|
35
|
+
|
|
32
36
|
return (
|
|
33
37
|
<FormContext.Provider
|
|
34
38
|
value={{
|
|
@@ -36,13 +40,13 @@ export const FormPage = ({ formName, cols = [1, 1, 1], getUpdater, fields, value
|
|
|
36
40
|
formName,
|
|
37
41
|
}}
|
|
38
42
|
>
|
|
39
|
-
<
|
|
43
|
+
<div className={classes.wrapper}>
|
|
40
44
|
{colFields.map((fields, index) => (
|
|
41
45
|
<Form key={index} spanWidth={colSpans[index] || 1}>
|
|
42
46
|
<FieldElements getUpdater={getUpdater} fields={fields} />
|
|
43
47
|
</Form>
|
|
44
48
|
))}
|
|
45
|
-
</
|
|
49
|
+
</div>
|
|
46
50
|
</FormContext.Provider>
|
|
47
51
|
);
|
|
48
52
|
};
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import Immutable from "immutable";
|
|
3
3
|
import { Provider } from "react-redux";
|
|
4
|
+
import { generateClassName } from "../../utils/testUtils";
|
|
4
5
|
import { IntlProvider } from "react-intl";
|
|
5
6
|
import Form from "./FormElement";
|
|
6
7
|
import FieldElements from "./FieldElements";
|
|
7
|
-
import
|
|
8
|
-
import { FormPage,
|
|
8
|
+
import Field from "./Field";
|
|
9
|
+
import { FormPage, FormContext } from "./Form";
|
|
10
|
+
import { StylesProvider } from "@material-ui/core";
|
|
11
|
+
import { TextInput } from "./Inputs/Text";
|
|
9
12
|
|
|
10
13
|
describe("FormPage", () => {
|
|
11
14
|
let state, store, getUpdater, fields, manyFields, values;
|
|
@@ -36,94 +39,110 @@ describe("FormPage", () => {
|
|
|
36
39
|
it("renders a form with a single field", () =>
|
|
37
40
|
expect(
|
|
38
41
|
<Provider store={store}>
|
|
39
|
-
<
|
|
40
|
-
<
|
|
41
|
-
|
|
42
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
43
|
+
<IntlProvider locale="en">
|
|
44
|
+
<FormPage formName="testForm" fields={fields} getUpdater={getUpdater} values={values} />
|
|
45
|
+
</IntlProvider>
|
|
46
|
+
</StylesProvider>
|
|
42
47
|
</Provider>,
|
|
43
48
|
"when mounted",
|
|
44
49
|
"to satisfy",
|
|
45
50
|
<Provider store={store}>
|
|
46
|
-
<
|
|
47
|
-
<
|
|
48
|
-
<
|
|
49
|
-
<
|
|
50
|
-
<
|
|
51
|
-
<
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
52
|
+
<IntlProvider locale="en">
|
|
53
|
+
<FormContext.Provider value={{ values, formName: "testForm" }}>
|
|
54
|
+
<div>
|
|
55
|
+
<Form spanWidth={1}>
|
|
56
|
+
<Field>
|
|
57
|
+
<label>A text</label>
|
|
58
|
+
<TextInput value="foo" />
|
|
59
|
+
</Field>
|
|
60
|
+
</Form>
|
|
61
|
+
</div>
|
|
62
|
+
</FormContext.Provider>
|
|
63
|
+
</IntlProvider>
|
|
64
|
+
</StylesProvider>
|
|
58
65
|
</Provider>,
|
|
59
66
|
));
|
|
60
67
|
|
|
61
68
|
it("still respects 'wide' flag", () =>
|
|
62
69
|
expect(
|
|
63
70
|
<Provider store={store}>
|
|
64
|
-
<
|
|
65
|
-
<
|
|
66
|
-
|
|
71
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
72
|
+
<IntlProvider locale="en">
|
|
73
|
+
<FormPage wide fields={fields} getUpdater={getUpdater} values={values} />
|
|
74
|
+
</IntlProvider>
|
|
75
|
+
</StylesProvider>
|
|
67
76
|
</Provider>,
|
|
68
77
|
"when mounted",
|
|
69
78
|
"to satisfy",
|
|
70
79
|
<Provider store={store}>
|
|
71
|
-
<
|
|
72
|
-
<
|
|
73
|
-
<
|
|
74
|
-
<
|
|
75
|
-
<
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
81
|
+
<IntlProvider locale="en">
|
|
82
|
+
<FormContext.Provider value={{ values }}>
|
|
83
|
+
<div>
|
|
84
|
+
<Form spanWidth={1}>
|
|
85
|
+
<FieldElements getUpdater={getUpdater} fields={fields} />
|
|
86
|
+
</Form>
|
|
87
|
+
</div>
|
|
88
|
+
</FormContext.Provider>
|
|
89
|
+
</IntlProvider>
|
|
90
|
+
</StylesProvider>
|
|
80
91
|
</Provider>,
|
|
81
92
|
));
|
|
82
93
|
|
|
83
94
|
it("still respects 'wide' flag with multiple fields", () =>
|
|
84
95
|
expect(
|
|
85
96
|
<Provider store={store}>
|
|
86
|
-
<
|
|
87
|
-
<
|
|
88
|
-
|
|
97
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
98
|
+
<IntlProvider locale="en">
|
|
99
|
+
<FormPage wide cols={[2, 1]} fields={manyFields} getUpdater={getUpdater} values={values} />
|
|
100
|
+
</IntlProvider>
|
|
101
|
+
</StylesProvider>
|
|
89
102
|
</Provider>,
|
|
90
103
|
"when mounted",
|
|
91
104
|
"to satisfy",
|
|
92
105
|
<Provider store={store}>
|
|
93
|
-
<
|
|
94
|
-
<
|
|
95
|
-
<
|
|
96
|
-
<
|
|
97
|
-
<
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
106
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
107
|
+
<IntlProvider locale="en">
|
|
108
|
+
<FormContext.Provider value={{ values }}>
|
|
109
|
+
<div>
|
|
110
|
+
<Form spanWidth={1}>
|
|
111
|
+
<FieldElements getUpdater={getUpdater} fields={manyFields} />
|
|
112
|
+
</Form>
|
|
113
|
+
</div>
|
|
114
|
+
</FormContext.Provider>
|
|
115
|
+
</IntlProvider>
|
|
116
|
+
</StylesProvider>
|
|
102
117
|
</Provider>,
|
|
103
118
|
));
|
|
104
119
|
|
|
105
120
|
it("renders a form with a multiple fields", () =>
|
|
106
121
|
expect(
|
|
107
122
|
<Provider store={store}>
|
|
108
|
-
<
|
|
109
|
-
<
|
|
110
|
-
|
|
123
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
124
|
+
<IntlProvider locale="en">
|
|
125
|
+
<FormPage cols={[2, 1]} fields={manyFields} getUpdater={getUpdater} values={values} />
|
|
126
|
+
</IntlProvider>
|
|
127
|
+
</StylesProvider>
|
|
111
128
|
</Provider>,
|
|
112
129
|
"when mounted",
|
|
113
130
|
"to satisfy",
|
|
114
131
|
<Provider store={store}>
|
|
115
|
-
<
|
|
116
|
-
<
|
|
117
|
-
<
|
|
118
|
-
<
|
|
119
|
-
<
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
<
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
132
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
133
|
+
<IntlProvider locale="en">
|
|
134
|
+
<FormContext.Provider value={{ values }}>
|
|
135
|
+
<div>
|
|
136
|
+
<Form spanWidth={2}>
|
|
137
|
+
<FieldElements getUpdater={getUpdater} fields={manyFields.slice(0, 5)} />
|
|
138
|
+
</Form>
|
|
139
|
+
<Form spanWidth={1}>
|
|
140
|
+
<FieldElements getUpdater={getUpdater} fields={manyFields.slice(5, 10)} />
|
|
141
|
+
</Form>
|
|
142
|
+
</div>
|
|
143
|
+
</FormContext.Provider>
|
|
144
|
+
</IntlProvider>
|
|
145
|
+
</StylesProvider>
|
|
127
146
|
</Provider>,
|
|
128
147
|
));
|
|
129
148
|
});
|
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { makeStyles } from "@material-ui/core/styles";
|
|
2
|
+
import React from "react";
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
const useStyles = makeStyles(() => ({
|
|
5
|
+
form: {
|
|
6
|
+
boxSizing: "border-box",
|
|
7
|
+
flexBasis: 0,
|
|
8
|
+
flexShrink: 0,
|
|
9
|
+
display: "flex",
|
|
10
|
+
flexDirection: "column",
|
|
11
|
+
padding: 0,
|
|
12
|
+
paddingRight: 20,
|
|
13
|
+
paddingTop: 0,
|
|
14
|
+
fontSize: 12,
|
|
15
|
+
flexGrow: props => props.spanWidth,
|
|
16
|
+
"&:first-child": {
|
|
17
|
+
paddingLeft: 20,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
}));
|
|
14
21
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
const Form = ({ spanWidth = 1, children }) => {
|
|
23
|
+
const classes = useStyles({ spanWidth });
|
|
24
|
+
|
|
25
|
+
return <div className={classes.form}>{children}</div>;
|
|
26
|
+
};
|
|
19
27
|
|
|
20
28
|
export default Form;
|