@pareto-engineering/design-system 2.0.0-alpha.48 → 2.0.0-alpha.49
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/FormInput/FormInput.js +7 -0
- package/dist/cjs/f/fields/QueryCombobox/QueryCombobox.js +11 -5
- package/dist/cjs/f/fields/QuerySelect/QuerySelect.js +201 -0
- package/dist/cjs/f/fields/QuerySelect/index.js +15 -0
- package/dist/cjs/f/fields/QuerySelect/styles.scss +21 -0
- package/dist/cjs/f/fields/SelectInput/SelectInput.js +15 -3
- package/dist/cjs/f/fields/SelectInput/styles.scss +27 -14
- package/dist/cjs/f/fields/index.js +9 -1
- package/dist/es/f/FormInput/FormInput.js +8 -1
- package/dist/es/f/fields/QueryCombobox/QueryCombobox.js +11 -5
- package/dist/es/f/fields/QuerySelect/QuerySelect.js +179 -0
- package/dist/es/f/fields/QuerySelect/index.js +2 -0
- package/dist/es/f/fields/QuerySelect/styles.scss +21 -0
- package/dist/es/f/fields/SelectInput/SelectInput.js +14 -3
- package/dist/es/f/fields/SelectInput/styles.scss +27 -14
- package/dist/es/f/fields/index.js +2 -1
- package/package.json +1 -1
- package/src/__snapshots__/Storyshots.test.js.snap +582 -246
- package/src/stories/f/FormInput.stories.jsx +122 -4
- package/src/stories/f/QueryCombobox.stories.jsx +4 -2
- package/src/stories/f/QuerySelect.stories.jsx +134 -0
- package/src/stories/f/__generated__/FormInputAllTaskStatusesQuery.graphql.js +122 -0
- package/src/stories/f/__generated__/QuerySelectAllTaskStatusesQuery.graphql.js +122 -0
- package/src/ui/f/FormInput/FormInput.jsx +10 -0
- package/src/ui/f/fields/QueryCombobox/QueryCombobox.jsx +12 -8
- package/src/ui/f/fields/QuerySelect/QuerySelect.jsx +200 -0
- package/src/ui/f/fields/QuerySelect/index.js +2 -0
- package/src/ui/f/fields/SelectInput/SelectInput.jsx +16 -3
- package/src/ui/f/fields/SelectInput/styles.scss +27 -14
- package/src/ui/f/fields/index.js +1 -0
|
@@ -74,6 +74,13 @@ var FormInput = _ref => {
|
|
|
74
74
|
}, otherProps));
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
if (type === 'query-select') {
|
|
78
|
+
return /*#__PURE__*/React.createElement(_fields.QuerySelect, _extends({
|
|
79
|
+
className: newClassName,
|
|
80
|
+
disabled: disabled
|
|
81
|
+
}, otherProps));
|
|
82
|
+
}
|
|
83
|
+
|
|
77
84
|
if (extraTypes !== null && extraTypes !== void 0 && extraTypes[type]) {
|
|
78
85
|
var Component = extraTypes[type];
|
|
79
86
|
return /*#__PURE__*/React.createElement(Component, _extends({
|
|
@@ -43,7 +43,6 @@ var QueryCombobox = _ref => {
|
|
|
43
43
|
description,
|
|
44
44
|
disabled,
|
|
45
45
|
debounceMs,
|
|
46
|
-
graphQlNode,
|
|
47
46
|
searchVariable,
|
|
48
47
|
extraVariables,
|
|
49
48
|
optionsKeyMap,
|
|
@@ -66,6 +65,10 @@ var QueryCombobox = _ref => {
|
|
|
66
65
|
var environment = (0, _reactRelay.useRelayEnvironment)();
|
|
67
66
|
var [isFetching, setIsFetching] = (0, React.useState)(false);
|
|
68
67
|
var [options, setOptions] = (0, React.useState)([]);
|
|
68
|
+
var {
|
|
69
|
+
graphql,
|
|
70
|
+
accessor
|
|
71
|
+
} = query;
|
|
69
72
|
|
|
70
73
|
var getOptions = inputValue => {
|
|
71
74
|
if (isFetching) return;
|
|
@@ -77,7 +80,7 @@ var QueryCombobox = _ref => {
|
|
|
77
80
|
variables = _objectSpread(_objectSpread({}, variables), extraVariables);
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
(0, _reactRelay.fetchQuery)(environment,
|
|
83
|
+
(0, _reactRelay.fetchQuery)(environment, graphql, variables).subscribe({
|
|
81
84
|
start: () => {
|
|
82
85
|
setIsFetching(true);
|
|
83
86
|
},
|
|
@@ -89,7 +92,7 @@ var QueryCombobox = _ref => {
|
|
|
89
92
|
if (setError) setError(fetchError.message);
|
|
90
93
|
},
|
|
91
94
|
next: data => {
|
|
92
|
-
setOptions(data[
|
|
95
|
+
setOptions(data[accessor].edges.map(_ref2 => {
|
|
93
96
|
var {
|
|
94
97
|
node
|
|
95
98
|
} = _ref2;
|
|
@@ -172,9 +175,12 @@ QueryCombobox.propTypes = {
|
|
|
172
175
|
debounceMs: _propTypes.default.number,
|
|
173
176
|
|
|
174
177
|
/**
|
|
175
|
-
* The query to fetch the options
|
|
178
|
+
* The graphql query to fetch the options and the accessor to destructure the results from
|
|
176
179
|
*/
|
|
177
|
-
query: _propTypes.default.
|
|
180
|
+
query: _propTypes.default.shape({
|
|
181
|
+
accessor: _propTypes.default.string,
|
|
182
|
+
graphql: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object]).isRequired
|
|
183
|
+
}),
|
|
178
184
|
|
|
179
185
|
/**
|
|
180
186
|
* The extra variables required to be used in the query.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _reactRelay = require("react-relay");
|
|
11
|
+
|
|
12
|
+
var _formik = require("formik");
|
|
13
|
+
|
|
14
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
15
|
+
|
|
16
|
+
var _ = require("../..");
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
25
|
+
// Local Definitions
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* This is the component description.
|
|
29
|
+
*/
|
|
30
|
+
var QuerySelect = _ref => {
|
|
31
|
+
var {
|
|
32
|
+
id,
|
|
33
|
+
className: userClassName,
|
|
34
|
+
style,
|
|
35
|
+
name,
|
|
36
|
+
label,
|
|
37
|
+
query,
|
|
38
|
+
variables,
|
|
39
|
+
optionsKeyMap,
|
|
40
|
+
description,
|
|
41
|
+
disabled,
|
|
42
|
+
color,
|
|
43
|
+
loadingOption,
|
|
44
|
+
defaultOption // ...otherProps
|
|
45
|
+
|
|
46
|
+
} = _ref;
|
|
47
|
+
var [,, helpers] = (0, _formik.useField)(name);
|
|
48
|
+
var {
|
|
49
|
+
setError
|
|
50
|
+
} = helpers;
|
|
51
|
+
var environment = (0, _reactRelay.useRelayEnvironment)();
|
|
52
|
+
var [isFetching, setIsFetching] = (0, React.useState)(false);
|
|
53
|
+
var [options, setOptions] = (0, React.useState)([]);
|
|
54
|
+
var {
|
|
55
|
+
graphql,
|
|
56
|
+
accessor
|
|
57
|
+
} = query;
|
|
58
|
+
|
|
59
|
+
var getOptions = () => {
|
|
60
|
+
if (isFetching) return;
|
|
61
|
+
(0, _reactRelay.fetchQuery)(environment, graphql, variables).subscribe({
|
|
62
|
+
start: () => {
|
|
63
|
+
setIsFetching(true);
|
|
64
|
+
setOptions([loadingOption]);
|
|
65
|
+
},
|
|
66
|
+
complete: () => {
|
|
67
|
+
setIsFetching(false);
|
|
68
|
+
},
|
|
69
|
+
error: fetchError => {
|
|
70
|
+
setIsFetching(false);
|
|
71
|
+
if (setError) setError(fetchError.message);
|
|
72
|
+
},
|
|
73
|
+
next: data => {
|
|
74
|
+
setOptions([defaultOption, ...data[accessor].edges.map(_ref2 => {
|
|
75
|
+
var {
|
|
76
|
+
node
|
|
77
|
+
} = _ref2;
|
|
78
|
+
return {
|
|
79
|
+
value: node[optionsKeyMap.value],
|
|
80
|
+
label: node[optionsKeyMap.label]
|
|
81
|
+
};
|
|
82
|
+
})]);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
(0, React.useEffect)(() => {
|
|
88
|
+
getOptions();
|
|
89
|
+
}, [variables]);
|
|
90
|
+
return /*#__PURE__*/React.createElement(_.SelectInput, {
|
|
91
|
+
id: id,
|
|
92
|
+
className: userClassName,
|
|
93
|
+
style: style,
|
|
94
|
+
name: name,
|
|
95
|
+
label: label,
|
|
96
|
+
color: color,
|
|
97
|
+
description: description,
|
|
98
|
+
disabled: isFetching || disabled,
|
|
99
|
+
options: options,
|
|
100
|
+
isLoading: isFetching
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
QuerySelect.propTypes = {
|
|
105
|
+
/**
|
|
106
|
+
* The HTML id for this element
|
|
107
|
+
*/
|
|
108
|
+
id: _propTypes.default.string,
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The HTML class names for this element
|
|
112
|
+
*/
|
|
113
|
+
className: _propTypes.default.string,
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The React-written, css properties for this element.
|
|
117
|
+
*/
|
|
118
|
+
style: _propTypes.default.objectOf(_propTypes.default.string),
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The name of the custom select input
|
|
122
|
+
*/
|
|
123
|
+
name: _propTypes.default.string,
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The label of the custom select input
|
|
127
|
+
*/
|
|
128
|
+
label: _propTypes.default.string,
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The custom select input description
|
|
132
|
+
*/
|
|
133
|
+
description: _propTypes.default.string,
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Whether the input should be disabled
|
|
137
|
+
*/
|
|
138
|
+
disabled: _propTypes.default.bool,
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The base color of the custom select input
|
|
142
|
+
*/
|
|
143
|
+
color: _propTypes.default.string,
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The graphql query to fetch the options and the accessor to destructure the results from
|
|
147
|
+
*/
|
|
148
|
+
query: _propTypes.default.shape({
|
|
149
|
+
accessor: _propTypes.default.string,
|
|
150
|
+
graphql: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object]).isRequired
|
|
151
|
+
}),
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The variables that might be required to be used in the query to fetch
|
|
155
|
+
* select options.
|
|
156
|
+
*/
|
|
157
|
+
variables: _propTypes.default.objectOf(_propTypes.default.string),
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The select option keys to be used to map the data to the select options.
|
|
161
|
+
* i.e `{ value: 'id', label: 'name' }`
|
|
162
|
+
*/
|
|
163
|
+
optionsKeyMap: _propTypes.default.shape({
|
|
164
|
+
value: _propTypes.default.string.isRequired,
|
|
165
|
+
label: _propTypes.default.string.isRequired
|
|
166
|
+
}),
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The default select option for the query select
|
|
170
|
+
*/
|
|
171
|
+
defaultOption: _propTypes.default.shape({
|
|
172
|
+
value: _propTypes.default.string.isRequired,
|
|
173
|
+
label: _propTypes.default.string.isRequired,
|
|
174
|
+
disabled: _propTypes.default.bool.isRequired
|
|
175
|
+
}),
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The option to dipslayed when the select options are being fetched
|
|
179
|
+
*/
|
|
180
|
+
loadingOption: _propTypes.default.shape({
|
|
181
|
+
value: _propTypes.default.string.isRequired,
|
|
182
|
+
label: _propTypes.default.string.isRequired,
|
|
183
|
+
disabled: _propTypes.default.bool.isRequired
|
|
184
|
+
})
|
|
185
|
+
};
|
|
186
|
+
QuerySelect.defaultProps = {
|
|
187
|
+
disabled: false,
|
|
188
|
+
color: 'background2',
|
|
189
|
+
defaultOption: {
|
|
190
|
+
value: '',
|
|
191
|
+
label: 'Select an option',
|
|
192
|
+
disabled: true
|
|
193
|
+
},
|
|
194
|
+
loadingOption: {
|
|
195
|
+
value: '',
|
|
196
|
+
label: 'Fetching Options',
|
|
197
|
+
disabled: true
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
var _default = QuerySelect;
|
|
201
|
+
exports.default = _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "QuerySelect", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _QuerySelect.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var _QuerySelect = _interopRequireDefault(require("./QuerySelect"));
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
@use "@pareto-engineering/bem";
|
|
3
|
+
|
|
4
|
+
$default-loading-circle-displacement: .8em;
|
|
5
|
+
|
|
6
|
+
.#{bem.$base}.query-select {
|
|
7
|
+
position: relative;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
>.#{bem.$base}.select-input {
|
|
11
|
+
select:disabled {
|
|
12
|
+
appearance: none;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
>.#{bem.$base}.loading-circle {
|
|
17
|
+
position: absolute;
|
|
18
|
+
right: $default-loading-circle-displacement;
|
|
19
|
+
bottom: $default-loading-circle-displacement;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -13,6 +13,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
13
13
|
|
|
14
14
|
var _bem = _interopRequireDefault(require("@pareto-engineering/bem"));
|
|
15
15
|
|
|
16
|
+
var _a = require("../../../a");
|
|
17
|
+
|
|
16
18
|
var _common = require("../../common");
|
|
17
19
|
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -41,7 +43,8 @@ var SelectInput = _ref => {
|
|
|
41
43
|
options,
|
|
42
44
|
validate,
|
|
43
45
|
description,
|
|
44
|
-
disabled
|
|
46
|
+
disabled,
|
|
47
|
+
isLoading // ...otherProps
|
|
45
48
|
|
|
46
49
|
} = _ref;
|
|
47
50
|
(0, React.useLayoutEffect)(() => {
|
|
@@ -58,7 +61,9 @@ var SelectInput = _ref => {
|
|
|
58
61
|
|
|
59
62
|
}, /*#__PURE__*/React.createElement(_common.FormLabel, {
|
|
60
63
|
name: name
|
|
61
|
-
}, label), /*#__PURE__*/React.createElement("
|
|
64
|
+
}, label), /*#__PURE__*/React.createElement("div", {
|
|
65
|
+
className: "select-wrapper"
|
|
66
|
+
}, /*#__PURE__*/React.createElement("select", _extends({
|
|
62
67
|
className: "input"
|
|
63
68
|
}, field, {
|
|
64
69
|
value: field.value || '',
|
|
@@ -75,6 +80,8 @@ var SelectInput = _ref => {
|
|
|
75
80
|
value: newOption.value,
|
|
76
81
|
disabled: (newOption === null || newOption === void 0 ? void 0 : newOption.disabled) || false
|
|
77
82
|
}, newOption.label);
|
|
83
|
+
})), isLoading && /*#__PURE__*/React.createElement(_a.LoadingCircle, {
|
|
84
|
+
className: "x-main2"
|
|
78
85
|
})), (description || meta.touched && meta.error) && /*#__PURE__*/React.createElement(_common.FormDescription, {
|
|
79
86
|
isError: !!meta.error,
|
|
80
87
|
className: "v50 mt-v s-1"
|
|
@@ -134,7 +141,12 @@ SelectInput.propTypes = {
|
|
|
134
141
|
/**
|
|
135
142
|
* The color of the select input
|
|
136
143
|
*/
|
|
137
|
-
color: _propTypes.default.string
|
|
144
|
+
color: _propTypes.default.string,
|
|
145
|
+
|
|
146
|
+
/*
|
|
147
|
+
* Whether the query that is fetching the select options is still in flight
|
|
148
|
+
*/
|
|
149
|
+
isLoading: _propTypes.default.bool
|
|
138
150
|
};
|
|
139
151
|
SelectInput.defaultProps = {
|
|
140
152
|
disabled: false,
|
|
@@ -16,22 +16,35 @@ $default-margin: 1em;
|
|
|
16
16
|
margin-bottom: $default-margin
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
.select-wrapper {
|
|
20
|
+
position: relative;
|
|
21
|
+
|
|
22
|
+
>.#{bem.$base}.loading-circle {
|
|
23
|
+
position: absolute;
|
|
24
|
+
right: 0;
|
|
25
|
+
top: 50%;
|
|
26
|
+
transform: translateY(-50%);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
>.input {
|
|
30
|
+
width: 100%;
|
|
31
|
+
border: var(--theme-border-style) var(--dark-y);
|
|
32
|
+
background: var(--light-y);
|
|
33
|
+
color: var(--on-y);
|
|
34
|
+
padding: $default-padding;
|
|
35
|
+
|
|
36
|
+
&:not(:disabled):hover {
|
|
37
|
+
border: var(--theme-border-style) var(--light-background4);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&:disabled {
|
|
41
|
+
background-color: var(--dark-y);
|
|
42
|
+
appearance: none;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
&:focus {
|
|
46
|
+
background: var(--y);
|
|
47
|
+
}
|
|
35
48
|
}
|
|
36
49
|
}
|
|
37
50
|
}
|
|
@@ -39,6 +39,12 @@ Object.defineProperty(exports, "QueryCombobox", {
|
|
|
39
39
|
return _QueryCombobox.QueryCombobox;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
|
+
Object.defineProperty(exports, "QuerySelect", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function get() {
|
|
45
|
+
return _QuerySelect.QuerySelect;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
42
48
|
|
|
43
49
|
var _TextInput = require("./TextInput");
|
|
44
50
|
|
|
@@ -50,4 +56,6 @@ var _TextareaInput = require("./TextareaInput");
|
|
|
50
56
|
|
|
51
57
|
var _RatingsInput = require("./RatingsInput");
|
|
52
58
|
|
|
53
|
-
var _QueryCombobox = require("./QueryCombobox");
|
|
59
|
+
var _QueryCombobox = require("./QueryCombobox");
|
|
60
|
+
|
|
61
|
+
var _QuerySelect = require("./QuerySelect");
|
|
@@ -4,7 +4,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { memo, useLayoutEffect } from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
|
-
import { TextInput, TextareaInput, ChoicesInput, SelectInput, QueryCombobox } from "../fields"; // Local Definitions
|
|
7
|
+
import { TextInput, TextareaInput, ChoicesInput, SelectInput, QueryCombobox, QuerySelect } from "../fields"; // Local Definitions
|
|
8
8
|
// const baseClassName = styleNames.base
|
|
9
9
|
|
|
10
10
|
const componentClassName = 'form-input';
|
|
@@ -52,6 +52,13 @@ const FormInput = ({
|
|
|
52
52
|
}, otherProps));
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
if (type === 'query-select') {
|
|
56
|
+
return /*#__PURE__*/React.createElement(QuerySelect, _extends({
|
|
57
|
+
className: newClassName,
|
|
58
|
+
disabled: disabled
|
|
59
|
+
}, otherProps));
|
|
60
|
+
}
|
|
61
|
+
|
|
55
62
|
if (extraTypes !== null && extraTypes !== void 0 && extraTypes[type]) {
|
|
56
63
|
const Component = extraTypes[type];
|
|
57
64
|
return /*#__PURE__*/React.createElement(Component, _extends({
|
|
@@ -22,7 +22,6 @@ const QueryCombobox = ({
|
|
|
22
22
|
description,
|
|
23
23
|
disabled,
|
|
24
24
|
debounceMs,
|
|
25
|
-
graphQlNode,
|
|
26
25
|
searchVariable,
|
|
27
26
|
extraVariables,
|
|
28
27
|
optionsKeyMap,
|
|
@@ -45,6 +44,10 @@ const QueryCombobox = ({
|
|
|
45
44
|
const environment = useRelayEnvironment();
|
|
46
45
|
const [isFetching, setIsFetching] = useState(false);
|
|
47
46
|
const [options, setOptions] = useState([]);
|
|
47
|
+
const {
|
|
48
|
+
graphql,
|
|
49
|
+
accessor
|
|
50
|
+
} = query;
|
|
48
51
|
|
|
49
52
|
const getOptions = inputValue => {
|
|
50
53
|
if (isFetching) return;
|
|
@@ -58,7 +61,7 @@ const QueryCombobox = ({
|
|
|
58
61
|
};
|
|
59
62
|
}
|
|
60
63
|
|
|
61
|
-
fetchQuery(environment,
|
|
64
|
+
fetchQuery(environment, graphql, variables).subscribe({
|
|
62
65
|
start: () => {
|
|
63
66
|
setIsFetching(true);
|
|
64
67
|
},
|
|
@@ -70,7 +73,7 @@ const QueryCombobox = ({
|
|
|
70
73
|
if (setError) setError(fetchError.message);
|
|
71
74
|
},
|
|
72
75
|
next: data => {
|
|
73
|
-
setOptions(data[
|
|
76
|
+
setOptions(data[accessor].edges.map(({
|
|
74
77
|
node
|
|
75
78
|
}) => ({
|
|
76
79
|
value: node[optionsKeyMap.value],
|
|
@@ -150,9 +153,12 @@ QueryCombobox.propTypes = {
|
|
|
150
153
|
debounceMs: PropTypes.number,
|
|
151
154
|
|
|
152
155
|
/**
|
|
153
|
-
* The query to fetch the options
|
|
156
|
+
* The graphql query to fetch the options and the accessor to destructure the results from
|
|
154
157
|
*/
|
|
155
|
-
query: PropTypes.
|
|
158
|
+
query: PropTypes.shape({
|
|
159
|
+
accessor: PropTypes.string,
|
|
160
|
+
graphql: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired
|
|
161
|
+
}),
|
|
156
162
|
|
|
157
163
|
/**
|
|
158
164
|
* The extra variables required to be used in the query.
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useState, useEffect } from 'react';
|
|
4
|
+
import { useRelayEnvironment, fetchQuery } from 'react-relay';
|
|
5
|
+
import { useField } from 'formik';
|
|
6
|
+
import PropTypes from 'prop-types'; // Local Definitions
|
|
7
|
+
|
|
8
|
+
import { SelectInput } from "../..";
|
|
9
|
+
/**
|
|
10
|
+
* This is the component description.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const QuerySelect = ({
|
|
14
|
+
id,
|
|
15
|
+
className: userClassName,
|
|
16
|
+
style,
|
|
17
|
+
name,
|
|
18
|
+
label,
|
|
19
|
+
query,
|
|
20
|
+
variables,
|
|
21
|
+
optionsKeyMap,
|
|
22
|
+
description,
|
|
23
|
+
disabled,
|
|
24
|
+
color,
|
|
25
|
+
loadingOption,
|
|
26
|
+
defaultOption // ...otherProps
|
|
27
|
+
|
|
28
|
+
}) => {
|
|
29
|
+
const [,, helpers] = useField(name);
|
|
30
|
+
const {
|
|
31
|
+
setError
|
|
32
|
+
} = helpers;
|
|
33
|
+
const environment = useRelayEnvironment();
|
|
34
|
+
const [isFetching, setIsFetching] = useState(false);
|
|
35
|
+
const [options, setOptions] = useState([]);
|
|
36
|
+
const {
|
|
37
|
+
graphql,
|
|
38
|
+
accessor
|
|
39
|
+
} = query;
|
|
40
|
+
|
|
41
|
+
const getOptions = () => {
|
|
42
|
+
if (isFetching) return;
|
|
43
|
+
fetchQuery(environment, graphql, variables).subscribe({
|
|
44
|
+
start: () => {
|
|
45
|
+
setIsFetching(true);
|
|
46
|
+
setOptions([loadingOption]);
|
|
47
|
+
},
|
|
48
|
+
complete: () => {
|
|
49
|
+
setIsFetching(false);
|
|
50
|
+
},
|
|
51
|
+
error: fetchError => {
|
|
52
|
+
setIsFetching(false);
|
|
53
|
+
if (setError) setError(fetchError.message);
|
|
54
|
+
},
|
|
55
|
+
next: data => {
|
|
56
|
+
setOptions([defaultOption, ...data[accessor].edges.map(({
|
|
57
|
+
node
|
|
58
|
+
}) => ({
|
|
59
|
+
value: node[optionsKeyMap.value],
|
|
60
|
+
label: node[optionsKeyMap.label]
|
|
61
|
+
}))]);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
getOptions();
|
|
68
|
+
}, [variables]);
|
|
69
|
+
return /*#__PURE__*/React.createElement(SelectInput, {
|
|
70
|
+
id: id,
|
|
71
|
+
className: userClassName,
|
|
72
|
+
style: style,
|
|
73
|
+
name: name,
|
|
74
|
+
label: label,
|
|
75
|
+
color: color,
|
|
76
|
+
description: description,
|
|
77
|
+
disabled: isFetching || disabled,
|
|
78
|
+
options: options,
|
|
79
|
+
isLoading: isFetching
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
QuerySelect.propTypes = {
|
|
84
|
+
/**
|
|
85
|
+
* The HTML id for this element
|
|
86
|
+
*/
|
|
87
|
+
id: PropTypes.string,
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The HTML class names for this element
|
|
91
|
+
*/
|
|
92
|
+
className: PropTypes.string,
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The React-written, css properties for this element.
|
|
96
|
+
*/
|
|
97
|
+
style: PropTypes.objectOf(PropTypes.string),
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The name of the custom select input
|
|
101
|
+
*/
|
|
102
|
+
name: PropTypes.string,
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The label of the custom select input
|
|
106
|
+
*/
|
|
107
|
+
label: PropTypes.string,
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The custom select input description
|
|
111
|
+
*/
|
|
112
|
+
description: PropTypes.string,
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Whether the input should be disabled
|
|
116
|
+
*/
|
|
117
|
+
disabled: PropTypes.bool,
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The base color of the custom select input
|
|
121
|
+
*/
|
|
122
|
+
color: PropTypes.string,
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The graphql query to fetch the options and the accessor to destructure the results from
|
|
126
|
+
*/
|
|
127
|
+
query: PropTypes.shape({
|
|
128
|
+
accessor: PropTypes.string,
|
|
129
|
+
graphql: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired
|
|
130
|
+
}),
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The variables that might be required to be used in the query to fetch
|
|
134
|
+
* select options.
|
|
135
|
+
*/
|
|
136
|
+
variables: PropTypes.objectOf(PropTypes.string),
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The select option keys to be used to map the data to the select options.
|
|
140
|
+
* i.e `{ value: 'id', label: 'name' }`
|
|
141
|
+
*/
|
|
142
|
+
optionsKeyMap: PropTypes.shape({
|
|
143
|
+
value: PropTypes.string.isRequired,
|
|
144
|
+
label: PropTypes.string.isRequired
|
|
145
|
+
}),
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The default select option for the query select
|
|
149
|
+
*/
|
|
150
|
+
defaultOption: PropTypes.shape({
|
|
151
|
+
value: PropTypes.string.isRequired,
|
|
152
|
+
label: PropTypes.string.isRequired,
|
|
153
|
+
disabled: PropTypes.bool.isRequired
|
|
154
|
+
}),
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The option to dipslayed when the select options are being fetched
|
|
158
|
+
*/
|
|
159
|
+
loadingOption: PropTypes.shape({
|
|
160
|
+
value: PropTypes.string.isRequired,
|
|
161
|
+
label: PropTypes.string.isRequired,
|
|
162
|
+
disabled: PropTypes.bool.isRequired
|
|
163
|
+
})
|
|
164
|
+
};
|
|
165
|
+
QuerySelect.defaultProps = {
|
|
166
|
+
disabled: false,
|
|
167
|
+
color: 'background2',
|
|
168
|
+
defaultOption: {
|
|
169
|
+
value: '',
|
|
170
|
+
label: 'Select an option',
|
|
171
|
+
disabled: true
|
|
172
|
+
},
|
|
173
|
+
loadingOption: {
|
|
174
|
+
value: '',
|
|
175
|
+
label: 'Fetching Options',
|
|
176
|
+
disabled: true
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
export default QuerySelect;
|