Skip to content

Commit

Permalink
Remove Variables From Insert Menu (#5862)
Browse files Browse the repository at this point in the history
**Problem:**
Variables in scope are causing a lot of noise in the insert menu.

**Fix:**
Remove the previously included variables in scope from the list of
insertable components by just not including the additional values.

**Commit Details:**
- Remove the addition of `getVariablesInScope` from
`useGetInsertableComponents`.

**Manual Tests:**
I hereby swear that:

- [x] I opened a hydrogen project and it loaded
- [x] I could navigate to various routes in Preview mode
  • Loading branch information
seanparsons authored Jun 7, 2024
1 parent 0b2dbb1 commit 17596c1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 45 deletions.
26 changes: 1 addition & 25 deletions editor/src/components/canvas/ui/floating-insert-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,29 +114,5 @@ export function useGetInsertableComponents(
}
}, [packageStatus, propertyControlsInfo, projectContents, dependencies, fullPath, insertMenuMode])

const scopedVariables = useEditorState(
Substores.variablesInScope,
(store) =>
getVariablesInScope(
store.editor.selectedViews[0],
projectContents,
store.editor.variablesInScope,
store.editor.jsxMetadata,
),
'useGetInsertableComponents scopedVariables',
)

const insertableVariables = React.useMemo(() => {
if (fullPath == null) {
return []
} else {
return convertInsertableComponentsToFlatList(convertVariablesToElements(scopedVariables))
}
}, [fullPath, scopedVariables])

