mirror of
https://github.com/hanzoai/forum.git
synced 2026-09-30 21:51:19 +00:00
From plugin-api comment:
Registers a new tab to be displayed in "more topics" area at the bottom of a topic page.
```gjs
api.registerMoreTopicsTab({
id: "other-topics",
name: i18n("other_topics.tab"),
component: <template>tbd</template>,
condition: ({ topic }) => topic.otherTopics?.length > 0,
});
```
You can additionally use more-topics-tabs value transformer to conditionally show/hide
specific tabs.
```js
api.registerValueTransformer("more-topics-tabs", ({ value, context }) => {
if (context.user?.aFeatureFlag) {
// Remove "suggested" from the topics page
return value.filter(
(tab) =>
context.currentContext !== "topic" ||
tab.id !== "suggested-topics"
);
}
});
```
46 lines
1.6 KiB
Plaintext
46 lines
1.6 KiB
Plaintext
import { click, visit } from "@ember/test-helpers";
|
|
import { test } from "qunit";
|
|
import { PLUGIN_API_VERSION, withPluginApi } from "discourse/lib/plugin-api";
|
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
acceptance("More topics - Plugin API", function (needs) {
|
|
needs.user();
|
|
|
|
test("displays the tabs", async function (assert) {
|
|
withPluginApi(PLUGIN_API_VERSION, (api) => {
|
|
api.registerMoreTopicsTab({
|
|
id: "my-tab",
|
|
name: "News",
|
|
component: <template>hello there!</template>,
|
|
condition: ({ context, topic }) =>
|
|
context === "topic" && topic.id === 280,
|
|
});
|
|
|
|
api.registerMoreTopicsTab({
|
|
id: "my-pm-tab",
|
|
name: "Other",
|
|
component: <template>hi!</template>,
|
|
condition: ({ context }) => context === "pm",
|
|
});
|
|
});
|
|
|
|
await visit("/t/-/280");
|
|
assert.dom(".more-topics__container li").exists({ count: 2 });
|
|
assert.dom(".more-topics__container li:last-of-type").hasText("News");
|
|
|
|
await click(`.more-topics__container button[title="News"]`);
|
|
assert.dom(".more-topics__lists").hasText("hello there!");
|
|
|
|
await visit("/t/-/12");
|
|
assert.dom(".more-topics__container li").exists({ count: 2 });
|
|
assert.dom(".more-topics__container li:last-of-type").hasText("Other");
|
|
|
|
await click(`.more-topics__container button[title="Other"]`);
|
|
assert.dom(".more-topics__lists").hasText("hi!");
|
|
|
|
await visit("/t/-/54077");
|
|
assert.dom(".more-topics__container li").doesNotExist();
|
|
assert.dom(".more-topics__container #suggested-topics-title").exists();
|
|
});
|
|
});
|