Skip to content

Commit 90bfa7f

Browse files
committed
ui: form builder create a dropLocked feature to avoid having children in some situations
* closes #2003 Signed-off-by: papadopan <[email protected]>
1 parent 2605152 commit 90bfa7f

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

ui/cap-react/src/components/cms/components/SchemaWizard/SchemaPreview/SchemaTree/FieldTemplate.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,18 @@ const FieldTemplate = props => {
2424
uiSchema: [...formContext.uiSchema, ...(rawErrors[0].uiSchema || [])]
2525
};
2626

27+
const shouldBoxHideChildren = uiSchema => {
28+
return uiSchema["ui:field"] !== undefined;
29+
};
30+
2731
if (props.id == "root") {
2832
return (
29-
<HoverBox addProperty={props.addProperty} key={props.id} path={path}>
33+
<HoverBox
34+
addProperty={props.addProperty}
35+
key={props.id}
36+
path={path}
37+
shouldHideChildren={shouldBoxHideChildren(uiSchema)}
38+
>
3039
<Box
3140
flex={true}
3241
pad={formContext.schema.length == 0 ? "medium" : "none"}
@@ -40,11 +49,7 @@ const FieldTemplate = props => {
4049
let _renderObjectArray = undefined;
4150

4251
if (["array"].indexOf(schema.type) > -1) {
43-
_renderObjectArray = (
44-
<HoverBox addProperty={props.addProperty} key={props.id} path={path}>
45-
<Box>{children}</Box>
46-
</HoverBox>
47-
);
52+
_renderObjectArray = <Box>{children}</Box>;
4853
} else if (["object"].indexOf(schema.type) > -1) {
4954
_renderObjectArray = (
5055
<Box flex={true} style={{ position: "relative", overflow: "visible" }}>
@@ -82,7 +87,12 @@ const FieldTemplate = props => {
8287

8388
if (_renderObjectArray) {
8489
return (
85-
<HoverBox addProperty={props.addProperty} key={props.id} path={path}>
90+
<HoverBox
91+
addProperty={props.addProperty}
92+
key={props.id}
93+
path={path}
94+
shouldHideChildren={shouldBoxHideChildren(uiSchema)}
95+
>
8696
{_renderObjectArray}
8797
</HoverBox>
8898
);

ui/cap-react/src/components/cms/components/SchemaWizard/SchemaPreview/SchemaTree/HoverBox.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@ function getStyle(isOverCurrent) {
1212
};
1313
}
1414

15-
function HoverBox({ path, propKey, addProperty, children, index }) {
16-
// const [hasDropped, setHasDropped] = useState(false);
17-
// const [results, setResults] = useState({});
18-
// const [hasDroppedOnChild, setHasDroppedOnChild] = useState(false);
19-
// const ref = useRef(null);
15+
function HoverBox({
16+
path,
17+
propKey,
18+
addProperty,
19+
children,
20+
index,
21+
shouldHideChildren
22+
}) {
2023
const [{ isOverCurrent }, drop] = useDrop({
2124
accept: "FIELD_TYPE",
2225
drop: (item, monitor) => {
2326
const didDrop = monitor.didDrop();
24-
if (!didDrop) {
27+
28+
if (!didDrop && !shouldHideChildren) {
2529
addProperty(path, item.data.default);
2630
return { item, path, propKey };
2731
}
@@ -33,8 +37,13 @@ function HoverBox({ path, propKey, addProperty, children, index }) {
3337
isOverCurrent: monitor.isOver({ shallow: true })
3438
})
3539
});
40+
3641
return (
37-
<div ref={drop} style={getStyle(isOverCurrent)} index={index}>
42+
<div
43+
ref={drop}
44+
style={getStyle(isOverCurrent && !shouldHideChildren)}
45+
index={index}
46+
>
3847
{children}
3948
</div>
4049
);
@@ -45,7 +54,8 @@ HoverBox.propTypes = {
4554
path: PropTypes.array,
4655
addProperty: PropTypes.func,
4756
propKey: PropTypes.string,
48-
index: PropTypes.number
57+
index: PropTypes.number,
58+
shouldHideChildren: PropTypes.bool
4959
};
5060

5161
export default HoverBox;

ui/cap-react/src/components/cms/components/SchemaWizard/SchemaPreview/SchemaTree/SchemaTreeItem.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class SchemaTreeItem extends React.Component {
2626
this.props.addItem(this.props.path);
2727
};
2828

29+
shouldBoxAcceptChildren = uiSchema => {
30+
return uiSchema["ui:field"] !== undefined;
31+
};
32+
2933
render() {
3034
let _id =
3135
this.props.type == "array"
@@ -84,7 +88,8 @@ class SchemaTreeItem extends React.Component {
8488
) : null}
8589
{this.props.schema ? (
8690
<Box direction="row" align="center" wrap={false} flex={false}>
87-
{this.props.schema.type == "object" ? (
91+
{this.props.schema.type == "object" &&
92+
!this.shouldBoxAcceptChildren(this.props.uiSchema) ? (
8893
<Box
8994
direction="row"
9095
responsive={false}
@@ -122,7 +127,8 @@ SchemaTreeItem.propTypes = {
122127
type: PropTypes.string,
123128
colorIndex: PropTypes.string,
124129
display: PropTypes.bool,
125-
updateDisplay: PropTypes.func
130+
updateDisplay: PropTypes.func,
131+
uiSchema: PropTypes.object
126132
};
127133

128134
function mapDispatchToProps(dispatch) {

0 commit comments

Comments
 (0)