if (insertMenuMode === 'insert') {
return insertableComponents.concat(insertableVariables)
} else {
return insertableComponents
}
return insertableComponents
}
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,6 @@ Array [
"/Symbol(react.forward_ref)(EmotionCssPropInternal)/Symbol(react.forward_ref)(TippyWrapper)/UtopiaSpiedFunctionComponent(Tippy)/UtopiaSpiedExoticType(Symbol(react.fragment))",
"/UtopiaSpiedFunctionComponent(Tippy)/UtopiaSpiedExoticType(Symbol(react.fragment))/Symbol(react.forward_ref)(Styled(div))/div",
"/Symbol(react.forward_ref)(Styled(div))/div/IndicatorArrow/div:data-testid='indicator-elements-outside-visible-area'",
"//UtopiaSpiedExoticType(Symbol(react.fragment))//Symbol(react.memo)()",
"//UtopiaSpiedExoticType(Symbol(react.fragment))//UtopiaSpiedFunctionComponent(it)",
"/UtopiaSpiedExoticType(Symbol(react.fragment))//UtopiaSpiedFunctionComponent(it)/UtopiaSpiedFunctionComponent($)",
"//UtopiaSpiedFunctionComponent(it)/UtopiaSpiedFunctionComponent($)/UtopiaSpiedExoticType(Symbol(react.provider))",
"/null///Symbol(react.memo)(Symbol(react.forward_ref)())",
"/null///UtopiaSpiedFunctionComponent(PropertyLabelAndPlusButton)",
"/null///Symbol(react.memo)(PropertyLabel)",
Expand Down Expand Up @@ -1034,10 +1030,6 @@ Array [
"/Symbol(react.forward_ref)(EmotionCssPropInternal)/Symbol(react.forward_ref)(TippyWrapper)/UtopiaSpiedFunctionComponent(Tippy)/UtopiaSpiedExoticType(Symbol(react.fragment))",
"/UtopiaSpiedFunctionComponent(Tippy)/UtopiaSpiedExoticType(Symbol(react.fragment))/Symbol(react.forward_ref)(Styled(div))/div",
"/Symbol(react.forward_ref)(Styled(div))/div/IndicatorArrow/div:data-testid='indicator-elements-outside-visible-area'",
"//UtopiaSpiedExoticType(Symbol(react.fragment))//Symbol(react.memo)()",
"//UtopiaSpiedExoticType(Symbol(react.fragment))//UtopiaSpiedFunctionComponent(it)",
"/UtopiaSpiedExoticType(Symbol(react.fragment))//UtopiaSpiedFunctionComponent(it)/UtopiaSpiedFunctionComponent($)",
"//UtopiaSpiedFunctionComponent(it)/UtopiaSpiedFunctionComponent($)/UtopiaSpiedExoticType(Symbol(react.provider))",
"/Symbol(react.forward_ref)(EmotionCssPropInternal)/div/FrameUpdatingLayoutControl/Symbol(react.memo)(NumberInput)",
"/Symbol(react.forward_ref)(EmotionCssPropInternal)/div/FrameUpdatingLayoutControl/UtopiaSpiedFunctionComponent(InspectorContextMenuWrapper)",
"/div/FrameUpdatingLayoutControl/UtopiaSpiedFunctionComponent(InspectorContextMenuWrapper)/UtopiaSpiedFunctionComponent(MenuProvider)",
Expand Down Expand Up @@ -2087,10 +2079,6 @@ Array [
"/Symbol(react.forward_ref)(EmotionCssPropInternal)/div/UtopiaSpiedFunctionComponent(ContextMenu)/UtopiaSpiedFunctionComponent(it)",
"/div/UtopiaSpiedFunctionComponent(ContextMenu)/UtopiaSpiedFunctionComponent(it)/UtopiaSpiedFunctionComponent($)",
"/UtopiaSpiedFunctionComponent(ContextMenu)/UtopiaSpiedFunctionComponent(it)/UtopiaSpiedFunctionComponent($)/UtopiaSpiedExoticType(Symbol(react.provider))",
"//UtopiaSpiedExoticType(Symbol(react.fragment))//Symbol(react.memo)()",
"//UtopiaSpiedExoticType(Symbol(react.fragment))//UtopiaSpiedFunctionComponent(it)",
"/UtopiaSpiedExoticType(Symbol(react.fragment))//UtopiaSpiedFunctionComponent(it)/UtopiaSpiedFunctionComponent($)",
"//UtopiaSpiedFunctionComponent(it)/UtopiaSpiedFunctionComponent($)/UtopiaSpiedExoticType(Symbol(react.provider))",
"/UtopiaSpiedFunctionComponent(Provider)/UtopiaSpiedExoticType(Symbol(react.fragment))/UtopiaSpiedFunctionComponent(ComponentRenderer(storyboard))/Symbol(react.forward_ref)(SpyWrapper)",
"/UtopiaSpiedFunctionComponent(Provider)/UtopiaSpiedExoticType(Symbol(react.fragment))/UtopiaSpiedFunctionComponent(ComponentRenderer(storyboard))/Symbol(react.forward_ref)(SpyWrapper)",
"/UtopiaSpiedFunctionComponent(Provider)/UtopiaSpiedExoticType(Symbol(react.fragment))/UtopiaSpiedFunctionComponent(ComponentRenderer(storyboard))/Symbol(react.forward_ref)(SpyWrapper)",
Expand Down Expand Up @@ -2836,10 +2824,6 @@ Array [
"/div/div/UtopiaSpiedFunctionComponent(NewCanvasControlsInner)/Symbol(react.memo)(SelectionAreaRectangle)",
"/div/div/UtopiaSpiedFunctionComponent(NewCanvasControlsInner)/UtopiaSpiedExoticType(Symbol(react.fragment))",
"/Symbol(react.forward_ref)(Styled(div))/div/Symbol(react.forward_ref)(Styled(div))/div",
"//UtopiaSpiedExoticType(Symbol(react.fragment))//Symbol(react.memo)()",
"//UtopiaSpiedExoticType(Symbol(react.fragment))//UtopiaSpiedFunctionComponent(it)",
"/UtopiaSpiedExoticType(Symbol(react.fragment))//UtopiaSpiedFunctionComponent(it)/UtopiaSpiedFunctionComponent($)",
"//UtopiaSpiedFunctionComponent(it)/UtopiaSpiedFunctionComponent($)/UtopiaSpiedExoticType(Symbol(react.provider))",
"/UtopiaSpiedFunctionComponent(Provider)/UtopiaSpiedExoticType(Symbol(react.fragment))/UtopiaSpiedFunctionComponent(ComponentRenderer(storyboard))/Symbol(react.forward_ref)(SpyWrapper)",
"/UtopiaSpiedFunctionComponent(Provider)/UtopiaSpiedExoticType(Symbol(react.fragment))/UtopiaSpiedFunctionComponent(ComponentRenderer(storyboard))/Symbol(react.forward_ref)(SpyWrapper)",
"/UtopiaSpiedFunctionComponent(Provider)/UtopiaSpiedExoticType(Symbol(react.fragment))/UtopiaSpiedFunctionComponent(ComponentRenderer(storyboard))/Symbol(react.forward_ref)(SpyWrapper)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('React Render Count Tests -', () => {

const renderCountAfter = renderResult.getNumberOfRenders()
// if this breaks, GREAT NEWS but update the test please :)
expect(renderCountAfter - renderCountBefore).toMatchInlineSnapshot(`744`)
expect(renderCountAfter - renderCountBefore).toMatchInlineSnapshot(`740`)
expect(renderResult.getRenderInfo()).toMatchSnapshot()
})

Expand Down Expand Up @@ -127,7 +127,7 @@ describe('React Render Count Tests -', () => {

const renderCountAfter = renderResult.getNumberOfRenders()
// if this breaks, GREAT NEWS but update the test please :)
expect(renderCountAfter - renderCountBefore).toMatchInlineSnapshot(`909`)
expect(renderCountAfter - renderCountBefore).toMatchInlineSnapshot(`905`)
expect(renderResult.getRenderInfo()).toMatchSnapshot()
})

Expand Down Expand Up @@ -183,7 +183,7 @@ describe('React Render Count Tests -', () => {

const renderCountAfter = renderResult.getNumberOfRenders()
// if this breaks, GREAT NEWS but update the test please :)
expect(renderCountAfter - renderCountBefore).toMatchInlineSnapshot(`536`)
expect(renderCountAfter - renderCountBefore).toMatchInlineSnapshot(`532`)
expect(renderResult.getRenderInfo()).toMatchSnapshot()
})

Expand Down Expand Up @@ -249,7 +249,7 @@ describe('React Render Count Tests -', () => {

const renderCountAfter = renderResult.getNumberOfRenders()
// if this breaks, GREAT NEWS but update the test please :)
expect(renderCountAfter - renderCountBefore).toMatchInlineSnapshot(`650`)
expect(renderCountAfter - renderCountBefore).toMatchInlineSnapshot(`646`)
expect(renderResult.getRenderInfo()).toMatchSnapshot()
})
})

0 comments on commit 17596c1

Please sign in to comment.