Alternera.Plugin.Editor.LocationPicker (alternera_plugin_editor v0.9.0)

Copy Markdown View Source

The From and To of a step editor (TransformEditor, Script.Editor, RequestEditor): a place of the exchange (Alternera.Plugin.Location) picked as a kind (a select) and, for it, a name or a JSON path (a text field, with the source exchange's header and query names or body paths as suggestions, hints/2).

A role ("source", "target") is stored in the step's settings as %{"in" => kind, "name" | "path" => text} (a variable may have both: its name and a path inside it, read or written, from a second field, the -path input), and left out when it is the default, the side's whole body, so a step that keeps it is stored as before. Only the kinds the step's side allows are offered (Location.allowed/3); one stored before a direction switch is shown, marked, and refused on save.

The inputs are named <prefix>-loc-<role>-in and <prefix>-loc-<role>-address and report through the editor's own location event (or the one event names), which hands its params to changed/4. A caller that knows better than the side what fits (a row of a To list, TargetList) passes the kinds itself; the response status, one of them, takes no name. Changing the kind clears the field. A field reports alone (its own phx-change), so its kind is the one stored.

A source may also name an earlier step's output ({"in": "steps", "id": …, "output": …}, Plugin.StepOutputs): the steps before this one (steps_before, from EditorTree.steps_before/2) each give an option per output of their plugin (outputs/0), in a "Step output" group of the kind select, valued steps:<id>:<output>. An output that takes a key (keyed?: a header, a named output) shows a key field (<prefix>-loc-<role>-key), suggesting the keys the step is known to give it (keys, from the plugin's output_keys/1), and a path field under it, as a variable does; any other output an optional JSON path in the address field. A target never offers them: step outputs are read only.

An Outer pipeline parameter ({"in": "outer", "name": …}, spec 059 Q10, spec 063 D6) is a target only, a name and no path: an inner pipeline writes it for the wrappers around it, which declare it as a parameter of kind inner and read it as input.<name> after their Continue. It is offered as a target on every side and never as a source (Location.allowed/3 refuses reading it); the save refuses a write no wrapper declares (Changes.ValidateDeclarations).

Context ({"in": "context", "name": …}, spec 063 FR-020) is a source on every side, a name and an optional path inside its value. As a target it is a name and no path (context is written whole), offered only while the pipeline declares context: the pipeline editor puts the declared names in the hints (name_hints[:context]), which suggest them in the name field; without any, the To place is left out unless a stored target already names it. The save refuses a write of an undeclared name, or from anywhere but Before (Changes.ValidateDeclarations).

Summary

Functions

The settings after a location event: {:ok, settings} with the role the changed input belongs to stored as typed (or dropped as the default), :error when the event is not a picker's.

The kind a role names when nothing is stored: the side's whole body, and for an answer step the request body it reads and the response body it writes (Plugin.Location.own_body/1).

The first of errors about role (role_of_error/1), or nil.

The grid the pickers sit in, one row each: label, symbol, kind and field in columns, so From and To line up and the field takes the rest of the width. In a narrow panel the kind select gives way (its text cut) before the field gets narrower than 9rem.

The suggestions a field gets, by kind, as the SuggestInput hook reads them (JSON, or nil without any): the source exchange's header and query names (PipelinesLive.NameHints), its bodies' JSON paths, and the parameters of the pipeline's path template (:path, which the pipeline editor adds). Names only, never values. A header kind offers the recorded names first, then the common ones (Editor.HeaderSuggestions), so it suggests something with no exchange.

The kinds a role may name on a side, as {value, label}. side is the step's direction (Runner.side_direction/2): "request" in Before reads and writes the request only, "response" in After writes the response only, "answer" (the own Implementation steps, which make the response) reads and writes both (Plugin.Location.allowed/3).

Whether a save error names the place location picks, though it is not worded about a role or a row: a check of the whole pipeline names what a step writes in its own words. An Outer pipeline parameter is the inner parameter of the pipelines around ("writes inner parameter a, b after …", "inner parameter a is declared …"). A picker shown such an error outlines its fields (picker/1's errors).

One role's picker: its label, the symbol of its kind, the kind select and the field.

The role a save error is about ("source", "target", "input", "each"), or nil: the plugins word a location's refusal as Transform source: …, Script target: …, or Transform: a request step cannot read … / … cannot write … for one its direction does not allow, and a Request step's as Request: source: … / Request: target… (Plugin.Location.allowed/3), and a row of any plugin's To list as Request: To row 2 (…): … (whatever the plugin puts before To row, Plugin.Targets.row_error/1), a target shown at its row by TargetList (a one-row list, Transform's, at its target picker), and a Set step's row as Set value 2: …, which Plugins.Set.Editor shows at the row; "input" is a Call's or a For each's input row, Call: input 2: … (Plugin.RowError), which the Call editor shows at the input; "each" is a For each's array, For each: each: …, shown at its Each picker. The pipeline editor leaves these out of the step's error box, since the editor shows them at their place.

