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

Reskin groups index with using Primer components

Jan Sandbrink8af816b87de6
diff --git a/app/components/groups/row_component.rb b/app/components/groups/row_component.rb
new file mode 100644
index 00000000000..51d7bebcc93
--- /dev/null
+++ b/app/components/groups/row_component.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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 Groups
+ class RowComponent < OpPrimer::BorderBoxRowComponent
+ def name
+ render(Primer::Beta::Link.new(href: edit_group_path(model), font_weight: :bold)) { model.name }
+ end
+
+ def user_count
+ model.users.count
+ end
+
+ def created_at
+ helpers.format_date(model.created_at)
+ end
+ end
+end
diff --git a/app/components/groups/table_component.rb b/app/components/groups/table_component.rb
new file mode 100644
index 00000000000..964f857d06b
--- /dev/null
+++ b/app/components/groups/table_component.rb
@@ -0,0 +1,76 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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 Groups
+ class TableComponent < OpPrimer::BorderBoxTableComponent
+ columns :name, :user_count, :created_at
+ mobile_labels :user_count, :created_at
+
+ def mobile_title
+ Group.model_name.human(count: 2)
+ end
+
+ def row_class
+ RowComponent
+ end
+
+ def headers
+ [
+ [:name, { caption: Group.human_attribute_name(:name) }],
+ [:user_count, { caption: t(".user_count") }],
+ [:created_at, { caption: Group.human_attribute_name(:created_at) }]
+ ]
+ end
+
+ def render_blank_slate
+ render(Primer::Beta::Blankslate.new(border: false)) do |component|
+ component.with_visual_icon(icon: blank_icon, size: :medium) if blank_icon
+ component.with_heading(tag: :h2) { blank_title }
+ component.with_description { blank_description }
+ component.with_primary_action(label: t(:label_group_new), tag: :a, href: new_group_path) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ t("activerecord.models.group")
+ end
+ end
+ end
+
+ def blank_title
+ t(".blank_slate.title")
+ end
+
+ def blank_description
+ t(".blank_slate.description")
+ end
+
+ def blank_icon
+ :people
+ end
+ end
+end
diff --git a/app/views/groups/index.html.erb b/app/views/groups/index.html.erb
index d7227ddc3ee..261b17a9802 100644
--- a/app/views/groups/index.html.erb
+++ b/app/views/groups/index.html.erb
@@ -32,6 +32,7 @@ See COPYRIGHT and LICENSE files for more details.
<%=
render(Primer::OpenProject::PageHeader.new) do |header|
header.with_title { t(:label_group_plural) }
+ header.with_description { t(".description") }
header.with_breadcrumbs(
[{ href: admin_index_path, text: t("label_administration") },
{ href: admin_settings_users_path, text: t(:label_user_and_permission) },
@@ -54,60 +55,4 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
-<% if @groups.any? %>
- <div class="generic-table--container">
- <div class="generic-table--results-container">
- <table class="generic-table" data-controller="table-highlighting">
- <colgroup>
- <col>
- <col>
- <col data-highlight="false">
- </colgroup>
- <thead>
- <tr>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= Group.model_name.human %>
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= t(:label_user_plural) %>
- </span>
- </div>
- </div>
- </th>
- <th><div class="generic-table--empty-header"></div></th>
- </tr>
- </thead>
- <tbody>
- <% @groups.each do |group| %>
- <tr>
- <td><%= link_to h(group), action: "edit", id: group %></td>
- <td><%= group.users.size %></td>
- <td class="buttons">
- <%= link_to "", group,
- data: { confirm: t(:text_are_you_sure) },
- method: :delete,
- class: "icon icon-delete",
- title: t(:button_delete) %>
- </td>
- </tr>
- <% end %>
- </tbody>
- </table>
-
- </div>
- </div>
-<% else %>
- <%= no_results_box(
- action_url: new_group_path,
- display_action: true
- ) %>
-<% end %>
+<%= render(Groups::TableComponent.new(rows: @groups)) %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index c3ee8304999..a7685d94827 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -405,8 +405,12 @@ en:
groups:
index:
- no_results_title_text: There are currently no groups.
- no_results_content_text: Create a new group
+ description: By grouping users together, you can add them as members to the same projects or assign the same global roles to them.
+ table_component:
+ blank_slate:
+ description: You can define groups of users with specific names
+ title: No groups set up yet
+ user_count: User count
users:
no_results_title_text: There are currently no users part of this group.
memberships:
diff --git a/spec/features/groups/groups_spec.rb b/spec/features/groups/groups_spec.rb
index f993768a187..2c12347e237 100644
--- a/spec/features/groups/groups_spec.rb
+++ b/spec/features/groups/groups_spec.rb
@@ -41,19 +41,13 @@ RSpec.describe "group memberships through groups page", :js do
allow(User).to receive(:current).and_return admin
end
- it "I can delete a group" do
+ it "I can see groups" do
groups_page.visit!
expect(groups_page).to have_group "Bob's Team"
- groups_page.delete_group! "Bob's Team"
+ click_on "Bob's Team"
- expect_flash(type: :info, message: I18n.t(:notice_deletion_scheduled))
- expect(groups_page).to have_group "Bob's Team"
-
- perform_enqueued_jobs
-
- groups_page.visit!
- expect(groups_page).not_to have_group "Bob's Team"
+ expect(page).to have_current_path(edit_group_path(group))
end
end
end
diff --git a/spec/support/pages/groups.rb b/spec/support/pages/groups.rb
index ac1208fc42f..c41d0b0f672 100644
--- a/spec/support/pages/groups.rb
+++ b/spec/support/pages/groups.rb
@@ -52,18 +52,8 @@ module Pages
group(group_name).add_user! user_name
end
- def delete_group!(name)
- accept_alert do
- find_group(name).find("a[data-method=delete]").click
- end
- end
-
- def find_group(name)
- find("tr", text: name)
- end
-
def has_group?(name)
- has_selector? "tr", text: name
+ has_selector? ".op-border-box-grid--row-item", text: name
end
def group(group_name)