Skip to content

Commit 22a29ff

Browse files
committed
[#74940] WIP migrate document types list
Move the document type index onto BorderBoxListComponent while preserving the existing drag-and-drop row data and header layout. https://community.openproject.org/wp/74940
1 parent 2f74656 commit 22a29ff

2 files changed

Lines changed: 99 additions & 14 deletions

File tree

modules/documents/app/components/documents/admin/document_types/index_component.html.erb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,26 @@
4848
end
4949

5050
flex.with_row do
51-
render(border_box_container(data: drop_target_config)) do |component|
52-
component.with_header(font_weight: :bold) do
53-
grid_layout("op-documents-types-list--header", tag: :div, align_items: :center) do |grid|
54-
grid.with_area(:name, tag: :div, mr: 3) do
55-
render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t("documents.index_page.type") }
56-
end
57-
58-
grid.with_area(:"documents-count", tag: :div, hide: :sm) do
59-
render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t("label_documents") }
60-
end
61-
end
62-
end
51+
render(
52+
OpenProject::Common::BorderBoxListComponent.new(
53+
container: "#{wrapper_key}-list",
54+
position: :relative,
55+
data: drop_target_config
56+
)
57+
) do |list|
58+
list.with_header(
59+
title: I18n.t("documents.index_page.type"),
60+
title_tag: :h3,
61+
count: document_types.size
62+
)
6363

6464
if document_types.empty?
65-
component.with_row do
65+
list.with_item do
6666
render(Primer::Beta::Text.new(color: :subtle)) { t(:no_results_title_text) }
6767
end
6868
else
6969
document_types.each do |document_type|
70-
component.with_row(test_selector: "document-type-row-#{document_type.id}", data: draggable_item_config(document_type)) do
70+
list.with_item(test_selector: "document-type-row-#{document_type.id}", data: draggable_item_config(document_type)) do
7171
render(item_component_class.new(enumeration: document_type, max_position: max_position))
7272
end
7373
end
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
require "rails_helper"
32+
33+
RSpec.describe Documents::Admin::DocumentTypes::IndexComponent, type: :component do
34+
subject(:rendered_component) do
35+
with_controller_class(Documents::Admin::Settings::DocumentTypesController) do
36+
with_request_url("/admin/settings/document_types") do
37+
render_inline(described_class.new(enumerations: document_types))
38+
end
39+
end
40+
end
41+
42+
let(:document_types) { DocumentType.order(:position) }
43+
44+
context "with document types" do
45+
let!(:note_type) { create(:document_type, name: "Note", position: 1) }
46+
let!(:report_type) { create(:document_type, name: "Report", position: 2) }
47+
48+
it "renders the document types in a border box list with preserved controls and drag-and-drop data" do
49+
expect(rendered_component).to have_css(".Box.op-border-box-list")
50+
expect(rendered_component).to have_css(".Box[data-generic-drag-and-drop-target='container']")
51+
expect(rendered_component).to have_css(".Box[data-target-container-accessor=':scope > ul']")
52+
expect(rendered_component).to have_css(".Box[data-target-allowed-drag-type='enumeration']")
53+
54+
expect(rendered_component).to have_css("[data-test-selector='admin-document-types-subheader']")
55+
expect(rendered_component).to have_css("[data-test-selector='add-document-type-button']")
56+
expect(rendered_component).to have_css("h3", text: I18n.t("documents.index_page.type"))
57+
expect(rendered_component).to have_css(".Counter", text: "2")
58+
59+
rows = rendered_component.css(".Box-row[data-draggable-type='enumeration']")
60+
expect(rows.size).to eq(2)
61+
62+
expect(rendered_component).to have_css(
63+
".Box-row[data-test-selector='document-type-row-#{note_type.id}']" \
64+
"[data-draggable-id='#{note_type.id}']" \
65+
"[data-draggable-type='enumeration']" \
66+
"[data-drop-url$='/admin/settings/document_types/#{note_type.id}/move']",
67+
text: "Note"
68+
)
69+
expect(rendered_component).to have_css(
70+
".Box-row[data-test-selector='document-type-row-#{report_type.id}']" \
71+
"[data-draggable-id='#{report_type.id}']" \
72+
"[data-draggable-type='enumeration']" \
73+
"[data-drop-url$='/admin/settings/document_types/#{report_type.id}/move']",
74+
text: "Report"
75+
)
76+
end
77+
end
78+
79+
context "without document types" do
80+
it "renders the existing empty result text as a border box list row" do
81+
expect(rendered_component).to have_css(".Box.op-border-box-list")
82+
expect(rendered_component).to have_css(".Box-row", text: I18n.t(:no_results_title_text))
83+
end
84+
end
85+
end

0 commit comments

Comments
 (0)