Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(composer): submodel and hierarchy search fix #320

Merged
merged 1 commit into from
Nov 4, 2022

Conversation

sheilaXu
Copy link
Contributor

@sheilaXu sheilaXu commented Nov 4, 2022

Overview

  • fix the issue where only root nodes can be searched
  • only show the matching nodes in a flat list, not their children
  • gate sub-model feature with flag
  • show SubModelTree for ModelRef component and fix duplicated trees when sub model is promoted to a node

search issue:

search-issue-viewing.mov

search fix:

search-fix-viewing.mov

sub-model issue:

submodel-issue.mov

sub-model fix:

submodel-fix.mov

Legal

This project is available under the Apache 2.0 License.

@sheilaXu sheilaXu marked this pull request as ready for review November 4, 2022 02:02
}: ISceneNodeInternal | Readonly<ISceneNodeInternal>) => {
const toSceneHeirarchyNode = (
{ ref, name, parentRef, childRefs = [], components }: ISceneNodeInternal | Readonly<ISceneNodeInternal>,
hideChild?: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this belongs here, this is kind of polluting the object model. Hiding children in search results is a view concern, it shouldn't affect the underlying data model.

Suggestion: We could move the filtering logic to the getChildNodes hook instead, and just make that aware of the search filters or similar.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be the simplest way to achieve this though, so it's fine.


const getChildNodes = useCallback(
(parentRef?: string) => {
const nodeMap = useStore(sceneComposerId).getState().document.nodeMap;
const results = Object.values(nodeMap)
.filter((node) => node.parentRef === parentRef)
.map(toSceneHeirarchyNode)
.map((node) => toSceneHeirarchyNode(node))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change creates an unnecessary wrapping function. Super minor, but it's technically another pointer the GC needs to clean up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the map function auto provide a number as second parameter, so if I don't wrap it, there will be error

@@ -196,7 +196,7 @@ const SceneHierarchyDataProvider: FC<SceneHierarchyDataProviderProps> = ({ selec
<DndProvider backend={HTML5Backend}>
<Context.Provider
value={{
rootNodes: rootNodes.map(toSceneHeirarchyNode),
rootNodes: rootNodes.map((node) => toSceneHeirarchyNode(node, !isEmpty(searchTerms))),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this, I would almost prefer to see a "filteredNodes" property passed through context instead, but we can save that for when we rework search properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a filter callback? that's probably more scalable. i can have a try in my next change

@@ -47,7 +48,8 @@ const SceneHierarchyTreeItem: FC<SceneHierarchyTreeItemProps> = ({
(type as unknown as IModelRefComponentInternal)?.modelType !== ModelType.Environment,
);

const showSubModel = isValidModelRef && !!model && !isViewing();
const [{ variation: subModelSelectionEnabled }] = useFeature(COMPOSER_FEATURES[COMPOSER_FEATURES.SubModelSelection]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just pass useFeature(COMPOSER_FEATURES.SubModelSelection)? Curious if the extra nesting is really necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm following how useFeature is used for other features, not quite sure why we did this.... probably because this COMPOSER_FEATURES enum used to be int enum not string enum..

</React.Fragment>
))}
{showSubModel && <SubModelTree parentRef={key} expanded={false} object3D={model!} selectable />}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads up that my incoming change will move this back into the React.Fragment with fixes for hierarchy placement. Non-blocking, but please let me know if you have any concerns with this regarding your fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't put it into the Fragment because this tree is for the root ModelRef node, not for the child SubModelRef nodes. the current code breaks submodel feature because when I create a new scene and add a model to it, I won't be able to see the tree and cannot add sub model ref component to the scene, so this tree never show up

@sheilaXu sheilaXu merged commit 364cefb into main Nov 4, 2022
@sheilaXu sheilaXu deleted the fix-hierarchy-search branch November 4, 2022 16:16
@github-actions github-actions bot mentioned this pull request Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants