govuk_publishing_components 29.0.0 → 29.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2a6d452bad04acba831509df0a7ed9a45222ec20c745985beb49af0f9e7fd7a
4
- data.tar.gz: 73e0d20cac3a9214e0c3c9dc052e419e52c41580578e87f1fdbf768b82d22e71
3
+ metadata.gz: 966bb67ed287fd8f755238732b57bacee7913faa29effa54f69a64c3f7dae03f
4
+ data.tar.gz: 84876bd7eec64af2b9b514f4da5b075dd220bcd2566903eff1c1130ddb05f039
5
5
  SHA512:
6
- metadata.gz: 88203478b10e3b75f0c6b3aecf161c72102cf27978c9ee67ff129bc7b1e0c9798792165ec637855f2057458b2e5bae49fb6b6ac62e17cdd96466c755b06f9b33
7
- data.tar.gz: 76d93abedcb28c9cea6983364fe0410067c895364c50d51b672e8a40df4d4fb42d8793502e8c9dd9719b205a94b0e668c45c3a5d992a21a95785eced6d389693
6
+ metadata.gz: 8e994cd04b7a498b550c83d276cb71fbdc4983180b3cdebe6bb92e04a5dc6adf5fa7f9b8043c451063f433d1e3d28517746374937158409631e6405d3d64a179
7
+ data.tar.gz: 91905f09481b56158cef17108e3a3d86c0de65ad8e05e6d1c3af29925ce06fee38b6e0cbaad21db7f20fe867644dd91c7daca1db1a1fcfbe74aa56dc36ddec12
@@ -3,7 +3,7 @@
3
3
 
4
4
  var GOVUK = global.GOVUK || {}
5
5
  // For usage and initialisation see:
6
- // https://github.com/alphagov/govuk_frontend_toolkit/blob/master/docs/analytics.md#create-an-analytics-tracker
6
+ // https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics/analytics.md
7
7
 
