@pareto-engineering/design-system 2.0.0-alpha.43 → 2.0.0-alpha.46

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.
Files changed (89) hide show
  1. package/.env.scripts.example +4 -0
  2. package/.eslintrc.js +25 -1
  3. package/babel.config.js +1 -0
  4. package/dist/cjs/f/FormInput/FormInput.js +13 -3
  5. package/dist/cjs/f/FormInput/styles.scss +11 -0
  6. package/dist/cjs/f/fields/QueryCombobox/QueryCombobox.js +214 -0
  7. package/dist/cjs/f/fields/QueryCombobox/common/Combobox/Combobox.js +194 -0
  8. package/dist/cjs/f/fields/QueryCombobox/common/Combobox/index.js +15 -0
  9. package/dist/cjs/f/fields/QueryCombobox/common/Menu/Menu.js +103 -0
  10. package/dist/cjs/f/fields/QueryCombobox/common/Menu/index.js +15 -0
  11. package/dist/cjs/f/fields/QueryCombobox/common/MultipleCombobox/MultipleCombobox.js +281 -0
  12. package/dist/cjs/f/fields/QueryCombobox/common/MultipleCombobox/index.js +15 -0
  13. package/dist/cjs/f/fields/QueryCombobox/common/index.js +21 -0
  14. package/dist/cjs/f/fields/QueryCombobox/index.js +15 -0
  15. package/dist/cjs/f/fields/QueryCombobox/styles.scss +84 -0
  16. package/dist/cjs/f/fields/SelectInput/SelectInput.js +0 -1
  17. package/dist/cjs/f/fields/SelectInput/styles.scss +8 -6
  18. package/dist/cjs/f/fields/index.js +9 -1
  19. package/dist/cjs/index.js +13 -0
  20. package/dist/cjs/test/QueryLoader/QueryLoader.js +41 -0
  21. package/dist/cjs/test/QueryLoader/__generated__/QueryLoaderHelloQuery.graphql.js +71 -0
  22. package/dist/cjs/test/QueryLoader/common/PreloadedTestData/PreloadedTestData.js +49 -0
  23. package/dist/cjs/test/QueryLoader/common/PreloadedTestData/index.js +15 -0
  24. package/dist/cjs/test/QueryLoader/common/index.js +13 -0
  25. package/dist/cjs/test/QueryLoader/index.js +15 -0
  26. package/dist/cjs/test/QueryLoader/styles.scss +9 -0
  27. package/dist/cjs/test/index.js +13 -0
  28. package/dist/es/f/FormInput/FormInput.js +13 -3
  29. package/dist/es/f/FormInput/styles.scss +11 -0
  30. package/dist/es/f/fields/QueryCombobox/QueryCombobox.js +191 -0
  31. package/dist/es/f/fields/QueryCombobox/common/Combobox/Combobox.js +174 -0
  32. package/dist/es/f/fields/QueryCombobox/common/Combobox/index.js +2 -0
  33. package/dist/es/f/fields/QueryCombobox/common/Menu/Menu.js +77 -0
  34. package/dist/es/f/fields/QueryCombobox/common/Menu/index.js +2 -0
  35. package/dist/es/f/fields/QueryCombobox/common/MultipleCombobox/MultipleCombobox.js +253 -0
  36. package/dist/es/f/fields/QueryCombobox/common/MultipleCombobox/index.js +2 -0
  37. package/dist/es/f/fields/QueryCombobox/common/index.js +2 -0
  38. package/dist/es/f/fields/QueryCombobox/index.js +2 -0
  39. package/dist/es/f/fields/QueryCombobox/styles.scss +84 -0
  40. package/dist/es/f/fields/SelectInput/SelectInput.js +0 -1
  41. package/dist/es/f/fields/SelectInput/styles.scss +8 -6
  42. package/dist/es/f/fields/index.js +2 -1
  43. package/dist/es/index.js +2 -1
  44. package/dist/es/test/QueryLoader/QueryLoader.js +29 -0
  45. package/dist/es/test/QueryLoader/__generated__/QueryLoaderHelloQuery.graphql.js +71 -0
  46. package/dist/es/test/QueryLoader/common/PreloadedTestData/PreloadedTestData.js +31 -0
  47. package/dist/es/test/QueryLoader/common/PreloadedTestData/index.js +2 -0
  48. package/dist/es/test/QueryLoader/common/index.js +1 -0
  49. package/dist/es/test/QueryLoader/index.js +2 -0
  50. package/dist/es/test/QueryLoader/styles.scss +9 -0
  51. package/dist/es/test/index.js +1 -0
  52. package/package.json +16 -3
  53. package/relay.config.js +12 -0
  54. package/schema.graphql +4075 -0
  55. package/scripts/fetchSchema.js +74 -0
  56. package/src/__snapshots__/Storyshots.test.js.snap +323 -8
  57. package/src/stories/f/FormInput.stories.jsx +115 -0
  58. package/src/stories/f/QueryCombobox.stories.jsx +220 -0
  59. package/src/stories/f/__generated__/FormInputAllTeamsQuery.graphql.js +139 -0
  60. package/src/stories/f/__generated__/QueryComboboxAllTeamsQuery.graphql.js +139 -0
  61. package/src/stories/test/QueryLoader.stories.jsx +36 -0
  62. package/src/stories/utils/generateNodeId.js +12 -0
  63. package/src/stories/utils/relay/EnvironmentProvider.jsx +14 -0
  64. package/src/stories/utils/relay/environment.js +5 -0
  65. package/src/stories/utils/relay/index.js +4 -0
  66. package/src/stories/utils/relay/mockRelayOperation.js +14 -0
  67. package/src/stories/utils/relay/mockResolvers.js +299 -0
  68. package/src/stories/utils/testData.js +63 -0
  69. package/src/ui/f/FormInput/FormInput.jsx +16 -1
  70. package/src/ui/f/FormInput/styles.scss +11 -0
  71. package/src/ui/f/fields/QueryCombobox/QueryCombobox.jsx +207 -0
  72. package/src/ui/f/fields/QueryCombobox/common/Combobox/Combobox.jsx +214 -0
  73. package/src/ui/f/fields/QueryCombobox/common/Combobox/index.js +2 -0
  74. package/src/ui/f/fields/QueryCombobox/common/Menu/Menu.jsx +103 -0
  75. package/src/ui/f/fields/QueryCombobox/common/Menu/index.js +2 -0
  76. package/src/ui/f/fields/QueryCombobox/common/index.js +2 -0
  77. package/src/ui/f/fields/QueryCombobox/index.js +2 -0
  78. package/src/ui/f/fields/QueryCombobox/styles.scss +84 -0
  79. package/src/ui/f/fields/SelectInput/SelectInput.jsx +1 -1
  80. package/src/ui/f/fields/SelectInput/styles.scss +8 -6
  81. package/src/ui/f/fields/index.js +1 -0
  82. package/src/ui/index.js +1 -0
  83. package/src/ui/test/QueryLoader/QueryLoader.jsx +41 -0
  84. package/src/ui/test/QueryLoader/__generated__/QueryLoaderHelloQuery.graphql.js +68 -0
  85. package/src/ui/test/QueryLoader/common/PreloadedTestData/PreloadedTestData.jsx +51 -0
  86. package/src/ui/test/QueryLoader/common/PreloadedTestData/index.js +2 -0
  87. package/src/ui/test/QueryLoader/common/index.js +1 -0
  88. package/src/ui/test/QueryLoader/index.js +2 -0
  89. package/src/ui/test/index.js +1 -0
