🐛 (editor) Fix bug preventing user to manually zoom in / out
Closes #156
This commit is contained in:
@@ -179,20 +179,20 @@ export const Graph = ({
|
|||||||
useEventListener('click', handleClick, editorContainerRef.current)
|
useEventListener('click', handleClick, editorContainerRef.current)
|
||||||
useEventListener('mousemove', handleMouseMove)
|
useEventListener('mousemove', handleMouseMove)
|
||||||
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
const zoomIn = () => zoom(zoomButtonsScaleBlock)
|
||||||
const zoomIn = useCallback(() => zoom(zoomButtonsScaleBlock), [])
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
const zoomOut = () => zoom(-zoomButtonsScaleBlock)
|
||||||
const zoomOut = useCallback(() => zoom(-zoomButtonsScaleBlock), [])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DraggableCore onDrag={onDrag} enableUserSelectHack={false}>
|
<DraggableCore onDrag={onDrag} enableUserSelectHack={false}>
|
||||||
<Flex ref={graphContainerRef} position="relative" {...props}>
|
<Flex ref={graphContainerRef} position="relative" {...props}>
|
||||||
<ZoomButtons onZoomIn={zoomIn} onZoomOut={zoomOut} />
|
<ZoomButtons onZoomInClick={zoomIn} onZoomOutClick={zoomOut} />
|
||||||
<Flex
|
<Flex
|
||||||
flex="1"
|
flex="1"
|
||||||
w="full"
|
w="full"
|
||||||
h="full"
|
h="full"
|
||||||
position="absolute"
|
position="absolute"
|
||||||
|
data-testid="graph"
|
||||||
style={{
|
style={{
|
||||||
transform,
|
transform,
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
import { Stack, IconButton } from '@chakra-ui/react'
|
import { Stack, IconButton } from '@chakra-ui/react'
|
||||||
import { PlusIcon, MinusIcon } from 'assets/icons'
|
import { PlusIcon, MinusIcon } from 'assets/icons'
|
||||||
import { memo } from 'react'
|
|
||||||
import { headerHeight } from '../TypebotHeader'
|
import { headerHeight } from '../TypebotHeader'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onZoomIn: () => void
|
onZoomInClick: () => void
|
||||||
onZoomOut: () => void
|
onZoomOutClick: () => void
|
||||||
}
|
}
|
||||||
export const ZoomButtons = memo(({ onZoomIn, onZoomOut }: Props) => (
|
export const ZoomButtons = ({
|
||||||
|
onZoomInClick: onZoomIn,
|
||||||
|
onZoomOutClick: onZoomOut,
|
||||||
|
}: Props) => (
|
||||||
<Stack
|
<Stack
|
||||||
pos="fixed"
|
pos="fixed"
|
||||||
top={`calc(${headerHeight}px + 70px)`}
|
top={`calc(${headerHeight}px + 70px)`}
|
||||||
@@ -20,7 +22,7 @@ export const ZoomButtons = memo(({ onZoomIn, onZoomOut }: Props) => (
|
|||||||
>
|
>
|
||||||
<IconButton
|
<IconButton
|
||||||
icon={<PlusIcon />}
|
icon={<PlusIcon />}
|
||||||
aria-label={'Zoom out'}
|
aria-label={'Zoom in'}
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={onZoomIn}
|
onClick={onZoomIn}
|
||||||
bgColor="white"
|
bgColor="white"
|
||||||
@@ -35,4 +37,4 @@ export const ZoomButtons = memo(({ onZoomIn, onZoomOut }: Props) => (
|
|||||||
borderTopRadius={0}
|
borderTopRadius={0}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
))
|
)
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ test('Drag and drop blocks and items should work', async ({ page }) => {
|
|||||||
'Item 3'
|
'Item 3'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
test('Undo / Redo buttons should work', async ({ page }) => {
|
test('Undo / Redo and Zoom buttons should work', async ({ page }) => {
|
||||||
const typebotId = cuid()
|
const typebotId = cuid()
|
||||||
await createTypebots([
|
await createTypebots([
|
||||||
{
|
{
|
||||||
@@ -132,6 +132,22 @@ test('Undo / Redo buttons should work', async ({ page }) => {
|
|||||||
await expect(page.locator('text="Group #1"')).toBeVisible()
|
await expect(page.locator('text="Group #1"')).toBeVisible()
|
||||||
await page.click('button[aria-label="Redo"]')
|
await page.click('button[aria-label="Redo"]')
|
||||||
await expect(page.locator('text="Group #1"')).toBeHidden()
|
await expect(page.locator('text="Group #1"')).toBeHidden()
|
||||||
|
await page.getByRole('button', { name: 'Zoom in' }).click()
|
||||||
|
await expect(page.getByTestId('graph')).toHaveAttribute(
|
||||||
|
'style',
|
||||||
|
/scale\(1\.2\);$/
|
||||||
|
)
|
||||||
|
await page.getByRole('button', { name: 'Zoom in' }).click()
|
||||||
|
await expect(page.getByTestId('graph')).toHaveAttribute(
|
||||||
|
'style',
|
||||||
|
/scale\(1\.4\);$/
|
||||||
|
)
|
||||||
|
await page.getByRole('button', { name: 'Zoom out' }).dblclick()
|
||||||
|
await page.getByRole('button', { name: 'Zoom out' }).dblclick()
|
||||||
|
await expect(page.getByTestId('graph')).toHaveAttribute(
|
||||||
|
'style',
|
||||||
|
/scale\(0\.6\);$/
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Rename and icon change should work', async ({ page }) => {
|
test('Rename and icon change should work', async ({ page }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user