Skip to content

Commit 8895e05

Browse files
authored
Merge pull request #789 from citizensadvice/update-scores-to-render-half-stars
chore/Update scores to render half stars
2 parents 63a56fb + 9af25a7 commit 8895e05

12 files changed

Lines changed: 134 additions & 29 deletions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.score
22
%p.score__text
33
= score_text
4-
= render CsrTable::StarsComponent.new(highlight_stars: highlight_stars?, score: score_number) if scored?
4+
= render CsrTable::StarsComponent.new(highlight_stars: highlight_stars?, score: score_number, half_stars: half_stars?) if scored?
55
- if content?
66
%p.score__content
77
= content

app/components/csr_table/score_component.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
module CsrTable
44
class ScoreComponent < ViewComponent::Base
5-
def initialize(score:, show_decimal_score: false, decimal_places: 1, highlight_stars: false)
5+
def initialize(score:, show_decimal_score: false, decimal_places: 1, highlight_stars: false, half_stars: false)
66
super()
77
@score = score
88
@show_decimal_score = show_decimal_score
99
@decimal_places = decimal_places
1010
@highlight_stars = highlight_stars
11+
@half_stars = half_stars
1112
end
1213

1314
def render?
@@ -24,6 +25,10 @@ def show_decimal_score?
2425
@show_decimal_score
2526
end
2627

28+
def half_stars?
29+
@half_stars
30+
end
31+
2732
def highlight_stars?
2833
@highlight_stars
2934
end

