Refactor and clean up

This commit is contained in:
Mir Bhatia
2026-04-28 16:18:03 +02:00
parent eea4c36b7c
commit 9e0a7367fe
4 changed files with 10 additions and 11 deletions
@@ -77,7 +77,7 @@ See COPYRIGHT and LICENSE files for more details.
<% if @statuses.any? %>
<%= form_tag(
workflow_tab_path(@type),
id: "workflow_form",
id: form_id,
method: :patch,
autocomplete: "off",
data: {
@@ -33,6 +33,8 @@ module Workflows
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
FORM_ID = "workflow_form"
def initialize(tab:, roles:, type:, available_roles:, statuses:, has_status_changes:)
super
@tab = tab
@@ -45,12 +47,14 @@ module Workflows
private
def form_id = FORM_ID
def data_attributes
{
controller: "admin--workflow-role-select",
"admin--workflow-role-select-base-url-value": helpers.edit_workflow_tab_path(@type, @tab),
"admin--workflow-role-select-current-role-ids-value": @roles.map(&:id).join(","),
"admin--workflow-role-select-admin--workflow-checkbox-state-outlet": "#workflow_form"
"admin--workflow-role-select-current-role-ids-value": @roles.map(&:id),
"admin--workflow-role-select-admin--workflow-checkbox-state-outlet": "##{form_id}"
}
end
end
-4
View File
@@ -56,10 +56,6 @@ class WorkflowsController < ApplicationController
@types = ::Type.order(:position)
end
def find_role
@role = eligible_roles.find(params[:role_id])
end
def find_type
@type = ::Type.find(params[:type_id])
end
@@ -38,12 +38,12 @@ import WorkflowCheckboxStateController from './workflow-checkbox-state.controlle
*/
export default class WorkflowRoleSelectController extends Controller {
static outlets = ['admin--workflow-checkbox-state'];
static values = { baseUrl: String, currentRoleIds: String };
static values = { baseUrl: String, currentRoleIds: Array };
declare readonly adminWorkflowCheckboxStateOutlet:WorkflowCheckboxStateController;
declare readonly hasAdminWorkflowCheckboxStateOutlet:boolean;
declare baseUrlValue:string;
declare currentRoleIdsValue:string;
declare currentRoleIdsValue:unknown[];
connect() {
this.element.addEventListener('panelClosed', this.handlePanelClosed);
@@ -66,8 +66,7 @@ export default class WorkflowRoleSelectController extends Controller {
return;
}
const currentIds = this.currentRoleIdsValue.split(',').filter(Boolean);
if (selectedIds.slice().sort().join(',') === currentIds.slice().sort().join(',')) return;
if (selectedIds.slice().sort().join(',') === this.currentRoleIdsValue.slice().sort().join(',')) return;
this.navigateTo(this.buildUrl(selectedIds as string[]));
};