Skip to content

Commit

Permalink
Refactor pf_inline_alert (#3893)
Browse files Browse the repository at this point in the history
Further refactor of pf_inline_alert
  • Loading branch information
mayorova committed Sep 19, 2024
1 parent 1de699d commit 2114f9f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
22 changes: 11 additions & 11 deletions app/helpers/patternfly_components_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ 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, **options)
plain_class = options[:plain] ? 'pf-m-plain' : ''
variant = options[:variant]
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(options[: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 2114f9f

Please sign in to comment.