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:
parent
4b29ab8572
commit
3eb6fc058a
|
@ -38,6 +38,10 @@ export default class AdminPluginsListItem extends Component {
|
|||
return this.args.plugin.nameTitleizedLower.match(this.sidebarState.filter);
|
||||
}
|
||||
|
||||
get showPluginSettingsButton() {
|
||||
return this.currentUser.admin && this.args.plugin.hasSettings;
|
||||
}
|
||||
|
||||
<template>
|
||||
<tr
|
||||
data-plugin-name={{@plugin.name}}
|
||||
|
@ -101,8 +105,18 @@ export default class AdminPluginsListItem extends Component {
|
|||
{{/if}}
|
||||
</td>
|
||||
<td class="admin-plugins-list__settings">
|
||||
{{#if this.currentUser.admin}}
|
||||
{{#if @plugin.hasSettings}}
|
||||
{{#if this.showPluginSettingsButton}}
|
||||
{{#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
|
||||
class="btn-default btn btn-icon-text"
|
||||
@route="adminSiteSettingsCategory"
|
||||
|
|
|
@ -29,6 +29,10 @@ export default class AdminPlugin {
|
|||
this.extras = args.extras;
|
||||
}
|
||||
|
||||
get useNewShowRoute() {
|
||||
return this.adminRoute?.use_new_show_route;
|
||||
}
|
||||
|
||||
get snakeCaseName() {
|
||||
return this.name.replaceAll("-", "_");
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
|
@ -114,6 +114,10 @@
|
|||
.admin-site-settings-filter-controls {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.setting-label {
|
||||
margin-left: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
&__empty-list {
|
||||
|
|
Loading…
Reference in New Issue