Skip to content

Commit

Permalink
Add link dialog tab - configuration
Browse files Browse the repository at this point in the history
Provide a configuration to configure the tabs in the link dialog. It is now possible to add new tabs without overwriting or defacing the Admin UI.
  • Loading branch information
sascha-karnatz committed Mar 4, 2024
1 parent 1fde2e9 commit 1264b63
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
3 changes: 1 addition & 2 deletions app/views/alchemy/admin/pages/link.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<sl-tab-group id="overlay_tabs">
<% tabs = [Alchemy::Admin::LinkDialog::InternalTab, Alchemy::Admin::LinkDialog::AnchorTab, Alchemy::Admin::LinkDialog::ExternalTab, Alchemy::Admin::LinkDialog::FileTab] %>
<% tabs.each do |tab| %>
<% Alchemy.link_dialog_tabs.each do |tab| %>
<%= render tab.new %>
<% end %>
</sl-tab-group>
36 changes: 36 additions & 0 deletions lib/alchemy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,40 @@ def self.publish_targets
# JS Importmap instance
singleton_class.attr_accessor :importmap
self.importmap = Importmap::Map.new

# Configure tabs in the link dialog
#
# With this configuration that tabs in the link dialog can be extended
# without overwriting or defacing the Admin Interface.
#
# == Example
#
# # components/acme/link_tab.rb
# module Acme
# class LinkTab < ::Alchemy::Admin::LinkDialog::BaseTab
# def title
# "Awesome Tab Title"
# end
#
# def name
# :unique_name
# end
#
# def fields
# [ title_input, target_select ]
# end
# end
# end
#
# # config/initializers/alchemy.rb
# Alchemy.link_dialog_tabs << Acme::LinkTab
#
def self.link_dialog_tabs
@_link_dialog_tabs ||= Set.new([
Alchemy::Admin::LinkDialog::InternalTab,
Alchemy::Admin::LinkDialog::AnchorTab,
Alchemy::Admin::LinkDialog::ExternalTab,
Alchemy::Admin::LinkDialog::FileTab
])
end
end
25 changes: 25 additions & 0 deletions spec/features/admin/link_overlay_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

require "rails_helper"

class TestTab < Alchemy::Admin::LinkDialog::BaseTab
def title
"Test Tab"
end

def name
:test_tab
end

def fields
[title_input, target_select]
end
end

RSpec.describe "Link overlay", type: :system do
let!(:language) { create(:alchemy_language) }

Expand Down Expand Up @@ -29,6 +43,17 @@
visit link_admin_pages_path
within("#overlay_tabs") { expect(page).to have_content("File") }
end

context "add new tab" do
before do
Alchemy.link_dialog_tabs << TestTab
end

it "has a new tab" do
visit link_admin_pages_path
within("#overlay_tabs") { expect(page).to have_content("Test Tab") }
end
end
end

context "linking pages", js: true do
Expand Down

0 comments on commit 1264b63

Please sign in to comment.