8
8
  var Analytics = function (config) {
9
9
  this.pii = new GOVUK.Pii()
@@ -13,6 +13,8 @@
13
13
  return document.querySelectorAll('[data-track-count="accordionSection"]').length
14
14
  case isDocumentCollectionPage():
15
15
  return document.querySelectorAll('.document-collection .group-title').length
16
+ case isNewBrowsePage():
17
+ return document.querySelectorAll('[data-track-count="cardList"]').length
16
18
  case isMainstreamBrowsePage():
17
19
  return countVisible(document.querySelectorAll('#subsection ul')) || document.querySelectorAll('#section ul').length || document.querySelectorAll('#root ul').length
18
20
  case isTopicPage():
@@ -44,6 +46,8 @@
44
46
  return document.querySelectorAll('a[data-track-category="navAccordionLinkClicked"]').length
45
47
  case isDocumentCollectionPage():
46
48
  return document.querySelectorAll('.document-collection .group-document-list li a').length
49
+ case isNewBrowsePage():
50
+ return document.querySelectorAll('[data-track-count="cardLink"]').length
47
51
  case isMainstreamBrowsePage():
48
52
  return countVisible(document.querySelectorAll('#subsection ul a')) || document.querySelectorAll('#section ul a').length || document.querySelectorAll('#root ul a').length
49
53
  case isTopicPage():
@@ -67,6 +71,7 @@
67
71
  var metaApplicationSelector = 'meta[name="govuk:rendering-application"]'
68
72
  var metaFormatSelector = 'meta[name="govuk:format"]'
69
73
  var metaNavigationTypeSelector = 'meta[name="govuk:navigation-page-type"]'
74
+ var metaSectionSelector = 'meta[name="govuk:section"]'
70
75
 
71
76
  function getMetaAttribute (selector) {
72
77
  var element = document.querySelector(selector)
@@ -93,6 +98,12 @@
93
98
  getMetaAttribute(metaNavigationTypeSelector) === 'leaf'
94
99
  }
95
100
 
101
+ function isNewBrowsePage () {
102
+ return getMetaAttribute(metaApplicationSelector) === 'collections' &&
103
+ getMetaAttribute(metaSectionSelector) === 'new_browse_page' &&
104
+ getMetaAttribute(metaFormatSelector) === 'mainstream_browse_page'
105
+ }
106
+
96
107
  function isMainstreamBrowsePage () {
97
108
  return getMetaAttribute(metaApplicationSelector) === 'collections' &&
98
109
  getMetaAttribute(metaFormatSelector) === 'mainstream_browse_page'
@@ -13,6 +13,9 @@ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion;
13
13
  this.sectionClassExpanded = 'govuk-accordion__section--expanded'
14
14
  this.sectionHeaderClass = 'govuk-accordion__section-header'
15
15
  this.sectionInnerContent = 'govuk-accordion__section-content'
16
+ this.showAllControls = 'govuk-accordion__show-all'
17
+ this.sectionButton = 'govuk-accordion__section-button'
18
+ this.headingText = 'govuk-accordion__section-heading-text'
16
19
 
17
20
  // Translated component content and language attribute pulled from data attributes
18
21
  this.$module.actions = {}
@@ -27,12 +30,21 @@ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion;
27
30
  GemAccordion.prototype.init = function () {
28
31
  // Indicate that JavaScript has worked
29
32
  this.$module.classList.add('gem-c-accordion--active')
33
+ this.$module.querySelector('.' + this.showAllControls).classList.add('gem-c-accordion__show-all')
30
34
 
31
35
  // Feature flag for anchor tag navigation used on manuals
32
36
  if (this.$module.getAttribute('data-anchor-navigation') === 'true') {
33
37
  this.openByAnchorOnLoad()
34
38
  this.addEventListenersForAnchors()
35
39
  }
40
+ // Feature flag for "Show all sections" GA click event tracking
41
+ if (this.$module.getAttribute('data-track-show-all-clicks') === 'true') {
42
+ this.addAccordionOpenAllTracking()
43
+ }
44
+ // Feature flag for each section GA click event tracking
45
+ if (this.$module.getAttribute('data-track-sections') === 'true') {
46
+ this.addEventListenerSections()
47
+ }
36
48
  }
37
49
 
38
50
  // Navigate to and open accordions with anchored content on page load if a hash is present
@@ -90,5 +102,38 @@ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion;
90
102
  }
91
103
  }
92
104
 
105
+ // To track the Accordion's "Show all sections" / "Hide all sections" button click events and pass them to the GA event tracking
106
+ GemAccordion.prototype.addAccordionOpenAllTracking = function () {
107
+ this.$module.querySelector('.' + this.showAllControls).addEventListener('click', function (event) {
108
+ var expanded = event.target.getAttribute('aria-expanded') === 'true'
109
+ var label = expanded ? 'Show all sections' : 'Hide all sections'
110
+ var action = expanded ? 'accordionOpened' : 'accordionClosed'
111
+ var options = { transport: 'beacon', label: label }
112
+ if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
113
+ window.GOVUK.analytics.trackEvent('pageElementInteraction', action, options)
114
+ }
115
+ })
116
+ }
117
+
118
+ GemAccordion.prototype.addEventListenerSections = function () {
119
+ var sections = this.$module.querySelectorAll('.' + this.sectionButton)
120
+ nodeListForEach(sections, function (section) {
121
+ section.addEventListener('click', this.addAccordionSectionTracking.bind(this, section))
122
+ }.bind(this))
123
+ }
124
+
125
+ // If the Accordion's sections are opened on click, then pass them to the GA event tracking
126
+ GemAccordion.prototype.addAccordionSectionTracking = function (section) {
127
+ var expanded = section.getAttribute('aria-expanded') === 'false'
128
+ var label = section.querySelector('.' + this.headingText).textContent
129
+ var action = expanded ? 'accordionOpened' : 'accordionClosed'
130
+ var options = { transport: 'beacon', label: label }
131
+
132
+ if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
133
+ window.GOVUK.analytics.trackEvent('pageElementInteraction', action, options)
134
+ console.log('pageElementInteraction', action, options)
135
+ }
136
+ }
137
+
93
138
  Modules.GemAccordion = GemAccordion
94
139
  })(window.GOVUK.Modules)
