-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9683 from alphagov/content-modelling/700-create-r…
…ollup-for-view-page-and-review-page (700) Create rollup for view page and review page
- Loading branch information
Showing
16 changed files
with
198 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...gines/content_block_manager/app/assets/stylesheets/content_block_manager/application.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
.../assets/stylesheets/content_block_manager/components/_host-editions-rollup-component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.rollup-details { | ||
background: govuk-colour("light-grey"); | ||
margin-bottom: govuk-spacing(8); | ||
|
||
.govuk-grid-column-full { | ||
padding: 0; | ||
} | ||
|
||
&__title { | ||
@include govuk-visually-hidden; | ||
} | ||
|
||
&__rollup-metric { | ||
.gem-c-glance-metric { | ||
border: none; | ||
margin: govuk-spacing(6); | ||
padding: 0; | ||
|
||
&__heading { | ||
@include govuk-font(19, $weight: regular, $line-height: 1); | ||
|
||
min-height: 1em; | ||
} | ||
|
||
&__context { | ||
border: none; | ||
min-height: 0; | ||
} | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...content_block_manager/content_block/document/show/host_editions_rollup_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<div class="govuk-grid-row rollup-details"> | ||
<div class="govuk-grid-column-full"> | ||
<h2 class="rollup-details__title">Metrics</h2> | ||
<% metrics.each do |name, value| %> | ||
<div class="govuk-grid-column-one-quarter rollup-details__rollup-metric <%= name %>"> | ||
<%= | ||
render( | ||
"govuk_publishing_components/components/glance_metric", | ||
name: name.to_s.titleize, | ||
figure: value[:figure], | ||
measurement_display_label: value[:display_label], | ||
measurement_explicit_label: value[:explicit_label], | ||
heading_level: 3, | ||
) | ||
%> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> |
25 changes: 25 additions & 0 deletions
25
...nents/content_block_manager/content_block/document/show/host_editions_rollup_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class ContentBlockManager::ContentBlock::Document::Show::HostEditionsRollupComponent < ViewComponent::Base | ||
METRICS = %i[locations instances organisations views].freeze | ||
|
||
def initialize(rollup:) | ||
@rollup = rollup | ||
end | ||
|
||
private | ||
|
||
attr_reader :rollup | ||
|
||
def metrics | ||
METRICS.index_with do |metric| | ||
abbreviate(rollup.send(metric)) | ||
end | ||
end | ||
|
||
def abbreviate(number) | ||
{ | ||
figure: number_to_human(number, format: "%n"), | ||
display_label: number_to_human(number, format: "%u", units: { unit: "", thousand: "k", million: "m", billion: "b" }), | ||
explicit_label: number_to_human(number, format: "%u"), | ||
} | ||
end | ||
end |
4 changes: 3 additions & 1 deletion
4
lib/engines/content_block_manager/app/models/content_block_manager/host_content_items.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
module ContentBlockManager | ||
class HostContentItems < Data.define(:items, :total, :total_pages) | ||
class HostContentItems < Data.define(:items, :total, :total_pages, :rollup) | ||
extend Forwardable | ||
|
||
ARRAY_METHODS = ([].methods - Object.methods) | ||
|
||
def_delegators :items, *ARRAY_METHODS | ||
|
||
class Rollup < Data.define(:views, :locations, :instances, :organisations); end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...anager/test/components/content_block/document/show/host_editions_rollup_component_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require "test_helper" | ||
|
||
class ContentBlockManager::ContentBlock::Document::Show::HostEditionsRollupComponentTest < ViewComponent::TestCase | ||
extend Minitest::Spec::DSL | ||
|
||
let(:described_class) { ContentBlockManager::ContentBlock::Document::Show::HostEditionsRollupComponent } | ||
|
||
it "returns rolled up data with small numbers" do | ||
rollup = build(:rollup, views: 12, locations: 2, instances: 3, organisations: 1) | ||
|
||
render_inline(described_class.new(rollup:)) | ||
|
||
assert_selector ".rollup-details__rollup-metric.views .gem-c-glance-metric__heading", text: "Views" | ||
assert_selector ".rollup-details__rollup-metric.views .gem-c-glance-metric__figure", text: "12" | ||
|
||
assert_selector ".rollup-details__rollup-metric.locations .gem-c-glance-metric__heading", text: "Locations" | ||
assert_selector ".rollup-details__rollup-metric.locations .gem-c-glance-metric__figure", text: "2" | ||
|
||
assert_selector ".rollup-details__rollup-metric.instances .gem-c-glance-metric__heading", text: "Instances" | ||
assert_selector ".rollup-details__rollup-metric.instances .gem-c-glance-metric__figure", text: "3" | ||
|
||
assert_selector ".rollup-details__rollup-metric.organisations .gem-c-glance-metric__heading", text: "Organisations" | ||
assert_selector ".rollup-details__rollup-metric.organisations .gem-c-glance-metric__figure", text: "1" | ||
end | ||
|
||
it "returns rolled up data with larger numbers" do | ||
rollup = build(:rollup, views: 12_000_000, locations: 15_000) | ||
|
||
render_inline(described_class.new(rollup:)) | ||
|
||
assert_selector ".rollup-details__rollup-metric.views .gem-c-glance-metric__heading", text: "Views" | ||
assert_selector ".rollup-details__rollup-metric.views .gem-c-glance-metric__figure", text: "12" | ||
assert_selector ".rollup-details__rollup-metric.views .gem-c-glance-metric__display-label", text: "m" | ||
assert_selector ".rollup-details__rollup-metric.views .gem-c-glance-metric__explicit-label", text: "Million" | ||
|
||
assert_selector ".rollup-details__rollup-metric.locations .gem-c-glance-metric__figure", text: "15" | ||
assert_selector ".rollup-details__rollup-metric.locations .gem-c-glance-metric__display-label", text: "k" | ||
assert_selector ".rollup-details__rollup-metric.locations .gem-c-glance-metric__explicit-label", text: "Thousand" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters