Show updated list of statuses in status dialog on apply

Before, the statuses in the list were only those read from the DB. Thus,
adding/removing statuses and clicking apply did not update the list
before saving the entire form
This commit is contained in:
Mir Bhatia
2026-03-18 12:29:35 +01:00
parent d9658acf35
commit bbf271abfe
4 changed files with 14 additions and 6 deletions
@@ -41,7 +41,8 @@ See COPYRIGHT and LICENSE files for more details.
label: role.name,
tag: :a,
href: helpers.edit_workflow_path(@type, role_id: role.id, tab: @tab || "always"),
active: role == @current_role
active: role == @current_role,
data: { turbo_frame: "_top" }
)
end
end
@@ -53,7 +54,7 @@ See COPYRIGHT and LICENSE files for more details.
scheme: :secondary,
leading_icon: :plus,
label: t("admin.workflows.status_button"),
href: helpers.status_dialog_workflows_path(role_id: @current_role&.id, type_id: @type&.id, tab: @tab),
href: helpers.status_dialog_workflows_path(role_id: @current_role&.id, type_id: @type&.id, tab: @tab, status_ids: @status_ids.presence),
data: { controller: "async-dialog" }
) do
t("admin.workflows.status_button")
@@ -32,12 +32,13 @@ module Workflows
class EditSubHeaderComponent < ApplicationComponent
include OpPrimer::ComponentHelpers
def initialize(tab:, current_role: nil, type: nil, available_roles: [])
def initialize(tab:, current_role: nil, type: nil, available_roles: [], status_ids: [])
super
@tab = tab
@current_role = current_role
@type = type
@available_roles = available_roles
@status_ids = status_ids
end
end
end
+7 -1
View File
@@ -102,7 +102,13 @@ class WorkflowsController < ApplicationController
def status_dialog
all_statuses = Status.order(:position)
current_statuses = @type && @role ? role_type_statuses : Status.none
current_statuses = if params[:status_ids].present?
Status.where(id: params[:status_ids].map(&:to_i)).order(:position)
elsif @type && @role
role_type_statuses
else
Status.none
end
respond_with_dialog Workflows::StatusDialogComponent.new(
all_statuses:,
+2 -2
View File
@@ -32,10 +32,10 @@ See COPYRIGHT and LICENSE files for more details.
<%= render Workflows::EditPageHeaderComponent.new(@type, tabs: workflow_tabs(@type)) %>
<% end %>
<%= render Workflows::EditSubHeaderComponent.new(tab: params[:tab], current_role: @role, type: @type, available_roles: @roles) %>
<% if @type && @role %>
<%= turbo_frame_tag "workflow-table" do %>
<%= render Workflows::EditSubHeaderComponent.new(tab: params[:tab], current_role: @role, type: @type, available_roles: @roles, status_ids: @statuses.pluck(:id)) %>
<% if @statuses.any? %>
<%= form_tag(
{ action: :update },