@@ -1,2 +1,7 @@
1
1
  @import "mixins/prefixed-transform";
2
2
  @import "govuk/components/accordion/accordion";
3
+
4
+ // Prevent elements inside the button from receiving click events
5
+ .gem-c-accordion__show-all > * {
6
+ pointer-events: none;
7
+ }
@@ -5,6 +5,8 @@
5
5
  id ||= "default-id-#{SecureRandom.hex(4)}"
6
6
  items ||= []
7
7
  anchor_navigation ||= false
8
+ track_show_all_clicks ||= false
9
+ track_sections ||= false
8
10
 
9
11
  accordion_classes = %w(gem-c-accordion govuk-accordion)
10
12
  accordion_classes << (shared_helper.get_margin_bottom)
@@ -22,6 +24,8 @@
22
24
  data_attributes ||= {}
23
25
  data_attributes[:module] = 'govuk-accordion gem-accordion'
24
26
  data_attributes[:anchor_navigation] = anchor_navigation
27
+ data_attributes[:track_show_all_clicks] = track_show_all_clicks
28
+ data_attributes[:track_sections] = track_sections
25
29
 
26
30
  translations.each do |key, translation|
27
31
  locales[key] = shared_helper.t_locale(translation)
@@ -18,8 +18,10 @@
18
18
  <%= heading %>
19
19
  <% end %>
20
20
  <% end %>
21
-
22
- <%= content_tag('ul', class: ul_classes) do %>
21
+ <%# data-track-count is used for analytics purposes in
22
+ https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/javascripts/govuk_publishing_components/analytics/page-content.js
23
+ %>
24
+ <%= content_tag('ul', class: ul_classes, "data-track-count": "cardList" ) do %>
23
25
  <%
24
26
  items.each do |item|
25
27
  link = item[:link]
@@ -33,7 +35,8 @@
33
35
  <%=
34
36
  link_to link[:text], link[:path],
35
37
  class: "govuk-link gem-c-cards__link",
36
- data: link[:data_attributes]
38
+ data: link[:data_attributes],
39
+ "data-track-count": "cardLink"
37
40
  %>
38
41
  <% end %>
39
42
  <% if item[:description] %>
@@ -12,9 +12,4 @@
12
12
  inverse: inverse,
13
13
  collapse_on_mobile: collapse_on_mobile %>
14
14
  <% end %>
15
- <% if breadcrumb_selector.priority_breadcrumbs %>
16
- <%= render 'govuk_publishing_components/components/step_by_step_nav_header', breadcrumb_selector.priority_breadcrumbs %>
17
- <% meta_tag = GovukPublishingComponents::Presenters::MetaTags.new(content_item, local_assigns, request).brexit_priority_breadcrumb_tag %>
18
- <meta name="<%= meta_tag.keys.first %>" content="<%= meta_tag.values.first %>">
19
- <% end %>
20
15
  </div>
@@ -309,3 +309,37 @@ examples:
309
309
  text: How people read
310
310
  content:
311
311
  html: <p class="govuk-body">This is the content for How people read.</p>
312
+ with_track_show_all_clicks:
313
+ description: |
314
+ To switch on Google Analytics for the "Show all sections" button on click, pass `track_show_all_clicks: true` the values passed on open will be
315
+ `Event Action: accordionOpened` `Event Category: pageElementInteraction` `Event Label: Show all sections`
316
+ data:
317
+ track_show_all_clicks: true
318
+ items:
319
+ - heading:
320
+ text: Writing well for the web
321
+ id: writing-well-for-the-web
322
+ content:
323
+ html: <p class="govuk-body">This is content for accordion 1 of 2</p><p class="govuk-body">This content contains a <a href="#anchor-nav-test" class="govuk-link">link</a></p>
324
+ - heading:
325
+ text: Writing well for specialists
326
+ content:
327
+ html: <p class="govuk-body" id="anchor-nav-test">This is content for accordion 2 of 2</p>
328
+ with_track_sections:
329
+ description: |
330
+ To switch on Google Analytics for each section, on click, pass `track_sections: true` the values passed on open will be
331
+ `Event Action: accordionOpened` / `accordionClosed` `Event Category: pageElementInteraction` and the `Event Label` being the heading text.
332
+
333
+ (`track_show_all_clicks: true` can be added to track the "Show all sections" button as well, if required)
334
+ data:
335
+ track_sections: true
336
+ items:
337
+ - heading:
338
+ text: Writing well for the web
339
+ id: writing-well-for-the-web
340
+ content:
341
+ html: <p class="govuk-body">This is content for accordion 1 of 2</p><p class="govuk-body">This content contains a <a href="#anchor-nav-test" class="govuk-link">link</a></p>
342
+ - heading:
343
+ text: Writing well for specialists
344
+ content:
345
+ html: <p class="govuk-body" id="anchor-nav-test">This is content for accordion 2 of 2</p>
@@ -4,7 +4,7 @@ module GovukPublishingComponents
4
4
  # Various departments are taking part in a pilot to use a form