@@ -0,0 +1,299 @@
1
+ const customMockResolvers = {
2
+ String :() => 'Test string',
3
+ UserNode:() => ({
4
+ id :'VXNlck5vZGU6OTZkZTA3M2MtNTE3Ni00ZjgyLTg4OWMtMzIwYmVmYzU5ODFj',
5
+ firstName :'Collins',
6
+ isSuperuser:false,
7
+ }),
8
+ TaskNode:() => ({
9
+ id :'VGFza05vZGU6MDAwZmQ4N2UtYjNlNS00NWE5LTg5ZjEtNWI0ZDViNWE2NTlj',
10
+ title :'Task1',
11
+ status:{
12
+ id :'VGFza1N0YXR1c05vZGU6OTczYmM4NTgtMzA0NC00NWNiLTg2MDQtYTRhM2JmNjFmZjEx',
13
+ status:'In Review',
14
+ },
15
+ requester:{
16
+ id :'VXNlck5vZGU6OTZkZTA3M2MtNTE3Ni00ZjgyLTg4OWMtMzIwYmVmYzU5ODFj',
17
+ firstName:'Collins',
18
+ },
19
+ userTeam:{
20
+ id :'VGVhbU5vZGU6MDAxZTIyOGEtYzA5My00MGI0LWE1MTUtYTNkMTM1NTE1MDNl',
21
+ name:'Team 1',
22
+ },
23
+ manager:{
24
+ id :'VXNlck5vZGU6OTZkZTA3M2MtNTE3Ni00ZjgyLTg4OWMtMzIwYmVmYzU5ODFj',
25
+ firstName:'manager',
26
+ },
27
+ createdAt :'2021-09-23',
28
+ dueDate :'2021-10-30',
29
+ requestDate:'2020-01-01',
30
+ description:'First task',
31
+ }),
32
+ TeamNode:() => ({
33
+ id :'VGVhbU5vZGU6MDAxZTIyOGEtYzA5My00MGI0LWE1MTUtYTNkMTM1NTE1MDNl',
34
+ name :'Team 1',
35
+ credits :20.12,
36
+ billingEmail:'team1@hellopareto.com',
37
+ hourlyRate :20,
38
+ partner :{
39
+ firstName:'Test1',
40
+ lastName :'assd',
41
+ },
42
+
43
+ }),
44
+ GroupNode:() => ({
45
+ id :'VGFza05vZGU6MDAwZmQ4N2UtYjNlNS00NWE5LTg5ZjEtNWI0ZDViNWE2NTlk',
46
+ name:'admin',
47
+ }),
48
+ TaskNodeConnection:() => ({
49
+ pageInfo:{
50
+ hasNextPage :true,
51
+ hasPreviousPage:true,
52
+ },
53
+ edges:[
54
+ {
55
+ node:{
56
+ id :'VGFza05vZGU6MDAwZmQ4N2UtYjNlNS00NWE5LTg5ZjEtNWI0ZDViNWE2NTlj',
57
+ title :'Task1',
58
+ status:{
59
+ id :'VGFza1N0YXR1c05vZGU6OTczYmM4NTgtMzA0NC00NWNiLTg2MDQtYTRhM2JmNjFmZjEx',
60
+ status:'In Review',
61
+ },
62
+ requester:{
63
+ id :'VXNlck5vZGU6OTZkZTA3M2MtNTE3Ni00ZjgyLTg4OWMtMzIwYmVmYzU5ODFj',
64
+ firstName:'Collins',
65
+ },
66
+ userTeam:{
67
+ id :'VGVhbU5vZGU6MDAxZTIyOGEtYzA5My00MGI0LWE1MTUtYTNkMTM1NTE1MDNl',
68
+ name:'Team 1',
69
+ },
70
+ manager:{
71
+ id :'VXNlck5vZGU6OTZkZTA3M2MtNTE3Ni00ZjgyLTg4OWMtMzIwYmVmYzU5ODFj',
72
+ firstName:'manager',
73
+ },
74
+ createdAt :'2021-09-23',
75
+ dueDate :'2021-10-30',
76
+ requestDate:'2020-01-01',
77
+ description:'First task',
78
+ },
79
+ },
80
+ {
81
+ node:{
82
+ id :'VGFza05vZGU6MDAwZmQ4N2UtYjNlNS00NWE5LTg5ZjEtNWI0ZDViNWE2NTlj',
83
+ title :'Task2',
84
+ status:{
85
+ id :'VGFza1N0YXR1c05vZGU6OTczYmM4NTgtMzA0NC00NWNiLTg2MDQtYTRhM2JmNjFmZjEx',
86
+ status:'In Review',
87
+ },
88
+ requester:{
89
+ id :'VXNlck5vZGU6OTZkZTA3M2MtNTE3Ni00ZjgyLTg4OWMtMzIwYmVmYzU5ODFj',
90
+ firstName:'Collins',
91
+ },
92
+ userTeam:{
93
+ id :'VGVhbU5vZGU6MDAxZTIyOGEtYzA5My00MGI0LWE1MTUtYTNkMTM1NTE1MDNl',
94
+ name:'Team 2',
95
+ },
96
+ manager:{
97
+ id :'VXNlck5vZGU6OTZkZTA3M2MtNTE3Ni00ZjgyLTg4OWMtMzIwYmVmYzU5ODFj',
98
+ firstName:'manager',
99
+ },
100
+ createdAt :'2021-09-23',
101
+ dueDate :'2021-10-30',
102
+ requestDate:'2020-01-01',
103
+ description:'Second task',
104
+ },
105
+ },
106
+ ],
107
+ }),
108
+ UserNodeConnection:(allArgs) => {
109
+ const { args :{ first, offset } } = allArgs
110
+
111
+ const edges = [
112
+ {
113
+ node:{
114
+ id :'VXNlck5vZGU6OTZkZTA3M2MtNTE3Ni00ZjgyLTg4OWMtMzIwYmVmYzU5ODFj',
115
+ firstName:'Collins',
116
+ },
117
+ },
118
+ {
119
+ node:{
120
+ id :'VXNlck5vZGU6MDEyN2E1NmItYjAxOS00NmQxLTg2NTEtYWEzOGIxZTUwNTA5',
121
+ firstName:'Amritha',
122
+ },
123
+ },
124
+ {
125
+ node:{
126
+ id :'VXNlck5vZGU6YzcwYWIxMDItZWE2Yy00ZWNhLTk0M2ItOTA2OWQwN2RiMDQ0',
127
+ firstName:'Marsya',
128
+ },
129
+ },
130
+ {
131
+ node:{
132
+ id :'VXNlck5vZGU6OTUyNjg1NWYtZTg3NC00ZTlkLWFlZTgtZDZjODc3NDNlNTRh',
133
+ firstName:'James',
134
+ },
135
+ },
136
+ {
137
+ node:{
138
+ id :'VXNlck5vZGU6OTFmOTE4NTYtNjg0Yi00ODhhLWE0YzktZGU5ZDQ5YmJjM2Mz',
139
+ firstName:'Adrian',
140
+ },
141
+ },
142
+ {
143
+ node:{
144
+ id :'VXNlck5vZGU6OTNkZGU3NGEtYTA2Yi00MDMzLWIwMDAtMTFkZDY0N2Y3OWE4',
145
+ firstName:'Melissa',
146
+ },
147
+ },
148
+ {
149
+ node:{
150
+ id :'VXNlck5vZGU6MjgyYTk1MjctMDI4OS00MDlhLWFjNTktYWJkNTFkODAyMjFj',
151
+ firstName:'Beto',
152
+ },
153
+ },
154
+ {
155
+ node:{
156
+ id :'VXNlck5vZGU6YmIxYzI5YmEtYTk0OS00M2I3LWIxMWEtZDQxMjM5ZWI0ZWI2',
157
+ firstName:'Romie',
158
+ },
159
+ },
160
+ {
161
+ node:{
162
+ id :'VXNlck5vZGU6ZjZhNzBiZTgtY2FkMC00NzNjLWEyODUtNDdkMGVmYjQxYTRl',
163
+ firstName:'Miguel',
164
+ },
165
+ },
166
+ {
167
+ node:{
168
+ id :'VXNlck5vZGU6Y2JlOGM4ZTYtY2Q2Zi00M2RlLWI4YmQtODU3YWRhZjYyMzVj',
169
+ firstName:'Phoebe',
170
+ },
171
+ },
172
+ {
173
+ node:{
174
+ id :'VXNlck5vZGU6NDA5MWM1MDUtYjY1MC00M2Y1LTg3NTEtMDc1NTBkMzJhYTcy',
175
+ firstName:'Kim',
176
+ },
177
+ },
178
+ {
179
+ node:{
180
+ id :'VXNlck5vZGU6ZjE0MGUxYTItM2I4My00NmY1LWIzMDQtYmFiOGZjMTc5ZmU4',
181
+ firstName:'Liz',
182
+ },
183
+ },
184
+ {
185
+ node:{
186
+ id :'VXNlck5vZGU6ZGYyOGE5MDYtM2NhMS00NTVmLWIzZmUtNjY5YWFkZTNiZjRk',
187
+ firstName:'Deepanshu',
188
+ },
189
+ },
190
+ {
191
+ node:{
192
+ id :'VXNlck5vZGU6MjBhMDBkYjgtZDExNi00YzAyLWEyOTUtYWM5MzIwMjUwMWU3',
193
+ firstName:'Jennica',
194
+ },
195
+ },
196
+ {
197
+ node:{
198
+ id :'VXNlck5vZGU6MjczNDllYjMtYzNmYi00ZmVkLWE1N2YtNTFjZGJlODI0MWU2',
199
+ firstName:'Michelle',
200
+ },
201
+ },
202
+ ]
203
+
204
+ return ({
205
+ pageInfo:{
206
+ hasNextPage :true,
207
+ hasPreviousPage:true,
208
+ },
209
+ edges:edges.slice(offset, offset + first),
210
+ })
211
+ },
212
+ WorkHoursNodeConnection:() => ({
213
+ pageInfo:{
214
+ hasNextPage :true,
215
+ hasPreviousPage:true,
216
+ },
217
+ edges:[
218
+ {
219
+ node:{
220
+ id :'V29ya0hvdXJzTm9kZTplYWJlYmEyNC0wNTlmLTQxMjEtODIzYi0yYmU2YzMxMmZlNzA=',
221
+ associate:{
222
+ firstName:'Des',
223
+ lastName :'assd',
224
+ },
225
+ timeSpent :15,
226
+ log :'asd',
227
+ paidOut :false,
228
+ sentInvoice:true,
229
+ createdAt :'2021-09-05T17:08:49.000-0430',
230
+ startedAt :'2021-09-05T17:08:49.000-0430',
231
+ },
232
+ },
233
+ {
234
+ node:{
235
+ id :'V29ya0hvdXJzTm9kZTplYmZiZTllZS04NWNkLTRhNDktYTZhMi0zNmNhMTU0M2EwMDU=',
236
+ associate:{
237
+ firstName:'Ella',
238
+ lastName :'asdasd',
239
+ },
240
+ timeSpent :25,
241
+ log :'aasdasdsd',
242
+ paidOut :true,
243
+ sentInvoice:false,
244
+ createdAt :'2021-09-15T17:08:49.000-0430',
245
+ startedAt :'2021-09-15T17:08:49.000-0430',
246
+ },
247
+ },
248
+ ],
249
+ }),
250
+ TeamNodeConnection:() => ({
251
+ pageInfo:{
252
+ hasNextPage :true,
253
+ hasPreviousPage:true,
254
+ },
255
+ edges:[
256
+ {
257
+ node:{
258
+ id :'VGVhbU5vZGU6MDAxZTIyOGEtYzA5My00MGI0LWE1MTUtYTNkMTM1NTE1MDNl',
259
+ name :'Team 1',
260
+ credits :20.12,
261
+ billingEmail:'team1@hellopareto.com',
262
+ hourlyRate :20,
263
+ partner :{
264
+ firstName:'Test1',
265
+ lastName :'assd',
266
+ },
267
+ },
268
+ },
269
+ {
270
+ node:{
271
+ id :'VGVhbU5vZGU6MDA0N2U4MzktODY0Zi00N2U5LTg3ZjgtZGUwMmM2Yzg1YWJm',
272
+ name :'Team 2',
273
+ credits :20.12,
274
+ billingEmail:'team2@hellopareto.com',
275
+ hourlyRate :20,
276
+ partner :{
277
+ firstName:'Test2',
278
+ lastName :'assd',
279
+ },
280
+ },
281
+ },
282
+ {
283
+ node:{
284
+ id :'VGVhbU5vZGU6MDExMmEyZmEtYzE0YS00MGRhLThiNWQtMDMzNTkyNDQ3ZDI2',
285
+ name :'Team 3',
286
+ credits :20.12,
287
+ billingEmail:'team3@hellopareto.com',
288
+ hourlyRate :20,
289
+ partner :{
290
+ firstName:'Test3',
291
+ lastName :'assd',
292
+ },
293
+ },
294
+ },
295
+ ],
296
+ }),
297
+ }
298
+
299
+ export default customMockResolvers
@@ -0,0 +1,63 @@
1
+ export const fruits = [
2
+ 'Apple',
3
+ 'Apricot',
4
+ 'Avocado',
5
+ 'Banana',
6
+ 'Bilberry',
7
+ 'Blackberry',
8
+ 'Blackcurrant',
9
+ 'Blueberry',
10
+ 'Currant',
11
+ 'Cherry',
12
+ 'Cherimoya',
13
+ 'Clementine',
14
+ 'Date',
15
+ 'Damson',
16
+ 'Durian',
17
+ 'Eggplant',
18
+ 'Elderberry',
19
+ 'Feijoa',
20
+ 'Gooseberry',
21
+ 'Grape',
22
+ 'Grapefruit',
23
+ 'Guava',
24
+ 'Huckleberry',
25
+ 'Jackfruit',
26
+ 'Jambul',
27
+ 'Kiwi fruit',
28
+ 'Kumquat',
29
+ 'Legume',
30
+ 'Lemon',
31
+ 'Lime',
32
+ 'Lychee',
33
+ 'Mango',
34
+ 'Mangostine',
35
+ 'Melon',
36
+ 'Cantaloupe',
37
+ 'Honeydew melon',
38
+ 'Rock melon',
39
+ 'Nectarine',
40
+ 'Orange',
41
+ 'Peach',
42
+ 'Pear',
43
+ 'Williams pear or Bartlett pear',
44
+ 'Pitaya',
45
+ 'Physalis',
46
+ 'Plum/prune (dried plum)',
47
+ 'Pineapple',
48
+ 'Pomegranate',
49
+ 'Raisin',
50
+ 'Raspberry',
51
+ 'Western raspberry (blackcap)',
52
+ 'Rambutan',
53
+ 'Redcurrant',
54
+ 'Salal berry',
55
+ 'Satsuma',
56
+ 'Star fruit',
57
+ 'Strawberry',
58
+ 'Tangerine',
59
+ 'Tomato',
60
+ 'Ugli fruit',
61
+ 'Watermelon',
62
+ 'Ziziphus mauritiana',
63
+ ]
@@ -1,7 +1,7 @@
1
1
  /* @pareto-engineering/generator-front 1.0.12 */
