UX: Hide AI preferences page completely if no settings for user (#644)

This commit is contained in:
Keegan George 2024-05-27 13:27:45 -07:00 committed by GitHub
parent 333b331eb9
commit 71affe75bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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 conditions aren't met.
// If we add more user settings in the future we can move this
// logic to the the specific settings 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,6 +1,5 @@
<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"
@ -16,9 +15,3 @@
@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}}

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..."