Introduce turbo_stream_flash helper and use it for collection edit

The collections/{entropy,publications,workflows} controllers all
respond via turbo stream, and now also provide a flash message.
This commit is contained in:
Mike Dalessio
2025-08-07 14:14:18 -04:00
parent a8a8a46efa
commit 988b20a36d
6 changed files with 24 additions and 6 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