@pareto-engineering/design-system 2.0.0-alpha.44 → 2.0.0-alpha.45
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/cjs/f/fields/QueryCombobox/QueryCombobox.js +36 -51
- package/dist/cjs/f/fields/QueryCombobox/common/Combobox/Combobox.js +47 -14
- package/dist/cjs/f/fields/QueryCombobox/common/Menu/Menu.js +1 -1
- package/dist/cjs/f/fields/QueryCombobox/common/index.js +1 -9
- package/dist/cjs/f/fields/QueryCombobox/styles.scss +45 -39
- package/dist/cjs/f/fields/index.js +9 -1
- package/dist/es/f/fields/QueryCombobox/QueryCombobox.js +40 -53
- package/dist/es/f/fields/QueryCombobox/common/Combobox/Combobox.js +48 -16
- package/dist/es/f/fields/QueryCombobox/common/Menu/Menu.js +1 -1
- package/dist/es/f/fields/QueryCombobox/common/index.js +1 -2
- package/dist/es/f/fields/QueryCombobox/styles.scss +45 -39
- package/dist/es/f/fields/index.js +2 -1
- package/package.json +3 -2
- package/src/__snapshots__/Storyshots.test.js.snap +158 -0
- package/src/stories/f/QueryCombobox.stories.jsx +220 -0
- package/src/stories/f/__generated__/QueryComboboxAllTeamsQuery.graphql.js +139 -0
- package/src/stories/utils/generateNodeId.js +12 -0
- package/src/stories/utils/testData.js +63 -0
- package/src/ui/f/fields/QueryCombobox/QueryCombobox.jsx +200 -0
- package/src/ui/f/fields/QueryCombobox/common/Combobox/Combobox.jsx +198 -0
- package/src/ui/f/fields/QueryCombobox/common/Combobox/index.js +2 -0
- package/src/ui/f/fields/QueryCombobox/common/Menu/Menu.jsx +103 -0
- package/src/ui/f/fields/QueryCombobox/common/Menu/index.js +2 -0
- package/src/ui/f/fields/QueryCombobox/common/index.js +2 -0
- package/src/ui/f/fields/QueryCombobox/index.js +2 -0
- package/src/ui/f/fields/QueryCombobox/styles.scss +71 -0
- package/src/ui/f/fields/index.js +1 -0
|
@@ -7,12 +7,12 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var React = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
|
+
var _formik = require("formik");
|
|
11
|
+
|
|
10
12
|
var _reactRelay = require("react-relay");
|
|
11
13
|
|
|
12
14
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
15
|
|
|
14
|
-
var _bem = _interopRequireDefault(require("@pareto-engineering/bem"));
|
|
15
|
-
|
|
16
16
|
var _common = require("./common");
|
|
17
17
|
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -27,19 +27,13 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
27
27
|
|
|
28
28
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
29
29
|
|
|
30
|
-
var baseClassName = _bem.default.base;
|
|
31
|
-
var componentClassName = 'query-combobox';
|
|
32
30
|
/**
|
|
33
31
|
* This is the component description.
|
|
34
32
|
*/
|
|
35
|
-
|
|
36
33
|
var QueryCombobox = _ref => {
|
|
37
34
|
var {
|
|
38
|
-
id,
|
|
39
|
-
className: userClassName,
|
|
40
|
-
style,
|
|
41
35
|
query,
|
|
42
|
-
multiple,
|
|
36
|
+
// multiple,
|
|
43
37
|
name,
|
|
44
38
|
label,
|
|
45
39
|
color,
|
|
@@ -49,34 +43,45 @@ var QueryCombobox = _ref => {
|
|
|
49
43
|
graphQlNode,
|
|
50
44
|
searchVariable,
|
|
51
45
|
extraVariables,
|
|
52
|
-
optionsKeyMap
|
|
53
|
-
setValue,
|
|
54
|
-
setError,
|
|
55
|
-
error // ...otherProps
|
|
46
|
+
optionsKeyMap // ...otherProps
|
|
56
47
|
|
|
57
48
|
} = _ref;
|
|
58
49
|
(0, React.useLayoutEffect)(() => {
|
|
59
50
|
Promise.resolve().then(() => _interopRequireWildcard(require("./styles.scss")));
|
|
60
51
|
}, []);
|
|
52
|
+
var [, meta, helpers] = (0, _formik.useField)(name);
|
|
53
|
+
var {
|
|
54
|
+
setValue,
|
|
55
|
+
setError
|
|
56
|
+
} = helpers;
|
|
57
|
+
var {
|
|
58
|
+
error,
|
|
59
|
+
value
|
|
60
|
+
} = meta;
|
|
61
61
|
var environment = (0, _reactRelay.useRelayEnvironment)();
|
|
62
62
|
var [isFetching, setIsFetching] = (0, React.useState)(false);
|
|
63
63
|
var [options, setOptions] = (0, React.useState)([]);
|
|
64
64
|
|
|
65
|
-
var
|
|
65
|
+
var getOptions = inputValue => {
|
|
66
66
|
if (isFetching) return;
|
|
67
|
-
|
|
67
|
+
var variables = {
|
|
68
68
|
[searchVariable]: inputValue
|
|
69
|
-
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
if (extraVariables) {
|
|
72
|
+
variables = _objectSpread(_objectSpread({}, variables), extraVariables);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
(0, _reactRelay.fetchQuery)(environment, query, variables).subscribe({
|
|
70
76
|
start: () => {
|
|
71
77
|
setIsFetching(true);
|
|
72
78
|
},
|
|
73
79
|
complete: () => {
|
|
74
80
|
setIsFetching(false);
|
|
75
81
|
},
|
|
76
|
-
error:
|
|
77
|
-
console.log(theError);
|
|
82
|
+
error: fetchError => {
|
|
78
83
|
setIsFetching(false);
|
|
79
|
-
if (setError) setError(
|
|
84
|
+
if (setError) setError(fetchError.message);
|
|
80
85
|
},
|
|
81
86
|
next: data => {
|
|
82
87
|
setOptions(data[graphQlNode].edges.map(_ref2 => {
|
|
@@ -94,22 +99,19 @@ var QueryCombobox = _ref => {
|
|
|
94
99
|
|
|
95
100
|
var comboboxProps = {
|
|
96
101
|
options,
|
|
97
|
-
|
|
102
|
+
getOptions,
|
|
98
103
|
debounceMs,
|
|
99
104
|
disabled,
|
|
100
105
|
name,
|
|
101
106
|
label,
|
|
102
107
|
description,
|
|
103
108
|
setValue,
|
|
104
|
-
error
|
|
109
|
+
error,
|
|
110
|
+
value,
|
|
111
|
+
color
|
|
105
112
|
};
|
|
106
|
-
var
|
|
107
|
-
return /*#__PURE__*/React.createElement(
|
|
108
|
-
id: id,
|
|
109
|
-
className: [baseClassName, componentClassName, userClassName, "y-".concat(color)].filter(e => e).join(' '),
|
|
110
|
-
style: style // {...otherProps}
|
|
111
|
-
|
|
112
|
-
}, /*#__PURE__*/React.createElement(Component, comboboxProps));
|
|
113
|
+
var Input = _common.Combobox;
|
|
114
|
+
return /*#__PURE__*/React.createElement(Input, comboboxProps);
|
|
113
115
|
};
|
|
114
116
|
|
|
115
117
|
QueryCombobox.propTypes = {
|
|
@@ -138,11 +140,6 @@ QueryCombobox.propTypes = {
|
|
|
138
140
|
*/
|
|
139
141
|
label: _propTypes.default.string,
|
|
140
142
|
|
|
141
|
-
/**
|
|
142
|
-
* The input field validator function
|
|
143
|
-
*/
|
|
144
|
-
validate: _propTypes.default.func,
|
|
145
|
-
|
|
146
143
|
/**
|
|
147
144
|
* The custom select input description
|
|
148
145
|
*/
|
|
@@ -180,7 +177,7 @@ QueryCombobox.propTypes = {
|
|
|
180
177
|
optionsKeyMap: _propTypes.default.shape({
|
|
181
178
|
value: _propTypes.default.string.isRequired,
|
|
182
179
|
label: _propTypes.default.string.isRequired
|
|
183
|
-
})
|
|
180
|
+
}),
|
|
184
181
|
|
|
185
182
|
/**
|
|
186
183
|
* Whether to allow multiple items selection
|
|
@@ -195,25 +192,13 @@ QueryCombobox.propTypes = {
|
|
|
195
192
|
/**
|
|
196
193
|
* The variable to be used to search the data
|
|
197
194
|
*/
|
|
198
|
-
searchVariable: _propTypes.default.string
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* The function to be called when the value changes
|
|
202
|
-
*/
|
|
203
|
-
setValue: _propTypes.default.func.isRequired,
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* The function to be called with an error when the it occurs
|
|
207
|
-
*/
|
|
208
|
-
setError: _propTypes.default.func,
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* The error object
|
|
212
|
-
*/
|
|
213
|
-
error: _propTypes.default.objectOf(_propTypes.default.string)
|
|
195
|
+
searchVariable: _propTypes.default.string
|
|
214
196
|
};
|
|
215
197
|
QueryCombobox.defaultProps = {
|
|
216
|
-
|
|
198
|
+
optionsKeyMap: {
|
|
199
|
+
value: 'id',
|
|
200
|
+
label: 'name'
|
|
201
|
+
},
|
|
217
202
|
multiple: false,
|
|
218
203
|
color: 'background2',
|
|
219
204
|
searchVariable: 'search'
|
|
@@ -15,6 +15,8 @@ var _bem = _interopRequireDefault(require("@pareto-engineering/bem"));
|
|
|
15
15
|
|
|
16
16
|
var _ = require("../../../..");
|
|
17
17
|
|
|
18
|
+
var _a = require("../../../../../a");
|
|
19
|
+
|
|
18
20
|
var _Menu = require("../Menu");
|
|
19
21
|
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -39,14 +41,17 @@ var Combobox = _ref => {
|
|
|
39
41
|
label,
|
|
40
42
|
name,
|
|
41
43
|
options: items,
|
|
42
|
-
|
|
44
|
+
getOptions,
|
|
43
45
|
setValue,
|
|
44
46
|
error,
|
|
45
|
-
description
|
|
47
|
+
description,
|
|
48
|
+
value,
|
|
49
|
+
color // ...otherProps
|
|
46
50
|
|
|
47
51
|
} = _ref;
|
|
48
52
|
var {
|
|
49
53
|
isOpen,
|
|
54
|
+
selectItem,
|
|
50
55
|
selectedItem,
|
|
51
56
|
getLabelProps,
|
|
52
57
|
getMenuProps,
|
|
@@ -56,34 +61,49 @@ var Combobox = _ref => {
|
|
|
56
61
|
getItemProps
|
|
57
62
|
} = (0, _downshift.useCombobox)({
|
|
58
63
|
items,
|
|
64
|
+
initialSelectedItem: value,
|
|
59
65
|
itemToString: item => item ? item.label : '',
|
|
60
66
|
onInputValueChange: _ref2 => {
|
|
61
67
|
var {
|
|
62
68
|
inputValue
|
|
63
69
|
} = _ref2;
|
|
64
|
-
|
|
70
|
+
getOptions(inputValue);
|
|
65
71
|
}
|
|
66
|
-
});
|
|
72
|
+
}); // If the user has selected an item, we'll set the value of the field
|
|
73
|
+
// or if the combobox state has a selected item, we'll set the value to the formik state
|
|
74
|
+
|
|
67
75
|
(0, React.useEffect)(() => {
|
|
68
76
|
if (selectedItem) {
|
|
69
|
-
setValue(selectedItem
|
|
77
|
+
setValue(selectedItem);
|
|
70
78
|
}
|
|
71
|
-
}, [selectedItem]);
|
|
79
|
+
}, [selectedItem]); // If the formik state has a value, we'll set the selected item to the combobox state
|
|
80
|
+
|
|
81
|
+
(0, React.useEffect)(() => {
|
|
82
|
+
if ((value === null || value === void 0 ? void 0 : value.value) !== (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value)) {
|
|
83
|
+
selectItem(value);
|
|
84
|
+
}
|
|
85
|
+
}, [value]);
|
|
86
|
+
var parentRef = (0, React.useRef)(null);
|
|
72
87
|
return /*#__PURE__*/React.createElement("div", {
|
|
73
88
|
id: id,
|
|
74
|
-
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
|
|
75
|
-
style: style
|
|
89
|
+
className: [baseClassName, componentClassName, userClassName, "y-".concat(color)].filter(e => e).join(' '),
|
|
90
|
+
style: style,
|
|
91
|
+
ref: parentRef
|
|
76
92
|
}, /*#__PURE__*/React.createElement(_.FormLabel, _extends({}, getLabelProps(), {
|
|
77
|
-
className: "input-label",
|
|
78
93
|
name: name
|
|
79
|
-
}), label), /*#__PURE__*/React.createElement("div",
|
|
94
|
+
}), label), /*#__PURE__*/React.createElement("div", _extends({}, getComboboxProps(), {
|
|
95
|
+
className: "input-wrapper"
|
|
96
|
+
}), /*#__PURE__*/React.createElement("input", _extends({}, getInputProps(), {
|
|
80
97
|
className: "input"
|
|
81
|
-
}))), /*#__PURE__*/React.createElement(
|
|
98
|
+
}))), /*#__PURE__*/React.createElement(_a.Popover, {
|
|
99
|
+
isOpen: isOpen,
|
|
100
|
+
parentRef: parentRef
|
|
101
|
+
}, /*#__PURE__*/React.createElement(_Menu.Menu, _extends({
|
|
82
102
|
isOpen: isOpen,
|
|
83
103
|
getItemProps: getItemProps,
|
|
84
104
|
highlightedIndex: highlightedIndex,
|
|
85
105
|
items: items
|
|
86
|
-
}, getMenuProps())), (description || error) && /*#__PURE__*/React.createElement(_.FormDescription, {
|
|
106
|
+
}, getMenuProps()))), (description || error) && /*#__PURE__*/React.createElement(_.FormDescription, {
|
|
87
107
|
isError: !!error
|
|
88
108
|
}, error || description));
|
|
89
109
|
};
|
|
@@ -125,7 +145,7 @@ Combobox.propTypes = {
|
|
|
125
145
|
/**
|
|
126
146
|
* The function to fetch the options from the backend
|
|
127
147
|
*/
|
|
128
|
-
|
|
148
|
+
getOptions: _propTypes.default.func,
|
|
129
149
|
|
|
130
150
|
/**
|
|
131
151
|
* The function to set the value of the custom select input
|
|
@@ -140,7 +160,20 @@ Combobox.propTypes = {
|
|
|
140
160
|
/**
|
|
141
161
|
* The error object
|
|
142
162
|
*/
|
|
143
|
-
error: _propTypes.default.objectOf(_propTypes.default.string)
|
|
163
|
+
error: _propTypes.default.objectOf(_propTypes.default.string),
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* The value of the custom select input
|
|
167
|
+
*/
|
|
168
|
+
value: _propTypes.default.shape({
|
|
169
|
+
value: _propTypes.default.string,
|
|
170
|
+
label: _propTypes.default.string
|
|
171
|
+
}),
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The base color of the combobox custom select input
|
|
175
|
+
*/
|
|
176
|
+
color: _propTypes.default.string
|
|
144
177
|
};
|
|
145
178
|
Combobox.defaultProps = {// someProp:false
|
|
146
179
|
};
|
|
@@ -55,7 +55,7 @@ var Menu = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
55
55
|
item,
|
|
56
56
|
index
|
|
57
57
|
}), {
|
|
58
|
-
className:
|
|
58
|
+
className: ['item', highlightedIndex === index && _bem.default.modifierActive].filter(Boolean).join(' ')
|
|
59
59
|
}), /*#__PURE__*/React.createElement("p", null, item.label))));
|
|
60
60
|
});
|
|
61
61
|
Menu.propTypes = {
|
|
@@ -15,15 +15,7 @@ Object.defineProperty(exports, "Combobox", {
|
|
|
15
15
|
return _Combobox.Combobox;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
Object.defineProperty(exports, "MultipleCombobox", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function get() {
|
|
21
|
-
return _MultipleCombobox.MultipleCombobox;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
18
|
|
|
25
19
|
var _Menu = require("./Menu");
|
|
26
20
|
|
|
27
|
-
var _Combobox = require("./Combobox");
|
|
28
|
-
|
|
29
|
-
var _MultipleCombobox = require("./MultipleCombobox");
|
|
21
|
+
var _Combobox = require("./Combobox");
|
|
@@ -6,60 +6,66 @@ $default-input-padding: .75em .75em .55em;
|
|
|
6
6
|
$default-padding: 1em;
|
|
7
7
|
$default-margin: 1em;
|
|
8
8
|
|
|
9
|
-
.#{bem.$base}.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
padding: $default-input-padding;
|
|
9
|
+
.#{bem.$base}.combobox,
|
|
10
|
+
.#{bem.$base}.multiple-combobox {
|
|
11
|
+
position: relative;
|
|
12
|
+
|
|
13
|
+
.#{bem.$base}.popover {
|
|
15
14
|
width: 100%;
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
>.menu {
|
|
17
|
+
list-style: none;
|
|
18
|
+
margin: 0;
|
|
19
|
+
outline: 0;
|
|
20
|
+
padding: 0;
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
&:disabled {
|
|
26
|
-
background-color: var(--dark-y);
|
|
27
|
-
}
|
|
22
|
+
>.item {
|
|
23
|
+
padding: $default-padding / 2;
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
&.#{bem.$modifier-active} {
|
|
26
|
+
background-color: var(--background2);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
>.input-wrapper {
|
|
33
|
+
>.input {
|
|
34
|
+
background: var(--light-y);
|
|
35
|
+
border: var(--theme-border-style) var(--dark-y);
|
|
36
|
+
color: var(--on-y);
|
|
37
|
+
padding: $default-input-padding;
|
|
38
|
+
width: 100%;
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
40
|
+
&::placeholder {
|
|
41
|
+
color: var(--metadata);
|
|
42
|
+
}
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
&:not(:disabled):hover {
|
|
45
|
+
border: var(--theme-border-style) var(--light-background4);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
&:disabled {
|
|
49
|
+
background-color: var(--dark-y);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&:focus {
|
|
53
|
+
background: var(--light-background4);
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
56
|
}
|
|
57
|
+
}
|
|
52
58
|
|
|
53
|
-
.multiple-combobox {
|
|
54
|
-
.selected-items {
|
|
55
|
-
display: flex;
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
60
|
+
.#{bem.$base}.multiple-combobox {
|
|
61
|
+
>.selected-items {
|
|
62
|
+
display: flex;
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
/* stylelint-disable selector-max-universal -- Allow */
|
|
65
|
+
>*:not(:first-child) {
|
|
66
|
+
margin-left: $default-margin;
|
|
63
67
|
}
|
|
68
|
+
|
|
69
|
+
/* stylelint-enable selector-max-universal */
|
|
64
70
|
}
|
|
65
71
|
}
|
|
@@ -33,6 +33,12 @@ Object.defineProperty(exports, "RatingsInput", {
|
|
|
33
33
|
return _RatingsInput.RatingsInput;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
+
Object.defineProperty(exports, "QueryCombobox", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function get() {
|
|
39
|
+
return _QueryCombobox.QueryCombobox;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
36
42
|
|
|
37
43
|
var _TextInput = require("./TextInput");
|
|
38
44
|
|
|
@@ -42,4 +48,6 @@ var _ChoicesInput = require("./ChoicesInput");
|
|
|
42
48
|
|
|
43
49
|
var _TextareaInput = require("./TextareaInput");
|
|
44
50
|
|
|
45
|
-
var _RatingsInput = require("./RatingsInput");
|
|
51
|
+
var _RatingsInput = require("./RatingsInput");
|
|
52
|
+
|
|
53
|
+
var _QueryCombobox = require("./QueryCombobox");
|
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useState, useLayoutEffect } from 'react';
|
|
4
|
+
import { useField } from 'formik';
|
|
4
5
|
import { useRelayEnvironment, fetchQuery } from 'react-relay';
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
|
-
import styleNames from '@pareto-engineering/bem'; // Local Definitions
|
|
6
|
+
import PropTypes from 'prop-types'; // Local Definitions
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
const baseClassName = styleNames.base;
|
|
10
|
-
const componentClassName = 'query-combobox';
|
|
8
|
+
import { Combobox } from "./common";
|
|
11
9
|
/**
|
|
12
10
|
* This is the component description.
|
|
13
11
|
*/
|
|
14
12
|
|
|
15
13
|
const QueryCombobox = ({
|
|
16
|
-
id,
|
|
17
|
-
className: userClassName,
|
|
18
|
-
style,
|
|
19
14
|
query,
|
|
20
|
-
multiple,
|
|
15
|
+
// multiple,
|
|
21
16
|
name,
|
|
22
17
|
label,
|
|
23
18
|
color,
|
|
@@ -27,35 +22,47 @@ const QueryCombobox = ({
|
|
|
27
22
|
graphQlNode,
|
|
28
23
|
searchVariable,
|
|
29
24
|
extraVariables,
|
|
30
|
-
optionsKeyMap
|
|
31
|
-
setValue,
|
|
32
|
-
setError,
|
|
33
|
-
error // ...otherProps
|
|
25
|
+
optionsKeyMap // ...otherProps
|
|
34
26
|
|
|
35
27
|
}) => {
|
|
36
28
|
useLayoutEffect(() => {
|
|
37
29
|
import("./styles.scss");
|
|
38
30
|
}, []);
|
|
31
|
+
const [, meta, helpers] = useField(name);
|
|
32
|
+
const {
|
|
33
|
+
setValue,
|
|
34
|
+
setError
|
|
35
|
+
} = helpers;
|
|
36
|
+
const {
|
|
37
|
+
error,
|
|
38
|
+
value
|
|
39
|
+
} = meta;
|
|
39
40
|
const environment = useRelayEnvironment();
|
|
40
41
|
const [isFetching, setIsFetching] = useState(false);
|
|
41
42
|
const [options, setOptions] = useState([]);
|
|
42
43
|
|
|
43
|
-
const
|
|
44
|
+
const getOptions = inputValue => {
|
|
44
45
|
if (isFetching) return;
|
|
45
|
-
|
|
46
|
-
[searchVariable]: inputValue
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
let variables = {
|
|
47
|
+
[searchVariable]: inputValue
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
if (extraVariables) {
|
|
51
|
+
variables = { ...variables,
|
|
52
|
+
...extraVariables
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fetchQuery(environment, query, variables).subscribe({
|
|
49
57
|
start: () => {
|
|
50
58
|
setIsFetching(true);
|
|
51
59
|
},
|
|
52
60
|
complete: () => {
|
|
53
61
|
setIsFetching(false);
|
|
54
62
|
},
|
|
55
|
-
error:
|
|
56
|
-
console.log(theError);
|
|
63
|
+
error: fetchError => {
|
|
57
64
|
setIsFetching(false);
|
|
58
|
-
if (setError) setError(
|
|
65
|
+
if (setError) setError(fetchError.message);
|
|
59
66
|
},
|
|
60
67
|
next: data => {
|
|
61
68
|
setOptions(data[graphQlNode].edges.map(({
|
|
@@ -70,22 +77,19 @@ const QueryCombobox = ({
|
|
|
70
77
|
|
|
71
78
|
const comboboxProps = {
|
|
72
79
|
options,
|
|
73
|
-
|
|
80
|
+
getOptions,
|
|
74
81
|
debounceMs,
|
|
75
82
|
disabled,
|
|
76
83
|
name,
|
|
77
84
|
label,
|
|
78
85
|
description,
|
|
79
86
|
setValue,
|
|
80
|
-
error
|
|
87
|
+
error,
|
|
88
|
+
value,
|
|
89
|
+
color
|
|
81
90
|
};
|
|
82
|
-
const
|
|
83
|
-
return /*#__PURE__*/React.createElement(
|
|
84
|
-
id: id,
|
|
85
|
-
className: [baseClassName, componentClassName, userClassName, `y-${color}`].filter(e => e).join(' '),
|
|
86
|
-
style: style // {...otherProps}
|
|
87
|
-
|
|
88
|
-
}, /*#__PURE__*/React.createElement(Component, comboboxProps));
|
|
91
|
+
const Input = Combobox;
|
|
92
|
+
return /*#__PURE__*/React.createElement(Input, comboboxProps);
|
|
89
93
|
};
|
|
90
94
|
|
|
91
95
|
QueryCombobox.propTypes = {
|
|
@@ -114,11 +118,6 @@ QueryCombobox.propTypes = {
|
|
|
114
118
|
*/
|
|
115
119
|
label: PropTypes.string,
|
|
116
120
|
|
|
117
|
-
/**
|
|
118
|
-
* The input field validator function
|
|
119
|
-
*/
|
|
120
|
-
validate: PropTypes.func,
|
|
121
|
-
|
|
122
121
|
/**
|
|
123
122
|
* The custom select input description
|
|
124
123
|
*/
|
|
@@ -156,7 +155,7 @@ QueryCombobox.propTypes = {
|
|
|
156
155
|
optionsKeyMap: PropTypes.shape({
|
|
157
156
|
value: PropTypes.string.isRequired,
|
|
158
157
|
label: PropTypes.string.isRequired
|
|
159
|
-
})
|
|
158
|
+
}),
|
|
160
159
|
|
|
161
160
|
/**
|
|
162
161
|
* Whether to allow multiple items selection
|
|
@@ -171,25 +170,13 @@ QueryCombobox.propTypes = {
|
|
|
171
170
|
/**
|
|
172
171
|
* The variable to be used to search the data
|
|
173
172
|
*/
|
|
174
|
-
searchVariable: PropTypes.string
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* The function to be called when the value changes
|
|
178
|
-
*/
|
|
179
|
-
setValue: PropTypes.func.isRequired,
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* The function to be called with an error when the it occurs
|
|
183
|
-
*/
|
|
184
|
-
setError: PropTypes.func,
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* The error object
|
|
188
|
-
*/
|
|
189
|
-
error: PropTypes.objectOf(PropTypes.string)
|
|
173
|
+
searchVariable: PropTypes.string
|
|
190
174
|
};
|
|
191
175
|
QueryCombobox.defaultProps = {
|
|
192
|
-
|
|
176
|
+
optionsKeyMap: {
|
|
177
|
+
value: 'id',
|
|
178
|
+
label: 'name'
|
|
179
|
+
},
|
|
193
180
|
multiple: false,
|
|
194
181
|
color: 'background2',
|
|
195
182
|
searchVariable: 'search'
|