5
5
  # rather than direct email for users to request accessible formats. When the pilot
6
6
  # scheme is rolled out further this can be removed.
7
- # Currently the pilot is paused so there are no participants.
7
+ # Currently the HMRC are participating in the pilot.
8
8
  EMAILS_IN_ACCESSIBLE_FORMAT_REQUEST_PILOT = %w[govuk_publishing_components@example.com].freeze
9
9
 
10
10
  delegate :opendocument?, :document?, :spreadsheet?, to: :content_type
@@ -17,19 +17,8 @@ module GovukPublishingComponents
17
17
  best_match_option[:step_by_step]
18
18
  end
19
19
 
20
- def priority_breadcrumbs
21
- return if hide_priority_breadcrumb?
22
- return parent_item_navigation.priority_breadcrumbs if content_item_navigation.html_publication_with_parent?
23
-
24
- content_item_navigation.priority_breadcrumbs
25
- end
26
-
27
20
  private
28
21
 
29
- def hide_priority_breadcrumb?
30
- content_item_navigation.content_tagged_to_current_step_by_step? && content_item_navigation.tagged_to_brexit?
31
- end
32
-
33
22
  def best_match_option
34
23
  return content_item_options unless content_item_navigation.html_publication_with_parent?
35
24
 
@@ -33,10 +33,6 @@ module GovukPublishingComponents
33
33
  @taxon_breadcrumbs ||= ContentBreadcrumbsBasedOnTaxons.call(content_item)
34
34
  end
35
35
 
36
- def priority_breadcrumbs
37
- @priority_breadcrumbs ||= ContentBreadcrumbsBasedOnPriority.call(content_item, query_parameters)
38
- end
39
-
40
36
  def topic_breadcrumbs
41
37
  @topic_breadcrumbs ||= ContentBreadcrumbsBasedOnTopic.call(content_item)
42
38
  end
@@ -92,22 +88,6 @@ module GovukPublishingComponents
92
88
  content_item.dig("links", "topics").present?
93
89
  end
94
90
 
95
- def tagged_to_brexit?
96
- taxons = content_item.dig("links", "taxons").to_a
97
- brexit_taxon = "d6c2de5d-ef90-45d1-82d4-5f2438369eea"
98
- world_brexit_taxon = "d4c4d91d-fbe7-4eff-bd57-189138c626c9"
99
-
100
- taxons.each do |taxon|
101
- if taxon["content_id"].eql?(brexit_taxon) ||
102
- taxon["content_id"].eql?(world_brexit_taxon) ||
103
- taxon.dig("links", "parent_taxons").to_a.any? { |taxon_item| taxon_item["content_id"].eql?(brexit_taxon) }
104
- return true
105
- end
106
- end
107
-
108
- false
109
- end
110
-
111
91
  def content_tagged_to_current_step_by_step?
112
92
  # TODO: remove indirection here
113
93
  step_nav_helper.show_header?
@@ -20,12 +20,7 @@ module GovukPublishingComponents
20
20
  meta_tags = add_organisation_tags(meta_tags)
21
21
  meta_tags = add_political_tags(meta_tags)
22
22
  meta_tags = add_taxonomy_tags(meta_tags)
