Ver Fonte

Common method to get shareScope

Shun Miyazawa há 1 ano atrás
pai
commit
2d891ca294

+ 7 - 3
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantManagementModal/AiAssistantManagementHome.tsx

@@ -6,10 +6,12 @@ import {
   ModalHeader, ModalBody, ModalFooter, Input,
 } from 'reactstrap';
 
+import type { AiAssistantAccessScope } from '~/features/openai/interfaces/ai-assistant';
 import { AiAssistantShareScope } from '~/features/openai/interfaces/ai-assistant';
 import { useCurrentUser } from '~/stores-universal/context';
 
 import type { SelectedPage } from '../../../../interfaces/selected-page';
+import { determineShareScope } from '../../../../utils/determine-share-scope';
 import { useAiAssistantManagementModal, AiAssistantManagementModalPageMode } from '../../../stores/ai-assistant';
 
 import { ShareScopeWarningModal } from './ShareScopeWarningModal';
@@ -20,6 +22,7 @@ type Props = {
   description: string;
   instruction: string;
   shareScope: AiAssistantShareScope,
+  accessScope: AiAssistantAccessScope,
   selectedPages: SelectedPage[];
   onNameChange: (value: string) => void;
   onDescriptionChange: (value: string) => void;
@@ -33,6 +36,7 @@ export const AiAssistantManagementHome = (props: Props): JSX.Element => {
     description,
     instruction,
     shareScope,
+    accessScope,
     selectedPages,
     onNameChange,
     onDescriptionChange,
@@ -69,13 +73,13 @@ export const AiAssistantManagementHome = (props: Props): JSX.Element => {
   }, [currentUser?.username, t]);
 
   const upsertAiAssistantHandler = useCallback(async() => {
-    if (grantedPages.length !== 0) {
+    if (determineShareScope(shareScope, accessScope) !== AiAssistantShareScope.OWNER && grantedPages.length !== 0) {
       setIsShareScopeWarningModalOpen(true);
       return;
     }
 
     await onUpsertAiAssistant();
-  }, [grantedPages.length, onUpsertAiAssistant]);
+  }, [accessScope, grantedPages.length, onUpsertAiAssistant, shareScope]);
 
   return (
     <>
@@ -179,7 +183,7 @@ export const AiAssistantManagementHome = (props: Props): JSX.Element => {
         isOpen={isShareScopeWarningModalOpen}
         grantedPages={grantedPages}
         closeModal={() => setIsShareScopeWarningModalOpen(false)}
-        onSubmit={upsertAiAssistantHandler}
+        onSubmit={onUpsertAiAssistant}
       />
     </>
   );

+ 1 - 0
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantManagementModal/AiAssistantManagementModal.tsx

@@ -240,6 +240,7 @@ const AiAssistantManagementModalSubstance = (): JSX.Element => {
             name={name}
             description={description}
             shareScope={selectedShareScope}
+            accessScope={selectedAccessScope}
             instruction={instruction}
             selectedPages={selectedPages}
             onNameChange={changeNameHandler}

+ 4 - 1
apps/app/src/features/openai/client/components/AiAssistant/Sidebar/AiAssistantTree.tsx

@@ -8,6 +8,7 @@ import { useCurrentUser } from '~/stores-universal/context';
 
 import type { AiAssistantAccessScope } from '../../../../interfaces/ai-assistant';
 import { AiAssistantShareScope, type AiAssistantHasId } from '../../../../interfaces/ai-assistant';
+import { determineShareScope } from '../../../../utils/determine-share-scope';
 import { deleteAiAssistant } from '../../../services/ai-assistant';
 import { useAiAssistantChatSidebar, useAiAssistantManagementModal } from '../../../stores/ai-assistant';
 import { useSWRMUTxThreads, useSWRxThreads } from '../../../stores/thread';
@@ -98,7 +99,7 @@ const ThreadItems: React.FC<ThreadItemsProps> = ({ aiAssistantData, onThreadClic
 *  AiAssistantItem
 */
 const getShareScopeIcon = (shareScope: AiAssistantShareScope, accessScope: AiAssistantAccessScope): string => {
-  const determinedSharedScope = shareScope === AiAssistantShareScope.SAME_AS_ACCESS_SCOPE ? accessScope : shareScope;
+  const determinedSharedScope = determineShareScope(shareScope, accessScope);
   switch (determinedSharedScope) {
     case AiAssistantShareScope.OWNER:
       return 'lock';
@@ -106,6 +107,8 @@ const getShareScopeIcon = (shareScope: AiAssistantShareScope, accessScope: AiAss
       return 'account_tree';
     case AiAssistantShareScope.PUBLIC_ONLY:
       return 'group';
+    case AiAssistantShareScope.SAME_AS_ACCESS_SCOPE:
+      return '';
   }
 };
 

+ 6 - 0
apps/app/src/features/openai/utils/determine-share-scope.ts

@@ -0,0 +1,6 @@
+import type { AiAssistantAccessScope } from '../interfaces/ai-assistant';
+import { AiAssistantShareScope } from '../interfaces/ai-assistant';
+
+export const determineShareScope = (shareScope: AiAssistantShareScope, accessScope: AiAssistantAccessScope): AiAssistantShareScope => {
+  return shareScope === AiAssistantShareScope.SAME_AS_ACCESS_SCOPE ? accessScope : shareScope;
+};