A platform for community discussion. Free, open, simple.
UX: only show AI persona dropdown with multiple options (#34527)
Krisa79aaa5eadd3
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-persona-llm-selector.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-persona-llm-selector.gjsindex 7013ecc49c6..6f86466bcce 100644--- a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-persona-llm-selector.gjs+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-persona-llm-selector.gjs@@ -129,6 +129,10 @@ export default class AiPersonaLlmSelector extends Component {.sort((a, b) => a.name.localeCompare(b.name));}+ get showPersonaSelector() {+ return this.botOptions?.length > 1;+ }+get showLLMSelector() {return this.allowLLMSelector && this.llmOptions.length > 1;}@@ -200,20 +204,22 @@ export default class AiPersonaLlmSelector extends Component {<template><div class="persona-llm-selector">- <div class="persona-llm-selector__selection-wrapper gpt-persona">- {{#if @showLabels}}- <label>{{i18n "discourse_ai.ai_bot.persona"}}</label>- {{/if}}- <DropdownSelectBox- class="persona-llm-selector__persona-dropdown"- @value={{this.value}}- @content={{this.botOptions}}- @options={{hash- icon=(if @showLabels "angle-down" "robot")- filterable=this.filterable- }}- />- </div>+ {{#if this.showPersonaSelector}}+ <div class="persona-llm-selector__selection-wrapper gpt-persona">+ {{#if @showLabels}}+ <label>{{i18n "discourse_ai.ai_bot.persona"}}</label>+ {{/if}}+ <DropdownSelectBox+ class="persona-llm-selector__persona-dropdown"+ @value={{this.value}}+ @content={{this.botOptions}}+ @options={{hash+ icon=(if @showLabels "angle-down" "robot")+ filterable=this.filterable+ }}+ />+ </div>+ {{/if}}{{#if this.showLLMSelector}}<div class="persona-llm-selector__selection-wrapper llm-selector">{{#if @showLabels}}diff --git a/plugins/discourse-ai/spec/system/ai_bot/ai_bot_helper_spec.rb b/plugins/discourse-ai/spec/system/ai_bot/ai_bot_helper_spec.rbindex de107fafbff..62dc2eae146 100644--- a/plugins/discourse-ai/spec/system/ai_bot/ai_bot_helper_spec.rb+++ b/plugins/discourse-ai/spec/system/ai_bot/ai_bot_helper_spec.rb@@ -28,21 +28,26 @@ RSpec.describe "AI chat channel summarization", type: :system doallowed_persona = AiPersona.lastallowed_persona.update!(allowed_group_ids: [group.id], enabled: true)+ # second persona to ensure dropdown shows (requires >1 option)+ second_persona = Fabricate(:ai_persona, allowed_group_ids: [group.id], enabled: true)+ second_persona.update!(allow_personal_messages: true)+visit "/latest"expect(page).to have_selector(".ai-bot-button")find(".ai-bot-button").clickfind(".gpt-persona").click- expect(page).to have_css(".gpt-persona ul li", count: 1)+ expect(page).to have_css(".gpt-persona ul li", count: 2)find(".llm-selector").clickexpect(page).to have_css(".llm-selector ul li", count: 2)expect(page).to have_selector(".d-editor-container")- # lets disable bots but still allow 1 personaallowed_persona.create_user!allowed_persona.update!(default_llm_id: gpt_4.id)+ second_persona.create_user!+ second_persona.update!(default_llm_id: gpt_4.id)gpt_4.update!(enabled_chat_bot: false)gpt_3_5_turbo.update!(enabled_chat_bot: false)@@ -51,7 +56,7 @@ RSpec.describe "AI chat channel summarization", type: :system dofind(".ai-bot-button").clickfind(".gpt-persona").click- expect(page).to have_css(".gpt-persona ul li", count: 1)+ expect(page).to have_css(".gpt-persona ul li", count: 2)expect(page).not_to have_selector(".llm-selector")SiteSetting.ai_bot_add_to_header = false