23
- meta_tags = add_step_by_step_tags(meta_tags)
24
- add_brexit_tags("govuk:brexit-audience", meta_tags)
25
- end
26
-
27
- def brexit_priority_breadcrumb_tag
28
- add_brexit_tags("govuk:brexit-superbreadcrumb")
23
+ add_step_by_step_tags(meta_tags)
29
24
  end
30
25
 
31
26
  private
@@ -116,37 +111,6 @@ module GovukPublishingComponents
116
111
  meta_tags
117
112
  end
118
113
 
119
- def add_brexit_tags(tag_key, meta_tags = {})
120
- links = content_item[:links]
121
- taxons = links[:taxons] unless links.nil?
122
-
123
- return meta_tags if taxons.blank?
124
- return meta_tags unless tagged_to_priority_taxon?
125
-
126
- taxon =
127
- tag_key == "govuk:brexit-audience" ? priority_brexit_taxon : priority_taxon
128
-
129
- brexit_audience = priority_taxon_helper.brexit_audience(taxon)
130
- meta_tags[tag_key] = brexit_audience if brexit_audience.present?
131
- meta_tags
132
- end
133
-
134
- def tagged_to_priority_taxon?
135
- priority_taxon_helper.priority_taxon.present?
136
- end
137
-
138
- def priority_taxon_helper
139
- @priority_taxon_helper ||= ContentBreadcrumbsBasedOnPriority.new(content_item.deep_stringify_keys, request.query_parameters)
140
- end
141
-
142
- def priority_taxon
143
- priority_taxon_helper.priority_taxon
144
- end
145
-
146
- def priority_brexit_taxon
147
- priority_taxon_helper.priority_brexit_taxon
148
- end
149
-
150
114
  def has_content_history?
151
115
  (content_item[:public_updated_at] && details[:first_public_at] && content_item[:public_updated_at] != details[:first_public_at]) ||
152
116
  (details[:change_history] && details[:change_history].size > 1)
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "29.0.0".freeze
2
+ VERSION = "29.2.0".freeze
3
3
  end
@@ -17,7 +17,6 @@ require "govuk_publishing_components/presenters/step_by_step_nav_helper"
17
17
  require "govuk_publishing_components/presenters/page_with_step_by_step_navigation"
18
18
  require "govuk_publishing_components/presenters/public_layout_helper"
19
19
  require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_ancestors"
20
- require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_priority"
21
20
  require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons"
22
21
  require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic"
23
22
  require "govuk_publishing_components/presenters/checkboxes_helper"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 29.0.0
4
+ version: 29.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-24 00:00:00.000000000 Z
11
+ date: 2022-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config
@@ -112,30 +112,30 @@ dependencies:
112
112
  name: capybara
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '3.25'
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: '3.25'
124
+ version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: faker
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: '2.11'
131
+ version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: '2.11'
138
+ version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: gds-api-adapters
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -154,30 +154,30 @@ dependencies:
154
154
  name: govuk_schemas
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - "~>"
157
+ - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: '4.0'
159
+ version: '0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - "~>"
164
+ - - ">="
165
165
  - !ruby/object:Gem::Version
166
- version: '4.0'
166
+ version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: govuk_test
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - "~>"
171
+ - - ">="
172
172
  - !ruby/object:Gem::Version
173
- version: '3'
173
+ version: '0'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - "~>"
178
+ - - ">="
179
179
  - !ruby/object:Gem::Version
180
- version: '3'
180
+ version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: i18n-coverage
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -196,16 +196,16 @@ dependencies:
196
196
  name: percy-capybara
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - "~>"
199
+ - - ">="
200
200
  - !ruby/object:Gem::Version
201
- version: 5.0.0
201
+ version: '0'
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
- - - "~>"
206
+ - - ">="
207
207
  - !ruby/object:Gem::Version
208
- version: 5.0.0
208
+ version: '0'
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: pry-byebug
211
211
  requirement: !ruby/object:Gem::Requirement
@@ -226,14 +226,14 @@ dependencies:
226
226
  requirements:
227
227
  - - ">="
228
228
  - !ruby/object:Gem::Version
