UX: Hide AI preferences page completely if no settings for user

This commit is contained in:
Keegan George 2024-05-27 12:44:17 -07:00
parent 2b98e84acf
commit 3ea1e8efd8
No known key found for this signature in database
GPG Key ID: 91B40E38537AC000
4 changed files with 31 additions and 36 deletions

View File

@ -3,9 +3,25 @@ import { LinkTo } from "@ember/routing";
import dIcon from "discourse-common/helpers/d-icon";
import i18n from "discourse-common/helpers/i18n";
function showAiPreferences(user, siteSettings) {
// Since we only have one AI related user setting we don't show
// AI preferences if these don't conditions aren't met.
// If we add more user settings in the future we can move this
// logic to the the specific settins and conditionally show it in the template.
const userGroups = user.groups.map((g) => g.id);
const captionGroups = siteSettings.ai_auto_image_caption_allowed_groups
.split("|")
.map((id) => parseInt(id, 10));
return userGroups.some((groupId) => captionGroups.includes(groupId));
}
export default class AutoImageCaptionSetting extends Component {
static shouldRender(outletArgs, helper) {
return helper.siteSettings.discourse_ai_enabled;
return (
helper.siteSettings.discourse_ai_enabled &&
showAiPreferences(outletArgs.model, helper.siteSettings)
);
}
<template>

View File

@ -11,15 +11,6 @@ export default class PreferencesAiController extends Controller {
@service siteSettings;
@tracked saved = false;
get canToggleAutoImageCaption() {
const userGroups = this.model.groups.map((g) => g.id);
const captionGroups = this.siteSettings.ai_auto_image_caption_allowed_groups
.split("|")
.map((id) => parseInt(id, 10));
return userGroups.some((groupId) => captionGroups.includes(groupId));
}
@action
save() {
this.saved = false;

View File

@ -1,24 +1,17 @@
<label class="control-label">{{i18n "discourse_ai.title"}}</label>
{{#if this.canToggleAutoImageCaption}}
<div class="control-group ai-setting">
<PreferenceCheckbox
@labelKey="discourse_ai.ai_helper.image_caption.automatic_caption_setting"
@checked={{this.model.user_option.auto_image_caption}}
data-setting-name="auto-image-caption"
class="pref-auto-image-caption"
/>
</div>
<div class="control-group ai-setting">
<PreferenceCheckbox
@labelKey="discourse_ai.ai_helper.image_caption.automatic_caption_setting"
@checked={{this.model.user_option.auto_image_caption}}
data-setting-name="auto-image-caption"
class="pref-auto-image-caption"
/>
</div>
<SaveControls
@id="user_ai_preference_save"
@model={{this.model}}
@action={{this.save}}
@saved={{this.saved}}
/>
{{else}}
<EmptyState
@title={{i18n "discourse_ai.user_preferences.empty_state.title"}}
@body={{i18n "discourse_ai.user_preferences.empty_state.body"}}
/>
{{/if}}
<SaveControls
@id="user_ai_preference_save"
@model={{this.model}}
@action={{this.save}}
@saved={{this.saved}}
/>

View File

@ -119,11 +119,6 @@ en:
discourse_ai:
title: "AI"
user_preferences:
empty_state:
title: "No AI specific user preferences available."
body: "There are currently no user preferences related to AI that are available for you to toggle."
modals:
select_option: "Select an option..."