app/components/csr_table/score_summary_component.html.haml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
%li.score-summary__item
88
%p.score-summary__text
99
Overall rating
10-
= render CsrTable::ScoreComponent.new(score: supplier.overall_rating, show_decimal_score: true, decimal_places: 2, highlight_stars: true)
10+
= render CsrTable::ScoreComponent.new(score: supplier.overall_rating, show_decimal_score: true, decimal_places: 2, highlight_stars: true, half_stars: true)
1111
%li.score-summary__item
1212
%p.score-summary__text
1313
Fewer complaints received
14-
= render CsrTable::ScoreComponent.new(score: supplier.complaints_rating, show_decimal_score: true)
14+
= render CsrTable::ScoreComponent.new(score: supplier.complaints_rating, show_decimal_score: true, half_stars: true)
1515
%li.score-summary__item
1616
%p.score-summary__text
1717
Contact waiting time
18-
= render CsrTable::ScoreComponent.new(score: supplier.contact_rating, show_decimal_score: true)
18+
= render CsrTable::ScoreComponent.new(score: supplier.contact_rating, show_decimal_score: true, half_stars: true)
1919
%li.score-summary__item
2020
%p.score-summary__text
2121
Billing and metering
22-
= render CsrTable::ScoreComponent.new(score: supplier.bill_accuracy_and_metering_rating, show_decimal_score: true)
22+
= render CsrTable::ScoreComponent.new(score: supplier.bill_accuracy_and_metering_rating, show_decimal_score: true, half_stars: true)
2323
%li.score-summary__item
2424
%p.score-summary__text
2525
Customer commitments
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
%svg.star.star--half{ width: "17", height: "14", viewBox: "0 0 17 15", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" }
2+
%use{ href:"#highlightedHalfStar" }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
module CsrTable
4+
module Star
5+
class HighlightedHalfComponent < ViewComponent::Base
6+
end
7+
end
8+
end

app/components/csr_table/stars_component.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ class StarsComponent < ViewComponent::Base
66

77
attr_reader :score
88

9-
def initialize(score:, highlight_stars: false)
9+
def initialize(score:, highlight_stars: false, half_stars: false)
1010
super()
1111
@highlight_stars = highlight_stars
1212
@score = score
13+
@half_stars = half_stars
1314
end
1415

1516
def star_classes
@@ -25,26 +26,32 @@ def stars
2526
empty_stars = MAX_SCORE - full_stars - half_stars
2627

2728
full_stars.times { star_list << :full }
28-
half_stars.times { star_list << :half }
29+
half_stars.times { star_list << half_star_type }
2930
empty_stars.times { star_list << :empty }
3031

3132
star_list
3233
end
3334

3435
def half_stars
35-
return 0 unless @highlight_stars
36+
return 0 unless @half_stars
3637

3738
score_decimal = @score.to_s.split(".").last
3839

3940
score_decimal.to_i < 5 ? 0 : 1
4041
end
4142

43+
def half_star_type
44+
@highlight_stars ? :highlighted_half : :half
45+
end
46+
4247
def render_star(star)
4348
case star
4449
when :full
4550
render CsrTable::Star::FullComponent.new
4651
when :half
4752
render CsrTable::Star::HalfComponent.new
53+
when :highlighted_half
54+
render CsrTable::Star::HighlightedHalfComponent.new
4855
else
4956
render CsrTable::Star::EmptyComponent.new
5057
end

app/components/csr_table/supplier_table_row_component.html.haml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
= render_overall_score
1111
%td.supplier-table__complaints
1212
.cads-table__content
13-
= render CsrTable::ScoreComponent.new(score: supplier.complaints_rating, show_decimal_score: true)
13+
= render CsrTable::ScoreComponent.new(score: supplier.complaints_rating, show_decimal_score: true, half_stars: true)
1414
%td.supplier-table__response
1515
.cads-table__content
16-
= render CsrTable::ScoreComponent.new(score: supplier.contact_rating, show_decimal_score: true)
16+
= render CsrTable::ScoreComponent.new(score: supplier.contact_rating, show_decimal_score: true, half_stars: true)
1717
%td.supplier-table__billing
1818
.cads-table__content
19-
= render CsrTable::ScoreComponent.new(score: supplier.bill_accuracy_and_metering_rating, show_decimal_score: true)
19+
= render CsrTable::ScoreComponent.new(score: supplier.bill_accuracy_and_metering_rating, show_decimal_score: true, half_stars: true)
2020
%td.supplier-table__guarantee
2121
.cads-table__content
2222
= render CsrTable::ScoreComponent.new(score: supplier.guarantee_rating)

app/components/csr_table/supplier_table_row_component.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ def row_classes
2929
def render_overall_score
3030
if highlight?
3131
render CsrTable::ScoreComponent.new(score: supplier.overall_rating, show_decimal_score: true, decimal_places: 2,
32-
highlight_stars: true)
32+
highlight_stars: true, half_stars: true)
3333
else
3434
render CsrTable::ScoreComponent.new(score: supplier.overall_rating,
3535
show_decimal_score: true, decimal_places: 2,
36-
highlight_stars: true).with_content(more_details_link)
36+
highlight_stars: true, half_stars: true).with_content(more_details_link)
3737
end
3838
end
3939

app/views/layouts/application.html.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
%body{ class: ("cas" if scotland?) }
2424
= render "shared/google_tag_manager_no_script"
2525
= render "shared/half_star_svg"
26+
= render "shared/highlighted_half_star_svg"
2627
- unless cookies_preference_page?
2728
= render CitizensAdviceCookiePreferences::CookieBanner.new
2829

app/views/shared/_half_star_svg.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
%path{ d: "M8.40002 0L10.1961 5.52786H16.0085L11.3062 8.94427L13.1023 14.4721L8.40002 11.0557L3.69774 14.4721L5.49385 8.94427L0.791572 5.52786H6.60391L8.40002 0Z", fill: "url(#paint0_linear_658_12679)" }
44
%defs
55
%lineargradient{ id: "paint0_linear_658_12679", x1: "8.15002", y1: "7.00012", x2: "8.65002", y2: "7.00012", gradientUnits: "userSpaceOnUse" }
6-
%stop{ offset: "0.507812", "stop-color": "#FFD250" }
7-
%stop{ offset: "0.515625", "stop-color": "white" }
6+
%stop{ offset: "0.507812", "stop-color": "#004b88" }
7+
%stop{ offset: "0.515625", "stop-color": "white" }

0 commit comments

Comments
 (0)