Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Clean up and updates ItemsComponents look to match the figma design

Marcello Rocha165a77f8c5e0
diff --git a/app/components/admin/custom_fields/hierarchy/items_component.html.erb b/app/components/admin/custom_fields/hierarchy/items_component.html.erb
index ad31202add3..3889cc39311 100644
--- a/app/components/admin/custom_fields/hierarchy/items_component.html.erb
+++ b/app/components/admin/custom_fields/hierarchy/items_component.html.erb
@@ -32,7 +32,7 @@ See COPYRIGHT and LICENSE files for more details.
flex_layout do |container|
container.with_row do
render(Primer::OpenProject::SubHeader.new) do |subheader|
- subheader.with_action_button(tag: :a, scheme: :primary, href: new_item_path) do |button|
+ subheader.with_action_button(tag: :a, scheme: :primary, href: new_item_path) do |button|
button.with_leading_visual_icon(icon: :plus)
I18n.t(:label_item)
end
@@ -42,12 +42,17 @@ See COPYRIGHT and LICENSE files for more details.
render(Primer::Beta::BorderBox.new) do |box|
box.with_header { item_header }
- if children.empty? && !show_new_item_form?
+ if children.empty?
box.with_row do
render(Primer::Beta::Blankslate.new(test_selector: "op-custom-fields--hierarchy-items-blankslate")) do |component|
- component.with_visual_icon(icon: "list-ordered")
- component.with_heading(tag: :h3).with_content(I18n.t("custom_fields.admin.items.blankslate.title"))
- component.with_description { I18n.t("custom_fields.admin.items.blankslate.description") }
+ component.with_visual_icon(icon: blank_icon)
+
+ component.with_heading(tag: :h3).with_content(I18n.t(blank_header_text))
+ component.with_description { I18n.t(blank_description_text) }
+ component.with_primary_action(tag: :a, href: new_item_path) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ I18n.t(:label_item)
+ end
end
end
else
@@ -56,16 +61,6 @@ See COPYRIGHT and LICENSE files for more details.
render Admin::CustomFields::Hierarchy::ItemComponent.new(item: item)
end
end
-
- if show_new_item_form?
- box.with_footer(test_selector: "op-custom-fields--new-item-form") do
- render Admin::CustomFields::Hierarchy::ItemFormComponent.new(
- target_item: @new_item,
- url: new_child_custom_field_item_path(root.custom_field_id, model),
- method: :post
- )
- end
- end
end
end
end
diff --git a/app/components/admin/custom_fields/hierarchy/items_component.rb b/app/components/admin/custom_fields/hierarchy/items_component.rb
index 94c31d83aef..b505999f19c 100644
--- a/app/components/admin/custom_fields/hierarchy/items_component.rb
+++ b/app/components/admin/custom_fields/hierarchy/items_component.rb
@@ -35,21 +35,32 @@ module Admin
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
- property :children
-
def initialize(item:, new_item: nil)
super(item)
@new_item = new_item
end
- def show_new_item_form? = @new_item
-
def root
@root ||= model.root? ? model : model.root
end
def new_item_path
- new_child_custom_field_item_path(root.custom_field_id, model)
+ position = children.any? ? children.last.sort_order + 1 : 0
+
+ new_child_custom_field_item_path(root.custom_field_id, model, position:)
+ end
+
+ def children
+ list = model.children
+ return list unless @new_item
+
+ position = @new_item.sort_order&.to_i
+
+ if position
+ list[0...position] + [@new_item] + list[position..]
+ else
+ list + [@new_item]
+ end
end
def item_header
@@ -60,6 +71,26 @@ module Admin
end
end
+ def blank_icon
+ model.root? ? "list-ordered" : "op-arrow-in"
+ end
+
+ def blank_header_text
+ if model.root?
+ "custom_fields.admin.items.blankslate.root.title"
+ else
+ "custom_fields.admin.items.blankslate.item.title"
+ end
+ end
+
+ def blank_description_text
+ if model.root?
+ "custom_fields.admin.items.blankslate.root.description"
+ else
+ "custom_fields.admin.items.blankslate.item.description"
+ end
+ end
+
private
def slices
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 50c86ac363c..a752108b58e 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -247,8 +247,12 @@ en:
items:
actions: "Item actions"
blankslate:
- title: "Your list of items is empty"
- description: "Start by adding items to the custom field of type hierarchy. Each item can be used to create a hierarchy bellow it. To navigate and create sub-items inside a hierarchy click on the created item."
+ root:
+ title: "Your list of items is empty"
+ description: "Start by adding items to the custom field of type hierarchy. Each item can be used to create a hierarchy bellow it. To navigate and create sub-items inside a hierarchy click on the created item."
+ item:
+ title: This item doesn't have any hierarchy level below
+ description: Add items to this list to create sub-items inside another one
placeholder:
label: "Item label"
short: "Short name"