🐛 (editor) Graph connectors still displayed when switching to dynamic buttons
Closes #348
This commit is contained in:
@ -6,15 +6,12 @@ import { FormControl, FormLabel, Stack } from '@chakra-ui/react'
|
|||||||
import { ChoiceInputOptions, Variable } from 'models'
|
import { ChoiceInputOptions, Variable } from 'models'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
type ButtonsOptionsFormProps = {
|
type Props = {
|
||||||
options?: ChoiceInputOptions
|
options?: ChoiceInputOptions
|
||||||
onOptionsChange: (options: ChoiceInputOptions) => void
|
onOptionsChange: (options: ChoiceInputOptions) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ButtonsOptionsForm = ({
|
export const ButtonsBlockSettings = ({ options, onOptionsChange }: Props) => {
|
||||||
options,
|
|
||||||
onOptionsChange,
|
|
||||||
}: ButtonsOptionsFormProps) => {
|
|
||||||
const handleIsMultipleChange = (isMultipleChoice: boolean) =>
|
const handleIsMultipleChange = (isMultipleChoice: boolean) =>
|
||||||
options && onOptionsChange({ ...options, isMultipleChoice })
|
options && onOptionsChange({ ...options, isMultipleChoice })
|
||||||
const handleButtonLabelChange = (buttonLabel: string) =>
|
const handleButtonLabelChange = (buttonLabel: string) =>
|
||||||
|
@ -23,11 +23,13 @@ export const SourceEndpoint = ({
|
|||||||
}: BoxProps & {
|
}: BoxProps & {
|
||||||
source: Source
|
source: Source
|
||||||
}) => {
|
}) => {
|
||||||
|
const id = source.itemId ?? source.blockId
|
||||||
const color = useColorModeValue('blue.200', 'blue.100')
|
const color = useColorModeValue('blue.200', 'blue.100')
|
||||||
const connectedColor = useColorModeValue('blue.300', 'blue.200')
|
const connectedColor = useColorModeValue('blue.300', 'blue.200')
|
||||||
const bg = useColorModeValue('gray.100', 'gray.700')
|
const bg = useColorModeValue('gray.100', 'gray.700')
|
||||||
const { setConnectingIds, previewingEdge, graphPosition } = useGraph()
|
const { setConnectingIds, previewingEdge, graphPosition } = useGraph()
|
||||||
const { setSourceEndpointYOffset: addSourceEndpoint } = useEndpoints()
|
const { setSourceEndpointYOffset, deleteSourceEndpointYOffset } =
|
||||||
|
useEndpoints()
|
||||||
const { groupsCoordinates } = useGroupsCoordinates()
|
const { groupsCoordinates } = useGroupsCoordinates()
|
||||||
const ref = useRef<HTMLDivElement | null>(null)
|
const ref = useRef<HTMLDivElement | null>(null)
|
||||||
const [groupHeight, setGroupHeight] = useState<number>()
|
const [groupHeight, setGroupHeight] = useState<number>()
|
||||||
@ -75,12 +77,18 @@ export const SourceEndpoint = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!endpointY) return
|
if (!endpointY) return
|
||||||
const id = source.itemId ?? source.blockId
|
setSourceEndpointYOffset?.({
|
||||||
addSourceEndpoint?.({
|
|
||||||
id,
|
id,
|
||||||
y: endpointY,
|
y: endpointY,
|
||||||
})
|
})
|
||||||
}, [addSourceEndpoint, endpointY, source.blockId, source.itemId])
|
}, [setSourceEndpointYOffset, endpointY, id])
|
||||||
|
|
||||||
|
useEffect(
|
||||||
|
() => () => {
|
||||||
|
deleteSourceEndpointYOffset?.(id)
|
||||||
|
},
|
||||||
|
[deleteSourceEndpointYOffset, id]
|
||||||
|
)
|
||||||
|
|
||||||
useEventListener(
|
useEventListener(
|
||||||
'pointerdown',
|
'pointerdown',
|
||||||
|
@ -36,7 +36,7 @@ import { ZapierSettings } from '@/features/blocks/integrations/zapier'
|
|||||||
import { RedirectSettings } from '@/features/blocks/logic/redirect'
|
import { RedirectSettings } from '@/features/blocks/logic/redirect'
|
||||||
import { SetVariableSettings } from '@/features/blocks/logic/setVariable'
|
import { SetVariableSettings } from '@/features/blocks/logic/setVariable'
|
||||||
import { TypebotLinkForm } from '@/features/blocks/logic/typebotLink'
|
import { TypebotLinkForm } from '@/features/blocks/logic/typebotLink'
|
||||||
import { ButtonsOptionsForm } from '@/features/blocks/inputs/buttons'
|
import { ButtonsBlockSettings } from '@/features/blocks/inputs/buttons'
|
||||||
import { ChatwootSettingsForm } from '@/features/blocks/integrations/chatwoot'
|
import { ChatwootSettingsForm } from '@/features/blocks/integrations/chatwoot'
|
||||||
import { MakeComSettings } from '@/features/blocks/integrations/makeCom'
|
import { MakeComSettings } from '@/features/blocks/integrations/makeCom'
|
||||||
import { HelpDocButton } from './HelpDocButton'
|
import { HelpDocButton } from './HelpDocButton'
|
||||||
@ -150,7 +150,7 @@ export const BlockSettings = ({
|
|||||||
}
|
}
|
||||||
case InputBlockType.CHOICE: {
|
case InputBlockType.CHOICE: {
|
||||||
return (
|
return (
|
||||||
<ButtonsOptionsForm
|
<ButtonsBlockSettings
|
||||||
options={block.options}
|
options={block.options}
|
||||||
onOptionsChange={handleOptionsChange}
|
onOptionsChange={handleOptionsChange}
|
||||||
/>
|
/>
|
||||||
|
@ -14,6 +14,7 @@ export type Endpoint = {
|
|||||||
export const endpointsContext = createContext<{
|
export const endpointsContext = createContext<{
|
||||||
sourceEndpointYOffsets: Map<string, Endpoint>
|
sourceEndpointYOffsets: Map<string, Endpoint>
|
||||||
setSourceEndpointYOffset?: (endpoint: Endpoint) => void
|
setSourceEndpointYOffset?: (endpoint: Endpoint) => void
|
||||||
|
deleteSourceEndpointYOffset?: (endpointId: string) => void
|
||||||
targetEndpointYOffsets: Map<string, Endpoint>
|
targetEndpointYOffsets: Map<string, Endpoint>
|
||||||
setTargetEnpointYOffset?: (endpoint: Endpoint) => void
|
setTargetEnpointYOffset?: (endpoint: Endpoint) => void
|
||||||
}>({
|
}>({
|
||||||
@ -35,6 +36,13 @@ export const EndpointsProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
)
|
)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
const deleteSourceEndpointYOffset = useCallback((endpointId: string) => {
|
||||||
|
setSourceEndpoints((endpoints) => {
|
||||||
|
endpoints.delete(endpointId)
|
||||||
|
return endpoints
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
|
||||||
const setTargetEnpointYOffset = useCallback((endpoint: Endpoint) => {
|
const setTargetEnpointYOffset = useCallback((endpoint: Endpoint) => {
|
||||||
setTargetEndpoints((endpoints) =>
|
setTargetEndpoints((endpoints) =>
|
||||||
new Map(endpoints).set(endpoint.id, endpoint)
|
new Map(endpoints).set(endpoint.id, endpoint)
|
||||||
@ -47,6 +55,7 @@ export const EndpointsProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
sourceEndpointYOffsets,
|
sourceEndpointYOffsets,
|
||||||
targetEndpointYOffsets,
|
targetEndpointYOffsets,
|
||||||
setSourceEndpointYOffset,
|
setSourceEndpointYOffset,
|
||||||
|
deleteSourceEndpointYOffset,
|
||||||
setTargetEnpointYOffset,
|
setTargetEnpointYOffset,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
Reference in New Issue
Block a user