swoop-common 2.1.33 → 2.1.35
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.
|
@@ -7,18 +7,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import React, { useEffect,
|
|
10
|
+
import React, { useEffect, useState } from 'react';
|
|
11
11
|
import { Paper, Button } from '@mui/material';
|
|
12
12
|
import { useLocalErrors } from '../hooks/errors';
|
|
13
13
|
import { ComponentPool } from '../registry/types';
|
|
14
14
|
import { registerComponent } from '../registry/components';
|
|
15
15
|
import { CoreService } from '../../api/generated/core';
|
|
16
16
|
import { useComponentPicker } from '../contexts/ComponentPickerContext';
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
import { InternalServices } from '../../api/init';
|
|
18
|
+
const FormComponentPicker = ({ selectedComponent, onChange, templateIds, getError, label, enabled }) => {
|
|
19
|
+
const [selected, setSelected] = useState();
|
|
19
20
|
const { get } = useComponentPicker();
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (selectedComponent)
|
|
23
|
+
InternalServices.CoreService.componentGet(selectedComponent).then(setSelected);
|
|
24
|
+
else
|
|
25
|
+
setSelected(undefined);
|
|
26
|
+
}, [selectedComponent]);
|
|
20
27
|
return (React.createElement(Paper, { component: "form", sx: { display: 'flex', flexDirection: 'column', gap: 1, p: 2, mb: 1 }, noValidate: true, autoComplete: "off" },
|
|
21
|
-
React.createElement(Button, { onClick: () => {
|
|
28
|
+
React.createElement(Button, { disabled: !enabled, onClick: () => {
|
|
22
29
|
get(templateIds)
|
|
23
30
|
.then((comp) => {
|
|
24
31
|
onChange(comp.id);
|
|
@@ -42,29 +49,10 @@ const FormComponentPicker = ({ components, selectedComponent, onChange, template
|
|
|
42
49
|
} }, selectedComponent ? selected === null || selected === void 0 ? void 0 : selected.name : "Select " + label + " Component")));
|
|
43
50
|
};
|
|
44
51
|
const FormRendererComponentPicker = ({ data, handleChange, path, label, enabled, schema }) => {
|
|
45
|
-
const [components, setComponents] = useState([]);
|
|
46
52
|
const getError = useLocalErrors(path);
|
|
47
|
-
|
|
48
|
-
const templateIds =
|
|
49
|
-
|
|
50
|
-
schema['x-templateIds'] || [], [schema]);
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
const load = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
-
try {
|
|
54
|
-
const fetched = yield fetchComponents();
|
|
55
|
-
let filtered = fetched.data;
|
|
56
|
-
if (templateIds.length > 0) {
|
|
57
|
-
filtered = filtered.filter(c => templateIds.includes(c.templateId));
|
|
58
|
-
}
|
|
59
|
-
setComponents(filtered);
|
|
60
|
-
}
|
|
61
|
-
catch (err) {
|
|
62
|
-
console.error('Error loading components:', err);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
load();
|
|
66
|
-
}, [templateIds]);
|
|
67
|
-
return (React.createElement(FormComponentPicker, { components: components, selectedComponent: data || null, onChange: (id) => handleChange(path, id), templateIds: templateIds, getError: getError, label: label, enabled: enabled }));
|
|
53
|
+
// @ts-expect-error
|
|
54
|
+
const templateIds = schema['x-templateIds'];
|
|
55
|
+
return (React.createElement(FormComponentPicker, { selectedComponent: data || null, onChange: (id) => handleChange(path, id), templateIds: templateIds, getError: getError, label: label, enabled: enabled }));
|
|
68
56
|
};
|
|
69
57
|
registerComponent("component", FormRendererComponentPicker, ComponentPool.FORM);
|
|
70
58
|
export const fetchComponents = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -73,7 +73,6 @@ const defaultConverter = (field, stage, omitTitle, isChild) => {
|
|
|
73
73
|
let templates = field.fieldType === "component"
|
|
74
74
|
? { "x-templateIds": field.componentOptions["x-templateIds"] }
|
|
75
75
|
: {};
|
|
76
|
-
console.log(templates);
|
|
77
76
|
let title = omitTitle ? undefined : field.name;
|
|
78
77
|
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (!isChild && !(Array.isArray(field.editableIn) ? field.editableIn : []).map(Number).includes(stage) && { readOnly: true })), { title, type: schema.schema.type, "x-type": schema.schema["x-type"] }), templates), (schema.schema.type === "object" && { properties })), (field.fieldType === "object" && { required: requiredFields })), (enumOpts && { enum: enumOpts })), (stagedEnumOpts && { items: { enum: stagedEnumOpts, type: "string" } })), (arrayItems && { items: arrayItems })), (field.fieldType === "object" && { properties }));
|
|
79
78
|
};
|