Skip to content

Commit 2654737

Browse files
committed
[WIP] Begin work on Select Tree Panel input
1 parent 9ca11c8 commit 2654737

File tree

5 files changed

+148
-10
lines changed

5 files changed

+148
-10
lines changed

lib/primer/open_project/forms/dsl/input_methods.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def select_panel(**, &)
7979
add_input SelectPanelInput.new(builder:, form:, **decorate_options(**), &)
8080
end
8181

82+
def select_tree_panel(**, &)
83+
add_input SelectTreePanelInput.new(builder:, form:, **decorate_options(**), &)
84+
end
85+
8286
def decorate_options(include_help_text: true, help_text_options: {}, **options)
8387
if include_help_text && supports_help_texts?(form.model)
8488
attribute_name = help_text_options[:attribute_name] || options[:name]
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
module Primer
32+
module OpenProject
33+
module Forms
34+
module Dsl
35+
# :nodoc:
36+
class SelectTreePanelInput < Primer::Forms::Dsl::Input
37+
attr_reader :name, :label, :block
38+
39+
def initialize(name:, label:, **system_arguments, &block)
40+
@name = name
41+
@label = label
42+
@block = block
43+
44+
super(**system_arguments)
45+
end
46+
47+
def to_component
48+
SelectTreePanel.new(input: self)
49+
end
50+
51+
# :nocov:
52+
def type
53+
:select_tree_panel
54+
end
55+
# :nocov:
56+
57+
# :nocov:
58+
def focusable?
59+
true
60+
end
61+
# :nocov:
62+
end
63+
end
64+
end
65+
end
66+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<%= render(FormControl.new(input: @input)) do %>
2+
<%= render(Primer::Alpha::SelectPanel.new(**@input.input_arguments)) do |menu| %>
3+
<% menu.with_show_button("aria-describedby": @label_id) { "Select..." } %>
4+
<% @input.block&.call(menu) %>
5+
<% end %>
6+
<% end %>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
module Primer
32+
module OpenProject
33+
module Forms
34+
# :nodoc:
35+
class SelectTreePanel < Primer::Forms::BaseComponent
36+
delegate :builder, :form, to: :@input
37+
38+
def initialize(input:)
39+
super()
40+
41+
@input = input
42+
@input.label_arguments[:id] = label_id
43+
44+
@input.input_arguments[:form_arguments] = {
45+
name: @input.name,
46+
builder: builder
47+
}
48+
49+
@input.input_arguments[:select_variant] ||= :single
50+
@input.input_arguments[:dynamic_label] = true unless @input.input_arguments.key(:dynamic_label)
51+
end
52+
53+
def label_id
54+
@label_id ||= "label-#{@input.base_id}"
55+
end
56+
end
57+
end
58+
end
59+
end

modules/webhooks/app/forms/webhooks/outgoing/enabled_projects_form.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,24 @@ class SelectedProjectsForm < ApplicationForm
3636
alias :webhook :model
3737

3838
form do |f|
39-
f.select_panel(
39+
f.select_tree_panel(
4040
name: :selected_project_ids,
4141
label: I18n.t(:"webhooks.outgoing.form.selected_project_ids.title"),
4242
title: I18n.t("types.edit.projects.select_projects"),
4343
visually_hide_label: true,
44-
disabled: webhook.all_projects?,
45-
select_variant: :multiple,
46-
dynamic_label: true,
47-
dynamic_label_prefix: I18n.t(:"webhooks.outgoing.form.selected_project_ids.title"),
48-
src: url_helpers.enabled_projects_menu_admin_outgoing_webhooks_path(
49-
select_variant: :multiple,
50-
selected_project_ids: webhook.all_projects? ? [] : webhook.project_ids
51-
),
52-
fetch_strategy: :remote
44+
disabled: webhook.all_projects?
45+
# select_variant: :multiple,
46+
# dynamic_label: true,
47+
# dynamic_label_prefix: I18n.t(:"webhooks.outgoing.form.selected_project_ids.title"),
48+
# src: url_helpers.enabled_projects_menu_admin_outgoing_webhooks_path(
49+
# select_variant: :multiple,
50+
# selected_project_ids: webhook.all_projects? ? [] : webhook.project_ids
51+
# ),
52+
# fetch_strategy: :remote
5353
) do |menu|
54+
menu.with_content("FOOO") do
55+
"FOOBAR CONTENT"
56+
end
5457
# available_projects.each do |label, value|
5558
# menu.with_item(
5659
# label:,

0 commit comments

Comments
 (0)