2
2
  import * as React from 'react'
3
3
 
4
- import { memo } from 'react'
4
+ import { memo, useLayoutEffect } from 'react'
5
5
 
6
6
  import PropTypes from 'prop-types'
7
7
 
@@ -10,6 +10,7 @@ import {
10
10
  TextareaInput,
11
11
  ChoicesInput,
12
12
  SelectInput,
13
+ QueryCombobox,
13
14
  } from '../fields'
14
15
 
15
16
  // Local Definitions
@@ -28,6 +29,10 @@ const FormInput = ({
28
29
  disabled,
29
30
  ...otherProps
30
31
  }) => {
32
+ useLayoutEffect(() => {
33
+ import('./styles.scss')
34
+ }, [])
35
+
31
36
  const newClassName = [
32
37
  className,
33
38
  componentClassName,
@@ -60,6 +65,15 @@ const FormInput = ({
60
65
  />
61
66
  )
62
67
  }
68
+ if (type === 'query-combobox') {
69
+ return (
70
+ <QueryCombobox
71
+ className={newClassName}
72
+ disabled={disabled}
73
+ {...otherProps}
74
+ />
75
+ )
76
+ }
63
77
  if (extraTypes?.[type]) {
64
78
  const Component = extraTypes[type]
65
79
  return (
@@ -102,6 +116,7 @@ FormInput.propTypes = {
102
116
  'select',
103
117
  'choices',
104
118
  'textarea',
119
+ 'query-combobox',
105
120
  // to be removed
106
121
  'extendedTypeInput',
107
122
  ]),
@@ -0,0 +1,11 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+
3
+ @use "@pareto-engineering/bem";
4
+
5
+ $default-margin: 1em;
6
+
7
+ .#{bem.$base}.form-input {
8
+ &+& {
9
+ margin-top: $default-margin;
10
+ }
11
+ }
@@ -0,0 +1,207 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ import * as React from 'react'
3
+
4
+ import { useState, useLayoutEffect } from 'react'
5
+
6
+ import { useField } from 'formik'
7
+
8
+ import { useRelayEnvironment, fetchQuery } from 'react-relay'
9
+
10
+ import PropTypes from 'prop-types'
11
+
12
+ // Local Definitions
13
+
14
+ import { Combobox } from './common'
15
+
16
+ /**
17
+ * This is the component description.
18
+ */
19
+ const QueryCombobox = ({
20
+ id,
21
+ style,
22
+ className,
23
+ query,
24
+ // multiple,
25
+ name,
26
+ label,
27
+ color,
28
+ description,
29
+ disabled,
30
+ debounceMs,
31
+ graphQlNode,
32
+ searchVariable,
33
+ extraVariables,
34
+ optionsKeyMap,
35
+ // ...otherProps
36
+ }) => {
37
+ useLayoutEffect(() => {
38
+ import('./styles.scss')
39
+ }, [])
40
+
41
+ const [, meta, helpers] = useField(name)
42
+
43
+ const { setValue, setError } = helpers
44
+
45
+ const { error, value } = meta
46
+
47
+ const environment = useRelayEnvironment()
48
+
49
+ const [isFetching, setIsFetching] = useState(false)
50
+
51
+ const [options, setOptions] = useState([])
52
+
53
+ const getOptions = (inputValue) => {
54
+ if (isFetching) return
55
+
56
+ let variables = { [searchVariable]: inputValue }
57
+
58
+ if (extraVariables) {
59
+ variables = {
60
+ ...variables,
61
+ ...extraVariables,
62
+ }
63
+ }
64
+
65
+ fetchQuery(
66
+ environment,
67
+ query,
68
+ variables,
69
+ )
70
+ .subscribe({
71
+ start:() => {
72
+ setIsFetching(true)
73
+ },
74
+ complete:() => {
75
+ setIsFetching(false)
76
+ },
77
+ error:(fetchError) => {
78
+ setIsFetching(false)
79
+ if (setError)setError(fetchError.message)
80
+ },
81
+ next:(data) => {
82
+ setOptions(data[graphQlNode].edges.map(({ node }) => ({
83
+ value:node[optionsKeyMap.value],
84
+ label:node[optionsKeyMap.label],
85
+ })))
86
+ },
87
+ })
88
+ }
89
+
90
+ const comboboxProps = {
91
+ id,
92
+ style,
93
+ options,
94
+ getOptions,
95
+ debounceMs,
96
+ disabled,
97
+ name,
98
+ label,
99
+ description,
100
+ setValue,
101
+ error,
102
+ value,
103
+ color,
104
+ isFetching,
105
+ className,
106
+ }
107
+
108
+ const Input = Combobox
109
+
110
+ return <Input {...comboboxProps} />
111
+ }
112
+
113
+ QueryCombobox.propTypes = {
114
+ /**
115
+ * The HTML id for this element
116
+ */
117
+ id:PropTypes.string,
118
+
119
+ /**
120
+ * The HTML class names for this element
121
+ */
122
+ className:PropTypes.string,
123
+
124
+ /**
125
+ * The React-written, css properties for this element.
126
+ */
127
+ style:PropTypes.objectOf(PropTypes.string),
128
+
129
+ /**
130
+ * The name of the custom select input
131
+ */
132
+ name:PropTypes.string,
133
+
134
+ /**
135
+ * The label of the custom select input
136
+ */
137
+ label:PropTypes.string,
138
+
139
+ /**
140
+ * The custom select input description
141
+ */
142
+ description:PropTypes.string,
143
+
144
+ /**
145
+ * Whether the input should be disabled
146
+ */
147
+ disabled:PropTypes.bool,
148
+
149
+ /**
150
+ * The base color of the custom select input
151
+ */
152
+ color:PropTypes.string,
153
+
154
+ /**
155
+ * The debounce time in milliseconds
156
+ */
157
+ debounceMs:PropTypes.number,
158
+
159
+ /**
160
+ * The query to fetch the options
161
+ */
162
+ query:PropTypes.oneOfType([
163
+ PropTypes.string,
164
+ PropTypes.object,
165
+ ]).isRequired,
166
+
167
+ /**
168
+ * The extra variables required to be used in the query.
169
+ */
170
+ extraVariables:PropTypes.objectOf(PropTypes.string),
171
+
172
+ /**
173
+ * The select option keys to be used to map the data to the select options.
174
+ * i.e `{ value: 'id', label: 'name' }`
175
+ */
176
+ optionsKeyMap:PropTypes.shape({
177
+ value:PropTypes.string.isRequired,
178
+ label:PropTypes.string.isRequired,
179
+ }),
180
+
181
+ /**
182
+ * Whether to allow multiple items selection
183
+ */
184
+ multiple:PropTypes.bool,
185
+
186
+ /**
187
+ * The graphql node to be used to destructure the fetched data
188
+ */
189
+ graphQlNode:PropTypes.string.isRequired,
190
+
191
+ /**
192
+ * The variable to be used to search the data
193
+ */
194
+ searchVariable:PropTypes.string,
195
+ }
196
+
197
+ QueryCombobox.defaultProps = {
198
+ optionsKeyMap:{
199
+ value:'id',
200
+ label:'name',
201
+ },
202
+ multiple :false,
203
+ color :'background2',
204
+ searchVariable:'search',
205
+ }
206
+
207
+ export default QueryCombobox