Skip to content

Commit

Permalink
add menu, handle moving and destroying
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Dec 12, 2024
1 parent 9d9f34c commit 280a668
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ See COPYRIGHT and LICENSE files for more details.
else
definitions.each do |definition|
component.with_row(data: { "projects--settings--border-box-filter-target": "searchItem" }) do
render(Settings::ProjectLifeCycleStepDefinitions::RowComponent.new(definition))
render(Settings::ProjectLifeCycleStepDefinitions::RowComponent.new(
definition,
first?: definition == definitions.first,
last?: definition == definitions.last,
))
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,40 @@ See COPYRIGHT and LICENSE files for more details.
render(Primer::Beta::Text.new) { t("project.count", count: definition.project_count) }
end
end
row_container.with_column do
render(Primer::Alpha::ActionMenu.new) do |menu|
menu.with_show_button(icon: "kebab-horizontal", "aria-label": t(:button_actions), scheme: :invisible)

menu.with_item(
label: t(:label_edit),
href: edit_admin_settings_project_life_cycle_step_definition_path(definition)
) do |item|
item.with_leading_visual_icon(icon: :pencil)
end

unless first?
move_action(menu:, move_to: :highest, label: t("label_agenda_item_move_to_top"), icon: "move-to-top")
move_action(menu:, move_to: :higher, label: t("label_agenda_item_move_up"), icon: "chevron-up")
end
unless last?
move_action(menu:, move_to: :lower, label: t("label_agenda_item_move_down"), icon: "chevron-down")
move_action(menu:, move_to: :lowest, label: t("label_agenda_item_move_to_bottom"), icon: "move-to-bottom")
end

menu.with_item(
label: t(:text_destroy),
scheme: :danger,
href: admin_settings_project_life_cycle_step_definition_path(definition),
form_arguments: {
method: :delete,
data: {
confirm: t("text_are_you_sure_with_project_life_cycle_step")
}
}
) do |item|
item.with_leading_visual_icon(icon: :trash)
end
end
end
end
%>
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ class RowComponent < ApplicationComponent
include OpTurbo::Streamable

alias_method :definition, :model

options :first?, :last?

private

def move_action(menu:, move_to:, label:, icon:)
menu.with_item(
label:,
href: move_admin_settings_project_life_cycle_step_definition_path(definition, move_to:),
form_arguments: {
method: :patch
}
) do |item|
item.with_leading_visual_icon(icon:)
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ProjectLifeCycleStepDefinitionsController < ::Admin::SettingsController
before_action :check_feature_flag

before_action :find_definitions, only: %i[index]
before_action :find_definition, only: %i[edit update]
before_action :find_definition, only: %i[edit update destroy move]

def index; end

Expand Down Expand Up @@ -73,6 +73,28 @@ def update
end
end

def destroy
if @definition.destroy
flash[:notice] = I18n.t(:notice_successful_delete)
else
# TODO: handle better
flash[:error] = I18n.t(:notice_bad_request)
end

redirect_to action: :index
end

def move
if @definition.update(params.permit(:move_to))
flash[:notice] = I18n.t(:notice_successful_update)
else
# TODO: handle better
flash[:error] = I18n.t(:notice_bad_request)
end

redirect_to action: :index
end

private

def check_feature_flag
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3758,6 +3758,7 @@ en:
text_are_you_sure_continue: "Are you sure you want to continue?"
text_are_you_sure_with_children: "Delete work package and all child work packages?"
text_are_you_sure_with_project_custom_fields: "Deleting this attribute will also delete its values in all projects. Are you sure you want to do this?"
text_are_you_sure_with_project_life_cycle_step: "Deleting this step will also delete its usages in all projects. Are you sure you want to do this?"
text_assign_to_project: "Assign to the project"
text_form_configuration: >
You can customize which fields will be displayed in work package forms.
Expand Down
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,14 @@
resource :projects, controller: "/admin/settings/projects_settings", only: %i[show update]
resource :new_project, controller: "/admin/settings/new_project_settings", only: %i[show update]
resources :project_life_cycle_step_definitions, controller: "/admin/settings/project_life_cycle_step_definitions",
only: %i[index create edit update] do
only: %i[index create edit update destroy] do
collection do
get :new_stage
get :new_gate
end
member do
patch :move
end
end
resources :project_custom_fields, controller: "/admin/settings/project_custom_fields" do
member do
Expand Down

0 comments on commit 280a668

Please sign in to comment.