Преглед изворни кода

impl convertToGrantedGroups

Shun Miyazawa пре 1 година
родитељ
комит
8aecff650f

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

@@ -1,5 +1,6 @@
 import React, { useCallback, useState } from 'react';
 import React, { useCallback, useState } from 'react';
 
 
+import type { IGrantedGroup } from '@growi/core';
 import { useTranslation } from 'react-i18next';
 import { useTranslation } from 'react-i18next';
 import { Modal, TabContent, TabPane } from 'reactstrap';
 import { Modal, TabContent, TabPane } from 'reactstrap';
 
 
@@ -24,6 +25,13 @@ const moduleClass = styles['grw-ai-assistant-management'] ?? '';
 
 
 const logger = loggerFactory('growi:openai:client:components:AiAssistantManagementModal');
 const logger = loggerFactory('growi:openai:client:components:AiAssistantManagementModal');
 
 
+const convertToGrantedGroups = (selectedGroups: PopulatedGrantedGroup[]): IGrantedGroup[] => {
+  return selectedGroups.map(group => ({
+    type: group.type,
+    item: group.item._id,
+  }));
+};
+
 const AiAssistantManagementModalSubstance = (): JSX.Element => {
 const AiAssistantManagementModalSubstance = (): JSX.Element => {
   // Hooks
   // Hooks
   const { t } = useTranslation();
   const { t } = useTranslation();
@@ -59,6 +67,9 @@ const AiAssistantManagementModalSubstance = (): JSX.Element => {
         .map(selectedPage => (selectedPage.isIncludeSubPage ? `${selectedPage.page.path}/*` : selectedPage.page.path))
         .map(selectedPage => (selectedPage.isIncludeSubPage ? `${selectedPage.page.path}/*` : selectedPage.page.path))
         .filter((path): path is string => path !== undefined && path !== null);
         .filter((path): path is string => path !== undefined && path !== null);
 
 
+      const grantedGroupsForShareScope = convertToGrantedGroups(selectedUserGroupsForShareScope);
+      const grantedGroupsForAccessScope = convertToGrantedGroups(selectedUserGroupsForAccessScope);
+
       await createAiAssistant({
       await createAiAssistant({
         name,
         name,
         description,
         description,
@@ -66,6 +77,8 @@ const AiAssistantManagementModalSubstance = (): JSX.Element => {
         pagePathPatterns,
         pagePathPatterns,
         shareScope: selectedShareScope,
         shareScope: selectedShareScope,
         accessScope: selectedAccessScope,
         accessScope: selectedAccessScope,
+        grantedGroupsForShareScope: selectedShareScope === AiAssistantShareScope.GROUPS ? grantedGroupsForShareScope : undefined,
+        grantedGroupsForAccessScope: selectedAccessScope === AiAssistantAccessScope.GROUPS ? grantedGroupsForAccessScope : undefined,
       });
       });
 
 
       toastSuccess('アシスタントを作成しました');
       toastSuccess('アシスタントを作成しました');
@@ -74,7 +87,16 @@ const AiAssistantManagementModalSubstance = (): JSX.Element => {
       toastError('アシスタントの作成に失敗しました');
       toastError('アシスタントの作成に失敗しました');
       logger.error(err);
       logger.error(err);
     }
     }
-  }, [description, instruction, name, selectedAccessScope, selectedPages, selectedShareScope]);
+  }, [
+    description,
+    instruction,
+    name,
+    selectedAccessScope,
+    selectedPages,
+    selectedShareScope,
+    selectedUserGroupsForAccessScope,
+    selectedUserGroupsForShareScope,
+  ]);
 
 
 
 
   /*
   /*