Skip to content

fix(flash): restore autohide on server-rendered alerts#624

Open
jirkamotejl wants to merge 5 commits into
devel_35from
fix/server-rendered-flash-autohide
Open

fix(flash): restore autohide on server-rendered alerts#624
jirkamotejl wants to merge 5 commits into
devel_35from
fix/server-rendered-flash-autohide

Conversation

@jirkamotejl

Copy link
Copy Markdown
Contributor

Summary

  • Restore autohide: true support on Rails flash messages rendered through Folio::Console::Ui::FlashComponent — the flag was silently dropped in the Cells → ViewComponent refactor (3bc0859c5) after originally landing in autohide server-rendered alerts #393.
  • Add the missing Stimulus value (f-c-ui-alert-autohide-value) and connect() handler on the f-c-ui-alert controller. Replace the inline setTimeout in Ui.Alert.create with a dataset attribute so JS-created and server-rendered alerts share one autohide path.
  • Bump folio to 7.6.6.

Why

A host app sets redirect_to some_path, flash: { notice: t(".uploading_images"), autohide: true }. With the current code:

  1. FlashComponent filters out the autohide key (correct — it must not render as its own flash variant).
  2. AlertComponent does not accept autohide:, so it is not passed through.
  3. The Stimulus controller has only close (e) — no connect(), no autohide timer.

Result: the rendered alert sits on the page until the user clicks ✕ or reloads. JS-side flashes (Ui.Flash.info(msg, { autohide: true })) keep working because Ui.Alert.create carries its own inline setTimeout.

This PR restores parity for both code paths and consolidates them on the Stimulus controller.

