Commit db77fb80 authored by Caner Candan's avatar Caner Candan

feat(assembler): add child to either children prop or node prop

parent bfd381f3
Pipeline #18601289 skipped with stages
......@@ -54,7 +54,8 @@ export default class LeftDrawerComponent extends Component {
handleOnLeftDrawerCloseClick = () => {
debug('handleOnLeftDrawerCloseClick()')
const {
sessionId, session: { rightOpen }, updateSession,
sessionId, updateSession,
session: { rightOpen },
} = this.props
updateSession({
id: sessionId,
......@@ -68,7 +69,7 @@ export default class LeftDrawerComponent extends Component {
const {
classes, components,
OnAddComponentToCanvasClick,
session: { leftOpen },
session: { leftOpen, focusedOccurrence },
} = this.props
return (
<Drawer
......@@ -89,8 +90,19 @@ export default class LeftDrawerComponent extends Component {
<List>
{/* list components */}
{ Object.keys(components).map(type => (
// disable if only focused on an occurrence without a
// focused prop and disable if the focused type is
// not `node` or `any`
<ListItem
key={type}
disabled={
focusedOccurrence &&
!(focusedOccurrence &&
focusedOccurrence.focusedProp &&
(focusedOccurrence.focusedProp.type === 'node' ||
focusedOccurrence.focusedProp.type === 'any')
)
}
dense
button
onClick={OnAddComponentToCanvasClick({
......
......@@ -41,14 +41,23 @@ export const config = {
propParent: null,
}
// parent parent id to pass to mutation variables
if (focusedOccurrence && focusedOccurrence.id) {
if (focusedOccurrence && focusedOccurrence.id && focusedOccurrence.focusedProp) {
const { focusedProp } = focusedOccurrence
// if a prop is selected and it's a node, therefore the new
// occurrence is assigned to it
if (focusedProp && focusedProp.type === 'node' && focusedProp !== 'children') {
const {
id, name, type, oneOf, value,
} = focusedProp
const {
id, name, type, oneOf, value,
} = focusedProp
if (name === 'children') {
// if prop children selected, the new occurrence is assigned as a
// direct child of the parent occurrence
variablesFields.parentId = focusedOccurrence.id
optimisticFields.parent = {
id: focusedOccurrence.id,
__typename: 'Occurrence',
component: focusedOccurrence.component,
}
} else if (type === 'node') {
// if a non-children prop is selected and it's a node,
// the new occurrence is assigned to it
variablesFields.propParentId = focusedOccurrence.id
optimisticFields.propParent = {
id,
......@@ -59,15 +68,6 @@ export const config = {
value,
child: null,
}
} else {
// if no prop selected, the new occurrence is assigned as a
// direct child of the parent occurrence
variablesFields.parentId = focusedOccurrence.id
optimisticFields.parent = {
id: focusedOccurrence.id,
__typename: 'Occurrence',
component: focusedOccurrence.component,
}
}
}
// prepare props object to pass to mutatiton variables
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment