@luomus/laji-form 15.1.5 → 15.1.7
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/lib/ApiClient.d.ts +46 -0
- package/lib/ApiClient.js +93 -0
- package/lib/Context.d.ts +8 -0
- package/lib/Context.js +18 -0
- package/lib/ReactContext.d.ts +7 -0
- package/lib/ReactContext.js +5 -0
- package/lib/components/BaseComponent.d.ts +9 -0
- package/lib/components/BaseComponent.js +29 -0
- package/lib/components/LajiForm.d.ts +221 -0
- package/lib/components/LajiForm.js +616 -0
- package/lib/components/VirtualSchemaField.d.ts +42 -0
- package/lib/components/VirtualSchemaField.js +74 -0
- package/lib/components/components.d.ts +119 -0
- package/lib/components/components.js +606 -0
- package/lib/components/fields/AnnotationField.d.ts +34 -0
- package/lib/components/fields/AnnotationField.js +242 -0
- package/lib/components/fields/AnyToBooleanField.d.ts +18 -0
- package/lib/components/fields/AnyToBooleanField.js +20 -0
- package/lib/components/fields/ArrayBulkField.d.ts +23 -0
- package/lib/components/fields/ArrayBulkField.js +82 -0
- package/lib/components/fields/ArrayCombinerField.d.ts +36 -0
- package/lib/components/fields/ArrayCombinerField.js +138 -0
- package/lib/components/fields/ArrayField.d.ts +39 -0
- package/lib/components/fields/ArrayField.js +148 -0
- package/lib/components/fields/AsArrayField.d.ts +292 -0
- package/lib/components/fields/AsArrayField.js +38 -0
- package/lib/components/fields/AudioArrayField.d.ts +22 -0
- package/lib/components/fields/AudioArrayField.js +100 -0
- package/lib/components/fields/AutoArrayField.d.ts +24 -0
- package/lib/components/fields/AutoArrayField.js +56 -0
- package/lib/components/fields/AutosuggestField.d.ts +69 -0
- package/lib/components/fields/AutosuggestField.js +299 -0
- package/lib/components/fields/CombinedValueDisplayField.d.ts +41 -0
- package/lib/components/fields/CombinedValueDisplayField.js +100 -0
- package/lib/components/fields/ConditionalOnChangeField.d.ts +42 -0
- package/lib/components/fields/ConditionalOnChangeField.js +107 -0
- package/lib/components/fields/ConditionalUiSchemaField.d.ts +123 -0
- package/lib/components/fields/ConditionalUiSchemaField.js +143 -0
- package/lib/components/fields/ContextInjectionField.d.ts +24 -0
- package/lib/components/fields/ContextInjectionField.js +68 -0
- package/lib/components/fields/DataLeakerField.d.ts +40 -0
- package/lib/components/fields/DataLeakerField.js +68 -0
- package/lib/components/fields/DefaultValueArrayField.d.ts +34 -0
- package/lib/components/fields/DefaultValueArrayField.js +59 -0
- package/lib/components/fields/DependentBooleanField.d.ts +38 -0
- package/lib/components/fields/DependentBooleanField.js +87 -0
- package/lib/components/fields/DependentDisableField.d.ts +35 -0
- package/lib/components/fields/DependentDisableField.js +71 -0
- package/lib/components/fields/EnumRangeArrayField.d.ts +27 -0
- package/lib/components/fields/EnumRangeArrayField.js +115 -0
- package/lib/components/fields/ExtraLabelRowField.d.ts +38 -0
- package/lib/components/fields/ExtraLabelRowField.js +100 -0
- package/lib/components/fields/FakePropertyField.d.ts +18 -0
- package/lib/components/fields/FakePropertyField.js +48 -0
- package/lib/components/fields/FilterArrayField.d.ts +73 -0
- package/lib/components/fields/FilterArrayField.js +121 -0
- package/lib/components/fields/FlatField.d.ts +29 -0
- package/lib/components/fields/FlatField.js +171 -0
- package/lib/components/fields/GeocoderField.d.ts +47 -0
- package/lib/components/fields/GeocoderField.js +372 -0
- package/lib/components/fields/GridLayoutField.d.ts +18 -0
- package/lib/components/fields/GridLayoutField.js +32 -0
- package/lib/components/fields/HiddenField.d.ts +10 -0
- package/lib/components/fields/HiddenField.js +11 -0
- package/lib/components/fields/ImageArrayField.d.ts +172 -0
- package/lib/components/fields/ImageArrayField.js +699 -0
- package/lib/components/fields/ImageDisplayField.d.ts +18 -0
- package/lib/components/fields/ImageDisplayField.js +44 -0
- package/lib/components/fields/InitiallyHiddenField.d.ts +21 -0
- package/lib/components/fields/InitiallyHiddenField.js +58 -0
- package/lib/components/fields/InjectDefaultValueField.d.ts +37 -0
- package/lib/components/fields/InjectDefaultValueField.js +68 -0
- package/lib/components/fields/InjectField.d.ts +46 -0
- package/lib/components/fields/InjectField.js +88 -0
- package/lib/components/fields/InputWithDefaultValueButtonField.d.ts +25 -0
- package/lib/components/fields/InputWithDefaultValueButtonField.js +61 -0
- package/lib/components/fields/LocalityField.d.ts +22 -0
- package/lib/components/fields/LocalityField.js +94 -0
- package/lib/components/fields/LocationChooserField.d.ts +27 -0
- package/lib/components/fields/LocationChooserField.js +440 -0
- package/lib/components/fields/MapArrayField.d.ts +78 -0
- package/lib/components/fields/MapArrayField.js +1783 -0
- package/lib/components/fields/MapField.d.ts +48 -0
- package/lib/components/fields/MapField.js +434 -0
- package/lib/components/fields/MultiAnyToBooleanField.d.ts +25 -0
- package/lib/components/fields/MultiAnyToBooleanField.js +100 -0
- package/lib/components/fields/MultiArrayField.d.ts +53 -0
- package/lib/components/fields/MultiArrayField.js +224 -0
- package/lib/components/fields/MultiLanguageField.d.ts +13 -0
- package/lib/components/fields/MultiLanguageField.js +52 -0
- package/lib/components/fields/MultiTagArrayField.d.ts +36 -0
- package/lib/components/fields/MultiTagArrayField.js +142 -0
- package/lib/components/fields/NamedPlaceChooserField.d.ts +29 -0
- package/lib/components/fields/NamedPlaceChooserField.js +380 -0
- package/lib/components/fields/NamedPlaceSaverField.d.ts +29 -0
- package/lib/components/fields/NamedPlaceSaverField.js +237 -0
- package/lib/components/fields/NestField.d.ts +148 -0
- package/lib/components/fields/NestField.js +289 -0
- package/lib/components/fields/ObjectField.d.ts +2 -0
- package/lib/components/fields/ObjectField.js +119 -0
- package/lib/components/fields/PdfArrayField.d.ts +21 -0
- package/lib/components/fields/PdfArrayField.js +40 -0
- package/lib/components/fields/PrefillingArrayField.d.ts +22 -0
- package/lib/components/fields/PrefillingArrayField.js +65 -0
- package/lib/components/fields/SchemaField.d.ts +7 -0
- package/lib/components/fields/SchemaField.js +109 -0
- package/lib/components/fields/ScopeField.d.ts +85 -0
- package/lib/components/fields/ScopeField.js +521 -0
- package/lib/components/fields/SectionArrayField.d.ts +38 -0
- package/lib/components/fields/SectionArrayField.js +618 -0
- package/lib/components/fields/SelectTreeField.d.ts +39 -0
- package/lib/components/fields/SelectTreeField.js +143 -0
- package/lib/components/fields/SingleActiveArrayField.d.ts +49 -0
- package/lib/components/fields/SingleActiveArrayField.js +974 -0
- package/lib/components/fields/SingleItemArrayField.d.ts +15 -0
- package/lib/components/fields/SingleItemArrayField.js +60 -0
- package/lib/components/fields/SortArrayField.d.ts +73 -0
- package/lib/components/fields/SortArrayField.js +351 -0
- package/lib/components/fields/SplitField.d.ts +28 -0
- package/lib/components/fields/SplitField.js +65 -0
- package/lib/components/fields/StringToArrayField.d.ts +24 -0
- package/lib/components/fields/StringToArrayField.js +48 -0
- package/lib/components/fields/SumField.d.ts +35 -0
- package/lib/components/fields/SumField.js +83 -0
- package/lib/components/fields/TableField.d.ts +18 -0
- package/lib/components/fields/TableField.js +136 -0
- package/lib/components/fields/TagArrayField.d.ts +38 -0
- package/lib/components/fields/TagArrayField.js +128 -0
- package/lib/components/fields/ToggleAdditionalArrayFieldsField.d.ts +26 -0
- package/lib/components/fields/ToggleAdditionalArrayFieldsField.js +81 -0
- package/lib/components/fields/UiFieldApplierField.d.ts +30 -0
- package/lib/components/fields/UiFieldApplierField.js +106 -0
- package/lib/components/fields/UiFieldMapperArrayField.d.ts +42 -0
- package/lib/components/fields/UiFieldMapperArrayField.js +121 -0
- package/lib/components/fields/UnitCountShorthandField.d.ts +22 -0
- package/lib/components/fields/UnitCountShorthandField.js +149 -0
- package/lib/components/fields/UnitListShorthandArrayField.d.ts +26 -0
- package/lib/components/fields/UnitListShorthandArrayField.js +108 -0
- package/lib/components/fields/UnitShorthandField.d.ts +32 -0
- package/lib/components/fields/UnitShorthandField.js +220 -0
- package/lib/components/templates/ArrayFieldTemplate.d.ts +85 -0
- package/lib/components/templates/ArrayFieldTemplate.js +416 -0
- package/lib/components/templates/BaseInputTemplate.d.ts +11 -0
- package/lib/components/templates/BaseInputTemplate.js +80 -0
- package/lib/components/templates/DescriptionField.d.ts +1 -0
- package/lib/components/templates/DescriptionField.js +37 -0
- package/lib/components/templates/ErrorListTemplate.d.ts +9 -0
- package/lib/components/templates/ErrorListTemplate.js +95 -0
- package/lib/components/templates/FieldTemplate.d.ts +6 -0
- package/lib/components/templates/FieldTemplate.js +112 -0
- package/lib/components/templates/ObjectFieldTemplate.d.ts +7 -0
- package/lib/components/templates/ObjectFieldTemplate.js +66 -0
- package/lib/components/templates/TitleField.d.ts +9 -0
- package/lib/components/templates/TitleField.js +51 -0
- package/lib/components/widgets/AnyToBooleanWidget.d.ts +20 -0
- package/lib/components/widgets/AnyToBooleanWidget.js +49 -0
- package/lib/components/widgets/AutosuggestWidget.d.ts +66 -0
- package/lib/components/widgets/AutosuggestWidget.js +1127 -0
- package/lib/components/widgets/CheckboxWidget.d.ts +37 -0
- package/lib/components/widgets/CheckboxWidget.js +139 -0
- package/lib/components/widgets/DateTimeWidget.d.ts +62 -0
- package/lib/components/widgets/DateTimeWidget.js +251 -0
- package/lib/components/widgets/DateWidget.d.ts +23 -0
- package/lib/components/widgets/DateWidget.js +41 -0
- package/lib/components/widgets/HiddenWidget.d.ts +15 -0
- package/lib/components/widgets/HiddenWidget.js +19 -0
- package/lib/components/widgets/ImageSelectWidget.d.ts +14 -0
- package/lib/components/widgets/ImageSelectWidget.js +57 -0
- package/lib/components/widgets/InformalTaxonGroupChooserWidget.d.ts +43 -0
- package/lib/components/widgets/InformalTaxonGroupChooserWidget.js +237 -0
- package/lib/components/widgets/InputGroupWidget.d.ts +21 -0
- package/lib/components/widgets/InputGroupWidget.js +36 -0
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.d.ts +21 -0
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.js +47 -0
- package/lib/components/widgets/NumberWidget.d.ts +13 -0
- package/lib/components/widgets/NumberWidget.js +21 -0
- package/lib/components/widgets/PlainTextWidget.d.ts +12 -0
- package/lib/components/widgets/PlainTextWidget.js +24 -0
- package/lib/components/widgets/SelectWidget.d.ts +52 -0
- package/lib/components/widgets/SelectWidget.js +158 -0
- package/lib/components/widgets/SeparatedDateTimeWidget.d.ts +19 -0
- package/lib/components/widgets/SeparatedDateTimeWidget.js +59 -0
- package/lib/components/widgets/TaxonImageWidget.d.ts +13 -0
- package/lib/components/widgets/TaxonImageWidget.js +30 -0
- package/lib/components/widgets/TextSelectWidget.d.ts +25 -0
- package/lib/components/widgets/TextSelectWidget.js +94 -0
- package/lib/components/widgets/TextareaWidget.d.ts +32 -0
- package/lib/components/widgets/TextareaWidget.js +87 -0
- package/lib/components/widgets/TimeWidget.d.ts +11 -0
- package/lib/components/widgets/TimeWidget.js +19 -0
- package/lib/components/widgets/URLWidget.d.ts +14 -0
- package/lib/components/widgets/URLWidget.js +12 -0
- package/lib/components/widgets/UpperCaseWidget.d.ts +13 -0
- package/lib/components/widgets/UpperCaseWidget.js +21 -0
- package/lib/index.d.ts +20 -0
- package/lib/index.js +50 -0
- package/lib/services/blocker-service.d.ts +11 -0
- package/lib/services/blocker-service.js +55 -0
- package/lib/services/custom-event-service.d.ts +17 -0
- package/lib/services/custom-event-service.js +35 -0
- package/lib/services/dom-id-service.d.ts +8 -0
- package/lib/services/dom-id-service.js +30 -0
- package/lib/services/focus-service.d.ts +13 -0
- package/lib/services/focus-service.js +60 -0
- package/lib/services/id-service.d.ts +22 -0
- package/lib/services/id-service.js +130 -0
- package/lib/services/key-handler-service.d.ts +56 -0
- package/lib/services/key-handler-service.js +184 -0
- package/lib/services/root-instance-service.d.ts +25 -0
- package/lib/services/root-instance-service.js +49 -0
- package/lib/services/settings-service.d.ts +34 -0
- package/lib/services/settings-service.js +154 -0
- package/lib/services/singleton-map-service.d.ts +23 -0
- package/lib/services/singleton-map-service.js +44 -0
- package/lib/services/submit-hook-service.d.ts +24 -0
- package/lib/services/submit-hook-service.js +73 -0
- package/lib/styles.d.ts +1 -0
- package/lib/styles.js +4 -0
- package/lib/themes/bs3.d.ts +3 -0
- package/lib/themes/bs3.js +133 -0
- package/lib/themes/bs5.d.ts +3 -0
- package/lib/themes/bs5.js +111 -0
- package/lib/themes/glyphicon-fa-mapping.d.ts +3 -0
- package/lib/themes/glyphicon-fa-mapping.js +271 -0
- package/lib/themes/stub.d.ts +3 -0
- package/lib/themes/stub.js +82 -0
- package/lib/themes/theme.d.ts +233 -0
- package/lib/themes/theme.js +2 -0
- package/lib/translations.json +847 -0
- package/lib/utils.d.ts +167 -0
- package/lib/utils.js +1185 -0
- package/lib/validation.d.ts +7 -0
- package/lib/validation.js +141 -0
- package/package.json +2 -2
- package/test-export/test-utils.d.ts +3 -2
- package/test-export/test-utils.js +14 -13
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const React = require("react");
|
|
10
|
+
const PropTypes = require("prop-types");
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
|
+
const LajiForm_1 = require("../LajiForm");
|
|
13
|
+
const BaseComponent_1 = require("../BaseComponent");
|
|
14
|
+
const Context_1 = require("../../Context");
|
|
15
|
+
const ReactContext_1 = require("../../ReactContext");
|
|
16
|
+
const components_1 = require("../components");
|
|
17
|
+
const Spinner = require("react-spinner");
|
|
18
|
+
const utils_2 = require("@luomus/laji-map/lib/utils");
|
|
19
|
+
let AnnotationField = class AnnotationField extends React.Component {
|
|
20
|
+
constructor(props) {
|
|
21
|
+
super(props);
|
|
22
|
+
this.getButton = () => {
|
|
23
|
+
const annotations = this.getAnnotations();
|
|
24
|
+
return {
|
|
25
|
+
glyph: "comment",
|
|
26
|
+
tooltip: this.props.formContext.translations.ShowAnnotations,
|
|
27
|
+
tooltipPlacement: "left",
|
|
28
|
+
fn: this.onClick,
|
|
29
|
+
variant: annotations && annotations.length ? "primary" : "default"
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
this.onClick = () => () => {
|
|
33
|
+
this.setState({ show: !this.state.show });
|
|
34
|
+
};
|
|
35
|
+
this.onHide = () => {
|
|
36
|
+
this.setState({ show: false });
|
|
37
|
+
};
|
|
38
|
+
this.getAnnotations = () => {
|
|
39
|
+
const { annotations = {} } = this.props.formContext.uiSchemaContext;
|
|
40
|
+
const { id } = this.props.formData;
|
|
41
|
+
return Context_1.default(`${this.props.formContext.contextId}_ANNOTATIONS`)[id] || annotations[id];
|
|
42
|
+
};
|
|
43
|
+
this.state = { show: false };
|
|
44
|
+
}
|
|
45
|
+
render() {
|
|
46
|
+
const { adminOnly, container, add, filter, uiSchema: annotationUiSchema, buttonsPath = "/", formId } = utils_1.getUiOptions(this.props.uiSchema);
|
|
47
|
+
const innerUiSchema = utils_1.getInnerUiSchema(this.props.uiSchema);
|
|
48
|
+
let uiSchema = adminOnly && !this.props.formContext.uiSchemaContext.isAdmin
|
|
49
|
+
|| !this.props.formContext.uiSchemaContext.isEdit
|
|
50
|
+
|| !this.props.formData.id
|
|
51
|
+
? innerUiSchema
|
|
52
|
+
: utils_1.injectButtons(innerUiSchema, [this.getButton()], buttonsPath);
|
|
53
|
+
let Container = undefined;
|
|
54
|
+
const { Modal } = this.context.theme;
|
|
55
|
+
switch (container) {
|
|
56
|
+
case "modal":
|
|
57
|
+
Container = ({ children }) => {
|
|
58
|
+
return (React.createElement(Modal, { show: true, dialogClassName: "laji-form", onHide: this.onHide },
|
|
59
|
+
React.createElement(Modal.Header, { closeButton: true }),
|
|
60
|
+
React.createElement(Modal.Body, null, children)));
|
|
61
|
+
};
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
Container = ({ children }) => React.createElement("div", null, children);
|
|
65
|
+
}
|
|
66
|
+
const { SchemaField } = this.props.registry.fields;
|
|
67
|
+
return (React.createElement("div", null,
|
|
68
|
+
React.createElement(SchemaField, Object.assign({}, this.props, { uiSchema: uiSchema })),
|
|
69
|
+
(this.props.formData.id && (container !== "modal" || this.state.show)) &&
|
|
70
|
+
React.createElement(Container, null,
|
|
71
|
+
React.createElement(AnnotationBox, { id: this.props.formData.id, annotations: this.getAnnotations(), lang: this.props.formContext.lang, formContext: this.props.formContext, add: add, uiSchema: annotationUiSchema, filter: filter, formId: formId }))));
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
AnnotationField.contextType = ReactContext_1.default;
|
|
75
|
+
AnnotationField.propTypes = {
|
|
76
|
+
uiSchema: PropTypes.shape({
|
|
77
|
+
"ui:options": PropTypes.shape({
|
|
78
|
+
adminOnly: PropTypes.bool,
|
|
79
|
+
container: PropTypes.oneOf(["modal"]),
|
|
80
|
+
add: PropTypes.object,
|
|
81
|
+
filter: PropTypes.object,
|
|
82
|
+
uiSchema: PropTypes.object,
|
|
83
|
+
buttonsPath: PropTypes.string,
|
|
84
|
+
formId: PropTypes.string
|
|
85
|
+
}),
|
|
86
|
+
uiSchema: PropTypes.object
|
|
87
|
+
}).isRequired,
|
|
88
|
+
schema: PropTypes.shape({
|
|
89
|
+
type: PropTypes.oneOf(["object"])
|
|
90
|
+
}).isRequired,
|
|
91
|
+
formData: PropTypes.object.isRequired
|
|
92
|
+
};
|
|
93
|
+
AnnotationField = __decorate([
|
|
94
|
+
BaseComponent_1.default
|
|
95
|
+
], AnnotationField);
|
|
96
|
+
exports.default = AnnotationField;
|
|
97
|
+
Context_1.default("SCHEMA_FIELD_WRAPPERS").AnnotationField = true;
|
|
98
|
+
class AnnotationBox extends React.Component {
|
|
99
|
+
constructor(props) {
|
|
100
|
+
super(props);
|
|
101
|
+
this.onAnnotationSubmit = ({ formData }) => {
|
|
102
|
+
const { type } = this.getAddOptions();
|
|
103
|
+
const rootID = this.props.formContext.services.rootInstance.getFormData().id;
|
|
104
|
+
this.props.formContext.services.blocker.push();
|
|
105
|
+
this.props.formContext.apiClient.fetchRaw("/annotations", undefined, {
|
|
106
|
+
method: "POST",
|
|
107
|
+
body: JSON.stringify(Object.assign(Object.assign({}, formData), { targetID: this.props.id, rootID, type, byRole: "MMAN.formAdmin" }))
|
|
108
|
+
}).then(response => {
|
|
109
|
+
if (response.status >= 400) {
|
|
110
|
+
throw new Error("Request failed");
|
|
111
|
+
}
|
|
112
|
+
return response.json();
|
|
113
|
+
}).then(annotation => {
|
|
114
|
+
this.props.formContext.services.blocker.pop();
|
|
115
|
+
const annotationContext = Context_1.default(`${this.props.formContext.contextId}_ANNOTATIONS`);
|
|
116
|
+
const annotations = [annotation];
|
|
117
|
+
annotationContext[this.props.id] = annotations;
|
|
118
|
+
this.setState({ annotations: annotations, fail: false });
|
|
119
|
+
}).catch(() => {
|
|
120
|
+
this.props.formContext.services.blocker.pop();
|
|
121
|
+
this.setState({ fail: true });
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
this.onAnnotationChange = (formData) => {
|
|
125
|
+
let state = {};
|
|
126
|
+
if (this.state.fail !== undefined) {
|
|
127
|
+
state.fail = undefined;
|
|
128
|
+
}
|
|
129
|
+
const { submitOnChange } = this.getAddOptions();
|
|
130
|
+
if (submitOnChange) {
|
|
131
|
+
this.onAnnotationSubmit({ formData });
|
|
132
|
+
}
|
|
133
|
+
state.addFormData = formData;
|
|
134
|
+
this.setState(state);
|
|
135
|
+
};
|
|
136
|
+
this.getAddOptions = () => {
|
|
137
|
+
const { add, formContext: { uiSchemaContext: { isAdmin } } } = this.props;
|
|
138
|
+
let addOptions = utils_2.isObject(add) ? add : {};
|
|
139
|
+
const submitOnChange = "submitOnChange" in addOptions ? addOptions.submitOnChange : false;
|
|
140
|
+
const type = isAdmin ? "MAN.typeAdmin" : addOptions.type;
|
|
141
|
+
return Object.assign(Object.assign({}, addOptions), { submitOnChange, type });
|
|
142
|
+
};
|
|
143
|
+
this.renderAdd = () => {
|
|
144
|
+
const { formContext, add } = this.props;
|
|
145
|
+
const { lang, translations } = formContext;
|
|
146
|
+
const { metadataForm } = this.state;
|
|
147
|
+
const { Alert } = this.context.theme;
|
|
148
|
+
if (!metadataForm) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
const _uiSchema = this.getUiSchema();
|
|
152
|
+
let addSchema = undefined;
|
|
153
|
+
let addUiSchema = undefined;
|
|
154
|
+
let submitOnChange = undefined;
|
|
155
|
+
let addFormData = undefined;
|
|
156
|
+
if (add && metadataForm && metadataForm.schema) {
|
|
157
|
+
const { adminOnly, filter: _filter, uiSchema: _addUiSchema, _submitOnChange, formData } = this.getAddOptions();
|
|
158
|
+
if (adminOnly && !formContext.uiSchemaContext.isAdmin) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
let propArray = Object.keys(metadataForm.schema.properties);
|
|
162
|
+
propArray = utils_1.filter(propArray, ["created", "annotationByPerson"], "blacklist");
|
|
163
|
+
if (_filter)
|
|
164
|
+
propArray = utils_1.filter(propArray, _filter.filter, _filter.filterType);
|
|
165
|
+
const addSchemaProperties = propArray.reduce((properties, prop) => {
|
|
166
|
+
properties[prop] = metadataForm.schema.properties[prop];
|
|
167
|
+
return properties;
|
|
168
|
+
}, {});
|
|
169
|
+
addSchema = Object.assign(Object.assign({}, metadataForm.schema), { properties: addSchemaProperties });
|
|
170
|
+
addUiSchema = _addUiSchema || Object.assign(Object.assign({}, _uiSchema), { "ui:readonly": false });
|
|
171
|
+
submitOnChange = _submitOnChange;
|
|
172
|
+
addFormData = this.state.addFormData || (formData
|
|
173
|
+
? utils_1.getDefaultFormState(addSchema, formData)
|
|
174
|
+
: undefined);
|
|
175
|
+
}
|
|
176
|
+
const renderSubmit = !submitOnChange;
|
|
177
|
+
return add && addSchema ? (React.createElement(LajiForm_1.default, Object.assign({}, metadataForm, { schema: addSchema, uiSchema: addUiSchema || _uiSchema, onSubmit: this.onAnnotationSubmit, onChange: this.onAnnotationChange, renderSubmit: renderSubmit, formData: addFormData, lang: lang, apiClient: this.props.formContext.apiClient.apiClient, uiSchemaContext: this.props.formContext.uiSchemaContext }), React.createElement("div", null,
|
|
178
|
+
this.state.fail !== undefined &&
|
|
179
|
+
React.createElement(Alert, { variant: this.state.fail ? "danger" : "success" }, translations[this.state.fail ? "SaveFail" : "SaveSuccess"]),
|
|
180
|
+
renderSubmit && React.createElement(components_1.Button, { id: "submit", type: "submit" }, translations.Submit)))) : null;
|
|
181
|
+
};
|
|
182
|
+
this.getUiSchema = () => {
|
|
183
|
+
const { uiSchema } = this.props;
|
|
184
|
+
const { metadataForm = {} } = this.state;
|
|
185
|
+
return uiSchema || Object.assign(Object.assign({}, metadataForm.uiSchema), { "ui:shortcuts": Object.assign(Object.assign({}, ((metadataForm.uiSchema || {})["ui:shorcuts"] || {})), (this.props.formContext.services.keyHandler.shortcuts)), "ui:showShortcutsButton": false });
|
|
186
|
+
};
|
|
187
|
+
this.onDelete = (id) => () => {
|
|
188
|
+
this.props.formContext.apiClient.fetchRaw(`/annotations/${id}`, undefined, {
|
|
189
|
+
method: "DELETE"
|
|
190
|
+
}).then(() => {
|
|
191
|
+
const annotationContext = Context_1.default(`${this.props.formContext.contextId}_ANNOTATIONS`);
|
|
192
|
+
const annotations = this.state.annotations.filter(({ id: _id }) => _id !== id);
|
|
193
|
+
annotationContext[this.props.id] = annotations;
|
|
194
|
+
this.setState({ deleteFail: false, annotations });
|
|
195
|
+
}).catch(() => {
|
|
196
|
+
this.setState({ deleteFail: true });
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
this.state = { annotations: props.annotations || [] };
|
|
200
|
+
}
|
|
201
|
+
componentDidMount() {
|
|
202
|
+
this.mounted = true;
|
|
203
|
+
this.props.formContext.apiClient.fetchCached(`/forms/${this.props.formId}`, { lang: this.props.lang, format: "schema" })
|
|
204
|
+
.then(metadataForm => {
|
|
205
|
+
if (!this.mounted)
|
|
206
|
+
return;
|
|
207
|
+
const { filter: _filter } = this.props;
|
|
208
|
+
let propArray = Object.keys(metadataForm.schema.properties);
|
|
209
|
+
if (_filter)
|
|
210
|
+
propArray = utils_1.filter(propArray, _filter.filter, _filter.filterType);
|
|
211
|
+
const schemaProperties = propArray.reduce((properties, prop) => {
|
|
212
|
+
properties[prop] = metadataForm.schema.properties[prop];
|
|
213
|
+
return properties;
|
|
214
|
+
}, {});
|
|
215
|
+
const schema = Object.assign(Object.assign({}, metadataForm.schema), { properties: schemaProperties });
|
|
216
|
+
this.setState({ metadataForm: Object.assign(Object.assign({}, metadataForm), { schema }) });
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
componentWillUnmount() {
|
|
220
|
+
this.mounted = false;
|
|
221
|
+
}
|
|
222
|
+
render() {
|
|
223
|
+
const { formContext: { translations, lang, apiClient } } = this.props;
|
|
224
|
+
const { metadataForm = {}, annotations = [] } = this.state;
|
|
225
|
+
const _uiSchema = Object.assign(Object.assign({}, this.getUiSchema()), { "ui:readonly": true });
|
|
226
|
+
const { Panel, ListGroup, ListGroupItem, Alert } = this.context.theme;
|
|
227
|
+
return (React.createElement(Panel, null,
|
|
228
|
+
React.createElement(Panel.Heading, null,
|
|
229
|
+
React.createElement("strong", null, translations.Comments)),
|
|
230
|
+
React.createElement(Panel.Body, null,
|
|
231
|
+
this.renderAdd(),
|
|
232
|
+
React.createElement(ListGroup, null, this.state.metadataForm ? annotations.slice(0).reverse().map((annotation, idx) => React.createElement(ListGroupItem, { key: idx, className: `annotation-list${idx % 2 === 0 ? "" : "-odd"}` },
|
|
233
|
+
React.createElement("div", null,
|
|
234
|
+
React.createElement(LajiForm_1.default, Object.assign({}, metadataForm, { uiSchema: _uiSchema, lang: lang, formData: annotation, renderSubmit: false, apiClient: apiClient.apiClient, uiSchemaContext: this.props.formContext.uiSchemaContext }))))) : React.createElement(Spinner, null)),
|
|
235
|
+
this.state.deleteFail &&
|
|
236
|
+
React.createElement(Alert, { variant: "danger" }, translations["DeleteFail"]))));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
AnnotationBox.contextType = ReactContext_1.default;
|
|
240
|
+
AnnotationBox.defaultProps = {
|
|
241
|
+
formId: "MHL.15"
|
|
242
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export default _anyToBoolean;
|
|
2
|
+
declare function _anyToBoolean(props: any): JSX.Element;
|
|
3
|
+
declare namespace _anyToBoolean {
|
|
4
|
+
namespace propTypes {
|
|
5
|
+
const uiSchema: PropTypes.Requireable<PropTypes.InferProps<{
|
|
6
|
+
"ui:options": PropTypes.Requireable<PropTypes.InferProps<{
|
|
7
|
+
trueValue: PropTypes.Validator<object>;
|
|
8
|
+
falseValue: PropTypes.Requireable<object>;
|
|
9
|
+
allowUndefined: PropTypes.Requireable<boolean>;
|
|
10
|
+
}>>;
|
|
11
|
+
}>>;
|
|
12
|
+
const schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
13
|
+
type: PropTypes.Requireable<string>;
|
|
14
|
+
}>>;
|
|
15
|
+
const formData: PropTypes.Requireable<object>;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
import * as PropTypes from "prop-types";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const AnyToBooleanWidget_1 = require("../widgets/AnyToBooleanWidget");
|
|
5
|
+
const PropTypes = require("prop-types");
|
|
6
|
+
const _anyToBoolean = (props) => React.createElement(AnyToBooleanWidget_1.AnyToBoolean, Object.assign({}, props));
|
|
7
|
+
_anyToBoolean.propTypes = {
|
|
8
|
+
uiSchema: PropTypes.shape({
|
|
9
|
+
"ui:options": PropTypes.shape({
|
|
10
|
+
trueValue: PropTypes.oneOfType([PropTypes.array, PropTypes.object]).isRequired,
|
|
11
|
+
falseValue: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
|
12
|
+
allowUndefined: PropTypes.bool
|
|
13
|
+
})
|
|
14
|
+
}),
|
|
15
|
+
schema: PropTypes.shape({
|
|
16
|
+
type: PropTypes.oneOf(["array", "object"])
|
|
17
|
+
}).isRequired,
|
|
18
|
+
formData: PropTypes.oneOfType([PropTypes.array, PropTypes.object])
|
|
19
|
+
};
|
|
20
|
+
exports.default = _anyToBoolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export default class ArrayBulkField extends React.Component<any, any, any> {
|
|
2
|
+
static propTypes: {
|
|
3
|
+
uiSchema: PropTypes.Validator<PropTypes.InferProps<{
|
|
4
|
+
"ui:options": PropTypes.Requireable<PropTypes.InferProps<{
|
|
5
|
+
rowAddAmount: PropTypes.Requireable<number>;
|
|
6
|
+
}>>;
|
|
7
|
+
}>>;
|
|
8
|
+
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
9
|
+
type: PropTypes.Requireable<string>;
|
|
10
|
+
}>>;
|
|
11
|
+
formData: PropTypes.Validator<any[]>;
|
|
12
|
+
};
|
|
13
|
+
constructor(props: any);
|
|
14
|
+
getStateFromProps: (props: any) => {
|
|
15
|
+
rowAddAmount: any;
|
|
16
|
+
rowAmount: number;
|
|
17
|
+
};
|
|
18
|
+
renderItems: () => any[];
|
|
19
|
+
onChangeForIdx: (idx: any) => (itemFormData: any) => void;
|
|
20
|
+
onAddClick: (event: any) => void;
|
|
21
|
+
}
|
|
22
|
+
import * as React from "react";
|
|
23
|
+
import * as PropTypes from "prop-types";
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const React = require("react");
|
|
10
|
+
const PropTypes = require("prop-types");
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
|
+
const components_1 = require("../components");
|
|
13
|
+
const BaseComponent_1 = require("../BaseComponent");
|
|
14
|
+
const utils_2 = require("@rjsf/utils");
|
|
15
|
+
let ArrayBulkField = class ArrayBulkField extends React.Component {
|
|
16
|
+
constructor(props) {
|
|
17
|
+
super(props);
|
|
18
|
+
this.getStateFromProps = (props) => {
|
|
19
|
+
let state = {};
|
|
20
|
+
const { rowAddAmount } = utils_1.getUiOptions(props.uiSchema);
|
|
21
|
+
state.rowAddAmount = 10;
|
|
22
|
+
if (rowAddAmount > 0)
|
|
23
|
+
state.rowAddAmount = rowAddAmount;
|
|
24
|
+
if (props.formData && props.formData.length > this.state.rowAmount) {
|
|
25
|
+
state.rowAmount = props.formData.length + state.rowAddAmount - (props.formData.length % state.rowAddAmount);
|
|
26
|
+
}
|
|
27
|
+
return state;
|
|
28
|
+
};
|
|
29
|
+
this.renderItems = () => {
|
|
30
|
+
let rows = [];
|
|
31
|
+
let idx = 0;
|
|
32
|
+
let data = this.props.formData || [];
|
|
33
|
+
while (data.length < this.state.rowAmount) {
|
|
34
|
+
data.push({});
|
|
35
|
+
}
|
|
36
|
+
const SchemaField = this.props.registry.fields.SchemaField;
|
|
37
|
+
if (data)
|
|
38
|
+
data.forEach((item) => {
|
|
39
|
+
rows.push(React.createElement(SchemaField, { key: idx, formData: item, onChange: this.onChangeForIdx(idx), schema: this.props.schema.items, uiSchema: this.props.uiSchema.items, idSchema: { $id: this.props.idSchema.$id + "_" + idx }, registry: this.props.registry, errorSchema: this.props.errorSchema[idx] }));
|
|
40
|
+
idx++;
|
|
41
|
+
});
|
|
42
|
+
return rows;
|
|
43
|
+
};
|
|
44
|
+
this.onChangeForIdx = (idx) => {
|
|
45
|
+
return (itemFormData) => {
|
|
46
|
+
let formData = this.props.formData;
|
|
47
|
+
if (!formData)
|
|
48
|
+
formData = [];
|
|
49
|
+
formData[idx] = itemFormData;
|
|
50
|
+
this.props.onChange(formData.filter(item => { return Object.keys(item).length; }));
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
this.onAddClick = (event) => {
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
this.setState({ rowAmount: this.state.rowAmount + this.state.rowAddAmount });
|
|
56
|
+
};
|
|
57
|
+
this.state = Object.assign({ rowAmount: 0 }, this.getStateFromProps(props));
|
|
58
|
+
}
|
|
59
|
+
render() {
|
|
60
|
+
const TitleFieldTemplate = utils_2.getTemplate("TitleFieldTemplate", this.props.registry, utils_1.getUiOptions(this.props.uiSchema));
|
|
61
|
+
return (React.createElement("fieldset", null,
|
|
62
|
+
React.createElement(TitleFieldTemplate, { title: this.props.schema.title || this.props.name, schema: this.props.schema, uiSchema: this.props.uiSchema, registry: this.props.registry }),
|
|
63
|
+
this.renderItems(),
|
|
64
|
+
React.createElement(components_1.Button, { onClick: this.onAddClick }, "Lis\u00E4\u00E4 havaintorivej\u00E4"),
|
|
65
|
+
React.createElement("br", null)));
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
ArrayBulkField.propTypes = {
|
|
69
|
+
uiSchema: PropTypes.shape({
|
|
70
|
+
"ui:options": PropTypes.shape({
|
|
71
|
+
rowAddAmount: PropTypes.number
|
|
72
|
+
})
|
|
73
|
+
}).isRequired,
|
|
74
|
+
schema: PropTypes.shape({
|
|
75
|
+
type: PropTypes.oneOf(["array"])
|
|
76
|
+
}).isRequired,
|
|
77
|
+
formData: PropTypes.array.isRequired
|
|
78
|
+
};
|
|
79
|
+
ArrayBulkField = __decorate([
|
|
80
|
+
BaseComponent_1.default
|
|
81
|
+
], ArrayBulkField);
|
|
82
|
+
exports.default = ArrayBulkField;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transforms an object schema containing arrays to an array schema containing objects.
|
|
3
|
+
*
|
|
4
|
+
* uischema = {"ui:options": {
|
|
5
|
+
* uiSchema: <uiSchema> (uiSchema which is passed to array items)
|
|
6
|
+
* }
|
|
7
|
+
*/
|
|
8
|
+
export default class ArrayCombinerField extends React.Component<any, any, any> {
|
|
9
|
+
static propTypes: {
|
|
10
|
+
uiSchema: PropTypes.Validator<PropTypes.InferProps<{
|
|
11
|
+
"ui:options": PropTypes.Requireable<PropTypes.InferProps<{
|
|
12
|
+
additionalItemsAmount: PropTypes.Requireable<number>;
|
|
13
|
+
}>>;
|
|
14
|
+
uiSchema: PropTypes.Requireable<object>;
|
|
15
|
+
}>>;
|
|
16
|
+
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
17
|
+
type: PropTypes.Requireable<string>;
|
|
18
|
+
}>>;
|
|
19
|
+
formData: PropTypes.Validator<object>;
|
|
20
|
+
};
|
|
21
|
+
static getName(): string;
|
|
22
|
+
constructor(props: any);
|
|
23
|
+
constructor(props: any, context: any);
|
|
24
|
+
getStateFromProps(props: any): {
|
|
25
|
+
schema: {
|
|
26
|
+
type: string;
|
|
27
|
+
};
|
|
28
|
+
errorSchema: any;
|
|
29
|
+
formData: any;
|
|
30
|
+
uiSchema: any;
|
|
31
|
+
onChange: (formData: any) => void;
|
|
32
|
+
};
|
|
33
|
+
onChange: (formData: any) => void;
|
|
34
|
+
}
|
|
35
|
+
import * as React from "react";
|
|
36
|
+
import * as PropTypes from "prop-types";
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const React = require("react");
|
|
10
|
+
const PropTypes = require("prop-types");
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
|
+
const merge = require("deepmerge");
|
|
13
|
+
const VirtualSchemaField_1 = require("../VirtualSchemaField");
|
|
14
|
+
/**
|
|
15
|
+
* Transforms an object schema containing arrays to an array schema containing objects.
|
|
16
|
+
*
|
|
17
|
+
* uischema = {"ui:options": {
|
|
18
|
+
* uiSchema: <uiSchema> (uiSchema which is passed to array items)
|
|
19
|
+
* }
|
|
20
|
+
*/
|
|
21
|
+
let ArrayCombinerField = class ArrayCombinerField extends React.Component {
|
|
22
|
+
constructor() {
|
|
23
|
+
super(...arguments);
|
|
24
|
+
this.onChange = (formData) => {
|
|
25
|
+
let origArraysContainer = {};
|
|
26
|
+
if (!formData || formData.length === 0) {
|
|
27
|
+
Object.keys(this.props.schema.properties).forEach((prop) => {
|
|
28
|
+
origArraysContainer[prop] = [];
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
formData.forEach((obj) => {
|
|
33
|
+
Object.keys(this.props.schema.properties).forEach((arrName) => {
|
|
34
|
+
origArraysContainer[arrName] ?
|
|
35
|
+
origArraysContainer[arrName].push(obj[arrName]) :
|
|
36
|
+
(origArraysContainer[arrName] = [obj[arrName]]);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
this.props.onChange(origArraysContainer);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
static getName() { return "ArrayCombinerField"; }
|
|
44
|
+
getStateFromProps(props) {
|
|
45
|
+
const { additionalItemsAmount } = this.getUiOptions();
|
|
46
|
+
let itemSchema = { type: "object", properties: {}, required: props.schema.required };
|
|
47
|
+
let schema = { type: "array" };
|
|
48
|
+
if (additionalItemsAmount)
|
|
49
|
+
schema.additionalItems = itemSchema;
|
|
50
|
+
if ("title" in props.schema)
|
|
51
|
+
schema.title = props.schema.title;
|
|
52
|
+
Object.keys(props.schema.properties).forEach((propertyName) => {
|
|
53
|
+
let propertyOrigin = props.schema.properties[propertyName];
|
|
54
|
+
let property = propertyOrigin.items;
|
|
55
|
+
if (property.type === "object" || property.type === "array")
|
|
56
|
+
throw "items properties can't be objects or arrays";
|
|
57
|
+
if (propertyOrigin.title)
|
|
58
|
+
property.title = propertyOrigin.title;
|
|
59
|
+
itemSchema.properties[propertyName] = property;
|
|
60
|
+
});
|
|
61
|
+
schema.items = itemSchema;
|
|
62
|
+
if (additionalItemsAmount) {
|
|
63
|
+
schema.items = Array(additionalItemsAmount).fill(itemSchema);
|
|
64
|
+
schema.additionalItems = itemSchema;
|
|
65
|
+
}
|
|
66
|
+
const uiSchema = Object.keys(props.schema.properties).reduce((_uiSchema, field) => {
|
|
67
|
+
if (field in _uiSchema) {
|
|
68
|
+
_uiSchema = Object.assign(Object.assign({}, _uiSchema), { items: Object.assign(Object.assign({}, (_uiSchema.items || {})), { [field]: _uiSchema[field] }) });
|
|
69
|
+
utils_1.immutableDelete(_uiSchema, field);
|
|
70
|
+
}
|
|
71
|
+
return _uiSchema;
|
|
72
|
+
}, props.uiSchema);
|
|
73
|
+
function objectsToArray(array, objects) {
|
|
74
|
+
if (objects)
|
|
75
|
+
Object.keys(objects).forEach(dataCol => {
|
|
76
|
+
if (objects[dataCol])
|
|
77
|
+
for (var row in objects[dataCol]) {
|
|
78
|
+
let val = objects[dataCol][row];
|
|
79
|
+
if (!array[row])
|
|
80
|
+
array[row] = {};
|
|
81
|
+
array[row][dataCol] = val;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return array;
|
|
85
|
+
}
|
|
86
|
+
function rotateErrorSchema(rotatedErrorSchema, errorSchema) {
|
|
87
|
+
if (errorSchema)
|
|
88
|
+
Object.keys(errorSchema).forEach(property => {
|
|
89
|
+
const error = errorSchema[property];
|
|
90
|
+
if (property === "__errors") {
|
|
91
|
+
rotatedErrorSchema.__errors = error;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
if (error)
|
|
95
|
+
Object.keys(error).forEach(idx => {
|
|
96
|
+
if (idx === "__errors") {
|
|
97
|
+
rotatedErrorSchema.__errors = rotatedErrorSchema.__errors ?
|
|
98
|
+
[...rotatedErrorSchema.__errors, ...error.__errors] :
|
|
99
|
+
error.__errors;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const propertyError = { [property]: error[idx] };
|
|
103
|
+
rotatedErrorSchema[idx] = rotatedErrorSchema[idx] ?
|
|
104
|
+
merge(rotatedErrorSchema[idx], propertyError) : propertyError;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
return rotatedErrorSchema;
|
|
110
|
+
}
|
|
111
|
+
let errorSchema = rotateErrorSchema({}, props.errorSchema);
|
|
112
|
+
let formData = objectsToArray([], props.formData);
|
|
113
|
+
formData.forEach((obj) => {
|
|
114
|
+
Object.keys(itemSchema.properties).forEach((prop) => {
|
|
115
|
+
if (!(prop in obj)) {
|
|
116
|
+
obj[prop] = utils_1.getDefaultFormState(itemSchema.properties[prop]);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
return { schema, errorSchema, formData, uiSchema, onChange: this.onChange };
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
ArrayCombinerField.propTypes = {
|
|
124
|
+
uiSchema: PropTypes.shape({
|
|
125
|
+
"ui:options": PropTypes.shape({
|
|
126
|
+
additionalItemsAmount: PropTypes.number
|
|
127
|
+
}),
|
|
128
|
+
uiSchema: PropTypes.object
|
|
129
|
+
}).isRequired,
|
|
130
|
+
schema: PropTypes.shape({
|
|
131
|
+
type: PropTypes.oneOf(["object"])
|
|
132
|
+
}).isRequired,
|
|
133
|
+
formData: PropTypes.object.isRequired
|
|
134
|
+
};
|
|
135
|
+
ArrayCombinerField = __decorate([
|
|
136
|
+
VirtualSchemaField_1.default
|
|
137
|
+
], ArrayCombinerField);
|
|
138
|
+
exports.default = ArrayCombinerField;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function onArrayFieldChange(formData: any, props: any): any;
|
|
2
|
+
export function copyItemFunction(that: any, copyItem: any): (props: any, { type, filter }: {
|
|
3
|
+
type: any;
|
|
4
|
+
filter: any;
|
|
5
|
+
}) => any;
|
|
6
|
+
export class ArrayFieldPatched {
|
|
7
|
+
constructor(...params: any[]);
|
|
8
|
+
_getNewFormDataRow: () => any;
|
|
9
|
+
onDropIndexClick: (index: any) => (event: any) => void;
|
|
10
|
+
renderArrayFieldItem(props: any): any;
|
|
11
|
+
getIdSchema(props: any, _index: any): any;
|
|
12
|
+
}
|
|
13
|
+
export default class _ArrayField extends React.Component<any, any, any> {
|
|
14
|
+
static contextType: React.Context<import("../../ReactContext").ContextProps>;
|
|
15
|
+
constructor(props: any);
|
|
16
|
+
constructor(props: any, context: any);
|
|
17
|
+
onChange: (formData: any) => void;
|
|
18
|
+
buttonDefinitions: {
|
|
19
|
+
copy: {
|
|
20
|
+
glyph: string;
|
|
21
|
+
fn: () => (...params: any[]) => void;
|
|
22
|
+
rules: {
|
|
23
|
+
minLength: number;
|
|
24
|
+
canAdd: boolean;
|
|
25
|
+
};
|
|
26
|
+
changesFormData: boolean;
|
|
27
|
+
};
|
|
28
|
+
addPredefined: {
|
|
29
|
+
fn: () => (onClickProps: any, { default: _default }: {
|
|
30
|
+
default: any;
|
|
31
|
+
}) => void;
|
|
32
|
+
rules: {
|
|
33
|
+
canAdd: boolean;
|
|
34
|
+
};
|
|
35
|
+
changesFormData: boolean;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
import * as React from "react";
|