sequential-workflow-editor icon indicating copy to clipboard operation
sequential-workflow-editor copied to clipboard

Returning or passing variables between steps

Open zacherkkila opened this issue 9 months ago • 2 comments

I appreciate your work on this library, very cool!

Just so you know, I am not sure it makes a big difference, but I am using the React designer.

I have been trying to figure out the standard way to handle this rather than building a custom variable service of some sort.

Step A - Performs a computation and stores it to a variable Step B - Uses the variable/return from the previous step

It seems that the scope is limited to the step itself when the variable is defined within the step.

image

However, I need to use the result of Step A and feed that into Step B. It is not available here

image

From the docs

When a variable is defined in the parent scope, it can be accessed in the child scope, but not vice versa.

Is the "log" step in the image not a child of the "output" step? It seems they are more treated as independent functions rather than a parent/child relationship

What is the best way to handle this scenario? Essentially a return variable from one step and use that return variable in the next step.

Output Step

interface OuputStep extends Step {
  type: 'output'
  componentType: 'task'
  properties: {
    output: NullableVariableDefinition
    showVariable: NullableVariable
  }
}

export const Output = createStepModel<OuputStep>('output', 'task', (step) => {
  step.category('Output')
  step.label('Output')
  step.property('output').value(
    createNullableVariableDefinitionValueModel({
      valueType: 'number',
      isRequired: true,
      defaultValue: {
        name: 'test',
        type: 'number',
      },
    })
  )
  step
    .property('showVariable')
    .value(
      createNullableVariableValueModel({
        isRequired: true,
        valueType: 'number',
      })
    )
    .label('Value to Log')
})

Log Step

interface ValueLogStepDef extends Step {
  componentType: 'task'
  properties: {
    valueToLog: NullableVariable
    alert: boolean
  }
}

export const ValueLog = createStepModel<ValueLogStepDef>('log', 'task', (step) => {
  step.category('Tracing')

  step
    .property('valueToLog')
    .value(
      createNullableVariableValueModel({
        isRequired: true,
        valueType: 'number',
      })
    )
    .label('Value to Log')

  step.property('alert').value(createBooleanValueModel({})).label('Alert?')
})

Definition

  const definitionModel = useMemo(
    () =>
      createDefinitionModel<T>((model) => {
        model.valueTypes(['string', 'number'])
        model.root(rootModel)
        model.steps([OutputStep, ValueLogStep])
      }),
    []
  )

Thank you very much!

zacherkkila avatar May 23 '24 14:05 zacherkkila