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

feat[#48620] Define `AttributeGroup` components

Kabiru Mwenja698b5c6ff30c
diff --git a/app/components/attribute_groups/attribute_group_component.html.erb b/app/components/attribute_groups/attribute_group_component.html.erb
new file mode 100644
index 00000000000..705138aaba1
--- /dev/null
+++ b/app/components/attribute_groups/attribute_group_component.html.erb
@@ -0,0 +1,9 @@
+<div class="attributes-group">
+ <%= group_header %>
+
+ <div class="attributes-key-value">
+ <% attributes_key_value.each do |attribute_key_value| %>
+ <%= attribute_key_value %>
+ <% end %>
+ </div>
+</div>
diff --git a/app/components/attribute_groups/attribute_group_component.rb b/app/components/attribute_groups/attribute_group_component.rb
new file mode 100644
index 00000000000..fdecc977edc
--- /dev/null
+++ b/app/components/attribute_groups/attribute_group_component.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module AttributeGroups
+ class AttributeGroupComponent < ::RailsComponent
+ renders_one :group_header, AttributeGroups::AttributeGroupHeaderComponent
+ renders_many :attributes_key_value, AttributeGroups::AttributeKeyValueComponent
+ end
+end
diff --git a/app/components/attribute_groups/attribute_group_header_component.html.erb b/app/components/attribute_groups/attribute_group_header_component.html.erb
new file mode 100644
index 00000000000..825f42d8a4e
--- /dev/null
+++ b/app/components/attribute_groups/attribute_group_header_component.html.erb
@@ -0,0 +1,5 @@
+<div class="attributes-group--header">
+ <div class="attributes-group--header-container">
+ <h3 class="attributes-group--header-text"><%= title %></h3>
+ </div>
+</div>
diff --git a/app/components/attribute_groups/attribute_group_header_component.rb b/app/components/attribute_groups/attribute_group_header_component.rb
new file mode 100644
index 00000000000..ad3606c919e
--- /dev/null
+++ b/app/components/attribute_groups/attribute_group_header_component.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module AttributeGroups
+ class AttributeGroupHeaderComponent < ::RailsComponent
+ options :title
+
+ def initialize(title:, **options)
+ super(title:, **options)
+ end
+ end
+end
diff --git a/app/components/attribute_groups/attribute_key_value_component.html.erb b/app/components/attribute_groups/attribute_key_value_component.html.erb
new file mode 100644
index 00000000000..7bf9bd3c504
--- /dev/null
+++ b/app/components/attribute_groups/attribute_key_value_component.html.erb
@@ -0,0 +1,6 @@
+<div class="attributes-key-value--key"><%= attribute_key %></div>
+<div class="attributes-key-value--value-container">
+ <div class="attributes-key-value--value -text">
+ <span><%= attribute_value %></span>
+ </div>
+</div>
diff --git a/app/components/attribute_groups/attribute_key_value_component.rb b/app/components/attribute_groups/attribute_key_value_component.rb
new file mode 100644
index 00000000000..6d141df77b7
--- /dev/null
+++ b/app/components/attribute_groups/attribute_key_value_component.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module AttributeGroups
+ class AttributeKeyValueComponent < ::RailsComponent
+ options :attribute_key, :attribute_value
+
+ def initialize(attribute_key:, attribute_value:, **options)
+ super(attribute_key:, attribute_value:, **options)
+ end
+ end
+end
diff --git a/spec/components/attribute_groups/attribute_group_component_spec.rb b/spec/components/attribute_groups/attribute_group_component_spec.rb
new file mode 100644
index 00000000000..672aafb789b
--- /dev/null
+++ b/spec/components/attribute_groups/attribute_group_component_spec.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require "rails_helper"
+
+RSpec.describe AttributeGroups::AttributeGroupComponent, type: :component do
+ subject(:component_render) do
+ render_inline(described_class.new) do |component|
+ component.with_group_header(title: "A Title")
+
+ component.with_attributes_key_value(
+ [{ attribute_key: "Attribute Key 1", attribute_value: "Attribute Value 1" },
+ { attribute_key: "Attribute Key 2", attribute_value: "Attribute Value 2" }]
+ )
+ end
+ end
+
+ before { component_render }
+
+ it 'renders the title' do
+ aggregate_failures 'group header' do
+ expect(page).to have_css('.attributes-group')
+ expect(page).to have_css('h3.attributes-group--header-text', text: 'A Title')
+ end
+
+ aggregate_failures 'attribute key value' do
+ expect(page).to have_css('.attributes-key-value')
+ expect(page).to have_css('.attributes-key-value--key', text: 'Attribute Key 1') &
+ have_css('.attributes-key-value--value.-text', text: 'Attribute Value 1')
+ expect(page).to have_css('.attributes-key-value--key', text: 'Attribute Key 2') &
+ have_css('.attributes-key-value--value.-text', text: 'Attribute Value 2')
+ end
+ end
+end
diff --git a/spec/components/attribute_groups/attribute_group_header_component_spec.rb b/spec/components/attribute_groups/attribute_group_header_component_spec.rb
new file mode 100644
index 00000000000..7e5f90b0f88
--- /dev/null
+++ b/spec/components/attribute_groups/attribute_group_header_component_spec.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require "rails_helper"
+
+RSpec.describe AttributeGroups::AttributeGroupHeaderComponent, type: :component do
+ subject(:component_render) do
+ render_inline(described_class.new(title: 'A Title'))
+ end
+
+ before { component_render }
+
+ it 'renders the title' do
+ expect(page).to have_css('h3.attributes-group--header-text', text: 'A Title')
+ end
+end
diff --git a/spec/components/attribute_groups/attribute_key_value_component_spec.rb b/spec/components/attribute_groups/attribute_key_value_component_spec.rb
new file mode 100644
index 00000000000..60eea991429
--- /dev/null
+++ b/spec/components/attribute_groups/attribute_key_value_component_spec.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require "rails_helper"
+
+RSpec.describe AttributeGroups::AttributeKeyValueComponent, type: :component do
+ subject(:component_render) do
+ render_inline(described_class.new(attribute_key: 'Attribute Key', attribute_value: 'Attribute Value'))
+ end
+
+ before { component_render }
+
+ it 'renders the attribute key and value' do
+ expect(page).to have_css('.attributes-key-value--key', text: 'Attribute Key') &
+ have_css('.attributes-key-value--value.-text', text: 'Attribute Value')
+ end
+end