2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-10-03 17:21:20 +08:00

UX: Redirect to plugin's site settings after enabling plugin

This commit is contained in:
Alan Guo Xiang Tan 2025-09-23 16:52:01 +08:00
parent 0ba2b0d44b
commit 9bd7742eab
No known key found for this signature in database
GPG key ID: 286D2AB58F8C86B6
3 changed files with 105 additions and 17 deletions

View file

@ -27,7 +27,22 @@ export default class AdminPluginsListItem extends Component {
try {
plugin.enabled = newValue;
await SiteSetting.update(plugin.enabledSetting, newValue);
this.session.requiresRefresh = true;

if (newValue && this.showPluginSettingsButton) {
if (plugin.useNewShowRoute) {
this.router.transitionTo("adminPlugins.show", plugin);
} else {
this.router.transitionTo(
"adminSiteSettingsCategory",
plugin.settingCategoryName,
{
queryParams: { filter: `plugin:${plugin.name}` },
}
);
}
} else {
this.session.requiresRefresh = true;
}
} catch (err) {
plugin.enabled = oldValue;
popupAjaxError(err);

View file

@ -37,21 +37,6 @@ export default class AdminPluginsIndexController extends Controller {
];
}

@action
async togglePluginEnabled(plugin) {
const oldValue = plugin.enabled;
const newValue = !oldValue;

try {
plugin.enabled = newValue;
await SiteSetting.update(plugin.enabledSetting, newValue);
this.session.requiresRefresh = true;
} catch (e) {
plugin.enabled = oldValue;
popupAjaxError(e);
}
}

// NOTE: See also AdminPluginsController, there is some duplication here
// while we convert plugins to use_new_show_route
get adminRoutes() {

View file

@ -1,4 +1,4 @@
import { click, visit } from "@ember/test-helpers";
import { click, currentURL, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";

@ -29,6 +29,38 @@ acceptance("Admin - Plugins", function (needs) {
commit_url:
"https://github.com/username/some-test-plugin/commit/1234567890abcdef",
},
{
id: "navigation-test-plugin",
name: "navigation-test-plugin",
humanized_name: "Navigation Test Plugin",
about: "Plugin for testing navigation behavior",
version: "0.2",
url: "https://example.com",
admin_route: {
location: "navigation-test",
label: "navigation.test.label",
use_new_show_route: false,
},
enabled: false,
enabled_setting: "navigation_test_plugin_enabled",
has_settings: true,
},
{
id: "new-route-plugin",
name: "new-route-plugin",
humanized_name: "New Route Plugin",
about: "Plugin for testing new route navigation",
version: "0.3",
url: "https://example.com",
admin_route: {
location: "new-route-test",
label: "new.route.test.label",
use_new_show_route: true,
},
enabled: false,
enabled_setting: "new_route_plugin_enabled",
has_settings: true,
},
],
})
);
@ -36,6 +68,22 @@ acceptance("Admin - Plugins", function (needs) {
server.put("/admin/site_settings/testplugin_enabled", () =>
helper.response(200, {})
);

server.put("/admin/site_settings/navigation_test_plugin_enabled", () =>
helper.response(200, {})
);

server.put("/admin/site_settings/new_route_plugin_enabled", () =>
helper.response(200, {})
);

server.get("/admin/plugins/new-route-plugin", () =>
helper.response({ plugin: {} })
);

server.get("/admin/config/site_settings.json", () =>
helper.response({ site_settings: [] })
);
});

test("shows plugin list and can toggle state", async function (assert) {
@ -63,13 +111,53 @@ acceptance("Admin - Plugins", function (needs) {

const toggleSelector =
"table.admin-plugins-list tr .admin-plugins-list__enabled button";

assert
.dom(toggleSelector)
.hasAria("checked", "true", "displays the plugin as enabled");

await click(toggleSelector);

assert
.dom(toggleSelector)
.hasAria("checked", "false", "displays the plugin as enabled");
});

test("navigates to site settings page when enabling plugin that does not use new show route", async function (assert) {
await visit("/admin/plugins");

const toggleSelector =
"table.admin-plugins-list tr[data-plugin-name='navigation-test-plugin'] .admin-plugins-list__enabled button";

assert
.dom(toggleSelector)
.hasAria("checked", "false", "plugin starts disabled");

await click(toggleSelector);

assert.strictEqual(
currentURL(),
"/admin/site_settings/category/all_results?filter=plugin%3Anavigation-test-plugin",
"navigates to plugin settings with filter"
);
});

test("navigates to plugin's settings page when enabling plugin that uses new show route", async function (assert) {
await visit("/admin/plugins");

const toggleSelector =
"table.admin-plugins-list tr[data-plugin-name='new-route-plugin'] .admin-plugins-list__enabled button";

assert
.dom(toggleSelector)
.hasAria("checked", "false", "plugin starts disabled");

await click(toggleSelector);

assert.strictEqual(
currentURL(),
"/admin/plugins/new-route-plugin/settings",
"navigates to new plugin show route when use_new_show_route is true"
);
});
});