229
- version: '1.5'
229
+ version: '0'
230
230
  type: :development
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - ">="
235
235
  - !ruby/object:Gem::Version
236
- version: '1.5'
236
+ version: '0'
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: rake
239
239
  requirement: !ruby/object:Gem::Requirement
@@ -252,16 +252,16 @@ dependencies:
252
252
  name: rspec-rails
253
253
  requirement: !ruby/object:Gem::Requirement
254
254
  requirements:
255
- - - "~>"
255
+ - - ">="
256
256
  - !ruby/object:Gem::Version
257
- version: '5.0'
257
+ version: '0'
258
258
  type: :development
259
259
  prerelease: false
260
260
  version_requirements: !ruby/object:Gem::Requirement
261
261
  requirements:
262
- - - "~>"
262
+ - - ">="
263
263
  - !ruby/object:Gem::Version
264
- version: '5.0'
264
+ version: '0'
265
265
  - !ruby/object:Gem::Dependency
266
266
  name: rubocop-govuk
267
267
  requirement: !ruby/object:Gem::Requirement
@@ -280,44 +280,44 @@ dependencies:
280
280
  name: sassc-rails
281
281
  requirement: !ruby/object:Gem::Requirement
282
282
  requirements:
283
- - - "~>"
283
+ - - ">="
284
284
  - !ruby/object:Gem::Version
285
- version: '2'
285
+ version: '0'
286
286
  type: :development
287
287
  prerelease: false
288
288
  version_requirements: !ruby/object:Gem::Requirement
289
289
  requirements:
290
- - - "~>"
290
+ - - ">="
291
291
  - !ruby/object:Gem::Version
292
- version: '2'
292
+ version: '0'
293
293
  - !ruby/object:Gem::Dependency
294
294
  name: uglifier
295
295
  requirement: !ruby/object:Gem::Requirement
296
296
  requirements:
297
297
  - - ">="
298
298
  - !ruby/object:Gem::Version
299
- version: 4.1.0
299
+ version: '0'
300
300
  type: :development
301
301
  prerelease: false
302
302
  version_requirements: !ruby/object:Gem::Requirement
303
303
  requirements:
304
304
  - - ">="
305
305
  - !ruby/object:Gem::Version
306
- version: 4.1.0
306
+ version: '0'
307
307
  - !ruby/object:Gem::Dependency
308
308
  name: webmock
309
309
  requirement: !ruby/object:Gem::Requirement
310
310
  requirements:
311
- - - "~>"
311
+ - - ">="
312
312
  - !ruby/object:Gem::Version
313
- version: 3.8.3
313
+ version: '0'
314
314
  type: :development
315
315
  prerelease: false
316
316
  version_requirements: !ruby/object:Gem::Requirement
317
317
  requirements:
318
- - - "~>"
318
+ - - ">="
319
319
  - !ruby/object:Gem::Version
320
- version: 3.8.3
320
+ version: '0'
321
321
  - !ruby/object:Gem::Dependency
322
322
  name: yard
323
323
  requirement: !ruby/object:Gem::Requirement
@@ -907,7 +907,6 @@ files:
907
907
  - lib/govuk_publishing_components/presenters/button_helper.rb
908
908
  - lib/govuk_publishing_components/presenters/checkboxes_helper.rb
909
909
  - lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_ancestors.rb
910
- - lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_priority.rb
911
910
  - lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
912
911
  - lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic.rb
913
912
  - lib/govuk_publishing_components/presenters/content_item.rb
