From 8bd55c35fb817737d0670e3183b86bbb01d24b24 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Thu, 12 Dec 2024 10:49:17 +1100 Subject: [PATCH] UX: Hide admin header for edit/new webhook (#30194) In this PR, we added functionality to hide the admin header for edit/new actions - https://github.com/discourse/discourse/pull/30175 To make it work properly, we have to rename `show` to `edit` which is also a more accurate name. --- .../admin/components/admin-chat-incoming-webhooks-list.gjs | 2 +- .../admin/components/chat-incoming-webhook-edit-form.gjs | 2 +- ...-plugins-show-discourse-chat-incoming-webhooks-edit.js} | 6 ++++-- .../{show.hbs => edit.hbs} | 0 .../controllers/chat/admin/incoming_webhooks_controller.rb | 2 +- .../assets/javascripts/discourse/admin-chat-route-map.js | 2 +- plugins/chat/plugin.rb | 4 ++-- plugins/chat/spec/system/admin/incoming_webhooks_spec.rb | 7 +++++++ 8 files changed, 17 insertions(+), 8 deletions(-) rename plugins/chat/admin/assets/javascripts/discourse/routes/{admin-plugins-show-discourse-chat-incoming-webhooks-show.js => admin-plugins-show-discourse-chat-incoming-webhooks-edit.js} (83%) rename plugins/chat/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-chat-incoming-webhooks/{show.hbs => edit.hbs} (100%) diff --git a/plugins/chat/admin/assets/javascripts/admin/components/admin-chat-incoming-webhooks-list.gjs b/plugins/chat/admin/assets/javascripts/admin/components/admin-chat-incoming-webhooks-list.gjs index db4e57446f7..4ce3ff7faaf 100644 --- a/plugins/chat/admin/assets/javascripts/admin/components/admin-chat-incoming-webhooks-list.gjs +++ b/plugins/chat/admin/assets/javascripts/admin/components/admin-chat-incoming-webhooks-list.gjs @@ -88,7 +88,7 @@ export default class AdminChatIncomingWebhooksList extends Component { >
{{i18n "chat.incoming_webhooks.edit"}} diff --git a/plugins/chat/admin/assets/javascripts/admin/components/chat-incoming-webhook-edit-form.gjs b/plugins/chat/admin/assets/javascripts/admin/components/chat-incoming-webhook-edit-form.gjs index 58ffc4e8c96..13f23a054c6 100644 --- a/plugins/chat/admin/assets/javascripts/admin/components/chat-incoming-webhook-edit-form.gjs +++ b/plugins/chat/admin/assets/javascripts/admin/components/chat-incoming-webhook-edit-form.gjs @@ -70,7 +70,7 @@ export default class ChatIncomingWebhookEditForm extends Component { this.router .transitionTo( - "adminPlugins.show.discourse-chat-incoming-webhooks.show", + "adminPlugins.show.discourse-chat-incoming-webhooks.edit", webhook ) .then(() => { diff --git a/plugins/chat/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-chat-incoming-webhooks-show.js b/plugins/chat/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-chat-incoming-webhooks-edit.js similarity index 83% rename from plugins/chat/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-chat-incoming-webhooks-show.js rename to plugins/chat/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-chat-incoming-webhooks-edit.js index 07cf5edc522..fc09995767e 100644 --- a/plugins/chat/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-chat-incoming-webhooks-show.js +++ b/plugins/chat/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-chat-incoming-webhooks-edit.js @@ -5,7 +5,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error"; import DiscourseRoute from "discourse/routes/discourse"; import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel"; -export default class DiscourseChatIncomingWebhooksShow extends DiscourseRoute { +export default class DiscourseChatIncomingWebhooksEdit extends DiscourseRoute { @service currentUser; async model(params) { @@ -14,7 +14,9 @@ export default class DiscourseChatIncomingWebhooksShow extends DiscourseRoute { } try { - const model = await ajax(`/admin/plugins/chat/hooks/${params.id}.json`); + const model = await ajax( + `/admin/plugins/chat/hooks/${params.id}/edit.json` + ); model.webhook = EmberObject.create(model.webhook); model.webhook.chat_channel = ChatChannel.create( diff --git a/plugins/chat/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-chat-incoming-webhooks/show.hbs b/plugins/chat/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-chat-incoming-webhooks/edit.hbs similarity index 100% rename from plugins/chat/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-chat-incoming-webhooks/show.hbs rename to plugins/chat/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-chat-incoming-webhooks/edit.hbs diff --git a/plugins/chat/app/controllers/chat/admin/incoming_webhooks_controller.rb b/plugins/chat/app/controllers/chat/admin/incoming_webhooks_controller.rb index 95beaa6fc46..bbfcc41ff67 100644 --- a/plugins/chat/app/controllers/chat/admin/incoming_webhooks_controller.rb +++ b/plugins/chat/app/controllers/chat/admin/incoming_webhooks_controller.rb @@ -16,7 +16,7 @@ module Chat ) end - def show + def edit webhook = Chat::IncomingWebhook.includes(:chat_channel).find(params[:incoming_chat_webhook_id]) render_serialized( diff --git a/plugins/chat/assets/javascripts/discourse/admin-chat-route-map.js b/plugins/chat/assets/javascripts/discourse/admin-chat-route-map.js index 0fdf407be59..eebf0bd22b1 100644 --- a/plugins/chat/assets/javascripts/discourse/admin-chat-route-map.js +++ b/plugins/chat/assets/javascripts/discourse/admin-chat-route-map.js @@ -7,7 +7,7 @@ export default { { path: "hooks" }, function () { this.route("new"); - this.route("show", { path: "/:id" }); + this.route("edit", { path: "/:id/edit" }); } ); }, diff --git a/plugins/chat/plugin.rb b/plugins/chat/plugin.rb index 76f4562f39a..31da38f55ec 100644 --- a/plugins/chat/plugin.rb +++ b/plugins/chat/plugin.rb @@ -409,8 +409,8 @@ after_initialize do :constraints => StaffConstraint.new get "/admin/plugins/chat/hooks/new" => "chat/admin/incoming_webhooks#new", :constraints => StaffConstraint.new - get "/admin/plugins/chat/hooks/:incoming_chat_webhook_id" => - "chat/admin/incoming_webhooks#show", + get "/admin/plugins/chat/hooks/:incoming_chat_webhook_id/edit" => + "chat/admin/incoming_webhooks#edit", :constraints => StaffConstraint.new delete "/admin/plugins/chat/hooks/:incoming_chat_webhook_id" => "chat/admin/incoming_webhooks#destroy", diff --git a/plugins/chat/spec/system/admin/incoming_webhooks_spec.rb b/plugins/chat/spec/system/admin/incoming_webhooks_spec.rb index 41deeb0686e..895d94e68fb 100644 --- a/plugins/chat/spec/system/admin/incoming_webhooks_spec.rb +++ b/plugins/chat/spec/system/admin/incoming_webhooks_spec.rb @@ -6,6 +6,7 @@ describe "Admin Chat Incoming Webhooks", type: :system do let(:dialog) { PageObjects::Components::Dialog.new } let(:admin_incoming_webhooks_page) { PageObjects::Pages::AdminIncomingWebhooks.new } + let(:admin_header) { PageObjects::Components::AdminHeader.new } before do chat_system_bootstrap(current_user) @@ -14,7 +15,13 @@ describe "Admin Chat Incoming Webhooks", type: :system do it "can create incoming webhooks" do admin_incoming_webhooks_page.visit + + expect(admin_header).to be_visible + admin_incoming_webhooks_page.click_new + + expect(admin_header).to be_hidden + admin_incoming_webhooks_page.form.field("name").fill_in("Test webhook") admin_incoming_webhooks_page.form.field("description").fill_in("Some test content") admin_incoming_webhooks_page.form.field("username").fill_in("system")