This repository was archived by the owner on Jul 22, 2025. It is now read-only.
generated from discourse/discourse-plugin-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 41
FEATURE: Display bot in feature list #1466
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 130 additions & 87 deletions
217
assets/javascripts/discourse/components/ai-features-list.gjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,98 +1,141 @@ | ||
| import Component from "@glimmer/component"; | ||
| import { concat } from "@ember/helper"; | ||
| import { gt } from "truth-helpers"; | ||
| import { action } from "@ember/object"; | ||
| import DButton from "discourse/components/d-button"; | ||
| import { i18n } from "discourse-i18n"; | ||
|
|
||
| const AiFeaturesList = <template> | ||
| <div class="ai-features-list"> | ||
| {{#each @modules as |module|}} | ||
| <div class="ai-module" data-module-name={{module.module_name}}> | ||
| <div class="ai-module__header"> | ||
| <div class="ai-module__module-title"> | ||
| <h3>{{i18n | ||
| (concat "discourse_ai.features." module.module_name ".name") | ||
| }}</h3> | ||
| <DButton | ||
| class="edit" | ||
| @label="discourse_ai.features.edit" | ||
| @route="adminPlugins.show.discourse-ai-features.edit" | ||
| @routeModels={{module.id}} | ||
| /> | ||
| export default class AiFeaturesList extends Component { | ||
| get sortedModules() { | ||
| return this.args.modules.sort((a, b) => { | ||
| const nameA = i18n(`discourse_ai.features.${a.module_name}.name`); | ||
| const nameB = i18n(`discourse_ai.features.${b.module_name}.name`); | ||
| return nameA.localeCompare(nameB); | ||
| }); | ||
| } | ||
|
|
||
| @action | ||
| hasGroups(feature) { | ||
| return this.groupList(feature).length > 0; | ||
| } | ||
|
|
||
| @action | ||
| groupList(feature) { | ||
| const groups = []; | ||
| const groupIds = new Set(); | ||
| if (feature.personas) { | ||
| feature.personas.forEach((persona) => { | ||
| if (persona.allowed_groups) { | ||
| persona.allowed_groups.forEach((group) => { | ||
| if (!groupIds.has(group.id)) { | ||
| groupIds.add(group.id); | ||
| groups.push(group); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| return groups; | ||
| } | ||
|
|
||
| <template> | ||
| <div class="ai-features-list"> | ||
| {{#each this.sortedModules as |module|}} | ||
| <div class="ai-module" data-module-name={{module.module_name}}> | ||
| <div class="ai-module__header"> | ||
| <div class="ai-module__module-title"> | ||
| <h3>{{i18n | ||
| (concat "discourse_ai.features." module.module_name ".name") | ||
| }}</h3> | ||
| <DButton | ||
| class="edit" | ||
| @label="discourse_ai.features.edit" | ||
| @route="adminPlugins.show.discourse-ai-features.edit" | ||
| @routeModels={{module.id}} | ||
| /> | ||
| </div> | ||
| <div>{{i18n | ||
| (concat | ||
| "discourse_ai.features." module.module_name ".description" | ||
| ) | ||
| }}</div> | ||
| </div> | ||
| <div>{{i18n | ||
| (concat | ||
| "discourse_ai.features." module.module_name ".description" | ||
| ) | ||
| }}</div> | ||
| </div> | ||
|
|
||
| <div class="admin-section-landing-wrapper ai-feature-cards"> | ||
| {{#each module.features as |feature|}} | ||
| <div | ||
| class="admin-section-landing-item ai-feature-card" | ||
| data-feature-name={{feature.name}} | ||
| > | ||
| <div class="admin-section-landing-item__content"> | ||
| <div class="ai-feature-card__feature-name"> | ||
| {{i18n | ||
| (concat | ||
| "discourse_ai.features." | ||
| module.module_name | ||
| "." | ||
| feature.name | ||
| ) | ||
| }} | ||
| {{#unless feature.enabled}} | ||
| <span>{{i18n "discourse_ai.features.disabled"}}</span> | ||
| {{/unless}} | ||
| </div> | ||
| <div class="ai-feature-card__persona"> | ||
| <span>{{i18n "discourse_ai.features.persona"}}</span> | ||
| {{#if feature.persona}} | ||
| <DButton | ||
| class="btn-flat btn-small ai-feature-card__persona-button" | ||
| @translatedLabel={{feature.persona.name}} | ||
| @route="adminPlugins.show.discourse-ai-personas.edit" | ||
| @routeModels={{feature.persona.id}} | ||
| /> | ||
| {{else}} | ||
| {{i18n "discourse_ai.features.no_persona"}} | ||
| {{/if}} | ||
| </div> | ||
| <div class="ai-feature-card__llm"> | ||
| <span>{{i18n "discourse_ai.features.llm"}}</span> | ||
| {{#if feature.llm_model.name}} | ||
| <DButton | ||
| class="btn-flat btn-small ai-feature-card__llm-button" | ||
| @translatedLabel={{feature.llm_model.name}} | ||
| @route="adminPlugins.show.discourse-ai-llms.edit" | ||
| @routeModels={{feature.llm_model.id}} | ||
| /> | ||
| {{else}} | ||
| {{i18n "discourse_ai.features.no_llm"}} | ||
| {{/if}} | ||
| </div> | ||
| {{#if feature.persona}} | ||
| <div class="ai-feature-card__groups"> | ||
| <span>{{i18n "discourse_ai.features.groups"}}</span> | ||
| {{#if (gt feature.persona.allowed_groups.length 0)}} | ||
| <ul class="ai-feature-card__item-groups"> | ||
| {{#each feature.persona.allowed_groups as |group|}} | ||
| <li>{{group.name}}</li> | ||
| {{/each}} | ||
| </ul> | ||
| <div class="admin-section-landing-wrapper ai-feature-cards"> | ||
| {{#each module.features as |feature|}} | ||
| <div | ||
| class="admin-section-landing-item ai-feature-card" | ||
| data-feature-name={{feature.name}} | ||
| > | ||
| <div class="admin-section-landing-item__content"> | ||
| <div class="ai-feature-card__feature-name"> | ||
| {{i18n | ||
| (concat | ||
| "discourse_ai.features." | ||
| module.module_name | ||
| "." | ||
| feature.name | ||
| ) | ||
| }} | ||
| {{#unless feature.enabled}} | ||
| <span>{{i18n "discourse_ai.features.disabled"}}</span> | ||
| {{/unless}} | ||
| </div> | ||
| <div class="ai-feature-card__persona"> | ||
| <span>{{i18n | ||
| "discourse_ai.features.persona" | ||
| count=feature.personas.length | ||
| }}</span> | ||
| {{#if feature.personas}} | ||
| {{#each feature.personas as |persona|}} | ||
SamSaffron marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <DButton | ||
| class="btn-flat btn-small ai-feature-card__persona-button" | ||
| @translatedLabel={{persona.name}} | ||
| @route="adminPlugins.show.discourse-ai-personas.edit" | ||
| @routeModels={{persona.id}} | ||
| /> | ||
| {{/each}} | ||
| {{else}} | ||
| {{i18n "discourse_ai.features.no_groups"}} | ||
| {{i18n "discourse_ai.features.no_persona"}} | ||
| {{/if}} | ||
| </div> | ||
| {{/if}} | ||
| <div class="ai-feature-card__llm"> | ||
| <span>{{i18n | ||
| "discourse_ai.features.llm" | ||
SamSaffron marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| count=feature.llm_models.length | ||
| }}</span> | ||
| {{#if feature.llm_models}} | ||
| {{#each feature.llm_models as |llm_model|}} | ||
| <DButton | ||
| class="btn-flat btn-small ai-feature-card__llm-button" | ||
| @translatedLabel={{llm_model.name}} | ||
| @route="adminPlugins.show.discourse-ai-llms.edit" | ||
| @routeModels={{llm_model.id}} | ||
| /> | ||
| {{/each}} | ||
| {{else}} | ||
| {{i18n "discourse_ai.features.no_llm"}} | ||
| {{/if}} | ||
| </div> | ||
| {{#if feature.personas}} | ||
| <div class="ai-feature-card__groups"> | ||
| <span>{{i18n "discourse_ai.features.groups"}}</span> | ||
| {{#if (this.hasGroups feature)}} | ||
| <ul class="ai-feature-card__item-groups"> | ||
| {{#each (this.groupList feature) as |group|}} | ||
| <li>{{group.name}}</li> | ||
| {{/each}} | ||
| </ul> | ||
| {{else}} | ||
| {{i18n "discourse_ai.features.no_groups"}} | ||
| {{/if}} | ||
| </div> | ||
| {{/if}} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| {{/each}} | ||
| {{/each}} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| {{/each}} | ||
| </div> | ||
| </template>; | ||
|
|
||
| export default AiFeaturesList; | ||
| {{/each}} | ||
| </div> | ||
| </template> | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.