@scenid/react-formulator 0.5.3 → 0.5.5
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/index.cjs.js +31 -35
- package/dist/index.esm.js +31 -35
- package/package.json +4 -1
- package/.babelrc +0 -30
- package/.eslintignore +0 -22
- package/.eslintrc +0 -70
- package/.firebaserc +0 -5
- package/.storybook/main.js +0 -12
- package/.storybook/preview.js +0 -9
- package/firebase.json +0 -22
- package/functions/.eslintignore +0 -1
- package/functions/.eslintrc.js +0 -29
- package/functions/index.js +0 -32
- package/functions/package-lock.json +0 -6810
- package/functions/package.json +0 -29
- package/rollup.config.js +0 -40
- package/src/Components/HiddenData.jsx +0 -24
- package/src/Components/SelectOrCreate.jsx +0 -156
- package/src/Editable/FormAutocomplete/FormAutocomplete.jsx +0 -155
- package/src/Editable/FormAutocomplete/useFetchOptions.js +0 -83
- package/src/Editable/FormBoolean.jsx +0 -46
- package/src/Editable/FormCatalogType.jsx +0 -29
- package/src/Editable/FormField.jsx +0 -231
- package/src/Editable/FormNumber.jsx +0 -36
- package/src/Editable/FormRepeater.jsx +0 -218
- package/src/Editable/FormSelect.jsx +0 -52
- package/src/Editable/FormText.jsx +0 -20
- package/src/FormGroupHeader.jsx +0 -85
- package/src/FormHelpers.js +0 -191
- package/src/FormSectionBlock.jsx +0 -71
- package/src/FormSectionCard.jsx +0 -62
- package/src/FormulatorForm.jsx +0 -539
- package/src/FormulatorFormSection.jsx +0 -456
- package/src/ReadOnly/FormReadOnlyBoolean.jsx +0 -36
- package/src/ReadOnly/FormReadOnlyField.jsx +0 -126
- package/src/ReadOnly/FormReadOnlyMarkdown.jsx +0 -20
- package/src/ReadOnly/FormReadOnlyNumber.jsx +0 -17
- package/src/ReadOnly/FormReadOnlyRepeater.jsx +0 -52
- package/src/ReadOnly/FormReadOnlySelect.jsx +0 -18
- package/src/ReadOnly/FormReadOnlyText.jsx +0 -45
- package/src/helpers.js +0 -13
- package/src/index.js +0 -20
- package/stories/CustomRenderField.jsx +0 -46
- package/stories/Forms.stories.jsx +0 -283
- package/stories/Introduction.stories.mdx +0 -206
- package/stories/StoryBase.jsx +0 -35
- package/stories/assets/code-brackets.svg +0 -1
- package/stories/assets/colors.svg +0 -1
- package/stories/assets/comments.svg +0 -1
- package/stories/assets/direction.svg +0 -1
- package/stories/assets/flow.svg +0 -1
- package/stories/assets/plugin.svg +0 -1
- package/stories/assets/repo.svg +0 -1
- package/stories/assets/stackalt.svg +0 -1
- package/stories/forms/login.render.schema.json +0 -23
- package/stories/forms/login.validation.schema.json +0 -29
- package/stories/forms/markdown.render.schema.json +0 -30
- package/stories/forms/markdown.validation.schema.json +0 -18
- package/stories/forms/register.render.schema.json +0 -32
- package/stories/forms/register.validation.schema.json +0 -34
- package/stories/forms/rlp.render.schema.json +0 -153
- package/stories/forms/rlp.translations.json +0 -883
- package/stories/forms/rlp.validation.schema.json +0 -1631
- package/stories/forms/types.schemas.js +0 -319
package/functions/package.json
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "functions",
|
|
3
|
-
"description": "Cloud Functions for Firebase",
|
|
4
|
-
"scripts": {
|
|
5
|
-
"lint": "eslint .",
|
|
6
|
-
"serve": "firebase emulators:start --only functions",
|
|
7
|
-
"shell": "firebase functions:shell",
|
|
8
|
-
"start": "npm run shell",
|
|
9
|
-
"deploy": "firebase deploy --only functions",
|
|
10
|
-
"logs": "firebase functions:log"
|
|
11
|
-
},
|
|
12
|
-
"engines": {
|
|
13
|
-
"node": "16"
|
|
14
|
-
},
|
|
15
|
-
"main": "index.js",
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"cors": "^2.8.5",
|
|
18
|
-
"eslint-config-standard": "^17.0.0",
|
|
19
|
-
"express": "^4.18.0",
|
|
20
|
-
"firebase-admin": "^10.0.2",
|
|
21
|
-
"firebase-functions": "^3.18.0"
|
|
22
|
-
},
|
|
23
|
-
"devDependencies": {
|
|
24
|
-
"eslint": "^8.9.0",
|
|
25
|
-
"eslint-config-google": "^0.14.0",
|
|
26
|
-
"firebase-functions-test": "^0.2.0"
|
|
27
|
-
},
|
|
28
|
-
"private": true
|
|
29
|
-
}
|
package/rollup.config.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import babel from '@rollup/plugin-babel'
|
|
2
|
-
|
|
3
|
-
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
|
|
4
|
-
import resolve from '@rollup/plugin-node-resolve'
|
|
5
|
-
import commonjs from '@rollup/plugin-commonjs'
|
|
6
|
-
import css from "rollup-plugin-import-css"
|
|
7
|
-
|
|
8
|
-
import pkg from './package.json'
|
|
9
|
-
|
|
10
|
-
export default {
|
|
11
|
-
input: 'src/index.js',
|
|
12
|
-
output: [
|
|
13
|
-
{ file: pkg.main, format: 'cjs' },
|
|
14
|
-
{ file: pkg.module, format: 'esm' }
|
|
15
|
-
],
|
|
16
|
-
plugins: [
|
|
17
|
-
peerDepsExternal(),
|
|
18
|
-
babel({
|
|
19
|
-
babelHelpers: 'runtime',
|
|
20
|
-
exclude: 'node_modules/**',
|
|
21
|
-
presets: [
|
|
22
|
-
'@babel/preset-env',
|
|
23
|
-
'@babel/preset-react'
|
|
24
|
-
],
|
|
25
|
-
plugins: [
|
|
26
|
-
'@babel/plugin-proposal-export-default-from',
|
|
27
|
-
[
|
|
28
|
-
'@babel/transform-runtime',
|
|
29
|
-
{ regenerator: true }
|
|
30
|
-
]
|
|
31
|
-
]
|
|
32
|
-
}),
|
|
33
|
-
resolve({
|
|
34
|
-
extensions: ['.js', '.jsx'],
|
|
35
|
-
preferBuiltins: true
|
|
36
|
-
}),
|
|
37
|
-
commonjs(),
|
|
38
|
-
css()
|
|
39
|
-
]
|
|
40
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
|
-
|
|
4
|
-
import { Box, Typography } from '@material-ui/core'
|
|
5
|
-
import { Alert } from '@material-ui/lab'
|
|
6
|
-
|
|
7
|
-
const HiddenData = ({ subject, label }) => (
|
|
8
|
-
<Box mb={2}>
|
|
9
|
-
<Alert severity="warning">
|
|
10
|
-
<Typography variant="body1">
|
|
11
|
-
{subject ? `${subject} ` : ''}
|
|
12
|
-
<span style={{ fontWeight: 'bold' }}>{label}</span>
|
|
13
|
-
ist ausgeblendet.
|
|
14
|
-
</Typography>
|
|
15
|
-
</Alert>
|
|
16
|
-
</Box>
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
HiddenData.propTypes = {
|
|
20
|
-
subject: PropTypes.string,
|
|
21
|
-
label: PropTypes.string.isRequired
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export default HiddenData
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
|
-
|
|
4
|
-
import { TextField, InputAdornment, CircularProgress } from '@material-ui/core'
|
|
5
|
-
|
|
6
|
-
import Autocomplete, { createFilterOptions } from '@material-ui/lab/Autocomplete'
|
|
7
|
-
|
|
8
|
-
const filter = createFilterOptions()
|
|
9
|
-
|
|
10
|
-
const renderInput = (
|
|
11
|
-
{
|
|
12
|
-
required,
|
|
13
|
-
label,
|
|
14
|
-
onInputChange,
|
|
15
|
-
variant,
|
|
16
|
-
loading
|
|
17
|
-
},
|
|
18
|
-
params
|
|
19
|
-
) => {
|
|
20
|
-
let InputProps = params.InputProps || {}
|
|
21
|
-
|
|
22
|
-
if (loading) {
|
|
23
|
-
InputProps = {
|
|
24
|
-
endAdornment: (
|
|
25
|
-
<InputAdornment position="end">
|
|
26
|
-
<CircularProgress
|
|
27
|
-
size={20}
|
|
28
|
-
thickness={4}
|
|
29
|
-
/>
|
|
30
|
-
</InputAdornment>
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<TextField
|
|
37
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
38
|
-
{...params}
|
|
39
|
-
required={required}
|
|
40
|
-
label={label}
|
|
41
|
-
variant={variant}
|
|
42
|
-
onChange={onInputChange}
|
|
43
|
-
InputProps={InputProps}
|
|
44
|
-
/>
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const SelectOrCreate = ({
|
|
49
|
-
id,
|
|
50
|
-
label,
|
|
51
|
-
variant,
|
|
52
|
-
loading,
|
|
53
|
-
required,
|
|
54
|
-
disabled,
|
|
55
|
-
allowCreate,
|
|
56
|
-
options,
|
|
57
|
-
searchKey,
|
|
58
|
-
renderOption,
|
|
59
|
-
renderNewOption,
|
|
60
|
-
value,
|
|
61
|
-
onOpen,
|
|
62
|
-
onClose,
|
|
63
|
-
onChange,
|
|
64
|
-
onInputChange
|
|
65
|
-
}) => (
|
|
66
|
-
<Autocomplete
|
|
67
|
-
id={id}
|
|
68
|
-
value={value}
|
|
69
|
-
fullWidth
|
|
70
|
-
disabled={disabled}
|
|
71
|
-
onOpen={onOpen}
|
|
72
|
-
onClose={onClose}
|
|
73
|
-
onChange={(_, newValue) => {
|
|
74
|
-
if (typeof newValue === 'string') {
|
|
75
|
-
if (!allowCreate && Array.isArray(options) && !options.find(o => o.entry === newValue)) onChange(undefined)
|
|
76
|
-
else onChange({ [searchKey]: newValue })
|
|
77
|
-
} else if (allowCreate && newValue && newValue.inputValue) {
|
|
78
|
-
// Create a new value from the user input
|
|
79
|
-
onChange({ [searchKey]: newValue.inputValue })
|
|
80
|
-
} else {
|
|
81
|
-
onChange(newValue)
|
|
82
|
-
}
|
|
83
|
-
}}
|
|
84
|
-
filterOptions={(allOptions, params) => {
|
|
85
|
-
const filtered = filter(allOptions, params)
|
|
86
|
-
|
|
87
|
-
// Suggest the creation of a new value
|
|
88
|
-
if (allowCreate && params.inputValue !== '') {
|
|
89
|
-
filtered.push({
|
|
90
|
-
inputValue: params.inputValue,
|
|
91
|
-
[searchKey]: renderNewOption(params.inputValue)
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return filtered
|
|
96
|
-
}}
|
|
97
|
-
selectOnFocus
|
|
98
|
-
clearOnBlur
|
|
99
|
-
handleHomeEndKeys
|
|
100
|
-
options={options}
|
|
101
|
-
getOptionLabel={option => {
|
|
102
|
-
// Value selected with enter, right from the input
|
|
103
|
-
if (typeof option === 'string') {
|
|
104
|
-
if (!allowCreate && Array.isArray(options) && !options.find(o => o.entry === option)) return ''
|
|
105
|
-
return option
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Add "xxx" option created dynamically
|
|
109
|
-
if (option.inputValue) {
|
|
110
|
-
return option.inputValue
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Regular option
|
|
114
|
-
return option[searchKey]
|
|
115
|
-
}}
|
|
116
|
-
renderOption={renderOption}
|
|
117
|
-
freeSolo
|
|
118
|
-
renderInput={params => (
|
|
119
|
-
renderInput(
|
|
120
|
-
{
|
|
121
|
-
required,
|
|
122
|
-
disabled,
|
|
123
|
-
label,
|
|
124
|
-
onInputChange,
|
|
125
|
-
variant,
|
|
126
|
-
loading
|
|
127
|
-
},
|
|
128
|
-
params
|
|
129
|
-
)
|
|
130
|
-
)}
|
|
131
|
-
/>
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
SelectOrCreate.propTypes = {
|
|
135
|
-
id: PropTypes.string,
|
|
136
|
-
label: PropTypes.string.isRequired,
|
|
137
|
-
variant: PropTypes.string,
|
|
138
|
-
loading: PropTypes.bool,
|
|
139
|
-
required: PropTypes.bool,
|
|
140
|
-
disabled: PropTypes.bool,
|
|
141
|
-
allowCreate: PropTypes.bool,
|
|
142
|
-
options: PropTypes.array.isRequired,
|
|
143
|
-
searchKey: PropTypes.string.isRequired,
|
|
144
|
-
renderOption: PropTypes.func.isRequired,
|
|
145
|
-
renderNewOption: PropTypes.func.isRequired,
|
|
146
|
-
value: PropTypes.oneOfType([
|
|
147
|
-
PropTypes.string,
|
|
148
|
-
PropTypes.object
|
|
149
|
-
]).isRequired,
|
|
150
|
-
onOpen: PropTypes.func,
|
|
151
|
-
onClose: PropTypes.func,
|
|
152
|
-
onChange: PropTypes.func.isRequired,
|
|
153
|
-
onInputChange: PropTypes.func.isRequired
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export default SelectOrCreate
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useCallback } from 'react'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
Box,
|
|
6
|
-
Typography,
|
|
7
|
-
FormControl,
|
|
8
|
-
FormHelperText,
|
|
9
|
-
TextField,
|
|
10
|
-
InputAdornment,
|
|
11
|
-
CircularProgress
|
|
12
|
-
} from '@material-ui/core'
|
|
13
|
-
|
|
14
|
-
import FormReadOnlyText from '../../ReadOnly/FormReadOnlyText'
|
|
15
|
-
import SelectOrCreate from '../../Components/SelectOrCreate'
|
|
16
|
-
|
|
17
|
-
import useFetchOptions from './useFetchOptions'
|
|
18
|
-
|
|
19
|
-
const FormAutocomplete = ({
|
|
20
|
-
name,
|
|
21
|
-
label,
|
|
22
|
-
value,
|
|
23
|
-
options: optionsArg,
|
|
24
|
-
baererToken,
|
|
25
|
-
allowCreate,
|
|
26
|
-
dirty,
|
|
27
|
-
hasErrors,
|
|
28
|
-
errors,
|
|
29
|
-
variant,
|
|
30
|
-
required,
|
|
31
|
-
disabled,
|
|
32
|
-
readOnly,
|
|
33
|
-
onChange
|
|
34
|
-
}) => {
|
|
35
|
-
const { loading, fetch, abort, options } = useFetchOptions(optionsArg, { token: baererToken })
|
|
36
|
-
|
|
37
|
-
const changeValue = useCallback(newValue => { onChange({ target: { name, value: newValue?.entry || '' } }) }, [onChange])
|
|
38
|
-
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
if (!readOnly) {
|
|
41
|
-
fetch()
|
|
42
|
-
}
|
|
43
|
-
}, [])
|
|
44
|
-
|
|
45
|
-
if (readOnly) {
|
|
46
|
-
return <FormReadOnlyText name={name} value={value} />
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!options) {
|
|
50
|
-
return (
|
|
51
|
-
<FormControl
|
|
52
|
-
error={dirty && hasErrors}
|
|
53
|
-
margin="dense"
|
|
54
|
-
fullWidth
|
|
55
|
-
required={required}
|
|
56
|
-
>
|
|
57
|
-
<TextField
|
|
58
|
-
label={label}
|
|
59
|
-
variant={variant}
|
|
60
|
-
value={value}
|
|
61
|
-
disabled
|
|
62
|
-
InputProps={{
|
|
63
|
-
endAdornment: (
|
|
64
|
-
<InputAdornment position="end">
|
|
65
|
-
<CircularProgress
|
|
66
|
-
size={20}
|
|
67
|
-
thickness={4}
|
|
68
|
-
/>
|
|
69
|
-
</InputAdornment>
|
|
70
|
-
)
|
|
71
|
-
}}
|
|
72
|
-
/>
|
|
73
|
-
</FormControl>
|
|
74
|
-
)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
<FormControl
|
|
79
|
-
error={dirty && hasErrors}
|
|
80
|
-
margin="dense"
|
|
81
|
-
fullWidth
|
|
82
|
-
required={required}
|
|
83
|
-
>
|
|
84
|
-
<SelectOrCreate
|
|
85
|
-
loading={loading}
|
|
86
|
-
label={label}
|
|
87
|
-
variant={variant}
|
|
88
|
-
allowCreate={allowCreate}
|
|
89
|
-
options={options}
|
|
90
|
-
searchKey="entry"
|
|
91
|
-
required={required}
|
|
92
|
-
disabled={disabled}
|
|
93
|
-
renderOption={option => (
|
|
94
|
-
<Box>
|
|
95
|
-
<Typography variant="body1">
|
|
96
|
-
{option.entry}
|
|
97
|
-
</Typography>
|
|
98
|
-
{
|
|
99
|
-
(option.count !== undefined && option.count !== null)
|
|
100
|
-
&& (
|
|
101
|
-
<Typography variant="caption">
|
|
102
|
-
{`${option.count} Einträge`}
|
|
103
|
-
</Typography>
|
|
104
|
-
)
|
|
105
|
-
}
|
|
106
|
-
</Box>
|
|
107
|
-
)}
|
|
108
|
-
renderNewOption={newValue => (
|
|
109
|
-
<Typography variant="body1">
|
|
110
|
-
<strong>{`"${newValue}" `}</strong>
|
|
111
|
-
erstellen
|
|
112
|
-
</Typography>
|
|
113
|
-
)}
|
|
114
|
-
value={value}
|
|
115
|
-
onOpen={() => {
|
|
116
|
-
changeValue({ entry: value })
|
|
117
|
-
fetch()
|
|
118
|
-
}}
|
|
119
|
-
onClose={abort}
|
|
120
|
-
onChange={changeValue}
|
|
121
|
-
/>
|
|
122
|
-
{
|
|
123
|
-
(dirty && !disabled && hasErrors)
|
|
124
|
-
&& (
|
|
125
|
-
<FormHelperText>
|
|
126
|
-
{errors.map(e => e.message).join('. ')}
|
|
127
|
-
</FormHelperText>
|
|
128
|
-
)
|
|
129
|
-
}
|
|
130
|
-
</FormControl>
|
|
131
|
-
)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
FormAutocomplete.propTypes = {
|
|
135
|
-
name: PropTypes.string,
|
|
136
|
-
label: PropTypes.string,
|
|
137
|
-
value: PropTypes.any,
|
|
138
|
-
options: PropTypes.oneOfType([
|
|
139
|
-
PropTypes.array,
|
|
140
|
-
PropTypes.string,
|
|
141
|
-
PropTypes.func
|
|
142
|
-
]).isRequired,
|
|
143
|
-
baererToken: PropTypes.string,
|
|
144
|
-
allowCreate: PropTypes.bool,
|
|
145
|
-
variant: PropTypes.oneOf(['standard', 'filled', 'outlined']),
|
|
146
|
-
required: PropTypes.bool,
|
|
147
|
-
disabled: PropTypes.bool,
|
|
148
|
-
readOnly: PropTypes.bool,
|
|
149
|
-
dirty: PropTypes.bool,
|
|
150
|
-
hasErrors: PropTypes.bool,
|
|
151
|
-
errors: PropTypes.array,
|
|
152
|
-
onChange: PropTypes.func
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export default FormAutocomplete
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { useCallback, useRef, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
const abortableOAuthFetch = async (url, { token, signal }) => {
|
|
4
|
-
let r, text, result
|
|
5
|
-
try {
|
|
6
|
-
const options = {
|
|
7
|
-
method: 'GET'
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (token) {
|
|
11
|
-
options.headers = {
|
|
12
|
-
'Content-Type': 'application/json',
|
|
13
|
-
Authorization: `Bearer ${token}`
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (signal) {
|
|
18
|
-
options.signal = signal
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
r = await fetch(url, options)
|
|
22
|
-
|
|
23
|
-
text = await r.text()
|
|
24
|
-
result = JSON.parse(text)
|
|
25
|
-
} catch (e) {
|
|
26
|
-
throw new Error(text)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (!r.ok) throw new Error(result.error)
|
|
30
|
-
|
|
31
|
-
return result
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const useFetchOptions = (arg, fetchOptions = {}) => {
|
|
35
|
-
const controller = useRef()
|
|
36
|
-
|
|
37
|
-
const [loading, setLoading] = useState(false)
|
|
38
|
-
const [options, setOptions] = useState()
|
|
39
|
-
|
|
40
|
-
const fetch = useCallback(async () => {
|
|
41
|
-
if (Array.isArray(arg)) return setOptions(arg)
|
|
42
|
-
if (typeof arg !== 'string' && typeof arg !== 'function') return setOptions([])
|
|
43
|
-
|
|
44
|
-
let fetcher = arg
|
|
45
|
-
if (typeof arg === 'string') {
|
|
46
|
-
fetcher = signal => abortableOAuthFetch(arg, { token: fetchOptions.token, signal })
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
controller.current = new AbortController()
|
|
50
|
-
setLoading(true)
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
const r = await fetcher(controller.current.signal)
|
|
54
|
-
controller.current = undefined
|
|
55
|
-
|
|
56
|
-
if (!Array.isArray(r)) throw new Error('autocomplete fetcher returned a non array value')
|
|
57
|
-
|
|
58
|
-
setOptions(r)
|
|
59
|
-
} catch (e) {
|
|
60
|
-
setLoading(false)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
setLoading(false)
|
|
64
|
-
}, [arg, controller.current, setLoading, setOptions])
|
|
65
|
-
|
|
66
|
-
const abort = useCallback(() => {
|
|
67
|
-
if (loading) setLoading(false)
|
|
68
|
-
|
|
69
|
-
if (controller.current) {
|
|
70
|
-
controller.current.abort()
|
|
71
|
-
controller.current = undefined
|
|
72
|
-
}
|
|
73
|
-
}, [loading, setLoading, controller.current])
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
loading,
|
|
77
|
-
fetch,
|
|
78
|
-
abort,
|
|
79
|
-
options
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export default useFetchOptions
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
|
-
|
|
4
|
-
import { Checkbox, Switch } from '@material-ui/core'
|
|
5
|
-
|
|
6
|
-
const isBoolean = val => val === false || val === true
|
|
7
|
-
const isChecked = (value, defaultValue) => (isBoolean(value) ? value : (defaultValue || false))
|
|
8
|
-
|
|
9
|
-
const FormBoolean = ({ variant, name, value, defaultValue, needsToBeTrue, onChange }) => {
|
|
10
|
-
const handleChange = e => {
|
|
11
|
-
let newValue = e.target.checked
|
|
12
|
-
if (needsToBeTrue === true && newValue === false) newValue = undefined
|
|
13
|
-
onChange({ target: { name, value: newValue } })
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (variant === 'checkbox') {
|
|
17
|
-
return (
|
|
18
|
-
<Checkbox
|
|
19
|
-
color="primary"
|
|
20
|
-
name={name}
|
|
21
|
-
checked={isChecked(value, defaultValue)}
|
|
22
|
-
onChange={handleChange}
|
|
23
|
-
/>
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<Switch
|
|
29
|
-
color="primary"
|
|
30
|
-
name={name}
|
|
31
|
-
checked={isChecked(value, defaultValue)}
|
|
32
|
-
onChange={handleChange}
|
|
33
|
-
/>
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
FormBoolean.propTypes = {
|
|
38
|
-
variant: PropTypes.string,
|
|
39
|
-
name: PropTypes.string.isRequired,
|
|
40
|
-
value: PropTypes.bool,
|
|
41
|
-
defaultValue: PropTypes.bool,
|
|
42
|
-
needsToBeTrue: PropTypes.bool,
|
|
43
|
-
onChange: PropTypes.func.isRequired
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export default FormBoolean
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
|
-
|
|
4
|
-
import FormAutocomplete from './FormAutocomplete/FormAutocomplete'
|
|
5
|
-
import FormSelect from './FormSelect'
|
|
6
|
-
|
|
7
|
-
const FormCatalogType = ({ type, options, autocomplete, ...props }) => {
|
|
8
|
-
if (autocomplete === true) {
|
|
9
|
-
return (
|
|
10
|
-
<FormAutocomplete
|
|
11
|
-
type="autocomplete"
|
|
12
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
13
|
-
{...props}
|
|
14
|
-
options={options.map(entry => ({ entry: entry.value }))}
|
|
15
|
-
/>
|
|
16
|
-
)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
20
|
-
return <FormSelect type={type} options={options} {...props} />
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
FormCatalogType.propTypes = {
|
|
24
|
-
type: PropTypes.string.isRequired,
|
|
25
|
-
options: PropTypes.array.isRequired,
|
|
26
|
-
autocomplete: PropTypes.bool
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export default FormCatalogType
|