Module: Baldur::UiHelperUnavailable
- Included in:
- UiHelper
- Defined in:
- app/helpers/baldur/ui_helper_unavailable.rb
Instance Method Summary collapse
- #ui_dependency_dataset_name(dataset_key) ⇒ Object
- #ui_unavailable_dependencies(dependencies:, warning_keys: nil) ⇒ Object
- #ui_unavailable_dependency_group_content(groups) ⇒ Object
- #ui_unavailable_dependency_groups(dependencies) ⇒ Object
- #ui_unavailable_explanation_content(reason:, dependencies:, warning_keys: nil) ⇒ Object
- #ui_unavailable_explanation_sections(reason:, groups:) ⇒ Object
- #ui_unavailable_metric(reason: nil, dependencies: nil, warning_keys: nil, text: 'Not available', text_class: 'text-xs text-muted') ⇒ Object
Instance Method Details
#ui_dependency_dataset_name(dataset_key) ⇒ Object
96 97 98 |
# File 'app/helpers/baldur/ui_helper_unavailable.rb', line 96 def ui_dependency_dataset_name(dataset_key) Baldur.config.dependency_dataset_name_resolver.call(dataset_key) end |
#ui_unavailable_dependencies(dependencies:, warning_keys: nil) ⇒ Object
30 31 32 33 34 35 |
# File 'app/helpers/baldur/ui_helper_unavailable.rb', line 30 def ui_unavailable_dependencies(dependencies:, warning_keys: nil) explicit_dependencies = Array(dependencies).compact return explicit_dependencies if explicit_dependencies.present? Array(Baldur.config.warning_dependency_resolver.call(warning_keys)) end |
#ui_unavailable_dependency_group_content(groups) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/helpers/baldur/ui_helper_unavailable.rb', line 77 def ui_unavailable_dependency_group_content(groups) lines = groups.map do |group| line = if group[:dataset_label].present? && group[:details].present? "• #{group[:dataset_label]} › #{group[:details]}" else "• #{group[:dataset_label].presence || group[:details]}" end content_tag(:span, line, class: 'block text-left') end safe_join([content_tag(:span, 'Upload/refresh:', class: 'block text-left'), *lines]) end |
#ui_unavailable_dependency_groups(dependencies) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/helpers/baldur/ui_helper_unavailable.rb', line 37 def ui_unavailable_dependency_groups(dependencies) grouped = {} order = [] Array(dependencies).each do |dependency| dep = dependency.respond_to?(:with_indifferent_access) ? dependency.with_indifferent_access : dependency dataset_key = dep[:dataset_key] field_key = dep[:field_key] snapshot_metric = dep[:snapshot_metric] next if dataset_key.blank? && field_key.blank? && snapshot_metric.blank? group_key = dataset_key.presence || '__no_dataset__' unless grouped.key?(group_key) grouped[group_key] = { dataset_key: dataset_key.presence, fields: [], metrics: [] } order << group_key end group = grouped[group_key] group[:fields] << field_key if field_key.present? && !group[:fields].include?(field_key) group[:metrics] << snapshot_metric if snapshot_metric.present? && !group[:metrics].include?(snapshot_metric) end order.filter_map do |group_key| group = grouped[group_key] details = [] details << group[:fields].join(', ') if group[:fields].present? details << "snapshot metric: #{group[:metrics].join(', ')}" if group[:metrics].present? next if group[:dataset_key].blank? && details.blank? { dataset_label: (ui_dependency_dataset_name(group[:dataset_key]) if group[:dataset_key].present?), details: details.join(' | ') } end end |
#ui_unavailable_explanation_content(reason:, dependencies:, warning_keys: nil) ⇒ Object
22 23 24 25 26 27 28 |
# File 'app/helpers/baldur/ui_helper_unavailable.rb', line 22 def ui_unavailable_explanation_content(reason:, dependencies:, warning_keys: nil) resolved_dependencies = ui_unavailable_dependencies(dependencies: dependencies, warning_keys: warning_keys) groups = ui_unavailable_dependency_groups(resolved_dependencies) return ui_unavailable_explanation_sections(reason: reason, groups: groups) if reason.present? || groups.present? Baldur.config. end |
#ui_unavailable_explanation_sections(reason:, groups:) ⇒ Object
89 90 91 92 93 94 |
# File 'app/helpers/baldur/ui_helper_unavailable.rb', line 89 def ui_unavailable_explanation_sections(reason:, groups:) parts = [] parts << content_tag(:span, reason, class: 'block text-left') if reason.present? parts << ui_unavailable_dependency_group_content(groups) if groups.present? safe_join(parts) end |
#ui_unavailable_metric(reason: nil, dependencies: nil, warning_keys: nil, text: 'Not available', text_class: 'text-xs text-muted') ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/baldur/ui_helper_unavailable.rb', line 3 def ui_unavailable_metric(reason: nil, dependencies: nil, warning_keys: nil, text: 'Not available', text_class: 'text-xs text-muted') content_tag(:span, class: 'inline-flex items-center gap-1 whitespace-nowrap align-middle') do safe_join( [ content_tag(:span, text, class: text_class), ui_tooltip( text: 'Why unavailable', content: ui_unavailable_explanation_content(reason: reason, dependencies: dependencies, warning_keys: warning_keys), icon: 'info', variant: :icon, inline: true ) ] ) end end |