getWorkflowConfig = async (req, id, table, trigger) => {
  let steps = await WorkflowStep.find(
    { trigger_id: trigger.id },
    { orderBy: "id" }
  );
  const initial_step = steps.find((step) => step.initial_step);
  if (initial_step)
    steps = [initial_step, ...steps.filter((s) => !s.initial_step)];
  const trigCfgForm = new Form({
    action: addOnDoneRedirect(`/actions/configure/${id}`, req),
    onChange: "saveAndContinue(this)",
    noSubmitButton: true,
    formStyle: "vert",
    fields: [
      {
        name: "save_traces",
        label: "Save step traces for each run",
        type: "Bool",
      },
    ],
  });
  trigCfgForm.values = trigger.configuration;
  let copilot_form = "";

  if (getState().functions.copilot_generate_workflow) {
    copilot_form = renderForm(
      new Form({
        action: `/actions/gen-copilot/${id}`,
        values: { description: trigger.description || "" },
        submitLabel: "Generate workflow with copilot",
        formStyle: "vert",
        fields: [
          {
            name: "description",
            label: "Description",
            type: "String",
            fieldview: "textarea",
          },
        ],
      }),
      req.csrfToken()
    );
  }
  return (
    copilot_form +
    pre({ class: "mermaid" }, WorkflowStep.generate_diagram(steps)) +
    script(
      { defer: "defer" },
      `function tryAddWFNodes() {
  const ns = $("g.node");
  if(!ns.length) setTimeout(tryAddWFNodes, 200)
  else {
    $("i.add-btw-nodes").on("click", (e)=>{
      const $e = $(e.target || e);
      const cls = $e.attr('class');
      const idnext = cls.split(" ").find(c=>c.startsWith("btw-nodes-")).
          substr(10);
      const [idprev, nmnext] = idnext.split("-");
      if(cls.includes("init-for-body"))
        location.href = '/actions/stepedit/${trigger.id}?after_step_for='+idprev+'&before_step='+nmnext;
      else
        location.href = '/actions/stepedit/${trigger.id}?after_step='+idprev+'&before_step='+nmnext;
    })
    $("g.node").on("click", (e)=>{
       const $e = $(e.target || e).closest("g.node")
       const cls = $e.attr('class')
       if(!cls) return;      
       //console.log(cls)
       if(cls.includes("wfstep")) {
       const id = cls.split(" ").find(c=>c.startsWith("wfstep")).
          substr(6);
       location.href = '/actions/stepedit/${trigger.id}/'+id;
       }
       if(cls.includes("wfaddstart")) {
         location.href = '/actions/stepedit/${trigger.id}?initial_step=true';
       } else if(cls.includes("wfadd")) {
         const id = cls.split(" ").find(c=>c.startsWith("wfadd")).
          substr(5);
         location.href = '/actions/stepedit/${trigger.id}?after_step='+id;
       }
      //console.log($e.attr('class'), id)
     })
  }
}
window.addEventListener('DOMContentLoaded',tryAddWFNodes)`
    ) +
    a(
      {
        href: `/actions/stepedit/${trigger.id}${
          initial_step ? "" : "?initial_step=true"
        }`,
        class: "btn btn-secondary",
      },
      i({ class: "fas fa-plus me-2" }),
      "Add step"
    ) +
    a(
      {
        href: `/actions/runs/?trigger=${trigger.id}`,
        class: "d-block",
      },
      "Show runs &raquo;"
    ) +
    renderForm(trigCfgForm, req.csrfToken())
  );
}
POST for existing trigger (Save trigger)
@name /edit/:id
@function
@memberof module:routes/actions~actionsRouter