Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Refactor single page notification component #4501

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
19 changes: 18 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,24 @@ spec/dummy/app/assets/builds/*
doc
.yardoc
tmp/failures.txt
node_modules
node_modules/@babel
node_modules/@nodelib
node_modules/@oclif
node_modules/acorn
node_modules/ajv
node_modules/caniuse-lite
node_modules/devtools-protocol
node_modules/es-abstract
node_modules/eslint
node_modules/eslint-plugin-import
node_modules/eslint-plugin-react
node_modules/lodash
node_modules/micromark
node_modules/percy-client
node_modules/postcss
node_modules/puppeteer
node_modules/stylelint
node_modules/table
yarn-error.log
coverage
.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
add_gem_component_stylesheet("single-page-notification-button")

local_assigns[:margin_bottom] ||= 3
js_enhancement ||= false

spnb_helper = GovukPublishingComponents::Presenters::SinglePageNotificationButtonHelper.new(local_assigns)
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("gem-c-single-page-notification-button")
component_helper.add_class("js-personalisation-enhancement") if local_assigns[:js_enhancement]
component_helper.add_data_attribute({ module: "single-page-notification-button" }) if js_enhancement
component_helper.add_data_attribute({ button_location: spnb_helper.button_location })
component_helper.add_data_attribute({ button_text_subscribe: spnb_helper.button_text_subscribe })
component_helper.add_data_attribute({ button_text_unsubscribe: spnb_helper.button_text_unsubscribe })

ga4_data_attributes = ga4_data_attributes ||= nil
ga4_link_data_attributes = ga4_data_attributes[:ga4_link] if ga4_data_attributes
Expand All @@ -18,7 +24,7 @@
<svg class="gem-c-single-page-notification-button__icon" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" height="18" width="18" viewBox="0 0 459.334 459.334"><path fill="currentColor" d="M177.216 404.514c-.001.12-.009.239-.009.359 0 30.078 24.383 54.461 54.461 54.461s54.461-24.383 54.461-54.461c0-.12-.008-.239-.009-.359H175.216zM403.549 336.438l-49.015-72.002v-89.83c0-60.581-43.144-111.079-100.381-122.459V24.485C254.152 10.963 243.19 0 229.667 0s-24.485 10.963-24.485 24.485v27.663c-57.237 11.381-100.381 61.879-100.381 122.459v89.83l-49.015 72.002a24.76 24.76 0 0 0 20.468 38.693H383.08a24.761 24.761 0 0 0 20.469-38.694z"/></svg><span class="gem-c-single-page-notication-button__text"><%= spnb_helper.button_text %></span>
<% end %>
<%= tag.div(**component_helper.all_attributes) do %>
<%= tag.form class: spnb_helper.classes, action: spnb_helper.form_action, method: "POST", data: spnb_helper.data do %>
<%= tag.form action: spnb_helper.form_action, method: "POST" do %>
<input type="hidden" name="base_path" value="<%= spnb_helper.base_path %>">
<% if spnb_helper.skip_the_gov_uk_account? %>
<input type="hidden" name="<%= spnb_helper.skip_account_param %>" value="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
module GovukPublishingComponents
module Presenters
class SinglePageNotificationButtonHelper
attr_reader :already_subscribed, :data_attributes, :base_path, :js_enhancement, :button_type, :button_location, :classes, :skip_account
attr_reader :already_subscribed, :data_attributes, :base_path, :button_type, :button_location, :skip_account, :button_text_subscribe, :button_text_unsubscribe

def initialize(local_assigns)
@local_assigns = local_assigns
@data_attributes = @local_assigns[:data_attributes] || {}
@js_enhancement = @local_assigns[:js_enhancement] || false
@already_subscribed = @local_assigns[:already_subscribed] || false
@base_path = @local_assigns[:base_path] || nil
@button_location = button_location_is_valid? ? @local_assigns[:button_location] : nil
@button_type = @local_assigns[:already_subscribed] ? "Unsubscribe" : "Subscribe"
@classes = %w[gem-c-single-page-notification-button]
@classes << "js-personalisation-enhancement" if js_enhancement
@button_text_subscribe = custom_button_text_is_valid? ? custom_subscribe_text : default_subscribe_text
@button_text_unsubscribe = custom_button_text_is_valid? ? custom_unsubscribe_text : default_unsubscribe_text
@skip_account = @local_assigns[:skip_account] || nil
end

def data
@data_attributes[:module] = "single-page-notification-button" if js_enhancement
# This attribute is passed through to the personalisation API to ensure when a new button is returned from the API, it has the same button_location
@data_attributes[:button_location] = button_location
@data_attributes[:button_text_subscribe] = @button_text_subscribe
@data_attributes[:button_text_unsubscribe] = @button_text_unsubscribe
@data_attributes
end

def button_location_is_valid?
%w[bottom top].include? @local_assigns[:button_location]
end
Expand Down
1 change: 1 addition & 0 deletions node_modules/.bin/acorn

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/cssesc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/ejs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/eslint

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/esparse

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/esvalidate

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/extract-zip

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/image-size

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/jake

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/jasmine-browser-runner

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/js-yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/json5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/loose-envify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/mkdirp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/nanoid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/percy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/percy-cli-readme

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/rimraf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/standard

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/standardx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/stylelint

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/which

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading