Commit 3ba9702d authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'winh-label-textcolor-default' into 'master'

Provide default for calculating label text color

Closes #32728

See merge request !11681
parents b3b6c781 f565c439
...@@ -69,13 +69,12 @@ module LabelsHelper ...@@ -69,13 +69,12 @@ module LabelsHelper
end end
def render_colored_label(label, label_suffix = '', tooltip: true) def render_colored_label(label, label_suffix = '', tooltip: true)
label_color = label.color || Label::DEFAULT_COLOR text_color = text_color_for_bg(label.color)
text_color = text_color_for_bg(label_color)
# Intentionally not using content_tag here so that this method can be called # Intentionally not using content_tag here so that this method can be called
# by LabelReferenceFilter # by LabelReferenceFilter
span = %(<span class="label color-label #{"has-tooltip" if tooltip}" ) + span = %(<span class="label color-label #{"has-tooltip" if tooltip}" ) +
%(style="background-color: #{label_color}; color: #{text_color}" ) + %(style="background-color: #{label.color}; color: #{text_color}" ) +
%(title="#{escape_once(label.description)}" data-container="body">) + %(title="#{escape_once(label.description)}" data-container="body">) +
%(#{escape_once(label.name)}#{label_suffix}</span>) %(#{escape_once(label.name)}#{label_suffix}</span>)
......
...@@ -133,6 +133,10 @@ class Label < ActiveRecord::Base ...@@ -133,6 +133,10 @@ class Label < ActiveRecord::Base
template template
end end
def color
super || DEFAULT_COLOR
end
def text_color def text_color
LabelsHelper.text_color_for_bg(self.color) LabelsHelper.text_color_for_bg(self.color)
end end
......
...@@ -49,6 +49,23 @@ describe Label, models: true do ...@@ -49,6 +49,23 @@ describe Label, models: true do
expect(label.color).to eq('#abcdef') expect(label.color).to eq('#abcdef')
end end
it 'uses default color if color is missing' do
label = described_class.new(color: nil)
expect(label.color).to be(Label::DEFAULT_COLOR)
end
end
describe '#text_color' do
it 'uses default color if color is missing' do
expect(LabelsHelper).to receive(:text_color_for_bg).with(Label::DEFAULT_COLOR).
and_return(spy)
label = described_class.new(color: nil)
label.text_color
end
end end
describe '#title' do describe '#title' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment