mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
Merge pull request #23533 from opf/chore/forms-dsl-input-for-filterable-tree-view
[chore] add forms dsl input for filterable tree views
This commit is contained in:
@@ -35,37 +35,25 @@ module Wikis
|
||||
f.hidden(name: :linkable_type)
|
||||
f.hidden(name: :linkable_id)
|
||||
|
||||
f.html_content do
|
||||
render(
|
||||
Primer::OpenProject::FilterableTreeView.new(
|
||||
src: helpers.search_wiki_pages_path(provider_id: model.provider_id, name: "wiki_page_selection"),
|
||||
form_arguments: { builder: rails_builder(f), name: "wiki_page_selection" },
|
||||
filter_mode_control_arguments: { hidden: true },
|
||||
filter_input_arguments: {
|
||||
placeholder: I18n.t("wikis.link_existing_wiki_page_form.placeholder"),
|
||||
# every other property is just refilling the default values,
|
||||
# as those are not merged into custom arguments
|
||||
name: :filter,
|
||||
label: I18n.t(:button_filter),
|
||||
type: :search,
|
||||
leading_visual: { icon: :search },
|
||||
visually_hide_label: true,
|
||||
show_clear_button: true
|
||||
},
|
||||
include_sub_items_check_box_arguments: { hidden: true },
|
||||
no_results_node_arguments: { label: I18n.t("wikis.link_existing_wiki_page_form.no_results") }
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Primer's FormObject stores the underlying ActionView/Primer form builder
|
||||
# as @builder. FilterableTreeView requires an ActionView::FormBuilder to
|
||||
# generate its hidden form inputs via hidden_field.
|
||||
def rails_builder(form)
|
||||
form.instance_variable_get(:@builder)
|
||||
f.filterable_tree_view(
|
||||
name: "wiki_page_selection",
|
||||
label: I18n.t("wikis.link_existing_wiki_page_form.label"),
|
||||
src: helpers.search_wiki_pages_path(provider_id: model.provider_id, name: "wiki_page_selection"),
|
||||
filter_mode_control_arguments: { hidden: true },
|
||||
filter_input_arguments: {
|
||||
placeholder: I18n.t("wikis.link_existing_wiki_page_form.placeholder"),
|
||||
# every other property is just refilling the default values,
|
||||
# as those are not merged into custom arguments
|
||||
name: :filter,
|
||||
label: I18n.t(:button_filter),
|
||||
type: :search,
|
||||
leading_visual: { icon: :search },
|
||||
visually_hide_label: true,
|
||||
show_clear_button: true
|
||||
},
|
||||
include_sub_items_check_box_arguments: { hidden: true },
|
||||
no_results_node_arguments: { label: I18n.t("wikis.link_existing_wiki_page_form.no_results") }
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -151,6 +151,7 @@ en:
|
||||
link_existing_wiki_page_dialog:
|
||||
title: Add existing wiki page
|
||||
link_existing_wiki_page_form:
|
||||
label: Wiki page
|
||||
no_results: No wiki pages found
|
||||
placeholder: Search for a wiki page
|
||||
oauth_login_component:
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
# 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.
|
||||
#++
|
||||
|
||||
require "spec_helper"
|
||||
|
||||
RSpec.describe Wikis::LinkExistingWikiPageForm, type: :forms do
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
include_context "with rendered form"
|
||||
|
||||
let(:model) { build_stubbed(:relation_wiki_page_link) }
|
||||
|
||||
it "renders the link attributes as hidden fields", :aggregate_failures do
|
||||
expect(page).to have_field("wikis_relation_page_link[provider_id]", type: :hidden, with: model.provider_id)
|
||||
expect(page).to have_field("wikis_relation_page_link[linkable_type]", type: :hidden, with: model.linkable_type)
|
||||
expect(page).to have_field("wikis_relation_page_link[linkable_id]", type: :hidden, with: model.linkable_id)
|
||||
end
|
||||
|
||||
it "renders the wiki page selection", :aggregate_failures do
|
||||
expect(page).to have_selector :fieldset, "Wiki page"
|
||||
expect(page).to have_element :"filterable-tree-view",
|
||||
src: search_wiki_pages_path(provider_id: model.provider_id,
|
||||
name: "wiki_page_selection")
|
||||
expect(page).to have_field "Filter", type: :search, placeholder: "Search for a wiki page"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user