Skip to content

Add host-wiring Embed macros, comment leaf-event forwarding, and V131 staff metadata migration - #585

Merged
ddon merged 4 commits into
BeamLabEU:mainfrom
mdon:main
Jun 7, 2026
Merged

Add host-wiring Embed macros, comment leaf-event forwarding, and V131 staff metadata migration#585
ddon merged 4 commits into
BeamLabEU:mainfrom
mdon:main

Conversation

@mdon

@mdonmdon commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Foundation/host-wiring improvements extracted while hardening the comment + AI-translation embedding patterns, plus the migration backing staff soft-delete.

Commits

  • Fix media detail comments: forward Leaf editor events to the component — the Leaf rich-text composer reports its content via a {:leaf_changed} process message to the host LiveView; media_detail wasn't forwarding it, so "Post Comment" silently posted empty content. Adds the runtime forward to CommentsComponent.forward_leaf_event/2 (+ catch-all).
  • Add AITranslate.Embed macro for host wiringPhoenixKitWeb.Components.AITranslate.Embed: an on_mount that injects the 6 identical ai_*handle_event clauses + the {:ai_translation}handle_info via attach_hook, removing the duplicated boilerplate every translate-form consumer was hand-copying. Default form re-sync matches the consumers' assign_form; optional ai_translate_assign_form/2 override.
  • Document required host wiring on callback-message components — loud "required host wiring / silent failure otherwise" moduledoc contracts on MediaSelectorModal, MarkdownEditor, and MediaGallery (these stay docs-only by design — per-consumer logic, not uniform boilerplate, so no macro).
  • Add V131 migration: metadata JSONB on staff people — general-purpose metadata JSONB NOT NULL DEFAULT '{}' on phoenix_kit_staff_people (mirrors entity_data); first consumer is staff soft-delete (stashes prior lifecycle status under metadata["trashed_from_status"]). Idempotent ADD COLUMN IF NOT EXISTS; @current_version → 131.

All compile clean against the integrated tree; no version/CHANGELOG bump (release-cut handled separately).

mdon added 4 commits June 7, 2026 09:44
media_detail embeds CommentsComponent but defined no handle_info, so the
composer's Leaf editor {:leaf_changed, ...} message (which carries the
comment content) was dropped by LiveView's default handler — "Post
Comment" silently no-opped. Add a handle_info that forwards it to
CommentsComponent.forward_leaf_event/2 (runtime-resolved; comments is
optional from core), plus a catch-all so other messages still no-op now
that handle_info is defined. Browser-verified: posting renders + count 0→1.
Every consumer of AITranslate.FormGlue (projects, catalogue) hand-
duplicated the same ~6 handle_event clauses (ai_toggle_modal /
ai_select_* / ai_generate_prompt / ai_translate_lang) plus the
handle_info({:ai_translation, ...}) that folds progress/result events
back into the form. Forgetting any was a silent failure (modal renders
but translations never run / progress never updates / form never
re-syncs).
`use PhoenixKitWeb.Components.AITranslate.Embed` injects all of it as
on_mount :handle_event / :handle_info lifecycle hooks, so it composes
with the form's own handlers (no clause-grouping clash, no clobbering) —
mirroring MediaBrowser.Embed / PhoenixKitComments.Embed. Form re-sync
defaults to assign(changeset:, form:) (the superset fitting every
consumer) with an optional ai_translate_assign_form/2 override.
Consumers still call FormGlue.assign_ai_translation/4 in mount (the
resource is dynamic).
MediaSelectorModal, MarkdownEditor and MediaGallery are LiveComponents
that report results by sending a process message to the host LiveView
(they have no handle_info of their own). Each consumer handles the
result with its own custom logic, so — unlike Comments/AITranslate —
there's no uniform boilerplate to fold into a `use ...Embed` macro.
Forgetting the host handler is a silent failure (selection/edit dropped,
no crash). Harden each moduledoc with an explicit "required host wiring"
contract spelling out the exact message(s) the host MUST handle and the
silent-failure consequence, and noting why there's deliberately no macro.
Docs only — no behavior change.
@ddon
ddon merged commit ca6e8bd into BeamLabEU:mainJun 7, 2026
ddon pushed a commit that referenced this pull request Jun 7, 2026
…d shadowing
Address Mistral review follow-ups on PR #585:
- Align media_detail.ex {:leaf_changed} forwarder with the canonical
MediaBrowser.Embed pattern: function_exported?/2 guard, apply/3 to avoid
compile-time binding to the optional phoenix_kit_comments dep, explicit
:pass handling, and Logger.warning on unexpected return values (was
silently swallowed).
- Add accurate moduledoc note to AITranslate.Embed clarifying that host
handle_info/handle_event clauses for AI events are shadowed by the
halting lifecycle hook (correcting the review's "double-fire" framing —
hooks run before the LV callback and halt, so host clauses never fire).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ddon pushed a commit that referenced this pull request Jun 7, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ddon pushed a commit that referenced this pull request Jun 7, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ddon pushed a commit that referenced this pull request Jun 7, 2026
The {:leaf_changed, _} forwarding block (optional-dep guard + apply/3 +
:pass/contract-drift handling) was duplicated near-verbatim between
MediaBrowser.Embed (macro-injected) and MediaDetail (inline). Extract it to
PhoenixKitWeb.CommentsForwarding so the phoenix_kit_comments contract lives in
one place; a future contract change updates one call site, not two.
Both handlers now delegate to forward_leaf_changed/2. The MediaBrowser.Embed
macro no longer injects `require Logger` into hosts — the only Logger use moved
into the shared module.
Addresses the cleanup finding from the PR #585 code review.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ddon pushed a commit that referenced this pull request Jun 7, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ddon pushed a commit that referenced this pull request Jun 7, 2026
Release entry for the PR #585 work + follow-ups: AITranslate.Embed macro,
V131 staff metadata migration, media-detail leaf-forwarding fix,
CommentsForwarding helper extraction, host-wiring docs, and dependency bumps.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mdon added a commit to mdon/phoenix_kit that referenced this pull request Jun 8, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@mdon@ddon