@pareto-engineering/design-system 2.0.0-alpha.42 → 2.0.0-alpha.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.scripts.example +4 -0
- package/.eslintrc.js +25 -1
- package/babel.config.js +1 -0
- package/dist/cjs/a/Popover/styles.scss +9 -19
- package/dist/cjs/f/FormInput/FormInput.js +5 -2
- package/dist/cjs/f/FormInput/styles.scss +11 -0
- package/dist/cjs/f/fields/QueryCombobox/QueryCombobox.js +207 -0
- package/dist/cjs/f/fields/QueryCombobox/common/Combobox/Combobox.js +181 -0
- package/dist/cjs/f/fields/QueryCombobox/common/Combobox/index.js +15 -0
- package/dist/cjs/f/fields/QueryCombobox/common/Menu/Menu.js +103 -0
- package/dist/cjs/f/fields/QueryCombobox/common/Menu/index.js +15 -0
- package/dist/cjs/f/fields/QueryCombobox/common/MultipleCombobox/MultipleCombobox.js +229 -0
- package/dist/cjs/f/fields/QueryCombobox/common/MultipleCombobox/index.js +15 -0
- package/dist/cjs/f/fields/QueryCombobox/common/index.js +21 -0
- package/dist/cjs/f/fields/QueryCombobox/index.js +15 -0
- package/dist/cjs/f/fields/QueryCombobox/styles.scss +71 -0
- package/dist/cjs/f/fields/SelectInput/SelectInput.js +0 -1
- package/dist/cjs/f/fields/SelectInput/styles.scss +8 -6
- package/dist/cjs/f/fields/index.js +9 -1
- package/dist/cjs/index.js +13 -0
- package/dist/cjs/test/QueryLoader/QueryLoader.js +41 -0
- package/dist/cjs/test/QueryLoader/__generated__/QueryLoaderHelloQuery.graphql.js +71 -0
- package/dist/cjs/test/QueryLoader/common/PreloadedTestData/PreloadedTestData.js +49 -0
- package/dist/cjs/test/QueryLoader/common/PreloadedTestData/index.js +15 -0
- package/dist/cjs/test/QueryLoader/common/index.js +13 -0
- package/dist/cjs/test/QueryLoader/index.js +15 -0
- package/dist/cjs/test/QueryLoader/styles.scss +9 -0
- package/dist/cjs/test/index.js +13 -0
- package/dist/es/a/Popover/styles.scss +9 -19
- package/dist/es/f/FormInput/FormInput.js +4 -1
- package/dist/es/f/FormInput/styles.scss +11 -0
- package/dist/es/f/fields/QueryCombobox/QueryCombobox.js +184 -0
- package/dist/es/f/fields/QueryCombobox/common/Combobox/Combobox.js +161 -0
- package/dist/es/f/fields/QueryCombobox/common/Combobox/index.js +2 -0
- package/dist/es/f/fields/QueryCombobox/common/Menu/Menu.js +77 -0
- package/dist/es/f/fields/QueryCombobox/common/Menu/index.js +2 -0
- package/dist/es/f/fields/QueryCombobox/common/MultipleCombobox/MultipleCombobox.js +202 -0
- package/dist/es/f/fields/QueryCombobox/common/MultipleCombobox/index.js +2 -0
- package/dist/es/f/fields/QueryCombobox/common/index.js +2 -0
- package/dist/es/f/fields/QueryCombobox/index.js +2 -0
- package/dist/es/f/fields/QueryCombobox/styles.scss +71 -0
- package/dist/es/f/fields/SelectInput/SelectInput.js +0 -1
- package/dist/es/f/fields/SelectInput/styles.scss +8 -6
- package/dist/es/f/fields/index.js +2 -1
- package/dist/es/index.js +2 -1
- package/dist/es/test/QueryLoader/QueryLoader.js +29 -0
- package/dist/es/test/QueryLoader/__generated__/QueryLoaderHelloQuery.graphql.js +71 -0
- package/dist/es/test/QueryLoader/common/PreloadedTestData/PreloadedTestData.js +31 -0
- package/dist/es/test/QueryLoader/common/PreloadedTestData/index.js +2 -0
- package/dist/es/test/QueryLoader/common/index.js +1 -0
- package/dist/es/test/QueryLoader/index.js +2 -0
- package/dist/es/test/QueryLoader/styles.scss +9 -0
- package/dist/es/test/index.js +1 -0
- package/package.json +16 -3
- package/relay.config.js +12 -0
- package/schema.graphql +4075 -0
- package/scripts/fetchSchema.js +74 -0
- package/src/__snapshots__/Storyshots.test.js.snap +168 -8
- package/src/stories/f/QueryCombobox.stories.jsx +220 -0
- package/src/stories/f/__generated__/QueryComboboxAllTeamsQuery.graphql.js +139 -0
- package/src/stories/test/QueryLoader.stories.jsx +36 -0
- package/src/stories/utils/generateNodeId.js +12 -0
- package/src/stories/utils/relay/EnvironmentProvider.jsx +14 -0
- package/src/stories/utils/relay/environment.js +5 -0
- package/src/stories/utils/relay/index.js +4 -0
- package/src/stories/utils/relay/mockRelayOperation.js +14 -0
- package/src/stories/utils/relay/mockResolvers.js +299 -0
- package/src/stories/utils/testData.js +63 -0
- package/src/ui/a/Popover/styles.scss +9 -19
- package/src/ui/f/FormInput/FormInput.jsx +5 -1
- package/src/ui/f/FormInput/styles.scss +11 -0
- package/src/ui/f/fields/QueryCombobox/QueryCombobox.jsx +200 -0
- package/src/ui/f/fields/QueryCombobox/common/Combobox/Combobox.jsx +198 -0
- package/src/ui/f/fields/QueryCombobox/common/Combobox/index.js +2 -0
- package/src/ui/f/fields/QueryCombobox/common/Menu/Menu.jsx +103 -0
- package/src/ui/f/fields/QueryCombobox/common/Menu/index.js +2 -0
- package/src/ui/f/fields/QueryCombobox/common/index.js +2 -0
- package/src/ui/f/fields/QueryCombobox/index.js +2 -0
- package/src/ui/f/fields/QueryCombobox/styles.scss +71 -0
- package/src/ui/f/fields/SelectInput/SelectInput.jsx +1 -1
- package/src/ui/f/fields/SelectInput/styles.scss +8 -6
- package/src/ui/f/fields/index.js +1 -0
- package/src/ui/index.js +1 -0
- package/src/ui/test/QueryLoader/QueryLoader.jsx +41 -0
- package/src/ui/test/QueryLoader/__generated__/QueryLoaderHelloQuery.graphql.js +68 -0
- package/src/ui/test/QueryLoader/common/PreloadedTestData/PreloadedTestData.jsx +51 -0
- package/src/ui/test/QueryLoader/common/PreloadedTestData/index.js +2 -0
- package/src/ui/test/QueryLoader/common/index.js +1 -0
- package/src/ui/test/QueryLoader/index.js +2 -0
- package/src/ui/test/index.js +1 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import { useEffect, useRef } from 'react'
|
|
5
|
+
|
|
6
|
+
import PropTypes from 'prop-types'
|
|
7
|
+
|
|
8
|
+
import { useCombobox } from 'downshift'
|
|
9
|
+
|
|
10
|
+
import styleNames from '@pareto-engineering/bem'
|
|
11
|
+
|
|
12
|
+
import { FormLabel, FormDescription } from 'ui/f'
|
|
13
|
+
|
|
14
|
+
import { Popover } from 'ui/a'
|
|
15
|
+
|
|
16
|
+
// Local Definitions
|
|
17
|
+
|
|
18
|
+
import { Menu } from '../Menu'
|
|
19
|
+
|
|
20
|
+
const baseClassName = styleNames.base
|
|
21
|
+
|
|
22
|
+
const componentClassName = 'combobox'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* This is the component description.
|
|
26
|
+
*/
|
|
27
|
+
const Combobox = ({
|
|
28
|
+
id,
|
|
29
|
+
className:userClassName,
|
|
30
|
+
style,
|
|
31
|
+
label,
|
|
32
|
+
name,
|
|
33
|
+
options:items,
|
|
34
|
+
getOptions,
|
|
35
|
+
setValue,
|
|
36
|
+
error,
|
|
37
|
+
description,
|
|
38
|
+
value,
|
|
39
|
+
color,
|
|
40
|
+
// ...otherProps
|
|
41
|
+
}) => {
|
|
42
|
+
const {
|
|
43
|
+
isOpen,
|
|
44
|
+
selectItem,
|
|
45
|
+
selectedItem,
|
|
46
|
+
getLabelProps,
|
|
47
|
+
getMenuProps,
|
|
48
|
+
getInputProps,
|
|
49
|
+
highlightedIndex,
|
|
50
|
+
getComboboxProps,
|
|
51
|
+
getItemProps,
|
|
52
|
+
} = useCombobox({
|
|
53
|
+
items,
|
|
54
|
+
initialSelectedItem:value,
|
|
55
|
+
itemToString :(item) => (item ? item.label : ''),
|
|
56
|
+
onInputValueChange :({ inputValue }) => {
|
|
57
|
+
getOptions(inputValue)
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
// If the user has selected an item, we'll set the value of the field
|
|
62
|
+
// or if the combobox state has a selected item, we'll set the value to the formik state
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (selectedItem) {
|
|
65
|
+
setValue(selectedItem)
|
|
66
|
+
}
|
|
67
|
+
}, [selectedItem])
|
|
68
|
+
|
|
69
|
+
// If the formik state has a value, we'll set the selected item to the combobox state
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (value?.value !== selectedItem?.value) {
|
|
72
|
+
selectItem(value)
|
|
73
|
+
}
|
|
74
|
+
}, [value])
|
|
75
|
+
|
|
76
|
+
const parentRef = useRef(null)
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div
|
|
80
|
+
id={id}
|
|
81
|
+
className={[
|
|
82
|
+
|
|
83
|
+
baseClassName,
|
|
84
|
+
|
|
85
|
+
componentClassName,
|
|
86
|
+
userClassName,
|
|
87
|
+
`y-${color}`,
|
|
88
|
+
]
|
|
89
|
+
.filter((e) => e)
|
|
90
|
+
.join(' ')}
|
|
91
|
+
style={style}
|
|
92
|
+
ref={parentRef}
|
|
93
|
+
>
|
|
94
|
+
<FormLabel {...getLabelProps()} name={name}>
|
|
95
|
+
{label}
|
|
96
|
+
</FormLabel>
|
|
97
|
+
|
|
98
|
+
<div {...getComboboxProps()} className="input-wrapper">
|
|
99
|
+
<input {...getInputProps()} className="input" />
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<Popover
|
|
103
|
+
isOpen={isOpen}
|
|
104
|
+
parentRef={parentRef}
|
|
105
|
+
>
|
|
106
|
+
<Menu
|
|
107
|
+
isOpen={isOpen}
|
|
108
|
+
getItemProps={getItemProps}
|
|
109
|
+
highlightedIndex={highlightedIndex}
|
|
110
|
+
items={items}
|
|
111
|
+
{...getMenuProps()}
|
|
112
|
+
/>
|
|
113
|
+
</Popover>
|
|
114
|
+
|
|
115
|
+
{(description || error) && (
|
|
116
|
+
<FormDescription isError={!!error}>
|
|
117
|
+
{ error || description }
|
|
118
|
+
</FormDescription>
|
|
119
|
+
)}
|
|
120
|
+
</div>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
Combobox.propTypes = {
|
|
125
|
+
/**
|
|
126
|
+
* The HTML id for this element
|
|
127
|
+
*/
|
|
128
|
+
id:PropTypes.string,
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The HTML class names for this element
|
|
132
|
+
*/
|
|
133
|
+
className:PropTypes.string,
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The React-written, css properties for this element.
|
|
137
|
+
*/
|
|
138
|
+
style:PropTypes.objectOf(PropTypes.string),
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The label of the custom select input
|
|
142
|
+
*/
|
|
143
|
+
label:PropTypes.string,
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The custom select input options from the backend
|
|
147
|
+
*/
|
|
148
|
+
options:PropTypes.arrayOf(
|
|
149
|
+
PropTypes.shape({
|
|
150
|
+
value:PropTypes.string,
|
|
151
|
+
label:PropTypes.string,
|
|
152
|
+
}),
|
|
153
|
+
),
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The name of the custom select input
|
|
157
|
+
*/
|
|
158
|
+
name:PropTypes.string,
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* The function to fetch the options from the backend
|
|
162
|
+
*/
|
|
163
|
+
getOptions:PropTypes.func,
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* The function to set the value of the custom select input
|
|
167
|
+
*/
|
|
168
|
+
setValue:PropTypes.func.isRequired,
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The custom select input description
|
|
172
|
+
*/
|
|
173
|
+
description:PropTypes.string,
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The error object
|
|
177
|
+
*/
|
|
178
|
+
error:PropTypes.objectOf(PropTypes.string),
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The value of the custom select input
|
|
182
|
+
*/
|
|
183
|
+
value:PropTypes.shape({
|
|
184
|
+
value:PropTypes.string,
|
|
185
|
+
label:PropTypes.string,
|
|
186
|
+
}),
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The base color of the combobox custom select input
|
|
190
|
+
*/
|
|
191
|
+
color:PropTypes.string,
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
Combobox.defaultProps = {
|
|
195
|
+
// someProp:false
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export default Combobox
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import PropTypes from 'prop-types'
|
|
5
|
+
|
|
6
|
+
import styleNames from '@pareto-engineering/bem'
|
|
7
|
+
|
|
8
|
+
// Local Definitions
|
|
9
|
+
|
|
10
|
+
const baseClassName = styleNames.base
|
|
11
|
+
|
|
12
|
+
const componentClassName = 'menu'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This is the component description.
|
|
16
|
+
*/
|
|
17
|
+
const Menu = React.forwardRef(({
|
|
18
|
+
id,
|
|
19
|
+
className:userClassName,
|
|
20
|
+
style,
|
|
21
|
+
items,
|
|
22
|
+
isOpen,
|
|
23
|
+
highlightedIndex,
|
|
24
|
+
getItemProps,
|
|
25
|
+
...otherProps
|
|
26
|
+
}, ref) => (
|
|
27
|
+
<ul
|
|
28
|
+
id={id}
|
|
29
|
+
className={[
|
|
30
|
+
|
|
31
|
+
baseClassName,
|
|
32
|
+
|
|
33
|
+
componentClassName,
|
|
34
|
+
userClassName,
|
|
35
|
+
]
|
|
36
|
+
.filter((e) => e)
|
|
37
|
+
.join(' ')}
|
|
38
|
+
style={style}
|
|
39
|
+
ref={ref}
|
|
40
|
+
{...otherProps}
|
|
41
|
+
>
|
|
42
|
+
{isOpen && items.map((item, index) => (
|
|
43
|
+
<li
|
|
44
|
+
key={item.label}
|
|
45
|
+
{...getItemProps({ item, index })}
|
|
46
|
+
className={[
|
|
47
|
+
'item',
|
|
48
|
+
highlightedIndex === index && styleNames.modifierActive,
|
|
49
|
+
].filter(Boolean)
|
|
50
|
+
.join(' ')}
|
|
51
|
+
>
|
|
52
|
+
<p>
|
|
53
|
+
{item.label}
|
|
54
|
+
</p>
|
|
55
|
+
</li>
|
|
56
|
+
))}
|
|
57
|
+
</ul>
|
|
58
|
+
))
|
|
59
|
+
Menu.propTypes = {
|
|
60
|
+
/**
|
|
61
|
+
* The HTML id for this element
|
|
62
|
+
*/
|
|
63
|
+
id:PropTypes.string,
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The HTML class names for this element
|
|
67
|
+
*/
|
|
68
|
+
className:PropTypes.string,
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The React-written, css properties for this element.
|
|
72
|
+
*/
|
|
73
|
+
style:PropTypes.objectOf(PropTypes.string),
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The items to be displayed in the menu
|
|
77
|
+
*/
|
|
78
|
+
items:PropTypes.arrayOf(PropTypes.shape({
|
|
79
|
+
value:PropTypes.string,
|
|
80
|
+
label:PropTypes.string,
|
|
81
|
+
})),
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Whether or not the menu is open
|
|
85
|
+
*/
|
|
86
|
+
isOpen:PropTypes.bool,
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The index of the highlighted item
|
|
90
|
+
*/
|
|
91
|
+
highlightedIndex:PropTypes.number,
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The function to get the item props
|
|
95
|
+
*/
|
|
96
|
+
getItemProps:PropTypes.func,
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
Menu.defaultProps = {
|
|
100
|
+
// someProp:false
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export default Menu
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
|
|
3
|
+
@use "@pareto-engineering/bem";
|
|
4
|
+
|
|
5
|
+
$default-input-padding: .75em .75em .55em;
|
|
6
|
+
$default-padding: 1em;
|
|
7
|
+
$default-margin: 1em;
|
|
8
|
+
|
|
9
|
+
.#{bem.$base}.combobox,
|
|
10
|
+
.#{bem.$base}.multiple-combobox {
|
|
11
|
+
position: relative;
|
|
12
|
+
|
|
13
|
+
.#{bem.$base}.popover {
|
|
14
|
+
width: 100%;
|
|
15
|
+
|
|
16
|
+
>.menu {
|
|
17
|
+
list-style: none;
|
|
18
|
+
margin: 0;
|
|
19
|
+
outline: 0;
|
|
20
|
+
padding: 0;
|
|
21
|
+
|
|
22
|
+
>.item {
|
|
23
|
+
padding: $default-padding / 2;
|
|
24
|
+
|
|
25
|
+
&.#{bem.$modifier-active} {
|
|
26
|
+
background-color: var(--background2);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
>.input-wrapper {
|
|
33
|
+
>.input {
|
|
34
|
+
background: var(--light-y);
|
|
35
|
+
border: var(--theme-border-style) var(--dark-y);
|
|
36
|
+
color: var(--on-y);
|
|
37
|
+
padding: $default-input-padding;
|
|
38
|
+
width: 100%;
|
|
39
|
+
|
|
40
|
+
&::placeholder {
|
|
41
|
+
color: var(--metadata);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&:not(:disabled):hover {
|
|
45
|
+
border: var(--theme-border-style) var(--light-background4);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
&:disabled {
|
|
49
|
+
background-color: var(--dark-y);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&:focus {
|
|
53
|
+
background: var(--light-background4);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
.#{bem.$base}.multiple-combobox {
|
|
61
|
+
>.selected-items {
|
|
62
|
+
display: flex;
|
|
63
|
+
|
|
64
|
+
/* stylelint-disable selector-max-universal -- Allow */
|
|
65
|
+
>*:not(:first-child) {
|
|
66
|
+
margin-left: $default-margin;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* stylelint-enable selector-max-universal */
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -55,7 +55,7 @@ const SelectInput = ({
|
|
|
55
55
|
style={style}
|
|
56
56
|
// {...otherProps}
|
|
57
57
|
>
|
|
58
|
-
<FormLabel
|
|
58
|
+
<FormLabel name={name}>{label}</FormLabel>
|
|
59
59
|
<select className="input" {...field} value={field.value || ''} id={name} disabled={disabled}>
|
|
60
60
|
{
|
|
61
61
|
options.map((option) => {
|
|
@@ -6,24 +6,27 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
$default-padding: 0.75em;
|
|
9
|
-
|
|
9
|
+
$default-margin: 1em;
|
|
10
10
|
|
|
11
11
|
.#{bem.$base}.select-input {
|
|
12
12
|
display: flex;
|
|
13
13
|
flex-direction: column;
|
|
14
14
|
|
|
15
|
+
.#{bem.$base}.label {
|
|
16
|
+
margin-bottom: $default-margin
|
|
17
|
+
}
|
|
15
18
|
|
|
16
19
|
.input {
|
|
17
20
|
border: var(--theme-border-style) var(--dark-y);
|
|
18
21
|
background: var(--light-y);
|
|
19
|
-
color:var(--on-y);
|
|
22
|
+
color: var(--on-y);
|
|
20
23
|
padding: $default-padding;
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
&:not(:disabled):hover {
|
|
23
26
|
border: var(--theme-border-style) var(--light-background4);
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
&:disabled {
|
|
27
30
|
background-color: var(--dark-y);
|
|
28
31
|
}
|
|
29
32
|
|
|
@@ -31,5 +34,4 @@ $default-padding: 0.75em;
|
|
|
31
34
|
background: var(--y);
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
|
-
}
|
|
35
|
-
|
|
37
|
+
}
|
package/src/ui/f/fields/index.js
CHANGED
package/src/ui/index.js
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import { useEffect, Suspense } from 'react'
|
|
5
|
+
|
|
6
|
+
import { useQueryLoader } from 'react-relay'
|
|
7
|
+
|
|
8
|
+
// Local Definitions
|
|
9
|
+
|
|
10
|
+
import { PreloadedTestData } from './common'
|
|
11
|
+
|
|
12
|
+
const testQuery = graphql`
|
|
13
|
+
query QueryLoaderHelloQuery {
|
|
14
|
+
hello
|
|
15
|
+
}
|
|
16
|
+
`
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This is the component description.
|
|
20
|
+
*/
|
|
21
|
+
const QueryLoader = () => {
|
|
22
|
+
const [queryReference, loadQuery] = useQueryLoader(testQuery)
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
loadQuery({})
|
|
26
|
+
}, [])
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Suspense fallback="loading">
|
|
30
|
+
{queryReference ? (
|
|
31
|
+
<PreloadedTestData queryReference={queryReference} query={testQuery} />
|
|
32
|
+
) : null}
|
|
33
|
+
</Suspense>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
QueryLoader.defaultProps = {
|
|
38
|
+
// someProp:false
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default QueryLoader
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @flow
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/* eslint-disable */
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
/*::
|
|
10
|
+
import type { ConcreteRequest } from 'relay-runtime';
|
|
11
|
+
export type QueryLoaderHelloQueryVariables = {||};
|
|
12
|
+
export type QueryLoaderHelloQueryResponse = {|
|
|
13
|
+
+hello: ?string
|
|
14
|
+
|};
|
|
15
|
+
export type QueryLoaderHelloQuery = {|
|
|
16
|
+
variables: QueryLoaderHelloQueryVariables,
|
|
17
|
+
response: QueryLoaderHelloQueryResponse,
|
|
18
|
+
|};
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
query QueryLoaderHelloQuery {
|
|
24
|
+
hello
|
|
25
|
+
}
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const node/*: ConcreteRequest*/ = (function(){
|
|
29
|
+
var v0 = [
|
|
30
|
+
{
|
|
31
|
+
"alias": null,
|
|
32
|
+
"args": null,
|
|
33
|
+
"kind": "ScalarField",
|
|
34
|
+
"name": "hello",
|
|
35
|
+
"storageKey": null
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
return {
|
|
39
|
+
"fragment": {
|
|
40
|
+
"argumentDefinitions": [],
|
|
41
|
+
"kind": "Fragment",
|
|
42
|
+
"metadata": null,
|
|
43
|
+
"name": "QueryLoaderHelloQuery",
|
|
44
|
+
"selections": (v0/*: any*/),
|
|
45
|
+
"type": "Query",
|
|
46
|
+
"abstractKey": null
|
|
47
|
+
},
|
|
48
|
+
"kind": "Request",
|
|
49
|
+
"operation": {
|
|
50
|
+
"argumentDefinitions": [],
|
|
51
|
+
"kind": "Operation",
|
|
52
|
+
"name": "QueryLoaderHelloQuery",
|
|
53
|
+
"selections": (v0/*: any*/)
|
|
54
|
+
},
|
|
55
|
+
"params": {
|
|
56
|
+
"cacheID": "463f9ee8a82dd6ec8dedeb28649cce74",
|
|
57
|
+
"id": null,
|
|
58
|
+
"metadata": {},
|
|
59
|
+
"name": "QueryLoaderHelloQuery",
|
|
60
|
+
"operationKind": "query",
|
|
61
|
+
"text": "query QueryLoaderHelloQuery {\n hello\n}\n"
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
})();
|
|
65
|
+
// prettier-ignore
|
|
66
|
+
(node/*: any*/).hash = 'b92d001ab0208bd484a99f77c274d5ef';
|
|
67
|
+
|
|
68
|
+
module.exports = node;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import PropTypes from 'prop-types'
|
|
5
|
+
|
|
6
|
+
import { usePreloadedQuery } from 'react-relay'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This is the component description.
|
|
10
|
+
*/
|
|
11
|
+
const PreloadedTestData = ({
|
|
12
|
+
query,
|
|
13
|
+
queryReference,
|
|
14
|
+
// ...otherProps
|
|
15
|
+
}) => {
|
|
16
|
+
const data = usePreloadedQuery(query, queryReference)
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<pre>
|
|
20
|
+
{JSON.stringify(data, null, 2)}
|
|
21
|
+
</pre>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
PreloadedTestData.propTypes = {
|
|
26
|
+
/**
|
|
27
|
+
* The query to be used to query the test data
|
|
28
|
+
*/
|
|
29
|
+
query:PropTypes.objectOf(
|
|
30
|
+
PropTypes.PropTypes.oneOfType([
|
|
31
|
+
PropTypes.string,
|
|
32
|
+
PropTypes.object,
|
|
33
|
+
]),
|
|
34
|
+
),
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The query reference to be used to access the preloaded data
|
|
38
|
+
*/
|
|
39
|
+
queryReference:PropTypes.objectOf(
|
|
40
|
+
PropTypes.PropTypes.oneOfType([
|
|
41
|
+
PropTypes.string,
|
|
42
|
+
PropTypes.object,
|
|
43
|
+
]),
|
|
44
|
+
),
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
PreloadedTestData.defaultProps = {
|
|
48
|
+
// someProp:false
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default PreloadedTestData
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PreloadedTestData } from './PreloadedTestData'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { QueryLoader } from './QueryLoader'
|