nocode-js / sequential-workflow-editor

Powerful workflow editor builder for any workflow designer.
https://nocode-js.com/
MIT License
86 stars 8 forks source link

Dynamic definition model & steps #32

Closed ggparente95 closed 5 months ago

ggparente95 commented 7 months ago

Hi! I'm triying to create steps on realtime, which means that my backend sends the information about which steps will be used and the corresponding definition of them. In my case, I have a variable with all the steps and the definition about them, and now I have a React Component that loops for all of them and generate the Step content. But I would like to use the swd-editor to avoid developing validations & features that the editor has.


export interface LogStep extends Step {
  type: 'log';
  componentType: 'task';
  properties: {
    message: string;
  };
}

export const definitionModel = createDefinitionModel<MyDefinition>(model => {
  model.valueTypes(['string', 'number']);
  model.root(rootModel);
  model.steps([logStepModel]);
});

Is there any chance to generate the StepTypes and definition model dynamically based on schema data sent from the backend?

Thanks in advance!

b4rtaz commented 7 months ago

Hello @ggparente95!

I'm not sure if I understand the question correctly, but I'll try to answer.

The definition model is created by using a builder, so the way how you call this builder is not restricted to constant types. For example, you can build the model from some external source.

const Q = [
   { type: "x", hasTitle: true,  hasAge: false },
   { type: "y", hasTitle: false, hasAge: true  },
];

const definitionModel = createDefinitionModel<MyDefinition>(model => {
  const steps = [];
  for (const q of Q) {
     steps.push(createStepModel(q.type 'task', step => {
        if (q.hasTitle) step.property('title').value(/* ... */);
        if (q.hasAge)   step.property('age').value(/* ... */);
     }));
  }
  model.steps(steps);
});

Of course that model cannot be updated after creation, but you can create a new model and reload the desinger.