Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ Rails/LexicallyScopedActionFilter:
Style/OptionalBooleanParameter:
Exclude:
- 'app/workers/*.rb'

Lint/MissingSuper:
Exclude:
- 'app/components/*/*.rb'
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ gem "sprockets-rails"
gem "transitions", require: ["transitions", "active_record/transitions"]
gem "uglifier"
gem "validates_email_format_of"
gem "view_component"
gem "whenever", require: false

group :development, :test do
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,10 @@ GEM
validates_email_format_of (1.7.2)
i18n
version_gem (1.1.0)
view_component (2.71.0)
activesupport (>= 5.0.0, < 8.0)
concurrent-ruby (~> 1.0)
method_source (~> 1.0)
warden (1.2.9)
rack (>= 2.0.9)
warden-oauth2 (0.0.1)
Expand Down Expand Up @@ -828,6 +832,7 @@ DEPENDENCIES
transitions
uglifier
validates_email_format_of
view_component
webmock
whenever

Expand Down
1 change: 1 addition & 0 deletions app/components/admin/form_cancel_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a class="govuk-link" href="<%= path %>">Cancel</a>
31 changes: 31 additions & 0 deletions app/components/admin/form_cancel_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

class Admin::FormCancelComponent < ViewComponent::Base

def initialize(object:)
@url_maker = Whitehall::UrlMaker.new(host: Plek.find("whitehall"))
@object = object
end

private

def path
if @object.new_record?
case @object
when CorporateInformationPage
@url_maker.polymorphic_path([:admin, @object.owning_organisation, CorporateInformationPage])
when Edition
@url_maker.admin_editions_path
else
@url_maker.polymorphic_path([:admin, @object.class])
end
else
case @object
when CorporateInformationPage, Edition
@url_maker.admin_edition_path(@object)
else
@url_maker.polymorphic_path([:admin, object])
end
end
end
end
12 changes: 12 additions & 0 deletions test/components/admin/form_cancel_component_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "test_helper"

class Admin::FormCancelComponentTest < ViewComponent::TestCase
def test_component_renders_something_useful
# assert_equal(
# %(<span>Hello, components!</span>),
# render_inline(Admin::FormCancelComponent.new(message: "Hello, components!")).css("span").to_html
# )
end
end