DEV: Single admin plugin page for consistent admin plugin UX (#26024)

This commit adds new plugin show routes (`/admin/plugins/:plugin_id`) as we move
towards every plugin having a consistent UI/landing page.

As part of this, we are introducing a consistent way for plugins
to show an inner sidebar in their config page, via a new plugin
API `register_admin_config_nav_routes`

This accepts an array of links with a label/text, and an
ember route. Once this commit is merged we can start the process
of conforming other plugins to follow this pattern, as well
as supporting a single-page version of this for simpler plugins
that don't require an inner sidebar.

Part of /t/122841 internally
This commit is contained in:
Martin Brennan
2024-03-13 13:15:12 +10:00
committed by GitHub
parent 0b41b236d7
commit 4e7a75a7ec
26 changed files with 425 additions and 20 deletions

View File

@ -132,6 +132,16 @@ after_initialize do
end
end
add_to_serializer(
:admin_plugin,
:incoming_chat_webhooks,
include_condition: -> { self.name == "chat" },
) { Chat::IncomingWebhook.includes(:chat_channel).all }
add_to_serializer(:admin_plugin, :chat_channels, include_condition: -> { self.name == "chat" }) do
Chat::Channel.public_channels
end
add_to_serializer(:user_card, :can_chat_user) do
return false if !SiteSetting.chat_enabled
return false if scope.user.blank?

View File

@ -125,6 +125,24 @@ describe Chat do
end
end
describe "admin plugin serializer extension" do
let(:admin) { Fabricate(:admin) }
let(:chat_plugin) do
Plugin::Instance.parse_from_source(File.join(Rails.root, "plugins", "chat", "plugin.rb"))
end
let(:serializer) { AdminPluginSerializer.new(chat_plugin, scope: admin.guardian) }
it "includes all incoming webhooks via :incoming_chat_webhooks" do
webhook = Fabricate(:incoming_chat_webhook)
expect(serializer.incoming_chat_webhooks).to contain_exactly(webhook)
end
it "includes all chat channels via :chat_channels" do
channel = Fabricate(:chat_channel)
expect(serializer.chat_channels).to contain_exactly(channel)
end
end
describe "chat oneboxes" do
fab!(:chat_channel) { Fabricate(:category_channel) }
fab!(:user)

View File

@ -22,7 +22,7 @@ RSpec.describe ApplicationController do
sign_in(admin)
get "/latest"
expect(JSON.parse(preloaded_json["enabledPluginAdminRoutes"])).to include(
{ "label" => "chat.admin.title", "location" => "chat" },
{ "label" => "chat.admin.title", "location" => "chat", "use_new_show_route" => false },
)
end
end