[chore] add forms dsl input for filterable tree views

This commit is contained in:
Eric Schubert
2026-06-03 12:52:36 +02:00
committed by Alexander Brandon Coles
parent 2985562c74
commit 2c574f623e
5 changed files with 146 additions and 31 deletions
@@ -0,0 +1,66 @@
# 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 Primer
module OpenProject
module Forms
module Dsl
# :nodoc:
class FilterableTreeViewInput < Primer::Forms::Dsl::Input
attr_reader :name, :label, :block
def initialize(name:, label: nil, **system_arguments, &block)
@name = name
@label = label
@block = block
super(**system_arguments)
end
def to_component
FilterableTreeView.new(input: self)
end
# :nocov:
def type
:filterable_tree_view
end
# :nocov:
# :nocov:
def focusable?
true
end
# :nocov:
end
end
end
end
end
@@ -84,6 +84,10 @@ module Primer
add_input SelectPanelInput.new(builder:, form:, **decorate_options(**), &)
end
def filterable_tree_view(**, &)
add_input FilterableTreeViewInput.new(builder:, form:, **decorate_options(**), &)
end
def decorate_options(include_help_text: true, help_text_options: {}, **options)
if include_help_text && supports_help_texts?(form.model)
attribute_name = help_text_options[:attribute_name] || options[:name]
@@ -0,0 +1,7 @@
<%=
render(FormControl.new(input: @input)) do
render(Primer::OpenProject::FilterableTreeView.new(**@input.input_arguments)) do |tree_view|
@input.block&.call(tree_view)
end
end
%>
@@ -0,0 +1,51 @@
# 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 Primer
module OpenProject
module Forms
# :nodoc:
class FilterableTreeView < Primer::Forms::BaseComponent
delegate :builder, :form, to: :@input
def initialize(input:)
super()
@input = input
@input.input_arguments[:form_arguments] = {
name: @input.name,
builder: builder
}
end
end
end
end
end