🚸 (editor) Improve editor performance by rounding paths
Related to #575
This commit is contained in:
@@ -58,7 +58,9 @@ export const Graph = ({
|
|||||||
const [debouncedGraphPosition] = useDebounce(graphPosition, 200)
|
const [debouncedGraphPosition] = useDebounce(graphPosition, 200)
|
||||||
const transform = useMemo(
|
const transform = useMemo(
|
||||||
() =>
|
() =>
|
||||||
`translate(${graphPosition.x}px, ${graphPosition.y}px) scale(${graphPosition.scale})`,
|
`translate(${Number(graphPosition.x.toFixed(2))}px, ${Number(
|
||||||
|
graphPosition.y.toFixed(2)
|
||||||
|
)}px) scale(${graphPosition.scale})`,
|
||||||
[graphPosition]
|
[graphPosition]
|
||||||
)
|
)
|
||||||
const { user } = useUser()
|
const { user } = useUser()
|
||||||
|
|||||||
@@ -39,10 +39,14 @@ export const SourceEndpoint = ({
|
|||||||
const endpointY = useMemo(
|
const endpointY = useMemo(
|
||||||
() =>
|
() =>
|
||||||
ref.current
|
ref.current
|
||||||
? (ref.current?.getBoundingClientRect().y +
|
? Number(
|
||||||
(endpointHeight * graphPosition.scale) / 2 -
|
(
|
||||||
graphPosition.y) /
|
(ref.current?.getBoundingClientRect().y +
|
||||||
graphPosition.scale
|
(endpointHeight * graphPosition.scale) / 2 -
|
||||||
|
graphPosition.y) /
|
||||||
|
graphPosition.scale
|
||||||
|
).toFixed(2)
|
||||||
|
)
|
||||||
: undefined,
|
: undefined,
|
||||||
// We need to force recompute whenever the group height and position changes
|
// We need to force recompute whenever the group height and position changes
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
|||||||
@@ -28,10 +28,14 @@ export const TargetEndpoint = ({
|
|||||||
const endpointY = useMemo(
|
const endpointY = useMemo(
|
||||||
() =>
|
() =>
|
||||||
ref.current
|
ref.current
|
||||||
? (ref.current?.getBoundingClientRect().y +
|
? Number(
|
||||||
(endpointHeight * graphPosition.scale) / 2 -
|
(
|
||||||
graphPosition.y) /
|
(ref.current?.getBoundingClientRect().y +
|
||||||
graphPosition.scale
|
(endpointHeight * graphPosition.scale) / 2 -
|
||||||
|
graphPosition.y) /
|
||||||
|
graphPosition.scale
|
||||||
|
).toFixed(2)
|
||||||
|
)
|
||||||
: undefined,
|
: undefined,
|
||||||
// We need to force recompute whenever the group height and position changes
|
// We need to force recompute whenever the group height and position changes
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
|||||||
@@ -170,8 +170,8 @@ const NonMemoizedDraggableGroupNode = ({
|
|||||||
setIsMouseDown(false)
|
setIsMouseDown(false)
|
||||||
}
|
}
|
||||||
const newCoord = {
|
const newCoord = {
|
||||||
x: offsetX / graphPosition.scale,
|
x: Number((offsetX / graphPosition.scale).toFixed(2)),
|
||||||
y: offsetY / graphPosition.scale,
|
y: Number((offsetY / graphPosition.scale).toFixed(2)),
|
||||||
}
|
}
|
||||||
setCurrentCoordinates(newCoord)
|
setCurrentCoordinates(newCoord)
|
||||||
onGroupDrag(newCoord)
|
onGroupDrag(newCoord)
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { Typebot } from '@typebot.io/schemas'
|
||||||
|
|
||||||
|
export const roundGroupsCoordinate = (typebot: Typebot): Typebot => {
|
||||||
|
const groups = typebot.groups.map((group) => {
|
||||||
|
const { x, y } = group.graphCoordinates
|
||||||
|
return {
|
||||||
|
...group,
|
||||||
|
graphCoordinates: { x: Number(x.toFixed(2)), y: Number(y.toFixed(2)) },
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return { ...typebot, groups }
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import { getTypebot } from '@/features/typebot/helpers/getTypebot'
|
|||||||
import { archiveResults } from '@/features/results/helpers/archiveResults'
|
import { archiveResults } from '@/features/results/helpers/archiveResults'
|
||||||
import { isReadTypebotForbidden } from '@/features/typebot/helpers/isReadTypebotForbidden'
|
import { isReadTypebotForbidden } from '@/features/typebot/helpers/isReadTypebotForbidden'
|
||||||
import { removeTypebotOldProperties } from '@/features/typebot/helpers/removeTypebotOldProperties'
|
import { removeTypebotOldProperties } from '@/features/typebot/helpers/removeTypebotOldProperties'
|
||||||
|
import { roundGroupsCoordinate } from '@/features/typebot/helpers/roundGroupsCoordinate'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req, res)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
@@ -36,7 +37,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
collaborators.find((c) => c.userId === user.id)?.type ===
|
collaborators.find((c) => c.userId === user.id)?.type ===
|
||||||
CollaborationType.READ
|
CollaborationType.READ
|
||||||
return res.send({
|
return res.send({
|
||||||
typebot: removeTypebotOldProperties(typebot),
|
typebot: roundGroupsCoordinate(
|
||||||
|
removeTypebotOldProperties(typebot) as Typebot
|
||||||
|
),
|
||||||
publishedTypebot,
|
publishedTypebot,
|
||||||
isReadOnly,
|
isReadOnly,
|
||||||
webhooks,
|
webhooks,
|
||||||
|
|||||||
Reference in New Issue
Block a user