MishkaCmsBuilder.Activity.EditorHistory (Mishka CMS Builder v0.0.1-alpha.2)

Copy Markdown View Source

Activity source for the visual editor's own record — every change somebody made to a page, layout, component or error page in the page builder, tagged badge_label: "EDITOR".

Why it needs a source of its own

No other adapter can see these. MishkaCmsBuilder.HistoryEvent is not AshPaperTrail versioned, is not an AshEvents log and is not an Oban job — it is a lean append-only table the editor writes as somebody works, which is exactly why the timeline in the editor is fast. That makes it invisible to the global feed unless something goes and reads it, which is this.

One store, two surfaces: the sheet inside the editor answers "what happened to THIS document", and the feed answers "what happened across the site". Neither is a copy of the other.

History only, and deliberately

The resource broadcasts nothing — pub_sub is off on it, because a row is written on every settled change and re-reading a table for everybody on every keystroke is the noise the whole design avoids. So topics/1 is empty and handles?/1 is always false: this contributes to the merged history read and never to the live tail. A change appears in the feed on the next read, which for a record of what happened is the right trade.

Two actions, in the feed's own vocabulary: publish for a publish, update for every other change — because the feed has one shared set of action words that every source reports in, and widening it for this one would change how the others render. Which change it was is in the message beside it, in the same words the editor's own timeline uses: "Set gap (base) — <nav>".

One more branch of the log's query

The global feed is one UNION ALL (MishkaCmsCore.Activity.Query), and this is the branch the editor adds to it, registered on activity:sources as a MishkaCmsCore.Activity.Behaviours.UnionSource: union_branch/1 writes the SQL over page_builder_events with the query's own clause builders, and entry_from_row/1 reads back the rows it produced, which carry source = 'editor'.

See MishkaCmsCore.Activity.Behaviours.Source for the live feed's half.

Summary

Functions

Returns a specification to start this module under a supervisor.

Callback implementation for MishkaInstaller.Event.Hook.enable/0.

Turns one merged row into a feed entry.

Callback implementation for MishkaInstaller.Event.Hook.get/0.

Optional. See MishkaInstaller.Event.Hook.health_check/0. Override to report health.

Callback implementation for MishkaInstaller.Event.Hook.register/0.

Callback implementation for MishkaInstaller.Event.Hook.restart/0.

The resources whose feeds this source contributes to.

Callback implementation for MishkaInstaller.Event.Hook.start/0.

Callback implementation for MishkaInstaller.Event.Hook.stop/0.

Types

error_return()

@type error_return() ::
  {:error, [%{action: atom(), field: atom(), message: String.t()}]}

okey_return()

@type okey_return() :: {:ok, struct() | map() | module() | [any()]}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

config()

@spec config() :: keyword()

config(key)

@spec config(atom()) :: any()

enable()

@spec enable() :: okey_return() | error_return()

Callback implementation for MishkaInstaller.Event.Hook.enable/0.

entry_from_row(row)

@spec entry_from_row(map()) :: map()

Turns one merged row into a feed entry.

Called by MishkaCmsCore.Activity.Query for rows union_branch/1 produced.

get()

@spec get() :: keyword()

Callback implementation for MishkaInstaller.Event.Hook.get/0.

health_check()

@spec health_check() :: :ok | {:degraded, term()} | {:error, term()}

Optional. See MishkaInstaller.Event.Hook.health_check/0. Override to report health.

on_dependency_error(error)

@spec on_dependency_error(term()) :: term()

Optional. See MishkaInstaller.Event.Hook.on_dependency_error/1. Override to react.

register()

@spec register() :: okey_return() | error_return()

Callback implementation for MishkaInstaller.Event.Hook.register/0.

restart()

@spec restart() :: okey_return() | error_return()

Callback implementation for MishkaInstaller.Event.Hook.restart/0.

scopes()

@spec scopes() :: %{required(String.t()) => String.t()}

The resources whose feeds this source contributes to.

start()

@spec start() :: okey_return() | error_return()

Callback implementation for MishkaInstaller.Event.Hook.start/0.

start_link(args \\ [])

stop()

@spec stop() :: okey_return() | error_return()

Callback implementation for MishkaInstaller.Event.Hook.stop/0.

unregister()

@spec unregister() :: okey_return() | error_return()

Callback implementation for MishkaInstaller.Event.Hook.unregister/0.