From 30c5cc177797a38a659efd1b5ebb01a24b00d16e Mon Sep 17 00:00:00 2001 From: mdorf Date: Tue, 4 Mar 2025 15:33:52 -0800 Subject: [PATCH] resolved #396 - badge view off for long values --- app/components/concept_details_component.rb | 17 ++++++++++++++--- app/helpers/application_helper.rb | 3 +-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/components/concept_details_component.rb b/app/components/concept_details_component.rb index 2f55a5dda..e11a45787 100644 --- a/app/components/concept_details_component.rb +++ b/app/components/concept_details_component.rb @@ -40,15 +40,14 @@ def row_hash_properties(properties_set, ontology_acronym, &block) values = data[:values] url = data[:key] - - is_list = values.is_a?(Array) && values.size > 1 + style_as_badge = values.is_a?(Array) && values.size > 1 && short_values(values) ajax_links = Array(values).map do |v| if block_given? capture(v, &block) else if v.is_a?(String) - get_link_for_cls_ajax(v, ontology_acronym, '_blank', is_list) + get_link_for_cls_ajax(v, ontology_acronym, '_blank', style_as_badge) else display_in_multiple_languages([v].to_h, style_as_badge: true) end @@ -63,6 +62,18 @@ def row_hash_properties(properties_set, ontology_acronym, &block) out end + def short_values(vals) + vals.each do |str| + word_count = str.split.count + character_count = str.length + + unless word_count < 10 && character_count < 100 + return false + end + end + true + end + def properties_set_by_keys(keys, concept_properties, exclude_keys = []) concept_properties&.select do |k, v| (keys.include?(k) || !keys.select { |key| v[:key].to_s.include?(key) }.empty?) && !exclude_keys.include?(k) && diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d865e018b..c60dd47cf 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -379,12 +379,11 @@ def get_link_for_cls_ajax(cls_id, ont_acronym, target = nil, style_as_badge = fa if style_as_badge render ChipButtonComponent.new(text: cls_id) else - content_tag(:span, cls_id) + content_tag(:div, cls_id) end end end - def get_link_for_ont_ajax(ont_acronym) # Ajax call will replace the acronym with an ontology name (triggered by class='ont4ajax') href_ont = " href='#{bp_ont_link(ont_acronym)}' "