fix(flash): restore autohide on server-rendered alerts#624
Open
jirkamotejl wants to merge 5 commits into
Open
Conversation
* 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
autohide: truesupport on Rails flash messages rendered throughFolio::Console::Ui::FlashComponent— the flag was silently dropped in the Cells → ViewComponent refactor (3bc0859c5) after originally landing in autohide server-rendered alerts #393.f-c-ui-alert-autohide-value) andconnect()handler on thef-c-ui-alertcontroller. Replace the inlinesetTimeoutinUi.Alert.createwith a dataset attribute so JS-created and server-rendered alerts share one autohide path.Why
A host app sets
redirect_to some_path, flash: { notice: t(".uploading_images"), autohide: true }. With the current code:FlashComponentfilters out theautohidekey (correct — it must not render as its own flash variant).AlertComponentdoes not acceptautohide:, so it is not passed through.close (e)— noconnect(), 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 becauseUi.Alert.createcarries its own inlinesetTimeout.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— newautohide:kwarg, emitted viastimulus_controller(..., values: { autohide: @autohide }).app/components/folio/console/ui/flash_component.rb— readautohidefrom the input hash, expose viaattr_reader, still filter the key out of the alert iteration.app/components/folio/console/ui/flash_component.slim— passautohide: autohidetoAlertComponent.new.app/components/folio/console/ui/alert_component.js:Ui.Alert.createsetsdata-f-c-ui-alert-autohide-value(and optional…-autohide-delay-value) instead of running its ownsetTimeout.static values = { autohide: Boolean, autohideDelay: { type: Number, default: 5000 } }, starts the timer inconnect(), clears it indisconnect()andclose().test/components/folio/console/ui/alert_component_test.rb,flash_component_test.rb— non-rendering specs covering the new wiring (#dataand#autohide). Existingrender_inlinespecs are unchanged; they fail locally onbundle exec rails testbecause of a pre-existing sprockets/sass issue (redactor.scssnot found), unrelated to this PR.Defaults & compatibility
autohide: false). Opt in by settingflash: { ..., 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 explicitlyfalse; numeric values becomeautohideDelay(custom delay).Test plan
redirect_towithflash: { notice: "...", autohide: true }and confirm the alert disappears after 5 s without manual interaction.redirect_towithflash: { notice: "..." }(no autohide) and confirm the alert stays until ✕ / navigation.window.FolioConsole.Ui.Flash.info("hi")(or.success/.alert) still autohides — JS path.window.FolioConsole.Ui.Flash.info("hi", { autohide: false })stays — JS path opt-out.Related
3bc0859c5 refactor(components): console alert, console flash.