Skip to content

Commit a086aaa

Browse files
Merge pull request #38 from BasicPrimitives/dragtodiag
Added dragging nodes from search drawer to the diagram in org editor demo
2 parents dc26e4d + 3783f48 commit a086aaa

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

client/src/components/Options/TextOption.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class TextOption extends Component { // eslint-disable-line react/prefer-statele
126126
const { caption, propertyName, placeholder, isNullable } = this.props;
127127
const { value, message } = this.state;
128128
return (
129-
<form className={'option-panel-item'} noValidate autoComplete="off">
129+
<form className={'option-panel-item'} noValidate autoComplete="off" onSubmit={e => { e.preventDefault(); }}>
130130
<TextField
131131
required={!isNullable}
132132
key={propertyName}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react'
2+
import { useDrag } from 'react-dnd'
3+
import useStyles from './styles';
4+
import { Colors } from 'basicprimitives';
5+
6+
const ItemTypes = {
7+
NODE: 'node'
8+
}
9+
10+
export default function NodeDragSource({ itemConfig }) {
11+
const [{ opacity }, dragRef] = useDrag({
12+
item: { type: ItemTypes.NODE, id: itemConfig.id },
13+
collect: (monitor) => ({
14+
opacity: monitor.isDragging() ? 0.5 : 1
15+
})
16+
})
17+
const itemTitleColor = itemConfig.itemTitleColor != null ? itemConfig.itemTitleColor : Colors.RoyalBlue;
18+
const styles = useStyles();
19+
return (
20+
<div style = {{width: "100%", height: "100%"}}>
21+
<div ref={dragRef} style={{ opacity }} className={styles.DefaultTemplate}>
22+
<div key="title" className={styles.DefaultTitleBackground} style={{ backgroundColor: itemTitleColor }}>
23+
<div className={styles.DefaultTitle}>{itemConfig.title}</div>
24+
</div>
25+
<div key="photo" className={styles.DefaultPhotoFrame}>
26+
<img className={styles.DefaultPhoto} src={itemConfig.image} alt={itemConfig.title} />
27+
</div>
28+
<div key="description" className={styles.DefaultDescription}>{itemConfig.description}</div>
29+
</div>
30+
</div>
31+
)
32+
}

client/src/containers/OrgEditor/SearchDrawer.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ import Divider from '@material-ui/core/Divider';
1111
import { TextOption } from 'components';
1212
import List from '@material-ui/core/List';
1313
import ListItem from '@material-ui/core/ListItem';
14-
import ListItemIcon from '@material-ui/core/ListItemIcon';
15-
import PersonIcon from '@material-ui/icons/Person';
16-
import ListItemText from '@material-ui/core/ListItemText';
1714
import { hideDrawer, setFilterText, setCursorItem } from 'redux/modules/demos/orgeditor';
15+
import NodeDragSource from './NodeDragSource';
1816

1917
const drawerWidth = 350;
2018

@@ -33,6 +31,11 @@ const useStyles = makeStyles((theme) => ({
3331
// necessary for content to be below app bar
3432
...theme.mixins.toolbar,
3533
justifyContent: 'flex-start',
34+
},
35+
listItem: {
36+
margin: theme.spacing(1),
37+
width: 220,
38+
height: 120
3639
}
3740
}));
3841

@@ -73,12 +76,9 @@ function SearchDrawer(props) { // eslint-disable-line react/prefer-stateless-fun
7376
onChange={value => dispatch(setFilterText(value))}
7477
/>
7578
<List aria-label="children-list">
76-
{filteredItems.map((value, index) => (
77-
<ListItem key={`item-${value.id}`} button onClick={() => dispatch(setCursorItem(value.id, isPrimary))}>
78-
<ListItemIcon>
79-
<PersonIcon />
80-
</ListItemIcon>
81-
<ListItemText primary={value.title} />
79+
{filteredItems.map((itemConfig, index) => (
80+
<ListItem className={styles.listItem} key={`item-${itemConfig.id}`} button onClick={() => dispatch(setCursorItem(itemConfig.id, isPrimary))}>
81+
<NodeDragSource itemConfig={itemConfig}></NodeDragSource>
8282
</ListItem>
8383
))}
8484
</List>

0 commit comments

Comments
 (0)