Skip to content

Selection of connections cannot be cleared #215

@ma-efremoff

Description

@ma-efremoff

In my case I prefer to control selected blocks and connection by myself. Selection/deselection of blocks works correctly, but there is an issue with connections. My hook to control selections looks like:

React.useEffect(() => {
        const selectionIds = new Set(selectedBlocks);
        const connections = !selectedBlocks?.length
            ? data.connections 
            : data?.connections?.map((item) => {
                  if (selectionIds.has(item.sourceBlockId!) || selectionIds.has(item.targetBlockId!)) {
                      return {selected: true, ...item};
                  }
                  return {selected: false, ...item};Ï
              });
        setEntities({...data, connections});
    }, [data, selectedBlocks, setEntities]);

It is important to stress that initially my data.connections don't have selected field(the field is missing for each connection). So I provide the field (selected) for connection only when there are some selected blocks. Then when I deselect all blocks setEntities is called again with initial connections (without selected field).

It looks like there is some issue of internal state of graph, cause I do provide new version of connections without selected: true fields but selected connections stays selected. And the issue might be fixed by explicitly provided selected: false field for each connection:

React.useEffect(() => {
        const selectionIds = new Set(selectedBlocks);
        const connections = !selectedBlocks?.length
            // ? data.connections                                             // previous version with the issue
            ? data.connections?.map((item) => ({...item, selected: false}))   // fixed version
            : data?.connections?.map((item) => {
                  if (selectionIds.has(item.sourceBlockId!) || selectionIds.has(item.targetBlockId!)) {
                      return {selected: true, ...item};
                  }
                  return {selected: false, ...item};Ï
              });
        setEntities({...data, connections});
    }, [data, selectedBlocks, setEntities]);

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions