Skip to content

Commit

Permalink
Merge branch 'dev' into bug/59060-missing-hint-in-comment-box-label
Browse files Browse the repository at this point in the history
  • Loading branch information
jjabari-op authored Nov 18, 2024
2 parents 6d8c973 + 34719e1 commit af82b55
Show file tree
Hide file tree
Showing 716 changed files with 9,918 additions and 4,098 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/codeql-scan-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches: [ "dev", "release/*", "stable/*" ]
pull_request:
branches: [ "dev", "release/*", "stable/*" ]
paths-ignore:
- 'docs/**'
schedule:
- cron: '32 1 * * 2'

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/rubocop-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: rubocop

on:
pull_request:
paths-ignore:
- 'docs/**'

jobs:
rubocop:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ gem "appsignal", "~> 3.10.0", require: false

gem "view_component"
# Lookbook
gem "lookbook", "~> 2.3.3"
gem "lookbook", "~> 2.3.4"

# Require factory_bot for usage with openproject plugins testing
gem "factory_bot", "~> 6.5.0", require: false
Expand Down
22 changes: 10 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,8 @@ GEM
activerecord (>= 4.0)
awesome_nested_set (3.7.0)
activerecord (>= 4.0.0, < 8.0)
awrence (1.2.1)
aws-eventstream (1.3.0)
aws-partitions (1.996.0)
aws-partitions (1.1001.0)
aws-sdk-core (3.211.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.992.0)
Expand All @@ -351,7 +350,7 @@ GEM
aws-sdk-kms (1.95.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sigv4 (~> 1.5)
aws-sdk-s3 (1.169.0)
aws-sdk-s3 (1.170.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.5)
Expand Down Expand Up @@ -438,7 +437,7 @@ GEM
bigdecimal
rexml
crass (1.0.6)
css_parser (1.19.0)
css_parser (1.19.1)
addressable
csv (3.3.0)
cuprite (0.15.1)
Expand Down Expand Up @@ -703,7 +702,7 @@ GEM
launchy (3.0.1)
addressable (~> 2.8)
childprocess (~> 5.0)
lefthook (1.8.1)
lefthook (1.8.2)
letter_opener (1.10.0)
launchy (>= 2.2, < 4)
letter_opener_web (3.0.0)
Expand All @@ -727,7 +726,7 @@ GEM
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
lookbook (2.3.3)
lookbook (2.3.4)
activemodel
css_parser
htmlbeautifier (~> 1.3)
Expand Down Expand Up @@ -1062,7 +1061,7 @@ GEM
secure_headers (7.0.0)
selenium-devtools (0.129.0)
selenium-webdriver (~> 4.2)
selenium-webdriver (4.25.0)
selenium-webdriver (4.26.0)
base64 (~> 0.2)
logger (~> 1.4)
rexml (~> 3.2, >= 3.2.5)
Expand Down Expand Up @@ -1147,8 +1146,8 @@ GEM
public_suffix
vcr (6.3.1)
base64
vernier (1.2.1)
view_component (3.19.0)
vernier (1.3.1)
view_component (3.20.0)
activesupport (>= 5.2.0, < 8.1)
concurrent-ruby (~> 1.0)
method_source (~> 1.0)
Expand All @@ -1160,9 +1159,8 @@ GEM
rack (>= 2.0.9)
warden-basic_auth (0.2.1)
warden (~> 1.2)
webauthn (3.1.0)
webauthn (3.2.2)
android_key_attestation (~> 0.3.0)
awrence (~> 1.1)
bindata (~> 2.4)
cbor (~> 0.5.9)
cose (~> 1.1)
Expand Down Expand Up @@ -1273,7 +1271,7 @@ DEPENDENCIES
letter_opener_web
listen (~> 3.9.0)
lograge (~> 0.14.0)
lookbook (~> 2.3.3)
lookbook (~> 2.3.4)
mail (= 2.8.1)
markly (~> 0.10)
matrix (~> 0.4.2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ See COPYRIGHT and LICENSE files for more details.
<%=
component_wrapper(tag: "turbo-frame", refresh: :morph) do
if show_edit_form?
render Admin::CustomFields::Hierarchy::ItemFormComponent.new(
target_item: model,
url: custom_field_item_path(@root.custom_field_id, model),
method: :put
)
if show_form?
render Admin::CustomFields::Hierarchy::ItemFormComponent.new(model)
else
flex_layout(align_items: :center, justify_content: :space_between, test_selector: "op-custom-fields--hierarchy-item") do |item_container|
item_container.with_column(flex_layout: true) do |item_information|
item_information.with_column(mr: 2) do
render(Primer::OpenProject::DragHandle.new(draggable: true))
end
item_information.with_column(mr: 2) do
render(Primer::Beta::Link.new(href: custom_field_item_path(@root.custom_field_id, model), underline: false)) do
render(Primer::Beta::Text.new(font_weight: :bold)) { model.label }
Expand All @@ -62,8 +61,7 @@ See COPYRIGHT and LICENSE files for more details.
menu.with_show_button(icon: "kebab-horizontal",
scheme: :invisible,
"aria-label": I18n.t("custom_fields.admin.items.actions"))
edit_action_item(menu)
deletion_action_item(menu)
menu_items(menu)
end
end
end
Expand Down
122 changes: 113 additions & 9 deletions app/components/admin/custom_fields/hierarchy/item_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ItemComponent < ApplicationComponent
def initialize(item:, show_edit_form: false)
super(item)
@show_edit_form = show_edit_form
@root = item.root
@root = item.root || item.parent.root
end

def wrapper_uniq_by
Expand All @@ -49,29 +49,133 @@ def short_text
"(#{model.short})"
end

def show_edit_form? = @show_edit_form
def show_form? = @show_edit_form || model.new_record?

def children_count
I18n.t("custom_fields.admin.hierarchy.subitems", count: model.children.count)
end

def deletion_action_item(menu)
menu.with_item(label: I18n.t(:button_delete),
scheme: :danger,
tag: :a,
href: deletion_dialog_custom_field_item_path(custom_field_id: @root.custom_field_id, id: model.id),
content_arguments: { data: { controller: "async-dialog" } }) do |item|
item.with_leading_visual_icon(icon: :trash)
def first_item?
model.sort_order == 0
end

def last_item?
model.sort_order == model.parent.children.length - 1
end

def menu_items(menu)
edit_action_item(menu)
menu.with_divider
add_above_action_item(menu)
add_below_action_item(menu)
add_sub_item_action_item(menu)
menu.with_divider
if !first_item?
move_to_top_action_item(menu)
move_up_action_item(menu)
end
if !last_item?
move_down_action_item(menu)
move_to_bottom_action_item(menu)
end
menu.with_divider
deletion_action_item(menu)
end

private

def edit_action_item(menu)
menu.with_item(label: I18n.t(:button_edit),
tag: :a,
href: edit_custom_field_item_path(@root.custom_field_id, model)) do |item|
item.with_leading_visual_icon(icon: :pencil)
end
end

def add_above_action_item(menu)
menu.with_item(
label: I18n.t(:button_add_item_above),
tag: :a,
content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
href: new_child_custom_field_item_path(@root.custom_field_id, model.parent, position: model.sort_order)
) { _1.with_leading_visual_icon(icon: "fold-up") }
end

def add_below_action_item(menu)
menu.with_item(
label: I18n.t(:button_add_item_below),
tag: :a,
content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
href: new_child_custom_field_item_path(@root.custom_field_id, model.parent, position: model.sort_order + 1)
) { _1.with_leading_visual_icon(icon: "fold-down") }
end

def add_sub_item_action_item(menu)
menu.with_item(
label: I18n.t(:button_add_sub_item),
tag: :a,
content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
href: new_child_custom_field_item_path(@root.custom_field_id, model)
) { _1.with_leading_visual_icon(icon: "op-arrow-in") }
end

def move_to_top_action_item(menu)
form_inputs = [{ name: "new_sort_order", value: 0 }]

menu.with_item(label: I18n.t(:label_sort_highest),
tag: :button,
href: move_custom_field_item_path(@root.custom_field_id, model),
content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
form_arguments: { method: :post, inputs: form_inputs }) do |item|
item.with_leading_visual_icon(icon: "move-to-top")
end
end

def move_up_action_item(menu)
form_inputs = [{ name: "new_sort_order", value: model.sort_order - 1 }]

menu.with_item(label: I18n.t(:label_sort_higher),
tag: :button,
href: move_custom_field_item_path(@root.custom_field_id, model),
content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
form_arguments: { method: :post, inputs: form_inputs }) do |item|
item.with_leading_visual_icon(icon: "chevron-up")
end
end

def move_down_action_item(menu)
form_inputs = [{ name: "new_sort_order", value: model.sort_order + 2 }]

menu.with_item(label: I18n.t(:label_sort_lower),
tag: :button,
href: move_custom_field_item_path(@root.custom_field_id, model),
content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
form_arguments: { method: :post, inputs: form_inputs }) do |item|
item.with_leading_visual_icon(icon: "chevron-down")
end
end

def move_to_bottom_action_item(menu)
form_inputs = [{ name: "new_sort_order", value: model.parent.children.length + 1 }]

menu.with_item(label: I18n.t(:label_sort_lowest),
tag: :button,
href: move_custom_field_item_path(@root.custom_field_id, model),
content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
form_arguments: { method: :post, inputs: form_inputs }) do |item|
item.with_leading_visual_icon(icon: "move-to-bottom")
end
end

def deletion_action_item(menu)
menu.with_item(label: I18n.t(:button_delete),
scheme: :danger,
tag: :a,
href: deletion_dialog_custom_field_item_path(custom_field_id: @root.custom_field_id, id: model.id),
content_arguments: { data: { controller: "async-dialog" } }) do |item|
item.with_leading_visual_icon(icon: :trash)
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<%=
primer_form_with(url: @url, method: @method, test_selector: "op-custom-fields--new-item-form") do |f|
primer_form_with(**item_options) do |f|
render(CustomFields::Hierarchy::ItemForm.new(f, target_item: model))
end
%>
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,29 @@ module Hierarchy
class ItemFormComponent < ApplicationComponent
include OpTurbo::Streamable

def initialize(target_item:, url:, method:)
super(target_item)
@url = url
@method = method
def item_options
options = { url:, method: http_verb, data: { test_selector: "op-custom-fields--new-item-form" } }
options[:data][:turbo_frame] = ItemsComponent.wrapper_key if model.new_record?

options
end

def http_verb
model.new_record? ? :post : :put
end

def url
if model.new_record?
new_child_custom_field_item_path(root.custom_field_id, model.parent, position: model.sort_order)
else
custom_field_item_path(root.custom_field_id, model)
end
end

private

def root
@root ||= model.new_record? ? model.parent.root : model.root
end
end
end
Expand Down
Loading

0 comments on commit af82b55

Please sign in to comment.