Merge pull request #867 from basecamp/flavorjones/collections-flash

Collections controllers render flash notices
This commit is contained in:
Mike Dalessio
2025-08-07 15:06:59 -04:00
committed by GitHub
8 changed files with 34 additions and 13 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
class ApplicationController < ActionController::Base
include Authentication, CurrentRequest, CurrentTimezone, SetPlatform, WriterAffinity
include Authentication, CurrentRequest, CurrentTimezone, SetPlatform, TurboFlash, WriterAffinity
stale_when_importmap_changes
allow_browser versions: :modern
@@ -4,7 +4,10 @@ class Collections::EntropyConfigurationsController < ApplicationController
def update
@collection.entropy_configuration.update!(entropy_configuration_params)
render turbo_stream: turbo_stream.replace([ @collection, :entropy_configuration ], partial: "collections/edit/auto_close", locals: { collection: @collection })
render turbo_stream: [
turbo_stream.replace([ @collection, :entropy_configuration ], partial: "collections/edit/auto_close", locals: { collection: @collection }),
turbo_stream_flash(notice: "Saved")
]
end
private
@@ -3,12 +3,18 @@ class Collections::PublicationsController < ApplicationController
def create
@collection.publish
render turbo_stream: turbo_stream.replace([ @collection, :publication ], partial: "collections/edit/publication", locals: { collection: @collection })
render turbo_stream: [
turbo_stream.replace([ @collection, :publication ], partial: "collections/edit/publication", locals: { collection: @collection }),
turbo_stream_flash(notice: "Saved")
]
end
def destroy
@collection.unpublish
@collection.reload
render turbo_stream: turbo_stream.replace([ @collection, :publication ], partial: "collections/edit/publication", locals: { collection: @collection })
render turbo_stream: [
turbo_stream.replace([ @collection, :publication ], partial: "collections/edit/publication", locals: { collection: @collection }),
turbo_stream_flash(notice: "Saved")
]
end
end
@@ -5,7 +5,10 @@ class Collections::WorkflowsController < ApplicationController
def update
@collection.update! workflow: @workflow
render turbo_stream: turbo_stream.replace([ @collection, :workflows ], partial: "collections/edit/workflows", locals: { collection: @collection })
render turbo_stream: [
turbo_stream.replace([ @collection, :workflows ], partial: "collections/edit/workflows", locals: { collection: @collection }),
turbo_stream_flash(notice: "Saved")
]
end
private
+1 -1
View File
@@ -19,7 +19,7 @@ class CollectionsController < ApplicationController
@collection.update! collection_params
@collection.accesses.revise granted: grantees, revoked: revokees if grantees_changed?
redirect_to edit_collection_path(@collection), notice: "Changes saved"
redirect_to edit_collection_path(@collection), notice: "Saved"
end
def destroy
+6
View File
@@ -0,0 +1,6 @@
module TurboFlash
private
def turbo_stream_flash(**flash_options)
turbo_stream.replace(:flash, partial: "layouts/shared/flash", locals: { flash: flash_options })
end
end
+1 -7
View File
@@ -8,13 +8,7 @@
<%= yield :header %>
</header>
<% if notice = flash[:notice] || flash[:alert] %>
<div class="flash" data-controller="element-removal" data-action="animationend->element-removal#remove">
<div class="flash__inner shadow">
<%= notice %>
</div>
</div>
<% end %>
<%= render "layouts/shared/flash" %>
<main id="main">
<%= yield %>
+9
View File
@@ -0,0 +1,9 @@
<%= turbo_frame_tag :flash do %>
<% if notice = flash[:notice] || flash[:alert] %>
<div class="flash" data-controller="element-removal" data-action="animationend->element-removal#remove">
<div class="flash__inner shadow">
<%= notice %>
</div>
</div>
<% end %>
<% end %>