UX: Hide AI preferences page completely if no settings for user (#644)
This commit is contained in:
		
							parent
							
								
									333b331eb9
								
							
						
					
					
						commit
						71affe75bf
					
				| 
						 | 
					@ -3,9 +3,25 @@ import { LinkTo } from "@ember/routing";
 | 
				
			||||||
import dIcon from "discourse-common/helpers/d-icon";
 | 
					import dIcon from "discourse-common/helpers/d-icon";
 | 
				
			||||||
import i18n from "discourse-common/helpers/i18n";
 | 
					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 {
 | 
					export default class AutoImageCaptionSetting extends Component {
 | 
				
			||||||
  static shouldRender(outletArgs, helper) {
 | 
					  static shouldRender(outletArgs, helper) {
 | 
				
			||||||
    return helper.siteSettings.discourse_ai_enabled;
 | 
					    return (
 | 
				
			||||||
 | 
					      helper.siteSettings.discourse_ai_enabled &&
 | 
				
			||||||
 | 
					      showAiPreferences(outletArgs.model, helper.siteSettings)
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <template>
 | 
					  <template>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,15 +11,6 @@ export default class PreferencesAiController extends Controller {
 | 
				
			||||||
  @service siteSettings;
 | 
					  @service siteSettings;
 | 
				
			||||||
  @tracked saved = false;
 | 
					  @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
 | 
					  @action
 | 
				
			||||||
  save() {
 | 
					  save() {
 | 
				
			||||||
    this.saved = false;
 | 
					    this.saved = false;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,5 @@
 | 
				
			||||||
<label class="control-label">{{i18n "discourse_ai.title"}}</label>
 | 
					<label class="control-label">{{i18n "discourse_ai.title"}}</label>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{{#if this.canToggleAutoImageCaption}}
 | 
					 | 
				
			||||||
<div class="control-group ai-setting">
 | 
					<div class="control-group ai-setting">
 | 
				
			||||||
  <PreferenceCheckbox
 | 
					  <PreferenceCheckbox
 | 
				
			||||||
    @labelKey="discourse_ai.ai_helper.image_caption.automatic_caption_setting"
 | 
					    @labelKey="discourse_ai.ai_helper.image_caption.automatic_caption_setting"
 | 
				
			||||||
| 
						 | 
					@ -16,9 +15,3 @@
 | 
				
			||||||
  @action={{this.save}}
 | 
					  @action={{this.save}}
 | 
				
			||||||
  @saved={{this.saved}}
 | 
					  @saved={{this.saved}}
 | 
				
			||||||
/>
 | 
					/>
 | 
				
			||||||
{{else}}
 | 
					 | 
				
			||||||
  <EmptyState
 | 
					 | 
				
			||||||
    @title={{i18n "discourse_ai.user_preferences.empty_state.title"}}
 | 
					 | 
				
			||||||
    @body={{i18n "discourse_ai.user_preferences.empty_state.body"}}
 | 
					 | 
				
			||||||
  />
 | 
					 | 
				
			||||||
{{/if}}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -119,11 +119,6 @@ en:
 | 
				
			||||||
    discourse_ai:
 | 
					    discourse_ai:
 | 
				
			||||||
      title: "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:
 | 
					      modals:
 | 
				
			||||||
        select_option: "Select an option..."
 | 
					        select_option: "Select an option..."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue