Skip to content

Commit

Permalink
Refactor pf_inline_alert (#3893)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayorova authored Sep 19, 2024
1 parent 1de699d commit 7eea817
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
21 changes: 10 additions & 11 deletions app/helpers/patternfly_components_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ def title_tag(title)
end
end

def body_tag(body)
tag.div class: 'pf-c-alert__description' do
tag.p body
end
end
def description_tag(description)
return unless description

def pf_inline_alert(title, body, variant: nil)
tag.div class: "pf-c-alert pf-m-#{variant} pf-m-inline" do
icon_tag(variant) + title_tag(title) + body_tag(body)
tag.div class: 'pf-c-alert__description' do
tag.p description
end
end

def pf_inline_alert_plain(title, variant: nil)
tag.div class: "pf-c-alert pf-m-#{variant} pf-m-inline pf-m-plain" do
icon_tag(variant) + title_tag(title)
def pf_inline_alert(title, variant: nil, description: nil, plain: false)
plain_class = plain ? 'pf-m-plain' : ''
variant_class = variant ? "pf-m-#{variant}" : ''
classes = "pf-c-alert pf-m-inline #{plain_class} #{variant_class}"
tag.div class: classes do
icon_tag(variant) + title_tag(title) + description_tag(description)
end
end
end
6 changes: 3 additions & 3 deletions app/views/shared/_annotations.html.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- if resource.respond_to?(:managed_by) && resource.managed_by.present?
- var = defined?(variant) ? variant : :info
- if defined?(plain)
= pf_inline_alert_plain t('.managed_title', value: resource.managed_by), variant: var
= pf_inline_alert t('.managed_title', value: resource.managed_by), variant: var, plain: true
- else
- body = (defined?(description) && description) ? t('.managed_description') : nil
= pf_inline_alert t('.managed_title', value: resource.managed_by), body, variant: var
- description = (defined?(description) && description) ? t('.managed_description') : nil
= pf_inline_alert t('.managed_title', value: resource.managed_by), description: description, variant: var

0 comments on commit 7eea817

Please sign in to comment.