@pareto-engineering/design-system 2.0.0-alpha.70 → 2.0.0-alpha.71
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/c/Modal/Modal.js +4 -16
- package/dist/cjs/f/FormInput/FormInput.js +7 -0
- package/dist/cjs/f/common/Label/Label.js +1 -1
- package/dist/cjs/f/fields/QueryChoices/QueryChoices.js +168 -0
- package/dist/cjs/f/fields/QueryChoices/index.js +15 -0
- package/dist/cjs/f/fields/index.js +9 -1
- package/dist/es/c/Modal/Modal.js +4 -16
- package/dist/es/f/FormInput/FormInput.js +8 -1
- package/dist/es/f/common/Label/Label.js +1 -1
- package/dist/es/f/fields/QueryChoices/QueryChoices.js +137 -0
- package/dist/es/f/fields/QueryChoices/index.js +2 -0
- package/dist/es/f/fields/index.js +2 -1
- package/package.json +1 -1
- package/src/__snapshots__/Storyshots.test.js.snap +127 -10
- package/src/stories/c/Modal.stories.jsx +2 -1
- package/src/stories/f/QueryChoices.stories.jsx +135 -0
- package/src/stories/f/__generated__/QueryChoicesAllTaskStatusesQuery.graphql.js +122 -0
- package/src/stories/f/__generated__/QueryChoicesUserChoicesQuery.graphql.js +122 -0
- package/src/ui/c/Modal/Modal.jsx +4 -15
- package/src/ui/f/FormInput/FormInput.jsx +11 -0
- package/src/ui/f/common/Label/Label.jsx +1 -1
- package/src/ui/f/fields/QueryChoices/QueryChoices.jsx +153 -0
- package/src/ui/f/fields/QueryChoices/index.js +2 -0
- package/src/ui/f/fields/index.js +1 -0
|
@@ -33,20 +33,13 @@ var Modal = _ref => {
|
|
|
33
33
|
style,
|
|
34
34
|
children,
|
|
35
35
|
title,
|
|
36
|
-
setOpen,
|
|
37
36
|
color,
|
|
38
|
-
|
|
37
|
+
close // ...otherProps
|
|
39
38
|
|
|
40
39
|
} = _ref;
|
|
41
40
|
(0, React.useLayoutEffect)(() => {
|
|
42
41
|
Promise.resolve().then(() => _interopRequireWildcard(require("./styles.scss")));
|
|
43
42
|
}, []);
|
|
44
|
-
|
|
45
|
-
var close = () => {
|
|
46
|
-
setOpen === null || setOpen === void 0 ? void 0 : setOpen(false);
|
|
47
|
-
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
48
|
-
};
|
|
49
|
-
|
|
50
43
|
return /*#__PURE__*/React.createElement("div", {
|
|
51
44
|
id: id,
|
|
52
45
|
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
|
|
@@ -88,19 +81,14 @@ Modal.propTypes = {
|
|
|
88
81
|
title: _propTypes.default.string.isRequired,
|
|
89
82
|
|
|
90
83
|
/**
|
|
91
|
-
* The color for the button
|
|
92
|
-
*/
|
|
93
|
-
color: _propTypes.default.string.isRequired,
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* The function to open the modal
|
|
84
|
+
* The color for the header button
|
|
97
85
|
*/
|
|
98
|
-
|
|
86
|
+
color: _propTypes.default.string,
|
|
99
87
|
|
|
100
88
|
/**
|
|
101
89
|
* The function to run upon closing the modal, if any
|
|
102
90
|
*/
|
|
103
|
-
|
|
91
|
+
close: _propTypes.default.func
|
|
104
92
|
};
|
|
105
93
|
Modal.defaultProps = {//
|
|
106
94
|
};
|
|
@@ -81,6 +81,13 @@ var FormInput = _ref => {
|
|
|
81
81
|
}, otherProps));
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
if (type === 'query-choices') {
|
|
85
|
+
return /*#__PURE__*/React.createElement(_fields.QueryChoices, _extends({
|
|
86
|
+
className: newClassName,
|
|
87
|
+
disabled: disabled
|
|
88
|
+
}, otherProps));
|
|
89
|
+
}
|
|
90
|
+
|
|
84
91
|
if (type === 'rating') {
|
|
85
92
|
return /*#__PURE__*/React.createElement(_fields.RatingsInput, _extends({
|
|
86
93
|
className: newClassName
|
|
@@ -45,7 +45,7 @@ var Label = _ref => {
|
|
|
45
45
|
className: [baseClassName, componentClassName, userClassName, "x-".concat(color)].filter(e => e).join(' '),
|
|
46
46
|
style: style // {...otherProps}
|
|
47
47
|
|
|
48
|
-
}, children, optional && '(Optional)');
|
|
48
|
+
}, children, optional && ' (Optional)');
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
Label.propTypes = {
|
|
@@ -0,0 +1,168 @@
|
|
|
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 _ChoicesInput = require("../ChoicesInput");
|
|
17
|
+
|
|
18
|
+
var _excluded = ["name", "optionsKeyMap", "query", "variables", "validate", "loadingOption", "extraVariables"];
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
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); }
|
|
23
|
+
|
|
24
|
+
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; }
|
|
25
|
+
|
|
26
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
27
|
+
|
|
28
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
29
|
+
|
|
30
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
31
|
+
|
|
32
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
33
|
+
|
|
34
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
35
|
+
|
|
36
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* This is the component description.
|
|
40
|
+
*/
|
|
41
|
+
var QueryChoices = _ref => {
|
|
42
|
+
var {
|
|
43
|
+
name,
|
|
44
|
+
optionsKeyMap,
|
|
45
|
+
query,
|
|
46
|
+
variables,
|
|
47
|
+
validate,
|
|
48
|
+
loadingOption,
|
|
49
|
+
extraVariables
|
|
50
|
+
} = _ref,
|
|
51
|
+
otherProps = _objectWithoutProperties(_ref, _excluded);
|
|
52
|
+
|
|
53
|
+
var [,, helpers] = (0, _formik.useField)({
|
|
54
|
+
name,
|
|
55
|
+
validate
|
|
56
|
+
});
|
|
57
|
+
var {
|
|
58
|
+
setError
|
|
59
|
+
} = helpers;
|
|
60
|
+
var environment = (0, _reactRelay.useRelayEnvironment)();
|
|
61
|
+
var [isFetching, setIsFetching] = (0, React.useState)(false);
|
|
62
|
+
var [options, setOptions] = (0, React.useState)([loadingOption]);
|
|
63
|
+
var {
|
|
64
|
+
graphql,
|
|
65
|
+
accessor
|
|
66
|
+
} = query;
|
|
67
|
+
|
|
68
|
+
var getOptions = () => {
|
|
69
|
+
if (isFetching) return;
|
|
70
|
+
var searchVariables = variables;
|
|
71
|
+
|
|
72
|
+
if (extraVariables) {
|
|
73
|
+
searchVariables = _objectSpread(_objectSpread({}, variables), extraVariables);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
(0, _reactRelay.fetchQuery)(environment, graphql, searchVariables).subscribe({
|
|
77
|
+
start: () => {
|
|
78
|
+
setIsFetching(true);
|
|
79
|
+
},
|
|
80
|
+
complete: () => {
|
|
81
|
+
setIsFetching(false);
|
|
82
|
+
},
|
|
83
|
+
error: fetchError => {
|
|
84
|
+
setIsFetching(false);
|
|
85
|
+
if (setError) setError(fetchError.message);
|
|
86
|
+
},
|
|
87
|
+
next: data => {
|
|
88
|
+
setOptions([...data[accessor].edges.map(_ref2 => {
|
|
89
|
+
var {
|
|
90
|
+
node
|
|
91
|
+
} = _ref2;
|
|
92
|
+
return {
|
|
93
|
+
value: node[optionsKeyMap.value],
|
|
94
|
+
label: optionsKeyMap.getLabel(node)
|
|
95
|
+
};
|
|
96
|
+
})]);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
(0, React.useEffect)(() => {
|
|
102
|
+
getOptions();
|
|
103
|
+
}, [variables]);
|
|
104
|
+
return /*#__PURE__*/React.createElement(_ChoicesInput.ChoicesInput, _extends({
|
|
105
|
+
name: name,
|
|
106
|
+
validate: validate,
|
|
107
|
+
options: options
|
|
108
|
+
}, otherProps));
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
QueryChoices.propTypes = {
|
|
112
|
+
/**
|
|
113
|
+
* The choices name
|
|
114
|
+
*/
|
|
115
|
+
name: _propTypes.default.string.isRequired,
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The select option keys to be used to map the data to the select options.
|
|
119
|
+
* i.e `{ value: 'id', label: 'name' }`
|
|
120
|
+
*/
|
|
121
|
+
optionsKeyMap: _propTypes.default.shape({
|
|
122
|
+
value: _propTypes.default.string.isRequired,
|
|
123
|
+
getLabel: _propTypes.default.func.isRequired
|
|
124
|
+
}).isRequired,
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The graphql query to fetch the options and the accessor to destructure the results from
|
|
128
|
+
*/
|
|
129
|
+
query: _propTypes.default.shape({
|
|
130
|
+
accessor: _propTypes.default.string,
|
|
131
|
+
graphql: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object]).isRequired
|
|
132
|
+
}),
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The variables that might be required to be used in the query to fetch
|
|
136
|
+
* select options.
|
|
137
|
+
*/
|
|
138
|
+
variables: _propTypes.default.objectOf(_propTypes.default.string),
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The option to displayed when the select options are being fetched
|
|
142
|
+
*/
|
|
143
|
+
loadingOption: _propTypes.default.shape({
|
|
144
|
+
value: _propTypes.default.string.isRequired,
|
|
145
|
+
label: _propTypes.default.string.isRequired,
|
|
146
|
+
disabled: _propTypes.default.bool.isRequired
|
|
147
|
+
}),
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The input field validator function
|
|
151
|
+
*/
|
|
152
|
+
validate: _propTypes.default.string,
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* The extra variables that might be required to be used in the query to fetch
|
|
156
|
+
* select options.
|
|
157
|
+
*/
|
|
158
|
+
extraVariables: _propTypes.default.objectOf(_propTypes.default.string)
|
|
159
|
+
};
|
|
160
|
+
QueryChoices.defaultProps = {
|
|
161
|
+
loadingOption: {
|
|
162
|
+
value: '',
|
|
163
|
+
label: 'Fetching Options',
|
|
164
|
+
disabled: true
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
var _default = QueryChoices;
|
|
168
|
+
exports.default = _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "QueryChoices", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _QueryChoices.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var _QueryChoices = _interopRequireDefault(require("./QueryChoices"));
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -51,6 +51,12 @@ Object.defineProperty(exports, "Checkbox", {
|
|
|
51
51
|
return _Checkbox.Checkbox;
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
+
Object.defineProperty(exports, "QueryChoices", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function get() {
|
|
57
|
+
return _QueryChoices.QueryChoices;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
54
60
|
|
|
55
61
|
var _TextInput = require("./TextInput");
|
|
56
62
|
|
|
@@ -66,4 +72,6 @@ var _QueryCombobox = require("./QueryCombobox");
|
|
|
66
72
|
|
|
67
73
|
var _QuerySelect = require("./QuerySelect");
|
|
68
74
|
|
|
69
|
-
var _Checkbox = require("./Checkbox");
|
|
75
|
+
var _Checkbox = require("./Checkbox");
|
|
76
|
+
|
|
77
|
+
var _QueryChoices = require("./QueryChoices");
|
package/dist/es/c/Modal/Modal.js
CHANGED
|
@@ -17,20 +17,13 @@ const Modal = ({
|
|
|
17
17
|
style,
|
|
18
18
|
children,
|
|
19
19
|
title,
|
|
20
|
-
setOpen,
|
|
21
20
|
color,
|
|
22
|
-
|
|
21
|
+
close // ...otherProps
|
|
23
22
|
|
|
24
23
|
}) => {
|
|
25
24
|
useLayoutEffect(() => {
|
|
26
25
|
import("./styles.scss");
|
|
27
26
|
}, []);
|
|
28
|
-
|
|
29
|
-
const close = () => {
|
|
30
|
-
setOpen === null || setOpen === void 0 ? void 0 : setOpen(false);
|
|
31
|
-
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
32
|
-
};
|
|
33
|
-
|
|
34
27
|
return /*#__PURE__*/React.createElement("div", {
|
|
35
28
|
id: id,
|
|
36
29
|
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
|
|
@@ -72,19 +65,14 @@ Modal.propTypes = {
|
|
|
72
65
|
title: PropTypes.string.isRequired,
|
|
73
66
|
|
|
74
67
|
/**
|
|
75
|
-
* The color for the button
|
|
76
|
-
*/
|
|
77
|
-
color: PropTypes.string.isRequired,
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* The function to open the modal
|
|
68
|
+
* The color for the header button
|
|
81
69
|
*/
|
|
82
|
-
|
|
70
|
+
color: PropTypes.string,
|
|
83
71
|
|
|
84
72
|
/**
|
|
85
73
|
* The function to run upon closing the modal, if any
|
|
86
74
|
*/
|
|
87
|
-
|
|
75
|
+
close: PropTypes.func
|
|
88
76
|
};
|
|
89
77
|
Modal.defaultProps = {//
|
|
90
78
|
};
|
|
@@ -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, QuerySelect, RatingsInput, Checkbox } from "../fields"; // Local Definitions
|
|
7
|
+
import { TextInput, TextareaInput, ChoicesInput, SelectInput, QueryCombobox, QuerySelect, RatingsInput, Checkbox, QueryChoices } from "../fields"; // Local Definitions
|
|
8
8
|
// const baseClassName = styleNames.base
|
|
9
9
|
|
|
10
10
|
const componentClassName = 'form-input';
|
|
@@ -59,6 +59,13 @@ const FormInput = ({
|
|
|
59
59
|
}, otherProps));
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
if (type === 'query-choices') {
|
|
63
|
+
return /*#__PURE__*/React.createElement(QueryChoices, _extends({
|
|
64
|
+
className: newClassName,
|
|
65
|
+
disabled: disabled
|
|
66
|
+
}, otherProps));
|
|
67
|
+
}
|
|
68
|
+
|
|
62
69
|
if (type === 'rating') {
|
|
63
70
|
return /*#__PURE__*/React.createElement(RatingsInput, _extends({
|
|
64
71
|
className: newClassName
|
|
@@ -30,7 +30,7 @@ const Label = ({
|
|
|
30
30
|
className: [baseClassName, componentClassName, userClassName, `x-${color}`].filter(e => e).join(' '),
|
|
31
31
|
style: style // {...otherProps}
|
|
32
32
|
|
|
33
|
-
}, children, optional && '(Optional)');
|
|
33
|
+
}, children, optional && ' (Optional)');
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
Label.propTypes = {
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
import { useRelayEnvironment, fetchQuery } from 'react-relay';
|
|
7
|
+
import { useField } from 'formik';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import { ChoicesInput } from "../ChoicesInput";
|
|
10
|
+
/**
|
|
11
|
+
* This is the component description.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const QueryChoices = ({
|
|
15
|
+
name,
|
|
16
|
+
optionsKeyMap,
|
|
17
|
+
query,
|
|
18
|
+
variables,
|
|
19
|
+
validate,
|
|
20
|
+
loadingOption,
|
|
21
|
+
extraVariables,
|
|
22
|
+
...otherProps
|
|
23
|
+
}) => {
|
|
24
|
+
const [,, helpers] = useField({
|
|
25
|
+
name,
|
|
26
|
+
validate
|
|
27
|
+
});
|
|
28
|
+
const {
|
|
29
|
+
setError
|
|
30
|
+
} = helpers;
|
|
31
|
+
const environment = useRelayEnvironment();
|
|
32
|
+
const [isFetching, setIsFetching] = useState(false);
|
|
33
|
+
const [options, setOptions] = useState([loadingOption]);
|
|
34
|
+
const {
|
|
35
|
+
graphql,
|
|
36
|
+
accessor
|
|
37
|
+
} = query;
|
|
38
|
+
|
|
39
|
+
const getOptions = () => {
|
|
40
|
+
if (isFetching) return;
|
|
41
|
+
let searchVariables = variables;
|
|
42
|
+
|
|
43
|
+
if (extraVariables) {
|
|
44
|
+
searchVariables = { ...variables,
|
|
45
|
+
...extraVariables
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fetchQuery(environment, graphql, searchVariables).subscribe({
|
|
50
|
+
start: () => {
|
|
51
|
+
setIsFetching(true);
|
|
52
|
+
},
|
|
53
|
+
complete: () => {
|
|
54
|
+
setIsFetching(false);
|
|
55
|
+
},
|
|
56
|
+
error: fetchError => {
|
|
57
|
+
setIsFetching(false);
|
|
58
|
+
if (setError) setError(fetchError.message);
|
|
59
|
+
},
|
|
60
|
+
next: data => {
|
|
61
|
+
setOptions([...data[accessor].edges.map(({
|
|
62
|
+
node
|
|
63
|
+
}) => ({
|
|
64
|
+
value: node[optionsKeyMap.value],
|
|
65
|
+
label: optionsKeyMap.getLabel(node)
|
|
66
|
+
}))]);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
getOptions();
|
|
73
|
+
}, [variables]);
|
|
74
|
+
return /*#__PURE__*/React.createElement(ChoicesInput, _extends({
|
|
75
|
+
name: name,
|
|
76
|
+
validate: validate,
|
|
77
|
+
options: options
|
|
78
|
+
}, otherProps));
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
QueryChoices.propTypes = {
|
|
82
|
+
/**
|
|
83
|
+
* The choices name
|
|
84
|
+
*/
|
|
85
|
+
name: PropTypes.string.isRequired,
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The select option keys to be used to map the data to the select options.
|
|
89
|
+
* i.e `{ value: 'id', label: 'name' }`
|
|
90
|
+
*/
|
|
91
|
+
optionsKeyMap: PropTypes.shape({
|
|
92
|
+
value: PropTypes.string.isRequired,
|
|
93
|
+
getLabel: PropTypes.func.isRequired
|
|
94
|
+
}).isRequired,
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The graphql query to fetch the options and the accessor to destructure the results from
|
|
98
|
+
*/
|
|
99
|
+
query: PropTypes.shape({
|
|
100
|
+
accessor: PropTypes.string,
|
|
101
|
+
graphql: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired
|
|
102
|
+
}),
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The variables that might be required to be used in the query to fetch
|
|
106
|
+
* select options.
|
|
107
|
+
*/
|
|
108
|
+
variables: PropTypes.objectOf(PropTypes.string),
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The option to displayed when the select options are being fetched
|
|
112
|
+
*/
|
|
113
|
+
loadingOption: PropTypes.shape({
|
|
114
|
+
value: PropTypes.string.isRequired,
|
|
115
|
+
label: PropTypes.string.isRequired,
|
|
116
|
+
disabled: PropTypes.bool.isRequired
|
|
117
|
+
}),
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The input field validator function
|
|
121
|
+
*/
|
|
122
|
+
validate: PropTypes.string,
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The extra variables that might be required to be used in the query to fetch
|
|
126
|
+
* select options.
|
|
127
|
+
*/
|
|
128
|
+
extraVariables: PropTypes.objectOf(PropTypes.string)
|
|
129
|
+
};
|
|
130
|
+
QueryChoices.defaultProps = {
|
|
131
|
+
loadingOption: {
|
|
132
|
+
value: '',
|
|
133
|
+
label: 'Fetching Options',
|
|
134
|
+
disabled: true
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
export default QueryChoices;
|
|
@@ -5,4 +5,5 @@ export { TextareaInput } from "./TextareaInput";
|
|
|
5
5
|
export { RatingsInput } from "./RatingsInput";
|
|
6
6
|
export { QueryCombobox } from "./QueryCombobox";
|
|
7
7
|
export { QuerySelect } from "./QuerySelect";
|
|
8
|
-
export { Checkbox } from "./Checkbox";
|
|
8
|
+
export { Checkbox } from "./Checkbox";
|
|
9
|
+
export { QueryChoices } from "./QueryChoices";
|
package/package.json
CHANGED
|
@@ -3729,7 +3729,7 @@ exports[`Storyshots a/Timestamp Distance Format 1`] = `
|
|
|
3729
3729
|
className="base timestamp"
|
|
3730
3730
|
onClick={[Function]}
|
|
3731
3731
|
>
|
|
3732
|
-
|
|
3732
|
+
4 months ago
|
|
3733
3733
|
</p>
|
|
3734
3734
|
`;
|
|
3735
3735
|
|
|
@@ -12344,7 +12344,7 @@ exports[`Storyshots f/common/Label Optional 1`] = `
|
|
|
12344
12344
|
className="base form-label x-main2"
|
|
12345
12345
|
>
|
|
12346
12346
|
Sample Label
|
|
12347
|
-
|
|
12347
|
+
(Optional)
|
|
12348
12348
|
</label>
|
|
12349
12349
|
`;
|
|
12350
12350
|
|
|
@@ -12430,7 +12430,7 @@ exports[`Storyshots f/fields/Checkbox Optional 1`] = `
|
|
|
12430
12430
|
htmlFor="urgent"
|
|
12431
12431
|
>
|
|
12432
12432
|
Urgent
|
|
12433
|
-
|
|
12433
|
+
(Optional)
|
|
12434
12434
|
</label>
|
|
12435
12435
|
<input
|
|
12436
12436
|
checked={false}
|
|
@@ -13722,7 +13722,7 @@ exports[`Storyshots f/fields/ChoicesInput Optional 1`] = `
|
|
|
13722
13722
|
className="base form-label x-main2"
|
|
13723
13723
|
>
|
|
13724
13724
|
Select color
|
|
13725
|
-
|
|
13725
|
+
(Optional)
|
|
13726
13726
|
</p>
|
|
13727
13727
|
<div
|
|
13728
13728
|
className="choices"
|
|
@@ -14082,6 +14082,123 @@ exports[`Storyshots f/fields/ChoicesInput With Default Formik Value 1`] = `
|
|
|
14082
14082
|
</form>
|
|
14083
14083
|
`;
|
|
14084
14084
|
|
|
14085
|
+
exports[`Storyshots f/fields/QueryChoices Base 1`] = `
|
|
14086
|
+
<form
|
|
14087
|
+
action="#"
|
|
14088
|
+
onReset={[Function]}
|
|
14089
|
+
onSubmit={[Function]}
|
|
14090
|
+
>
|
|
14091
|
+
<div
|
|
14092
|
+
className="base choices-input x-background2 y-main2"
|
|
14093
|
+
style={
|
|
14094
|
+
Object {
|
|
14095
|
+
"--grid-columns-desktop": 3,
|
|
14096
|
+
"--grid-columns-mobile": 2,
|
|
14097
|
+
}
|
|
14098
|
+
}
|
|
14099
|
+
>
|
|
14100
|
+
<p
|
|
14101
|
+
className="base form-label x-main2"
|
|
14102
|
+
>
|
|
14103
|
+
Select Status
|
|
14104
|
+
</p>
|
|
14105
|
+
<div
|
|
14106
|
+
className="choices"
|
|
14107
|
+
>
|
|
14108
|
+
<div
|
|
14109
|
+
className="base choice"
|
|
14110
|
+
>
|
|
14111
|
+
<input
|
|
14112
|
+
checked={true}
|
|
14113
|
+
disabled={true}
|
|
14114
|
+
id="status-"
|
|
14115
|
+
name="status"
|
|
14116
|
+
onBlur={[Function]}
|
|
14117
|
+
onChange={[Function]}
|
|
14118
|
+
type="radio"
|
|
14119
|
+
value=""
|
|
14120
|
+
/>
|
|
14121
|
+
<label
|
|
14122
|
+
htmlFor="status-"
|
|
14123
|
+
>
|
|
14124
|
+
Fetching Options
|
|
14125
|
+
</label>
|
|
14126
|
+
</div>
|
|
14127
|
+
</div>
|
|
14128
|
+
</div>
|
|
14129
|
+
<div
|
|
14130
|
+
className="debugger"
|
|
14131
|
+
>
|
|
14132
|
+
<button
|
|
14133
|
+
className="base button x-main2"
|
|
14134
|
+
onClick={[Function]}
|
|
14135
|
+
type="button"
|
|
14136
|
+
>
|
|
14137
|
+
Open FormDebugger
|
|
14138
|
+
</button>
|
|
14139
|
+
</div>
|
|
14140
|
+
</form>
|
|
14141
|
+
`;
|
|
14142
|
+
|
|
14143
|
+
exports[`Storyshots f/fields/QueryChoices Optional 1`] = `
|
|
14144
|
+
<form
|
|
14145
|
+
action="#"
|
|
14146
|
+
onReset={[Function]}
|
|
14147
|
+
onSubmit={[Function]}
|
|
14148
|
+
>
|
|
14149
|
+
<div
|
|
14150
|
+
className="base choices-input x-background2 y-main2"
|
|
14151
|
+
style={
|
|
14152
|
+
Object {
|
|
14153
|
+
"--grid-columns-desktop": 3,
|
|
14154
|
+
"--grid-columns-mobile": 2,
|
|
14155
|
+
}
|
|
14156
|
+
}
|
|
14157
|
+
>
|
|
14158
|
+
<p
|
|
14159
|
+
className="base form-label x-main2"
|
|
14160
|
+
>
|
|
14161
|
+
Select Status
|
|
14162
|
+
(Optional)
|
|
14163
|
+
</p>
|
|
14164
|
+
<div
|
|
14165
|
+
className="choices"
|
|
14166
|
+
>
|
|
14167
|
+
<div
|
|
14168
|
+
className="base choice"
|
|
14169
|
+
>
|
|
14170
|
+
<input
|
|
14171
|
+
checked={true}
|
|
14172
|
+
disabled={true}
|
|
14173
|
+
id="status-"
|
|
14174
|
+
name="status"
|
|
14175
|
+
onBlur={[Function]}
|
|
14176
|
+
onChange={[Function]}
|
|
14177
|
+
type="radio"
|
|
14178
|
+
value=""
|
|
14179
|
+
/>
|
|
14180
|
+
<label
|
|
14181
|
+
htmlFor="status-"
|
|
14182
|
+
>
|
|
14183
|
+
Fetching Options
|
|
14184
|
+
</label>
|
|
14185
|
+
</div>
|
|
14186
|
+
</div>
|
|
14187
|
+
</div>
|
|
14188
|
+
<div
|
|
14189
|
+
className="debugger"
|
|
14190
|
+
>
|
|
14191
|
+
<button
|
|
14192
|
+
className="base button x-main2"
|
|
14193
|
+
onClick={[Function]}
|
|
14194
|
+
type="button"
|
|
14195
|
+
>
|
|
14196
|
+
Open FormDebugger
|
|
14197
|
+
</button>
|
|
14198
|
+
</div>
|
|
14199
|
+
</form>
|
|
14200
|
+
`;
|
|
14201
|
+
|
|
14085
14202
|
exports[`Storyshots f/fields/QueryCombobox Multiple Select 1`] = `
|
|
14086
14203
|
<form
|
|
14087
14204
|
action="#"
|
|
@@ -14309,7 +14426,7 @@ exports[`Storyshots f/fields/QueryCombobox Optional 1`] = `
|
|
|
14309
14426
|
id="downshift-2-label"
|
|
14310
14427
|
>
|
|
14311
14428
|
Search for a team
|
|
14312
|
-
|
|
14429
|
+
(Optional)
|
|
14313
14430
|
</label>
|
|
14314
14431
|
<div
|
|
14315
14432
|
aria-expanded={false}
|
|
@@ -14646,7 +14763,7 @@ exports[`Storyshots f/fields/QuerySelect Optional 1`] = `
|
|
|
14646
14763
|
htmlFor="status"
|
|
14647
14764
|
>
|
|
14648
14765
|
Select Task Status
|
|
14649
|
-
|
|
14766
|
+
(Optional)
|
|
14650
14767
|
</label>
|
|
14651
14768
|
<div
|
|
14652
14769
|
className="select-wrapper"
|
|
@@ -15240,7 +15357,7 @@ exports[`Storyshots f/fields/RatingsInput Optional 1`] = `
|
|
|
15240
15357
|
htmlFor="ratings"
|
|
15241
15358
|
>
|
|
15242
15359
|
Your Rating
|
|
15243
|
-
|
|
15360
|
+
(Optional)
|
|
15244
15361
|
</label>
|
|
15245
15362
|
<div
|
|
15246
15363
|
className="stars"
|
|
@@ -15526,7 +15643,7 @@ exports[`Storyshots f/fields/SelectInput Optional 1`] = `
|
|
|
15526
15643
|
htmlFor="workType"
|
|
15527
15644
|
>
|
|
15528
15645
|
Work Type
|
|
15529
|
-
|
|
15646
|
+
(Optional)
|
|
15530
15647
|
</label>
|
|
15531
15648
|
<div
|
|
15532
15649
|
className="select-wrapper"
|
|
@@ -15840,7 +15957,7 @@ exports[`Storyshots f/fields/TextInput Optional 1`] = `
|
|
|
15840
15957
|
htmlFor="firstName"
|
|
15841
15958
|
>
|
|
15842
15959
|
What's your first name ?
|
|
15843
|
-
|
|
15960
|
+
(Optional)
|
|
15844
15961
|
</label>
|
|
15845
15962
|
<input
|
|
15846
15963
|
className="input"
|
|
@@ -16280,7 +16397,7 @@ exports[`Storyshots f/fields/TextareaInput Optional 1`] = `
|
|
|
16280
16397
|
htmlFor="feedback"
|
|
16281
16398
|
>
|
|
16282
16399
|
What can we improve on?
|
|
16283
|
-
|
|
16400
|
+
(Optional)
|
|
16284
16401
|
</label>
|
|
16285
16402
|
<textarea
|
|
16286
16403
|
className="textarea"
|
|
@@ -43,7 +43,7 @@ const FunctionalTemplate = (args) => {
|
|
|
43
43
|
Click to open modal
|
|
44
44
|
</Button>
|
|
45
45
|
{isOpen && (
|
|
46
|
-
<Modal {...args}
|
|
46
|
+
<Modal {...args} close={() => setOpen(false)}>
|
|
47
47
|
{children}
|
|
48
48
|
</Modal>
|
|
49
49
|
)}
|
|
@@ -56,6 +56,7 @@ Base.args = {
|
|
|
56
56
|
children:<div>This is a modal.</div>,
|
|
57
57
|
color :'anchor',
|
|
58
58
|
title :'Modal Title',
|
|
59
|
+
close :() => console.log('You clicked the close button!'),
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
export const FunctionalModal = FunctionalTemplate.bind({})
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import { QueryChoices, FormDebugger } from 'ui'
|
|
5
|
+
|
|
6
|
+
import { Formik, Form } from 'formik'
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
RelayEnvironmentProvider,
|
|
10
|
+
mockRelayOperation,
|
|
11
|
+
environment,
|
|
12
|
+
} from '../utils/relay'
|
|
13
|
+
|
|
14
|
+
import generateNodeId from '../utils/generateNodeId'
|
|
15
|
+
|
|
16
|
+
export default {
|
|
17
|
+
title :'f/fields/QueryChoices',
|
|
18
|
+
component :QueryChoices,
|
|
19
|
+
subcomponents:{
|
|
20
|
+
// Item:QueryChoices.Item
|
|
21
|
+
},
|
|
22
|
+
decorators:[
|
|
23
|
+
// storyfn => <div className="">{ storyfn() }</div>,
|
|
24
|
+
(storyfn) => (
|
|
25
|
+
<RelayEnvironmentProvider>
|
|
26
|
+
{ storyfn() }
|
|
27
|
+
</RelayEnvironmentProvider>
|
|
28
|
+
),
|
|
29
|
+
],
|
|
30
|
+
argTypes:{
|
|
31
|
+
isLoading:{ control: 'boolean' },
|
|
32
|
+
optional :{ control: 'boolean' },
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const statuses = [
|
|
37
|
+
'Backlog',
|
|
38
|
+
'In Review',
|
|
39
|
+
'In Progress',
|
|
40
|
+
'Requested',
|
|
41
|
+
'Blocked',
|
|
42
|
+
'Completed',
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
const allTaskStatusesMockData = {
|
|
46
|
+
PageInfo() {
|
|
47
|
+
return {
|
|
48
|
+
hasNextPage :true,
|
|
49
|
+
hasPreviousPage:true,
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
TaskStatusNodeConnection:() => ({
|
|
53
|
+
pageInfo:{
|
|
54
|
+
hasNextPage :true,
|
|
55
|
+
hasPreviousPage:true,
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
edges:statuses.map((status) => ({
|
|
59
|
+
node:{
|
|
60
|
+
id:generateNodeId('TaskStatusNode'),
|
|
61
|
+
status,
|
|
62
|
+
},
|
|
63
|
+
})),
|
|
64
|
+
}),
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const FETCH_ALL_TASK_STATUSES = graphql`
|
|
68
|
+
query QueryChoicesAllTaskStatusesQuery {
|
|
69
|
+
allTaskStatuses {
|
|
70
|
+
edges {
|
|
71
|
+
node {
|
|
72
|
+
id
|
|
73
|
+
status
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
`
|
|
79
|
+
|
|
80
|
+
// eslint-disable-next-line react/prop-types
|
|
81
|
+
const Template = ({ isLoading, defaultFormikState, ...args }) => {
|
|
82
|
+
if (isLoading) {
|
|
83
|
+
setTimeout(() => {
|
|
84
|
+
mockRelayOperation(allTaskStatusesMockData)
|
|
85
|
+
environment.mock.queuePendingOperation(
|
|
86
|
+
FETCH_ALL_TASK_STATUSES,
|
|
87
|
+
{},
|
|
88
|
+
)
|
|
89
|
+
}, 500)
|
|
90
|
+
} else {
|
|
91
|
+
mockRelayOperation(allTaskStatusesMockData)
|
|
92
|
+
environment.mock.queuePendingOperation(
|
|
93
|
+
FETCH_ALL_TASK_STATUSES,
|
|
94
|
+
{},
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const Content = () => (
|
|
99
|
+
<>
|
|
100
|
+
<QueryChoices
|
|
101
|
+
name="status"
|
|
102
|
+
label="Select Status"
|
|
103
|
+
query={{
|
|
104
|
+
graphql :FETCH_ALL_TASK_STATUSES,
|
|
105
|
+
accessor:'allTaskStatuses',
|
|
106
|
+
}}
|
|
107
|
+
optionsKeyMap={{
|
|
108
|
+
value :'id',
|
|
109
|
+
getLabel:(node) => node.status,
|
|
110
|
+
}}
|
|
111
|
+
{...args}
|
|
112
|
+
/>
|
|
113
|
+
<FormDebugger />
|
|
114
|
+
</>
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
const initialValues = defaultFormikState ?? { status: '' }
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<Formik
|
|
121
|
+
initialValues={initialValues}
|
|
122
|
+
>
|
|
123
|
+
<Form>
|
|
124
|
+
<Content />
|
|
125
|
+
</Form>
|
|
126
|
+
</Formik>
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export const Base = Template.bind({})
|
|
131
|
+
|
|
132
|
+
export const Optional = Template.bind({})
|
|
133
|
+
Optional.args = {
|
|
134
|
+
optional:true,
|
|
135
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @flow
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/* eslint-disable */
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
/*::
|
|
10
|
+
import type { ConcreteRequest } from 'relay-runtime';
|
|
11
|
+
export type QueryChoicesAllTaskStatusesQueryVariables = {||};
|
|
12
|
+
export type QueryChoicesAllTaskStatusesQueryResponse = {|
|
|
13
|
+
+allTaskStatuses: ?{|
|
|
14
|
+
+edges: $ReadOnlyArray<?{|
|
|
15
|
+
+node: ?{|
|
|
16
|
+
+id: string,
|
|
17
|
+
+status: string,
|
|
18
|
+
|}
|
|
19
|
+
|}>
|
|
20
|
+
|}
|
|
21
|
+
|};
|
|
22
|
+
export type QueryChoicesAllTaskStatusesQuery = {|
|
|
23
|
+
variables: QueryChoicesAllTaskStatusesQueryVariables,
|
|
24
|
+
response: QueryChoicesAllTaskStatusesQueryResponse,
|
|
25
|
+
|};
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
query QueryChoicesAllTaskStatusesQuery {
|
|
31
|
+
allTaskStatuses {
|
|
32
|
+
edges {
|
|
33
|
+
node {
|
|
34
|
+
id
|
|
35
|
+
status
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
const node/*: ConcreteRequest*/ = (function(){
|
|
43
|
+
var v0 = [
|
|
44
|
+
{
|
|
45
|
+
"alias": null,
|
|
46
|
+
"args": null,
|
|
47
|
+
"concreteType": "TaskStatusNodeConnection",
|
|
48
|
+
"kind": "LinkedField",
|
|
49
|
+
"name": "allTaskStatuses",
|
|
50
|
+
"plural": false,
|
|
51
|
+
"selections": [
|
|
52
|
+
{
|
|
53
|
+
"alias": null,
|
|
54
|
+
"args": null,
|
|
55
|
+
"concreteType": "TaskStatusNodeEdge",
|
|
56
|
+
"kind": "LinkedField",
|
|
57
|
+
"name": "edges",
|
|
58
|
+
"plural": true,
|
|
59
|
+
"selections": [
|
|
60
|
+
{
|
|
61
|
+
"alias": null,
|
|
62
|
+
"args": null,
|
|
63
|
+
"concreteType": "TaskStatusNode",
|
|
64
|
+
"kind": "LinkedField",
|
|
65
|
+
"name": "node",
|
|
66
|
+
"plural": false,
|
|
67
|
+
"selections": [
|
|
68
|
+
{
|
|
69
|
+
"alias": null,
|
|
70
|
+
"args": null,
|
|
71
|
+
"kind": "ScalarField",
|
|
72
|
+
"name": "id",
|
|
73
|
+
"storageKey": null
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"alias": null,
|
|
77
|
+
"args": null,
|
|
78
|
+
"kind": "ScalarField",
|
|
79
|
+
"name": "status",
|
|
80
|
+
"storageKey": null
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
"storageKey": null
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"storageKey": null
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"storageKey": null
|
|
90
|
+
}
|
|
91
|
+
];
|
|
92
|
+
return {
|
|
93
|
+
"fragment": {
|
|
94
|
+
"argumentDefinitions": [],
|
|
95
|
+
"kind": "Fragment",
|
|
96
|
+
"metadata": null,
|
|
97
|
+
"name": "QueryChoicesAllTaskStatusesQuery",
|
|
98
|
+
"selections": (v0/*: any*/),
|
|
99
|
+
"type": "Query",
|
|
100
|
+
"abstractKey": null
|
|
101
|
+
},
|
|
102
|
+
"kind": "Request",
|
|
103
|
+
"operation": {
|
|
104
|
+
"argumentDefinitions": [],
|
|
105
|
+
"kind": "Operation",
|
|
106
|
+
"name": "QueryChoicesAllTaskStatusesQuery",
|
|
107
|
+
"selections": (v0/*: any*/)
|
|
108
|
+
},
|
|
109
|
+
"params": {
|
|
110
|
+
"cacheID": "6e05a3755df9f90893fa2a1a2759788b",
|
|
111
|
+
"id": null,
|
|
112
|
+
"metadata": {},
|
|
113
|
+
"name": "QueryChoicesAllTaskStatusesQuery",
|
|
114
|
+
"operationKind": "query",
|
|
115
|
+
"text": "query QueryChoicesAllTaskStatusesQuery {\n allTaskStatuses {\n edges {\n node {\n id\n status\n }\n }\n }\n}\n"
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
})();
|
|
119
|
+
// prettier-ignore
|
|
120
|
+
(node/*: any*/).hash = 'c71c37c5254bb38906c56c4ccd382a39';
|
|
121
|
+
|
|
122
|
+
module.exports = node;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @flow
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/* eslint-disable */
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
/*::
|
|
10
|
+
import type { ConcreteRequest } from 'relay-runtime';
|
|
11
|
+
export type QueryChoicesUserChoicesQueryVariables = {||};
|
|
12
|
+
export type QueryChoicesUserChoicesQueryResponse = {|
|
|
13
|
+
+allUsers: ?{|
|
|
14
|
+
+edges: $ReadOnlyArray<?{|
|
|
15
|
+
+node: ?{|
|
|
16
|
+
+id: string,
|
|
17
|
+
+firstName: string,
|
|
18
|
+
|}
|
|
19
|
+
|}>
|
|
20
|
+
|}
|
|
21
|
+
|};
|
|
22
|
+
export type QueryChoicesUserChoicesQuery = {|
|
|
23
|
+
variables: QueryChoicesUserChoicesQueryVariables,
|
|
24
|
+
response: QueryChoicesUserChoicesQueryResponse,
|
|
25
|
+
|};
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
query QueryChoicesUserChoicesQuery {
|
|
31
|
+
allUsers {
|
|
32
|
+
edges {
|
|
33
|
+
node {
|
|
34
|
+
id
|
|
35
|
+
firstName
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
const node/*: ConcreteRequest*/ = (function(){
|
|
43
|
+
var v0 = [
|
|
44
|
+
{
|
|
45
|
+
"alias": null,
|
|
46
|
+
"args": null,
|
|
47
|
+
"concreteType": "UserNodeConnection",
|
|
48
|
+
"kind": "LinkedField",
|
|
49
|
+
"name": "allUsers",
|
|
50
|
+
"plural": false,
|
|
51
|
+
"selections": [
|
|
52
|
+
{
|
|
53
|
+
"alias": null,
|
|
54
|
+
"args": null,
|
|
55
|
+
"concreteType": "UserNodeEdge",
|
|
56
|
+
"kind": "LinkedField",
|
|
57
|
+
"name": "edges",
|
|
58
|
+
"plural": true,
|
|
59
|
+
"selections": [
|
|
60
|
+
{
|
|
61
|
+
"alias": null,
|
|
62
|
+
"args": null,
|
|
63
|
+
"concreteType": "UserNode",
|
|
64
|
+
"kind": "LinkedField",
|
|
65
|
+
"name": "node",
|
|
66
|
+
"plural": false,
|
|
67
|
+
"selections": [
|
|
68
|
+
{
|
|
69
|
+
"alias": null,
|
|
70
|
+
"args": null,
|
|
71
|
+
"kind": "ScalarField",
|
|
72
|
+
"name": "id",
|
|
73
|
+
"storageKey": null
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"alias": null,
|
|
77
|
+
"args": null,
|
|
78
|
+
"kind": "ScalarField",
|
|
79
|
+
"name": "firstName",
|
|
80
|
+
"storageKey": null
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
"storageKey": null
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"storageKey": null
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"storageKey": null
|
|
90
|
+
}
|
|
91
|
+
];
|
|
92
|
+
return {
|
|
93
|
+
"fragment": {
|
|
94
|
+
"argumentDefinitions": [],
|
|
95
|
+
"kind": "Fragment",
|
|
96
|
+
"metadata": null,
|
|
97
|
+
"name": "QueryChoicesUserChoicesQuery",
|
|
98
|
+
"selections": (v0/*: any*/),
|
|
99
|
+
"type": "Query",
|
|
100
|
+
"abstractKey": null
|
|
101
|
+
},
|
|
102
|
+
"kind": "Request",
|
|
103
|
+
"operation": {
|
|
104
|
+
"argumentDefinitions": [],
|
|
105
|
+
"kind": "Operation",
|
|
106
|
+
"name": "QueryChoicesUserChoicesQuery",
|
|
107
|
+
"selections": (v0/*: any*/)
|
|
108
|
+
},
|
|
109
|
+
"params": {
|
|
110
|
+
"cacheID": "fe1c8d0544d6991186ae4ce7e07a0163",
|
|
111
|
+
"id": null,
|
|
112
|
+
"metadata": {},
|
|
113
|
+
"name": "QueryChoicesUserChoicesQuery",
|
|
114
|
+
"operationKind": "query",
|
|
115
|
+
"text": "query QueryChoicesUserChoicesQuery {\n allUsers {\n edges {\n node {\n id\n firstName\n }\n }\n }\n}\n"
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
})();
|
|
119
|
+
// prettier-ignore
|
|
120
|
+
(node/*: any*/).hash = '36060962ef74ee346f3a924ee90f28ef';
|
|
121
|
+
|
|
122
|
+
module.exports = node;
|
package/src/ui/c/Modal/Modal.jsx
CHANGED
|
@@ -24,20 +24,14 @@ const Modal = ({
|
|
|
24
24
|
style,
|
|
25
25
|
children,
|
|
26
26
|
title,
|
|
27
|
-
setOpen,
|
|
28
27
|
color,
|
|
29
|
-
|
|
28
|
+
close,
|
|
30
29
|
// ...otherProps
|
|
31
30
|
}) => {
|
|
32
31
|
useLayoutEffect(() => {
|
|
33
32
|
import('./styles.scss')
|
|
34
33
|
}, [])
|
|
35
34
|
|
|
36
|
-
const close = () => {
|
|
37
|
-
setOpen?.(false)
|
|
38
|
-
onClose?.()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
35
|
return (
|
|
42
36
|
<div
|
|
43
37
|
id={id}
|
|
@@ -90,19 +84,14 @@ Modal.propTypes = {
|
|
|
90
84
|
title:PropTypes.string.isRequired,
|
|
91
85
|
|
|
92
86
|
/**
|
|
93
|
-
* The color for the button
|
|
94
|
-
*/
|
|
95
|
-
color:PropTypes.string.isRequired,
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* The function to open the modal
|
|
87
|
+
* The color for the header button
|
|
99
88
|
*/
|
|
100
|
-
|
|
89
|
+
color:PropTypes.string,
|
|
101
90
|
|
|
102
91
|
/**
|
|
103
92
|
* The function to run upon closing the modal, if any
|
|
104
93
|
*/
|
|
105
|
-
|
|
94
|
+
close:PropTypes.func,
|
|
106
95
|
}
|
|
107
96
|
|
|
108
97
|
Modal.defaultProps = {
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
QuerySelect,
|
|
15
15
|
RatingsInput,
|
|
16
16
|
Checkbox,
|
|
17
|
+
QueryChoices,
|
|
17
18
|
} from '../fields'
|
|
18
19
|
|
|
19
20
|
// Local Definitions
|
|
@@ -87,6 +88,16 @@ const FormInput = ({
|
|
|
87
88
|
)
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
if (type === 'query-choices') {
|
|
92
|
+
return (
|
|
93
|
+
<QueryChoices
|
|
94
|
+
className={newClassName}
|
|
95
|
+
disabled={disabled}
|
|
96
|
+
{...otherProps}
|
|
97
|
+
/>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
90
101
|
if (type === 'rating') {
|
|
91
102
|
return (
|
|
92
103
|
<RatingsInput
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import { useEffect, useState } from 'react'
|
|
5
|
+
|
|
6
|
+
import { useRelayEnvironment, fetchQuery } from 'react-relay'
|
|
7
|
+
|
|
8
|
+
import { useField } from 'formik'
|
|
9
|
+
|
|
10
|
+
import PropTypes from 'prop-types'
|
|
11
|
+
|
|
12
|
+
import { ChoicesInput } from '../ChoicesInput'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This is the component description.
|
|
16
|
+
*/
|
|
17
|
+
const QueryChoices = ({
|
|
18
|
+
name,
|
|
19
|
+
optionsKeyMap,
|
|
20
|
+
query,
|
|
21
|
+
variables,
|
|
22
|
+
validate,
|
|
23
|
+
loadingOption,
|
|
24
|
+
extraVariables,
|
|
25
|
+
...otherProps
|
|
26
|
+
}) => {
|
|
27
|
+
const [, , helpers] = useField({ name, validate })
|
|
28
|
+
|
|
29
|
+
const { setError } = helpers
|
|
30
|
+
|
|
31
|
+
const environment = useRelayEnvironment()
|
|
32
|
+
|
|
33
|
+
const [isFetching, setIsFetching] = useState(false)
|
|
34
|
+
|
|
35
|
+
const [options, setOptions] = useState([loadingOption])
|
|
36
|
+
|
|
37
|
+
const { graphql, accessor } = query
|
|
38
|
+
|
|
39
|
+
const getOptions = () => {
|
|
40
|
+
if (isFetching) return
|
|
41
|
+
|
|
42
|
+
let searchVariables = variables
|
|
43
|
+
|
|
44
|
+
if (extraVariables) {
|
|
45
|
+
searchVariables = {
|
|
46
|
+
...variables,
|
|
47
|
+
...extraVariables,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fetchQuery(
|
|
52
|
+
environment,
|
|
53
|
+
graphql,
|
|
54
|
+
searchVariables,
|
|
55
|
+
)
|
|
56
|
+
.subscribe({
|
|
57
|
+
start:() => {
|
|
58
|
+
setIsFetching(true)
|
|
59
|
+
},
|
|
60
|
+
complete:() => {
|
|
61
|
+
setIsFetching(false)
|
|
62
|
+
},
|
|
63
|
+
error:(fetchError) => {
|
|
64
|
+
setIsFetching(false)
|
|
65
|
+
if (setError) setError(fetchError.message)
|
|
66
|
+
},
|
|
67
|
+
next:(data) => {
|
|
68
|
+
setOptions([
|
|
69
|
+
...data[accessor].edges.map(({ node }) => ({
|
|
70
|
+
value:node[optionsKeyMap.value],
|
|
71
|
+
label:optionsKeyMap.getLabel(node),
|
|
72
|
+
})),
|
|
73
|
+
])
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
getOptions()
|
|
80
|
+
}, [variables])
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<ChoicesInput
|
|
84
|
+
name={name}
|
|
85
|
+
validate={validate}
|
|
86
|
+
options={options}
|
|
87
|
+
{...otherProps}
|
|
88
|
+
/>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
QueryChoices.propTypes = {
|
|
93
|
+
/**
|
|
94
|
+
* The choices name
|
|
95
|
+
*/
|
|
96
|
+
name:PropTypes.string.isRequired,
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The select option keys to be used to map the data to the select options.
|
|
100
|
+
* i.e `{ value: 'id', label: 'name' }`
|
|
101
|
+
*/
|
|
102
|
+
optionsKeyMap:PropTypes.shape({
|
|
103
|
+
value :PropTypes.string.isRequired,
|
|
104
|
+
getLabel:PropTypes.func.isRequired,
|
|
105
|
+
}).isRequired,
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The graphql query to fetch the options and the accessor to destructure the results from
|
|
109
|
+
*/
|
|
110
|
+
query:PropTypes.shape({
|
|
111
|
+
accessor:PropTypes.string,
|
|
112
|
+
graphql :PropTypes.oneOfType([
|
|
113
|
+
PropTypes.string,
|
|
114
|
+
PropTypes.object,
|
|
115
|
+
]).isRequired,
|
|
116
|
+
}),
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The variables that might be required to be used in the query to fetch
|
|
120
|
+
* select options.
|
|
121
|
+
*/
|
|
122
|
+
variables:PropTypes.objectOf(PropTypes.string),
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The option to displayed when the select options are being fetched
|
|
126
|
+
*/
|
|
127
|
+
loadingOption:PropTypes.shape({
|
|
128
|
+
value :PropTypes.string.isRequired,
|
|
129
|
+
label :PropTypes.string.isRequired,
|
|
130
|
+
disabled:PropTypes.bool.isRequired,
|
|
131
|
+
}),
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The input field validator function
|
|
135
|
+
*/
|
|
136
|
+
validate:PropTypes.string,
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The extra variables that might be required to be used in the query to fetch
|
|
140
|
+
* select options.
|
|
141
|
+
*/
|
|
142
|
+
extraVariables:PropTypes.objectOf(PropTypes.string),
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
QueryChoices.defaultProps = {
|
|
146
|
+
loadingOption:{
|
|
147
|
+
value :'',
|
|
148
|
+
label :'Fetching Options',
|
|
149
|
+
disabled:true,
|
|
150
|
+
},
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export default QueryChoices
|
package/src/ui/f/fields/index.js
CHANGED