{:ok, id, output} for a step_kind/2 value, else :error.

The kind select's value for step id's output: steps:<id>:<output> (a step id never holds a colon, Pipelines.Step).

Functions

changed(params, prefix, settings, side)

@spec changed(map(), String.t(), map(), String.t()) :: {:ok, map()} | :error

The settings after a location event: {:ok, settings} with the role the changed input belongs to stored as typed (or dropped as the default), :error when the event is not a picker's.

default_body(arg1, side)

@spec default_body(String.t(), String.t()) :: String.t()

The kind a role names when nothing is stored: the side's whole body, and for an answer step the request body it reads and the response body it writes (Plugin.Location.own_body/1).

error_for(errors, role)

@spec error_for([String.t()], String.t()) :: String.t() | nil

The first of errors about role (role_of_error/1), or nil.

grid(assigns)

The grid the pickers sit in, one row each: label, symbol, kind and field in columns, so From and To line up and the field takes the rest of the width. In a narrow panel the kind select gives way (its text cut) before the field gets narrower than 9rem.

Attributes

  • id (:string) (required)

Slots

  • inner_block (required)

hints(name_hints, json_paths)

@spec hints(map(), map()) :: %{required(String.t()) => String.t() | list() | nil}

The suggestions a field gets, by kind, as the SuggestInput hook reads them (JSON, or nil without any): the source exchange's header and query names (PipelinesLive.NameHints), its bodies' JSON paths, and the parameters of the pipeline's path template (:path, which the pipeline editor adds). Names only, never values. A header kind offers the recorded names first, then the common ones (Editor.HeaderSuggestions), so it suggests something with no exchange.

"vars" are the variables the pipeline's steps name (:vars). "outer" are the inner parameters the wrappers around the pipeline declare (:outer), the names an Outer pipeline parameter may write. "template" is not JSON but the ${…} references the pipeline knows (TemplateSuggestions.base/1), which the "Text or a template" kind offers with the outputs of the steps before.

kinds(arg1, arg2)

@spec kinds(String.t(), String.t()) :: [{String.t(), String.t()}]

The kinds a role may name on a side, as {value, label}. side is the step's direction (Runner.side_direction/2): "request" in Before reads and writes the request only, "response" in After writes the response only, "answer" (the own Implementation steps, which make the response) reads and writes both (Plugin.Location.allowed/3).

names_location?(message, arg2)

@spec names_location?(String.t(), map()) :: boolean()

Whether a save error names the place location picks, though it is not worded about a role or a row: a check of the whole pipeline names what a step writes in its own words. An Outer pipeline parameter is the inner parameter of the pipelines around ("writes inner parameter a, b after …", "inner parameter a is declared …"). A picker shown such an error outlines its fields (picker/1's errors).

picker(assigns)

One role's picker: its label, the symbol of its kind, the kind select and the field.

Attributes

  • prefix (:string) (required)
  • role (:string) (required)
  • label (:string) (required)
  • side (:string) (required)
  • settings (:map) (required)
  • hints (:map) (required)
  • target (:any) (required)
  • input_class (:string) (required)
  • error (:string) - a save error about this role, shown under its row. Defaults to nil.
  • errors (:list) - the step's save errors: one that names the place picked (names_location?/2) outlines the fields, its text in their title (the step's error box says it). Defaults to [].
  • kinds (:list) - the kinds offered, as {value, label} (default: what the role may name on the side). Defaults to nil.
  • event (:string) - the editor's event the inputs report through. Defaults to "location".
  • paths (:boolean) - whether a body takes a JSON path (Transform) or is always whole (Script). Defaults to true.
  • steps_before (:list) - the earlier steps a source may read, %{id, outputs} with the plugin's outputs/0 (EditorTree.steps_before/2). Defaults to [].

role_of_error(message)

@spec role_of_error(String.t()) :: String.t() | nil

The role a save error is about ("source", "target", "input", "each"), or nil: the plugins word a location's refusal as Transform source: …, Script target: …, or Transform: a request step cannot read … / … cannot write … for one its direction does not allow, and a Request step's as Request: source: … / Request: target… (Plugin.Location.allowed/3), and a row of any plugin's To list as Request: To row 2 (…): … (whatever the plugin puts before To row, Plugin.Targets.row_error/1), a target shown at its row by TargetList (a one-row list, Transform's, at its target picker), and a Set step's row as Set value 2: …, which Plugins.Set.Editor shows at the row; "input" is a Call's or a For each's input row, Call: input 2: … (Plugin.RowError), which the Call editor shows at the input; "each" is a For each's array, For each: each: …, shown at its Each picker. The pipeline editor leaves these out of the step's error box, since the editor shows them at their place.

step_kind(kind)

@spec step_kind(String.t()) :: {:ok, String.t(), String.t()} | :error

{:ok, id, output} for a step_kind/2 value, else :error.

step_kind(id, output)

@spec step_kind(String.t(), String.t()) :: String.t()

The kind select's value for step id's output: steps:<id>:<output> (a step id never holds a colon, Pipelines.Step).