Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,48 @@
end
end

flex.with_row do
render(Primer::OpenProject::SubHeader.new(collapsed_search: false)) do |subheader|
subheader.with_filter_input(
name: "border-box-filter",
label: t("types.edit.project_attributes.filter"),
visually_hide_label: true,
placeholder: t("types.edit.project_attributes.filter"),
leading_visual: {
icon: :search,
size: :small
},
show_clear_button: true,
clear_button_id: clear_button_id,
data: {
action: "input->filter--filter-list#filterLists",
"filter--filter-list-target": "filter"
}
)
if visible_sections.empty?
flex.with_row do
render(Primer::Beta::Blankslate.new(border: true, test_selector: "type-project-attributes-blankslate")) do |blankslate|
blankslate.with_visual_icon(icon: :"list-unordered")
blankslate.with_heading(tag: :h3) { t("#{blankslate_i18n_scope}.title") }
blankslate.with_description { blankslate_description }
end
end
end

visible_sections.each do |project_custom_field_section, project_custom_fields|
else
flex.with_row do
render(
WorkPackageTypes::ProjectAttributes::SectionComponent.new(
variant: @variant,
project_custom_field_section:,
project_custom_fields:,
linked: linked?,
exclusion_state:
render(Primer::OpenProject::SubHeader.new(collapsed_search: false)) do |subheader|
subheader.with_filter_input(
name: "border-box-filter",
label: t("types.edit.project_attributes.filter"),
visually_hide_label: true,
placeholder: t("types.edit.project_attributes.filter"),
leading_visual: {
icon: :search,
size: :small
},
show_clear_button: true,
clear_button_id: clear_button_id,
data: {
action: "input->filter--filter-list#filterLists",
"filter--filter-list-target": "filter"
}
)
end
end

visible_sections.each do |project_custom_field_section, project_custom_fields|
flex.with_row do
render(
WorkPackageTypes::ProjectAttributes::SectionComponent.new(
variant: @variant,
project_custom_field_section:,
project_custom_fields:,
linked: linked?,
exclusion_state:
)
)
)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,28 @@ def exclusion_state
@exclusion_state = linked? ? WorkPackageTypes::ExclusionState.for(@variant, ASPECT) : nil
end

def blankslate_i18n_scope
"types.edit.project_attributes.blankslate.#{linked? ? 'linked' : 'independent'}"
end

def blankslate_description
return t("#{blankslate_i18n_scope}.description") if linked?

link_translate("#{blankslate_i18n_scope}.description",
links: { administration_url: admin_settings_project_custom_fields_path },
external: false)
end

def visible_sections
return @project_custom_field_sections unless linked?

result = []
@project_custom_field_sections.each do |section, custom_fields|
shown = custom_fields.select { |cf| show_in_linked_mode?(cf) }
result << [section, shown] if shown.any?
end
result
@visible_sections ||=
if linked?
@project_custom_field_sections.filter_map do |section, custom_fields|
shown = custom_fields.select { |cf| show_in_linked_mode?(cf) }
[section, shown] if shown.any?
end
else
@project_custom_field_sections
end
end

def show_in_linked_mode?(custom_field)
Expand Down
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6286,6 +6286,13 @@ en:
actions:
label_disable_all: "Disable all"
label_enable_all: "Enable all"
blankslate:
independent:
description: "Once you [create project attributes](administration_url), they will be visible here and can be added to a type."
title: "No project attributes available"
linked:
description: "This type does not have any project attributes associated with it."
title: "No project attributes configured"
description: "Select the project attributes that you want to enable for this work package type. Enabled project attributes are displayed in a separate tab in work packages of this type. Users with the necessary permissions can view and edit these attributes there."
disabled: "Disabled"
exclusions:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# 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.
#
# See COPYRIGHT and LICENSE files for more details.
#++

require "rails_helper"

RSpec.describe WorkPackageTypes::ProjectAttributes::IndexComponent, type: :component do
include Rails.application.routes.url_helpers

current_user { create(:admin) }

let(:type) { create(:type) }
let(:variant) { type.default_variant }
let(:sections) { ProjectCustomFieldSection.grouped_in_order(ProjectCustomField.visible) }

subject(:rendered_component) do
render_inline(described_class.new(variant:, project_custom_field_sections: sections))
end

def blankslate_text(mode, key)
I18n.t("types.edit.project_attributes.blankslate.#{mode}.#{key}")
end

context "when the variant configures the aspect itself" do
context "with no project attributes at all" do
it "renders the blankslate instead of the filter", :aggregate_failures do
expect(rendered_component).to have_test_selector("type-project-attributes-blankslate",
text: blankslate_text(:independent, :title))
expect(rendered_component).to have_link("create project attributes",
href: admin_settings_project_custom_fields_path)
expect(rendered_component).to have_no_field("border-box-filter")
end
end

context "with project attributes" do
before { create(:project_custom_field) }

it "renders the sections and the filter", :aggregate_failures do
expect(rendered_component).to have_no_test_selector("type-project-attributes-blankslate")
expect(rendered_component).to have_css(".Box-row")
expect(rendered_component).to have_field("border-box-filter")
end
end
end

context "when the variant is linked for the aspect", with_flag: { type_variants: true } do
let(:source_type) { create(:type) }
let(:source) { source_type.default_variant }
let(:custom_field) { create(:project_custom_field) }

before do
custom_field
link_configuration(variant, source:, aspect: TypeVariant::PROJECT_ATTRIBUTES)
end

context "when the source enables no project attribute" do
it "renders the blankslate instead of the filter", :aggregate_failures do
expect(rendered_component).to have_test_selector("type-project-attributes-blankslate",
text: blankslate_text(:linked, :title))
expect(rendered_component).to have_text(blankslate_text(:linked, :description))
expect(rendered_component).to have_no_field("border-box-filter")
end
end

context "when the source enables a project attribute" do
before do
ProjectCustomFieldTypeMapping.create!(type_variant: source, project_custom_field: custom_field)
end

it "renders the sections and the filter", :aggregate_failures do
expect(rendered_component).to have_no_test_selector("type-project-attributes-blankslate")
expect(rendered_component).to have_css(".Box-row")
expect(rendered_component).to have_field("border-box-filter")
end
end
end
end
Loading