Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importing node with custom dropdown are not properly initilaized #709

Open
1 task done
Rajeshwaran2001 opened this issue Jun 5, 2024 · 3 comments
Open
1 task done
Labels

Comments

@Rajeshwaran2001
Copy link

Rajeshwaran2001 commented Jun 5, 2024

Describe the bug

storing node and connection data to local storage

const nodes = editor.getNodes();
      const nodesString = JSON.stringify(nodes);
      const connections = JSON.stringify(editor.getConnections());

importing stored node and connection from local storage

const storedNodesString = localStorage.getItem('nodesData');
  const connectionDetails = localStorage.getItem('connectionData');
  async function importForParent(nodes: any[], parent = undefined) {
    const ctnodes = nodes.filter(node => node.parent === parent)
      for (const node of ctnodes) {
      await editor.addNode(node)
      await importForParent(nodes, node.id)
    }
  }

  async function importConnection(data: any[]) {
    const connections  = data;
    for (const c of connections) {
      const source = editor.getNode(c.source);
      const target = editor.getNode(c.target);

      if (
        source &&
        target &&
        (source.outputs as any)[c.sourceOutput] &&
        (target.inputs as any)[c.targetInput]
      ) {
        const conn = new Connection(
          source,
          c.sourceOutput as never,
          target,
          c.targetInput as never
        );

        await editor.addConnection(conn);
      }
    }
  }

  if (storedNodesString !== null) {
    const storedNodes = JSON.parse(storedNodesString);
    await importForParent(storedNodes)
  }
  else {
    await editor.addNode(startNode);
    await editor.addNode(endNode);
  }

  if(connectionDetails !== null) {
    const nodeconnection = JSON.parse(connectionDetails);
    await importConnection(nodeconnection);
  }
class AddNode extends Classic.Node implements DataflowNode {
  width = 209;
  height = 315;

  constructor(private customService: CustomDropdownService) {
    super('Processing Setup');
    this.addInput('a', new Classic.Input(socket, 'connect'));
    this.addOutput('b', new Classic.Output(socket, 'Success'));
    this.addOutput('value', new Classic.Output(socket, 'Failed'));

    this.addControl('CustomLinkControl', new CustomLinkControl());
    this.addControl('CustomDropDownControl', new CustomDropDownControl(customService));
    this.addControl('CustomMultilineTextControl', new CustomMultilineTextControl());

  }

  data() {
    return {};
  }
}

this is my node here CustomDropDownControl is not rendering when i am importing from json

Example to reproduce

No response

How to reproduce

  • Export node with custom drop down to JSON
  • Import JSON data to editor

Expected behavior

i have a custom drop down and Link Control but when am importing from JSON it renders default input control but i want it to render my custom controls

Dependencies

rete - 2.0.1

Platform

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Ni55aN
Copy link
Member

Ni55aN commented Jun 8, 2024

editor.addNode should accept AddNode instance. Instead, it receives JSON object

@Rajeshwaran2001
Copy link
Author

Rajeshwaran2001 commented Jun 9, 2024

Thanks that worked but how to set value to each control.

async function importForParent(nodes: any[], parent = undefined) {
    const ctnodes = nodes.filter(node => node.parent === parent)    
    for (const node of ctnodes) {
      if (node.label =='Processing Setup') {
        var addNode = new AddNode(customDropdownService);
        addNode.id = node.id;
        addNode.label = node.label;
        await editor.addNode(addNode)
      }
      else
        await editor.addNode(node)      
      await importForParent(nodes, node.id)
    }
  }

@Ni55aN
Copy link
Member

Ni55aN commented Jul 28, 2024

Thanks that worked but how to set value to each control.

It depends on the implementation of your control class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants