diff --git a/src/admin/components/Customize.jsx b/src/admin/components/Customize.jsx index 5e7548a..aeb27b1 100644 --- a/src/admin/components/Customize.jsx +++ b/src/admin/components/Customize.jsx @@ -74,11 +74,11 @@ const Customize = () => { { }, { key: "2", - label: "UI Schema Settings", + label: "UI Settings", children: path.length != 0 ? ( { key={uiPath} /> ) : ( - + Size Options { return ; }; + const PropertyEditor = () => { const [name, setName] = useState(); const screens = useBreakpoint(); @@ -57,6 +60,13 @@ const PropertyEditor = () => { const path = useSelector((state) => state.schemaWizard.field.path); const uiPath = useSelector((state) => state.schemaWizard.field.uiPath); + const schema = useSelector((state) => + get(state.schemaWizard, ["current", "schema", ...path]), + ); + const uiSchema = useSelector((state) => + get(state.schemaWizard, ["current", "uiSchema", ...uiPath]), + ); + const dispatch = useDispatch(); useEffect(() => { @@ -97,7 +107,7 @@ const PropertyEditor = () => { } /> - + {renderPath(path)} @@ -116,13 +126,20 @@ const PropertyEditor = () => { ), } } - style={{ textAlign: "center" }} + style={{ textAlign: "center", margin: "10px 0" }} > + {getIconByType( + schema, + uiSchema, + customizationContext.allFieldTypes, + )}{" "} {name} - + + + ); }; diff --git a/src/admin/components/SchemaPreview.jsx b/src/admin/components/SchemaPreview.jsx index 929652f..b736ddb 100644 --- a/src/admin/components/SchemaPreview.jsx +++ b/src/admin/components/SchemaPreview.jsx @@ -6,10 +6,9 @@ import { useDispatch, useSelector } from "react-redux"; import { selectProperty } from "../../store/schemaWizard"; const SchemaPreview = () => { + const schema = useSelector((state) => state.schemaWizard.current.schema); - const schema = useSelector((state) => state.schemaWizard.current.schema) - - const dispatch = useDispatch() + const dispatch = useDispatch(); return (
@@ -29,18 +28,25 @@ const SchemaPreview = () => { align="middle" style={{ padding: "0 10px" }} > - + {(schema && schema.title) || "root"} -
, + icon: { }, description: "Data in JSON format, Grouped section", className: "tour-object-field", child: {}, @@ -156,7 +163,9 @@ const collections = { ...common.optionsSchema, }, }, - optionsSchemaUiSchema: {}, + optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, + }, optionsUiSchema: { type: "object", title: "UI Schema", @@ -203,7 +212,9 @@ const collections = { ...common.optionsSchema, }, }, - optionsSchemaUiSchema: {}, + optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, + }, optionsUiSchema: { type: "object", title: "UI Schema", @@ -227,6 +238,7 @@ const collections = { }, }, optionsUiSchemaUiSchema: { + ...common.optionsUiSchemaUiSchema, "ui:options": { ...common.optionsUiSchemaUiSchema["ui:options"], itemsDisplayTitle: { @@ -248,7 +260,6 @@ const collections = { "ui:field": "codeEditor", }, }, - "ui:label": common.optionsUiSchemaUiSchema["ui:label"], }, default: { @@ -271,7 +282,9 @@ const collections = { ...common.optionsSchema, }, }, - optionsSchemaUiSchema: {}, + optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, + }, optionsUiSchema: { ...common.optionsUiSchema, }, @@ -300,7 +313,9 @@ const collections = { ...common.optionsSchema, }, }, - optionsSchemaUiSchema: {}, + optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, + }, optionsUiSchema: { ...common.optionsUiSchema, }, @@ -329,7 +344,9 @@ const collections = { ...common.optionsSchema, }, }, - optionsSchemaUiSchema: {}, + optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, + }, optionsUiSchema: { ...common.optionsUiSchema, }, @@ -372,6 +389,7 @@ const simple = { }, }, optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, readOnly: extra.optionsSchemaUiSchema.readOnly, isRequired: extra.optionsSchemaUiSchema.isRequired, pattern: { @@ -410,6 +428,7 @@ const simple = { }, }, optionsUiSchemaUiSchema: { + ...common.optionsUiSchemaUiSchema, "ui:options": { ...common.optionsUiSchemaUiSchema["ui:options"], mask: { @@ -420,7 +439,6 @@ const simple = { }, }, }, - "ui:label": common.optionsUiSchemaUiSchema["ui:label"], }, default: { schema: { @@ -446,6 +464,7 @@ const simple = { }, }, optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, readOnly: extra.optionsSchemaUiSchema.readOnly, isRequired: extra.optionsSchemaUiSchema.isRequired, }, @@ -520,6 +539,7 @@ const simple = { }, }, optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, readOnly: extra.optionsSchemaUiSchema.readOnly, isRequired: extra.optionsSchemaUiSchema.isRequired, }, @@ -604,6 +624,7 @@ const simple = { }, }, optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, readOnly: extra.optionsSchemaUiSchema.readOnly, isRequired: extra.optionsSchemaUiSchema.isRequired, }, @@ -652,6 +673,7 @@ const simple = { }, }, optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, readOnly: extra.optionsSchemaUiSchema.readOnly, isRequired: extra.optionsSchemaUiSchema.isRequired, }, @@ -713,6 +735,7 @@ const simple = { }, }, optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, readOnly: extra.optionsSchemaUiSchema.readOnly, isRequired: extra.optionsSchemaUiSchema.isRequired, }, @@ -829,6 +852,7 @@ const simple = { ], }, optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, readOnly: extra.optionsSchemaUiSchema.readOnly, isRequired: extra.optionsSchemaUiSchema.isRequired, }, @@ -885,6 +909,7 @@ const simple = { }, }, optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, customFormat: { "ui:placeholder": "DD/MM/YYYY", "ui:options": { @@ -934,6 +959,7 @@ const advanced = { }, }, optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, readOnly: extra.optionsSchemaUiSchema.readOnly, isRequired: extra.optionsSchemaUiSchema.isRequired, }, @@ -986,6 +1012,7 @@ const advanced = { }, }, optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, readOnly: extra.optionsSchemaUiSchema.readOnly, isRequired: extra.optionsSchemaUiSchema.isRequired, }, @@ -1030,6 +1057,7 @@ const advanced = { }, }, optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, readOnly: extra.optionsSchemaUiSchema.readOnly, isRequired: extra.optionsSchemaUiSchema.isRequired, }, @@ -1066,6 +1094,7 @@ const advanced = { }, }, optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, readOnly: extra.optionsSchemaUiSchema.readOnly, isRequired: extra.optionsSchemaUiSchema.isRequired, }, @@ -1167,6 +1196,7 @@ const advanced = { }, }, optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, readOnly: extra.optionsSchemaUiSchema.readOnly, isRequired: extra.optionsSchemaUiSchema.isRequired, validateWithUrl: { @@ -1274,6 +1304,7 @@ export const hiddenFields = { }, }, optionsSchemaUiSchema: { + ...common.optionsSchemaUiSchema, readOnly: extra.optionsSchemaUiSchema.readOnly, isRequired: extra.optionsSchemaUiSchema.isRequired, }, diff --git a/src/admin/utils/index.js b/src/admin/utils/index.jsx similarity index 61% rename from src/admin/utils/index.js rename to src/admin/utils/index.jsx index c03454d..456862a 100644 --- a/src/admin/utils/index.js +++ b/src/admin/utils/index.jsx @@ -1,3 +1,7 @@ +import { QuestionOutlined } from "@ant-design/icons"; +import { hiddenFields } from "./fieldTypes"; +import { Tooltip } from "antd"; + export const SIZE_OPTIONS = { xsmall: 8, small: 12, @@ -70,3 +74,39 @@ export const combineFieldTypes = (fieldTypes, customFieldTypes) => { }; export const timer = (ms) => new Promise((res) => setTimeout(res, ms)); + +export const getIconByType = (schema, uiSchema, fieldTypes) => { + let type = "unknown"; + // in case we can not define the type of the element from the uiSchema, + // extract the type from the schema + if ( + !uiSchema || + (!uiSchema["ui:widget"] && !uiSchema["ui:field"] && !uiSchema["ui:object"]) + ) { + type = schema.type === "string" ? "text" : schema.type; + } else { + if (uiSchema["ui:widget"]) { + type = schema.format === "uri" ? schema.format : uiSchema["ui:widget"]; + } + if (uiSchema["ui:field"]) { + type = uiSchema["ui:field"]; + } + if (uiSchema["ui:object"]) { + type = uiSchema["ui:object"]; + } + } + + const allFieldTypes = { + ...fieldTypes, + hidden: { fields: hiddenFields }, + }; + + for (const category in allFieldTypes) { + for (const [key, value] of Object.entries(allFieldTypes[category].fields)) { + if (key === type) { + return {value.icon}; + } + } + } + return ; +}; diff --git a/src/forms/Form.less b/src/forms/Form.less index ca7e29a..bc46183 100644 --- a/src/forms/Form.less +++ b/src/forms/Form.less @@ -157,9 +157,29 @@ .bounceShadow { animation: bounceShadow 5s forwards; } + + .propKeyCollapse + .ant-collapse-content-box + fieldset + .ant-col + .ant-col:last-of-type + .ant-form-item:last-of-type { + margin-bottom: 0; + } + + .propKeyCollapse + .ant-collapse-content-box + > .form-group + > .ant-form-item:last-of-type { + margin-bottom: 0; + } } .tabItemError { background-color: @field-error-bg-color !important; color: @field-error-color !important; } + +.scrollableTabs .ant-tabs-content-holder { + overflow-y: scroll; +} diff --git a/src/forms/templates/ArrayFieldTemplates/AccordionArrayFieldTemplate.jsx b/src/forms/templates/ArrayFieldTemplates/AccordionArrayFieldTemplate.jsx index 6f8c044..047c164 100644 --- a/src/forms/templates/ArrayFieldTemplates/AccordionArrayFieldTemplate.jsx +++ b/src/forms/templates/ArrayFieldTemplates/AccordionArrayFieldTemplate.jsx @@ -8,7 +8,7 @@ const AccordionArrayFieldTemplate = ({ items = [], formContext, id }) => { return ( ({ key: index, label: `Item #${index + 1}`, diff --git a/src/forms/templates/Field/FieldTemplate.jsx b/src/forms/templates/Field/FieldTemplate.jsx index 58fc6ec..b086a47 100644 --- a/src/forms/templates/Field/FieldTemplate.jsx +++ b/src/forms/templates/Field/FieldTemplate.jsx @@ -98,7 +98,11 @@ const FieldTemplate = ({ { const { colSpan = 24, @@ -86,26 +87,37 @@ const ObjectFieldTemplate = ({ /> ); return ( -
- +
+ + {!isUiOptions && ( + + + + )} - - - {properties .filter((e) => !e.hidden) @@ -121,7 +133,6 @@ const ObjectFieldTemplate = ({ - {canExpand(schema, uiSchema, formData) && !readonly && ( diff --git a/src/forms/templates/PropKeyEditorObjectFieldTemplate.jsx b/src/forms/templates/PropKeyEditorObjectFieldTemplate.jsx new file mode 100644 index 0000000..904a224 --- /dev/null +++ b/src/forms/templates/PropKeyEditorObjectFieldTemplate.jsx @@ -0,0 +1,30 @@ +import { Collapse, Space } from "antd"; + +const PropKeyEditorObjectFieldTemplate = ({ properties }) => { + const [first, ...rest] = properties; + const elements = [first, { title: "Field UI Options", content: rest }]; + + const isUiSettings = properties.find((prop) => prop.name === "ui:options"); + + return isUiSettings ? ( + ({ + key: index, + label: item.title || item.content.props.schema.title, + children: item.content.length + ? item.content.map((i) => i.content) + : item.content, + }))} + /> + ) : ( + + {properties.map((item) => item.content)} + + ); +}; + +export default PropKeyEditorObjectFieldTemplate; diff --git a/src/forms/templates/UiOptionsObjectFieldTemplate.jsx b/src/forms/templates/UiOptionsObjectFieldTemplate.jsx new file mode 100644 index 0000000..4eb7c6c --- /dev/null +++ b/src/forms/templates/UiOptionsObjectFieldTemplate.jsx @@ -0,0 +1,7 @@ +import ObjectFieldTemplate from "./ObjectFieldTemplate"; + +const UiOptionsObjectFieldTemplate = (props) => { + return ; +}; + +export default UiOptionsObjectFieldTemplate;