FEATURE: Use the new plugin show route from the plugin list (#27097)

Followup 4e7a75a7ec

Several plugins (Gamification, AI) now use the new
plugin show route. Any plugins that are using it can
now redirect to this page via the Settings button in
the plugin list, rather than taking the user to the
old site settings page filtered by category.
This commit is contained in:
Martin Brennan 2024-05-22 11:34:12 +10:00 committed by GitHub
parent 4b29ab8572
commit 3eb6fc058a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 83 additions and 2 deletions

View File

@ -38,6 +38,10 @@ export default class AdminPluginsListItem extends Component {
return this.args.plugin.nameTitleizedLower.match(this.sidebarState.filter); return this.args.plugin.nameTitleizedLower.match(this.sidebarState.filter);
} }
get showPluginSettingsButton() {
return this.currentUser.admin && this.args.plugin.hasSettings;
}
<template> <template>
<tr <tr
data-plugin-name={{@plugin.name}} data-plugin-name={{@plugin.name}}
@ -101,8 +105,18 @@ export default class AdminPluginsListItem extends Component {
{{/if}} {{/if}}
</td> </td>
<td class="admin-plugins-list__settings"> <td class="admin-plugins-list__settings">
{{#if this.currentUser.admin}} {{#if this.showPluginSettingsButton}}
{{#if @plugin.hasSettings}} {{#if @plugin.useNewShowRoute}}
<LinkTo
class="btn-default btn btn-icon-text"
@route="adminPlugins.show"
@model={{@plugin}}
data-plugin-setting-button={{@plugin.name}}
>
{{icon "cog"}}
{{i18n "admin.plugins.change_settings_short"}}
</LinkTo>
{{else}}
<LinkTo <LinkTo
class="btn-default btn btn-icon-text" class="btn-default btn btn-icon-text"
@route="adminSiteSettingsCategory" @route="adminSiteSettingsCategory"

View File

@ -29,6 +29,10 @@ export default class AdminPlugin {
this.extras = args.extras; this.extras = args.extras;
} }
get useNewShowRoute() {
return this.adminRoute?.use_new_show_route;
}
get snakeCaseName() { get snakeCaseName() {
return this.name.replaceAll("-", "_"); return this.name.replaceAll("-", "_");
} }

View File

@ -0,0 +1,59 @@
import { getOwner } from "@ember/application";
import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
module("Integration | Component | admin-plugins-list-item", function (hooks) {
setupRenderingTest(hooks);
function pluginAttrs() {
return {
id: "discourse-test-plugin",
name: "discourse-test-plugin",
admin_route: {
location: "discourse-test-plugin",
label: "admin.plugins.title",
use_new_show_route: false,
full_location: "admin",
},
has_settings: true,
};
}
test("settings link route", async function (assert) {
this.currentUser.admin = true;
const store = getOwner(this).lookup("service:store");
this.plugin = store.createRecord("admin-plugin", pluginAttrs());
await render(hbs`<AdminPluginsListItem @plugin={{this.plugin}} />`);
assert
.dom(".admin-plugins-list__settings a")
.hasAttribute(
"href",
"/admin/site_settings/category/plugins?filter=plugin%3Adiscourse-test-plugin"
);
this.plugin.adminRoute.use_new_show_route = true;
await render(hbs`<AdminPluginsListItem @plugin={{this.plugin}} />`);
assert
.dom(".admin-plugins-list__settings a")
.hasAttribute("href", "/admin/plugins/discourse-test-plugin");
});
test("settings link show or hide", async function (assert) {
this.currentUser.admin = true;
const store = getOwner(this).lookup("service:store");
this.plugin = store.createRecord("admin-plugin", pluginAttrs());
await render(hbs`<AdminPluginsListItem @plugin={{this.plugin}} />`);
assert.dom(".admin-plugins-list__settings a").exists();
this.plugin.hasSettings = false;
await render(hbs`<AdminPluginsListItem @plugin={{this.plugin}} />`);
assert.dom(".admin-plugins-list__settings a").doesNotExist();
});
});

View File

@ -114,6 +114,10 @@
.admin-site-settings-filter-controls { .admin-site-settings-filter-controls {
margin-bottom: 1em; margin-bottom: 1em;
} }
.setting-label {
margin-left: 18px;
}
} }
&__empty-list { &__empty-list {