@@ -1,118 +0,0 @@
1
- module GovukPublishingComponents
2
- module Presenters
3
- class ContentBreadcrumbsBasedOnPriority
4
- # keys are labels, values are the content_ids for the matching taxons
5
- # Where multiple matching taxons are present, the top most one is the highest priority
6
- # and the bottom one the lowest priority
7
- PRIORITY_TAXONS = {
8
- brexit_business: "634fd193-8039-4a70-a059-919c34ff4bfc",
9
- brexit_individuals: "614b2e65-56ac-4f8d-bb9c-d1a14167ba25",
10
- brexit_taxon: "d6c2de5d-ef90-45d1-82d4-5f2438369eea",
11
- }.freeze
12
-
13
- # Returns the highest priority taxon that has a content_id matching those in PRIORITY_TAXONS
14
- def self.call(content_item, query_parameters = nil)
15
- new(content_item, query_parameters).breadcrumbs
16
- end
17
-
18
- attr_reader :content_item, :query_parameters
19
-
20
- def initialize(content_item, query_parameters = nil)
21
- @content_item = content_item
22
- @query_parameters = query_parameters
23
- end
24
-
25
- def priority_taxon
26
- @priority_taxon ||= begin
27
- default_taxon = priority_taxons.min_by { |t| PRIORITY_TAXONS.values.index(t["content_id"]) }
28
- preferred_taxon || default_taxon
29
- end
30
- end
31
-
32
- def priority_brexit_taxon
33
- if tagged_to_both_brexit_child_taxons?
34
- priority_taxons.find { |t| t["content_id"] == PRIORITY_TAXONS[:brexit_taxon] }
35
- else
36
- priority_taxons.min_by { |t| PRIORITY_TAXONS.values.index(t["content_id"]) }
37
- end
38
- end
39
-
40
- def breadcrumbs
41
- priority_taxon && {
42
- title: priority_taxon["title"],
43
- path: breadcrumb_path,
44
- tracking_category: "breadcrumbClicked",
45
- tracking_action: tracking_action,
46
- tracking_label: content_item["base_path"],
47
- tracking_dimension_enabled: false,
48
- }
49
- end
50
-
51
- def brexit_audience(taxon)
52
- return nil unless taxon
53
-
54
- {
55
- PRIORITY_TAXONS[:brexit_business] => "Brexitbusiness",
56
- PRIORITY_TAXONS[:brexit_individuals] => "Brexitcitizen",
57
- PRIORITY_TAXONS[:brexit_taxon] => "Brexitbusinessandcitizen",
58
- }[taxon["content_id"]]
59
- end
60
-
61
- private
62
-
63
- def preferred_taxon
64
- if preferred_priority_taxon
65
- priority_taxons.find { |t| t["content_id"] == preferred_priority_taxon }
66
- elsif tagged_to_both_brexit_child_taxons?
67
- priority_taxons.find { |t| t["content_id"] == PRIORITY_TAXONS[:brexit_taxon] }
68
- end
69
- end
70
-
71
- def priority_taxons
72
- return [] unless content_item["links"].is_a?(Hash)
73
-
74
- taxons = content_item.dig("links", "taxons")
75
- taxon_tree(taxons).select do |taxon|
76
- priority_taxon?(taxon)
77
- end
78
- end
79
-
80
- def taxon_tree(taxons)
81
- return [] if taxons.blank?
82
-
83
- taxons + taxons.flat_map { |taxon| taxon_tree(taxon.dig("links", "parent_taxons")) }
84
- end
85
-
86
- def priority_taxon?(taxon)
87
- PRIORITY_TAXONS.values.include?(taxon["content_id"])
88
- end
89
-
90
- def brexit_child_taxon?(taxon)
91
- brexit_child_taxons.include?(taxon["content_id"])
92
- end
93
-
94
- def brexit_child_taxons
95
- [PRIORITY_TAXONS[:brexit_business], PRIORITY_TAXONS[:brexit_individuals]]
96
- end
97
-
98
- def preferred_priority_taxon
99
- query_parameters["priority-taxon"] if query_parameters
100
- end
101
-
102
- def tracking_action
103
- action = %w[superBreadcrumb]
104
- action << brexit_audience(priority_taxon)
105
- action.compact.join(" ")
106
- end
107
-
108
- def tagged_to_both_brexit_child_taxons?
109
- t = priority_taxons.select { |taxon| brexit_child_taxon?(taxon) }
110
- t.uniq.count > 1
111
- end
112
-
113
- def breadcrumb_path
114
- priority_taxon.dig("details", "url_override").present? ? priority_taxon.dig("details", "url_override") : priority_taxon["base_path"]
115
- end
116
- end
117
- end
118
- end