@luomus/laji-form 15.1.79 → 15.1.81
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/laji-form.js +1 -1
- package/lib/ApiClient.d.ts +1 -1
- package/lib/ApiClient.js +1 -1
- package/lib/components/fields/ImageArrayField.js +1 -1
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.d.ts +5 -0
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.js +26 -8
- package/package.json +3 -3
package/lib/ApiClient.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ type RelaxQuery<P, K extends string> = P extends {
|
|
|
18
18
|
} : {
|
|
19
19
|
query: Omit<Q, Extract<keyof Q, K>> & Partial<Pick<Q, Extract<keyof Q, K>>>;
|
|
20
20
|
}) : P;
|
|
21
|
-
type MiddlewareInjectedKeys = "collectionID" | "formID"
|
|
21
|
+
type MiddlewareInjectedKeys = "collectionID" | "formID";
|
|
22
22
|
type Parameters<T> = "parameters" extends keyof T ? T["parameters"] : never;
|
|
23
23
|
type ExtractContentIfExists<R> = R extends {
|
|
24
24
|
content: infer C;
|
package/lib/ApiClient.js
CHANGED
|
@@ -169,7 +169,7 @@ class ApiClient {
|
|
|
169
169
|
options = Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, (options.headers || {})), { "Content-Type": "application/json", "Accept": "application/json" }) });
|
|
170
170
|
body = JSON.stringify(body);
|
|
171
171
|
}
|
|
172
|
-
const response = yield this.apiClient.fetch(pathSegments.join(""),
|
|
172
|
+
const response = yield this.apiClient.fetch(pathSegments.join(""), ((params === null || params === void 0 ? void 0 : params.query) || {}), Object.assign({ method, body }, options));
|
|
173
173
|
if (response.status >= 400) {
|
|
174
174
|
const error = yield response.json();
|
|
175
175
|
throw new LajiApiError(error === null || error === void 0 ? void 0 : error.message, response.status);
|
|
@@ -464,7 +464,7 @@ function MediaArrayField(ComposedComponent) {
|
|
|
464
464
|
const metadataPromise = ("capturerVerbatim" in mediaMetadata)
|
|
465
465
|
? Promise.resolve(Object.assign(Object.assign({}, mediaMetadata), { capturerVerbatim: Array.isArray(mediaMetadata.capturerVerbatim) ? mediaMetadata.capturerVerbatim : [mediaMetadata.capturerVerbatim] }))
|
|
466
466
|
: MACode
|
|
467
|
-
? this.apiClient.get("/person/
|
|
467
|
+
? this.apiClient.get("/person/{id}", { path: { id: MACode } }).then(({ fullName = MACode }) => (Object.assign(Object.assign({ capturerVerbatim: Array.isArray(fullName) ? fullName : [fullName] }, mediaMetadata), { intellectualOwner: fullName }))).catch(() => Promise.resolve(mediaMetadata))
|
|
468
468
|
: Promise.resolve(mediaMetadata);
|
|
469
469
|
return Promise.all([exifDataPromise, metadataPromise]).then(([exifData, metadata]) => {
|
|
470
470
|
return Object.assign(Object.assign({}, exifData.defaultMediaMetadata), metadata);
|
|
@@ -12,6 +12,7 @@ export default class InputWithDefaultValueButtonWidget extends React.Component<a
|
|
|
12
12
|
resultKey: PropTypes.Validator<string>;
|
|
13
13
|
cache: PropTypes.Requireable<boolean>;
|
|
14
14
|
}>>;
|
|
15
|
+
disableButtonAfterUse: PropTypes.Requireable<boolean>;
|
|
15
16
|
onClick: PropTypes.Requireable<(...args: any[]) => any>;
|
|
16
17
|
}>>>;
|
|
17
18
|
}>>>;
|
|
@@ -21,11 +22,15 @@ export default class InputWithDefaultValueButtonWidget extends React.Component<a
|
|
|
21
22
|
value: PropTypes.Requireable<string>;
|
|
22
23
|
};
|
|
23
24
|
constructor(props: any);
|
|
25
|
+
fetching: boolean;
|
|
26
|
+
disabled: boolean;
|
|
24
27
|
state: {
|
|
25
28
|
fetching: boolean;
|
|
29
|
+
disabled: boolean;
|
|
26
30
|
};
|
|
27
31
|
render(): JSX.Element;
|
|
28
32
|
onClick: () => any;
|
|
33
|
+
changeValue: (value: any) => void;
|
|
29
34
|
}
|
|
30
35
|
import * as React from "react";
|
|
31
36
|
import * as PropTypes from "prop-types";
|
|
@@ -41,26 +41,31 @@ const PropTypes = __importStar(require("prop-types"));
|
|
|
41
41
|
const BaseInputTemplate_1 = __importDefault(require("../templates/BaseInputTemplate"));
|
|
42
42
|
const ReactContext_1 = __importDefault(require("../../ReactContext"));
|
|
43
43
|
const utils_1 = require("../../utils");
|
|
44
|
+
const react_spinner_1 = __importDefault(require("react-spinner"));
|
|
44
45
|
class InputWithDefaultValueButtonWidget extends React.Component {
|
|
45
46
|
constructor(props) {
|
|
46
47
|
super(props);
|
|
47
48
|
this.onClick = () => {
|
|
49
|
+
if (this.fetching || this.disabled) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
48
52
|
const { contextFieldForDefaultValue, apiQueryForDefaultValue, onClick } = (0, utils_1.getUiOptions)(this.props);
|
|
49
53
|
if (contextFieldForDefaultValue) {
|
|
50
54
|
const uiSchemaContext = this.props.formContext.uiSchemaContext || {};
|
|
51
55
|
const defaultValue = uiSchemaContext[contextFieldForDefaultValue];
|
|
52
|
-
this.
|
|
56
|
+
this.changeValue(defaultValue);
|
|
53
57
|
}
|
|
54
58
|
else if (apiQueryForDefaultValue) {
|
|
55
59
|
const { path, query = {}, resultKey, cache = false } = apiQueryForDefaultValue;
|
|
56
60
|
const apiClient = this.props.formContext.apiClient;
|
|
61
|
+
this.fetching = true;
|
|
57
62
|
this.setState({ fetching: true });
|
|
58
|
-
return apiClient.get(path, { query }, cache).then(result => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
this.setState({ fetching: false });
|
|
63
|
+
return apiClient.get(path, { query: Object.assign({ value: this.props.value }, query) }, cache).then(result => {
|
|
64
|
+
result = resultKey ? result === null || result === void 0 ? void 0 : result[resultKey] : result;
|
|
65
|
+
this.changeValue(result);
|
|
63
66
|
}).catch(() => {
|
|
67
|
+
}).finally(() => {
|
|
68
|
+
this.fetching = false;
|
|
64
69
|
this.setState({ fetching: false });
|
|
65
70
|
});
|
|
66
71
|
}
|
|
@@ -68,7 +73,17 @@ class InputWithDefaultValueButtonWidget extends React.Component {
|
|
|
68
73
|
onClick();
|
|
69
74
|
}
|
|
70
75
|
};
|
|
71
|
-
this.
|
|
76
|
+
this.changeValue = (value) => {
|
|
77
|
+
const { disableButtonAfterUse = false } = (0, utils_1.getUiOptions)(this.props);
|
|
78
|
+
this.props.onChange(value);
|
|
79
|
+
if (disableButtonAfterUse) {
|
|
80
|
+
this.disabled = true;
|
|
81
|
+
this.setState({ disabled: true });
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
this.fetching = false;
|
|
85
|
+
this.disabled = false;
|
|
86
|
+
this.state = { fetching: false, disabled: false };
|
|
72
87
|
}
|
|
73
88
|
render() {
|
|
74
89
|
const { InputGroup, Button } = this.context.theme;
|
|
@@ -77,7 +92,9 @@ class InputWithDefaultValueButtonWidget extends React.Component {
|
|
|
77
92
|
return (React.createElement(InputGroup, null,
|
|
78
93
|
React.createElement(BaseInputTemplate_1.default, Object.assign({}, this.props)),
|
|
79
94
|
React.createElement(InputGroup.Button, { className: "input-group-button" },
|
|
80
|
-
React.createElement(Button, { onClick: this.onClick, disabled: disabled || readonly || this.state.fetching, variant: buttonVariant },
|
|
95
|
+
React.createElement(Button, { onClick: this.onClick, disabled: disabled || readonly || this.state.fetching || this.state.disabled, variant: buttonVariant },
|
|
96
|
+
buttonLabel,
|
|
97
|
+
this.state.fetching && React.createElement(react_spinner_1.default, null)))));
|
|
81
98
|
}
|
|
82
99
|
}
|
|
83
100
|
InputWithDefaultValueButtonWidget.contextType = ReactContext_1.default;
|
|
@@ -93,6 +110,7 @@ InputWithDefaultValueButtonWidget.propTypes = {
|
|
|
93
110
|
resultKey: PropTypes.string.isRequired,
|
|
94
111
|
cache: PropTypes.bool
|
|
95
112
|
}),
|
|
113
|
+
disableButtonAfterUse: PropTypes.bool,
|
|
96
114
|
onClick: PropTypes.func
|
|
97
115
|
}).isRequired
|
|
98
116
|
}).isRequired,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luomus/laji-form",
|
|
3
|
-
"version": "15.1.
|
|
3
|
+
"version": "15.1.81",
|
|
4
4
|
"description": "React module capable of building dynamic forms from Laji form json schemas",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"test:lightweight": "npx playwright test --project chromium",
|
|
30
30
|
"test:docker:build": "docker build -t laji-form-test -f test.Dockerfile .",
|
|
31
31
|
"test:docker:run": "docker run laji-form-test",
|
|
32
|
-
"generate:api-client": "openapi-typescript https://apitest.laji.fi/
|
|
32
|
+
"generate:api-client": "openapi-typescript https://apitest.laji.fi/openapi-json -o ./generated/api.d.ts --properties-required-by-default"
|
|
33
33
|
},
|
|
34
34
|
"keywords": [
|
|
35
35
|
"react-jsonschema-form",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@luomus/laji-map": "^5.1.19",
|
|
44
|
-
"@luomus/laji-validate": "^0.0.
|
|
44
|
+
"@luomus/laji-validate": "^0.0.124",
|
|
45
45
|
"@rjsf/core": "~5.1.0",
|
|
46
46
|
"@rjsf/utils": "~5.1.0",
|
|
47
47
|
"@rjsf/validator-ajv6": "~5.1.0",
|