triggerForm = async (req, trigger) => {
  const roleOptions = (await User.get_roles()).map((r) => ({
    value: r.id,
    label: r.role,
  }));
  const actions = Trigger.abbreviated_actions;
  const tables = await Table.find({});
  let id;
  let form_action;
  if (typeof trigger !== "undefined") {
    id = trigger.id;
    form_action = `/actions/edit/${id}`;
  } else form_action = "/actions/new";
  form_action = addOnDoneRedirect(form_action, req);
  const hasChannel = Object.entries(getState().eventTypes)
    .filter(([k, v]) => v.hasChannel)
    .map(([k, v]) => k);

  const allActions = Trigger.action_options({
    notRequireRow: false,
    workflow: true,
  });
  const table_triggers = ["Insert", "Update", "Delete", "Validate"];
  const action_options = {};
  const actionsNotRequiringRow = Trigger.action_options({
    notRequireRow: true,
    workflow: true,
  });

  Trigger.when_options.forEach((t) => {
    if (table_triggers.includes(t)) action_options[t] = allActions;
    else action_options[t] = actionsNotRequiringRow;
  });
  const form = new Form({
    action: form_action,
    fields: [
      {
        name: "name",
        label: req.__("Name"),
        type: "String",
        required: true,
        attributes: { autofocus: true },
        sublabel: req.__("Name of action"),
      },
      {
        name: "when_trigger",
        label: req.__("When"),
        input_type: "select",
        required: true,
        options: Trigger.when_options.map((t) => ({ value: t, label: t })),
        sublabel: req.__("Event type which runs the trigger"),
        help: { topic: "Event types" },
        attributes: {
          explainers: {
            Often: req.__("Every 5 minutes"),
            Never: req.__(
              "Not scheduled but can be run as an action from a button click"
            ),
          },
        },
      },
      {
        name: "table_id",
        label: req.__("Table"),
        input_type: "select",
        options: [...tables.map((t) => ({ value: t.id, label: t.name }))],
        showIf: { when_trigger: table_triggers },
        sublabel: req.__(
          "The table for which the trigger condition is checked."
        ),
      },
      {
        name: "table_id",
        label: req.__("Table"),
        input_type: "select",
        options: [
          { value: "", label: "Table not set" },
          ...tables.map((t) => ({ value: t.id, label: t.name })),
        ],
        showIf: { when_trigger: "Never" },
        sublabel: req.__("Optionally associate a table with this trigger"),
      },
      {
        name: "channel",
        label: req.__("Time of day"),
        input_type: "time_of_day",
        showIf: { when_trigger: "Daily" },
        sublabel: req.__("UTC timezone"),
      },
      {
        name: "channel",
        label: req.__("Time to run"),
        input_type: "time_of_week",
        showIf: { when_trigger: "Weekly" },
        sublabel: req.__("UTC timezone"),
      },
      {
        name: "channel",
        label: req.__("Channel"),
        type: "String",
        sublabel: req.__("Leave blank for all channels"),
        showIf: { when_trigger: hasChannel },
      },
      {
        name: "action",
        label: req.__("Action"),
        type: "String",
        required: true,
        help: { topic: "Actions" },
        attributes: {
          calcOptions: ["when_trigger", action_options],
        },
        showIf: {
          when_trigger: Trigger.when_options.filter((t) => t !== "Never"),
        },
        sublabel: req.__("The action to be taken when the trigger fires"),
      },
      {
        name: "action",
        label: req.__("Action"),
        type: "String",
        required: true,
        help: { topic: "Actions" },
        attributes: {
          options: actionsNotRequiringRow,
        },
        showIf: {
          when_trigger: "Never",
          table_id: "",
        },
        sublabel: req.__("The action to be taken when the trigger fires"),
      },
      {
        name: "action",
        label: req.__("Action"),
        type: "String",
        required: true,
        help: { topic: "Actions" },
        attributes: {
          options: allActions,
        },
        showIf: {
          when_trigger: "Never",
          table_id: tables.map((t) => t.id),
        },
        sublabel: req.__("The action to be taken when the trigger fires"),
      },
      {
        name: "description",
        label: req.__("Description"),
        type: "String",
        fieldview: "textarea",
        sublabel: req.__(
          "Description allows you to give more information about the action"
        ),
      },
      {
        name: "min_role",
        label: req.__("Minimum role"),
        sublabel: req.__(
          "User must have this role or higher to make API call for action (trigger)"
        ),
        input_type: "select",
        showIf: { when_trigger: ["API call"] },
        options: roleOptions,
      },
      {
        name: "_raw_output",
        label: "Raw Output",
        parent_field: "configuration",
        sublabel: req.__("Do not wrap response in a success object"),
        type: "Bool",
        showIf: { when_trigger: ["API call"] },
      },
      {
        name: "_response_mime",
        label: "Response MIME type",
        parent_field: "configuration",
        type: "String",
        showIf: { when_trigger: ["API call"], _raw_output: true },
      },
    ],
  });
  // if (trigger) {
  //     form.hidden("id");
  //     form.values = trigger;
  //  }
  return form;
}
Trigger Edit Form
@param req
@param trigger
@returns {Promise<Form>}