What changed

  • app/components/folio/console/ui/alert_component.rb — new autohide: kwarg, emitted via stimulus_controller(..., values: { autohide: @autohide }).
  • app/components/folio/console/ui/flash_component.rb — read autohide from the input hash, expose via attr_reader, still filter the key out of the alert iteration.
  • app/components/folio/console/ui/flash_component.slim — pass autohide: autohide to AlertComponent.new.
  • app/components/folio/console/ui/alert_component.js:
    • Ui.Alert.create sets data-f-c-ui-alert-autohide-value (and optional …-autohide-delay-value) instead of running its own setTimeout.
    • Stimulus controller declares static values = { autohide: Boolean, autohideDelay: { type: Number, default: 5000 } }, starts the timer in connect(), clears it in disconnect() and close().
  • test/components/folio/console/ui/alert_component_test.rb, flash_component_test.rb — non-rendering specs covering the new wiring (#data and #autohide). Existing render_inline specs are unchanged; they fail locally on bundle exec rails test because of a pre-existing sprockets/sass issue (redactor.scss not found), unrelated to this PR.

Defaults & compatibility

  • Server flashes default to no autohide (autohide: false). Opt in by setting flash: { ..., autohide: true } in a controller — unchanged contract; it just works again.
  • FolioConsole.Ui.Alert.create({ autohide: true | false | <number> | undefined }) keeps the same semantics: autohide is on unless explicitly false; numeric values become autohideDelay (custom delay).

Test plan

  • Trigger a controller redirect_to with flash: { notice: "...", autohide: true } and confirm the alert disappears after 5 s without manual interaction.
  • Trigger a controller redirect_to with flash: { notice: "..." } (no autohide) and confirm the alert stays until ✕ / navigation.
  • Verify window.FolioConsole.Ui.Flash.info("hi") (or .success / .alert) still autohides — JS path.
  • Verify window.FolioConsole.Ui.Flash.info("hi", { autohide: false }) stays — JS path opt-out.
  • Click ✕ before autohide fires — alert closes immediately, no errors in console.

Related

  • Re-introduces behavior originally added in autohide server-rendered alerts #393 ("autohide server-rendered alerts"), which was inadvertently dropped by 3bc0859c5 refactor(components): console alert, console flash.

zanetagebka and others added 5 commits May 14, 2026 16:27
* fix(console): default file search results to newest first
Apply created_at DESC, id DESC ordering after filter_by_params in
 both HTML and JSON file controllers so newest uploads appear first regardless of active filter combination. User sort still wins via @sorted_by_param. Adds Folio::File.default_file_order scope.
…item (#618)

* fix(lightbox): respect placement-level metadata in stimulus_lightbox_item

When stimulus_lightbox_item is called with a Folio::FilePlacement::Base,
the helper now uses placement-level metadata instead of unwrapping to the
underlying file and only reading file metadata.

Behavior matrix:

- Standalone Folio::File argument: unchanged — caption comes from
  file.description, author from file.author.
- Placement without a description override: unchanged — placement.description
  is blank, so description_with_fallback falls back to file.description.
- Placement with a description override: caption now uses the placement's
  description (the value already shown in the visible figcaption that
  callers render via description_with_fallback). Previously the visible
  caption and the lightbox caption disagreed whenever an editor set a
  placement-specific description.
- Placement with file.attribution_source set: author now uses
  attribution_source first and falls back to file.author. This aligns the
  lightbox with Folio::File#credit_text and with how figcaptions/credits
  components have always rendered attribution.

A new author: keyword argument is added symmetric to the existing title:
argument. Both take precedence over the resolved defaults — call sites
that need to force a specific caption or attribution string can do so
without monkey-patching.

Tests cover six scenarios: standalone file, placement without override,
placement with description override, attribution_source precedence,
attribution_source fallback to author, and explicit title:/author:
overrides.

Bumps version to 7.7.0 — minor bump signals the behavioral change for
downstream consumers.

* chore(version): keep version at 7.6.5

Revert the version bump per review feedback — the previous commit pushed
7.6.5 → 7.7.0 to signal the behavioral change in stimulus_lightbox_item,
but downstream consumers in this repo's ecosystem pin folio by git SHA
rather than reading the gem version, so the bump isn't load-bearing.
The CHANGELOG entry under [Unreleased] already records the behavior
change for anyone reading release notes.
The Cells → ViewComponent refactor silently dropped the autohide
functionality previously delivered in #393. Server-side flashes set
with `flash: { ..., autohide: true }` were filtered through
FlashComponent but the flag never reached AlertComponent, and the
Stimulus controller `f-c-ui-alert` had no `connect()` handler — so
flashes from `redirect_to` stayed on screen until manually dismissed.

Restore the original UX:

- `Folio::Console::Ui::FlashComponent` exposes an `autohide` reader
  derived from the flash hash, passed down to each AlertComponent.
- `Folio::Console::Ui::AlertComponent` accepts an `autohide:` kwarg
  and renders it as a Stimulus value
  (`data-f-c-ui-alert-autohide-value`).
- The `f-c-ui-alert` Stimulus controller now reads `autohideValue`
  and `autohideDelayValue` (default 5000 ms), starts a `setTimeout`
  in `connect()`, and cancels it in `disconnect()` / `close()`.
- `FolioConsole.Ui.Alert.create` now sets the same dataset values
  instead of running its own inline `setTimeout`, so JS-created and
  server-rendered alerts share one autohide code path.

Defaults are unchanged: server flashes opt in via `autohide: true`;
`Ui.Alert.create` keeps autohide on unless `autohide: false` is
passed.

Bumps folio to 7.6.6.
…ed alerts

AlertComponent now accepts:
- `stimulus_controllers:` — array of extra Stimulus identifiers to mount
  alongside `f-c-ui-alert` on the root element.
- `data:` — hash of arbitrary `data-*` attributes merged onto the root.

FlashComponent forwards two new flash keys to AlertComponent:
- `alert_stimulus_controllers` → AlertComponent#stimulus_controllers
- `alert_data` → AlertComponent#data

This lets host apps attach custom Stimulus controllers and metadata to
flashes set by a controller `redirect_to … flash: { … }` without
monkey-patching either component. Example use case: a background-job
progress tracker that closes the flash when MessageBus events confirm
all enqueued jobs finished (success or error), with a per-photo
stop-bound timeout as fallback.

No behavior change for callers that don't pass the new args.
Sign up for free to 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.

3 participants