Skip to content

Commit

Permalink
fix(composer): Allows nodes to be dropped at root level (#390)
Browse files Browse the repository at this point in the history
Co-authored-by: Emily Dodds <dodemily@amazon.com>
  • Loading branch information
mumanity and mumanity authored Dec 21, 2022
1 parent 7a24423 commit d9d7978
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/scene-composer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
"lines": 77.35,
"statements": 76.47,
"functions": 76.8,
"branches": 63.1,
"branches": 62.98,
"branchesTrue": 100
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/scene-composer/src/components/Tree/tree.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ $active-color: #ec7211;
position: relative;
user-select: none;

&:first-child {
padding-top: 1rem;
padding-bottom: 1rem;
}

&.drop,
.drop {
border-bottom: 3px solid #fff;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useCallback, useContext, useState } from 'react';
import React, { FC, useCallback, useContext, useMemo, useState } from 'react';
import { Object3D } from 'three';

import ISceneHierarchyNode from '../../model/ISceneHierarchyNode';
Expand Down Expand Up @@ -34,19 +34,18 @@ const SceneHierarchyTreeItem: FC<SceneHierarchyTreeItemProps> = ({

const model = getObject3DBySceneNodeRef(key) as Object3D | undefined;
const [childNodes] = useChildNodes(key);
const isValidModelRef = componentTypes?.find(
(type) =>
type === KnownComponentType.ModelRef &&
(type as unknown as IModelRefComponentInternal)?.modelType !== ModelType.Environment,
);

const [{ variation: subModelSelectionEnabled }] = useFeature(COMPOSER_FEATURES[COMPOSER_FEATURES.SubModelSelection]);
const showSubModel = subModelSelectionEnabled === 'T1' && isValidModelRef && !!model && !isViewing();
const sceneComposerId = useContext(sceneComposerIdContext);
const { getSceneNodeByRef } = useSceneDocument(sceneComposerId);
const node = getSceneNodeByRef(key);
const component = findComponentByType(node, KnownComponentType.ModelRef) as IModelRefComponentInternal;
const componentRef = component?.ref;
const isValidModelRef = useMemo(() => {
return component && component?.modelType !== ModelType.Environment;
}, [component]);
const [{ variation: subModelSelectionEnabled }] = useFeature(COMPOSER_FEATURES[COMPOSER_FEATURES.SubModelSelection]);
const showSubModel = subModelSelectionEnabled === 'T1' && isValidModelRef && !!model && !isViewing();
const isSubModel = !!findComponentByType(node, KnownComponentType.SubModelRef);
const componentRef = findComponentByType(node, KnownComponentType.ModelRef)?.ref;

const { searchTerms } = useSceneHierarchyData();
const isSearching = searchTerms !== '';

Expand Down Expand Up @@ -81,7 +80,7 @@ const SceneHierarchyTreeItem: FC<SceneHierarchyTreeItemProps> = ({
labelText={<SceneNodeLabel objectRef={key} labelText={labelText} componentTypes={componentTypes} />}
onExpand={onExpandNode}
expanded={expanded}
expandable={node && (node.childRefs.length > 0 || !!showSubModel) && !isSearching}
expandable={((node && node.childRefs.length > 0) || showSubModel) && !isSearching}
selected={selected === key}
selectionMode={selectionMode}
onSelected={isViewing() ? onActivated : onToggle}
Expand Down

0 comments on commit d9d7978

Please sign in to comment.