Просмотр исходного кода

Show warning when grantedPage is selected

Shun Miyazawa 1 год назад
Родитель
Сommit
d20645f907

+ 6 - 4
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantManagementModal/AiAssistantManagementHome.tsx

@@ -8,6 +8,7 @@ import {
 import { AiAssistantShareScope } from '~/features/openai/interfaces/ai-assistant';
 import { AiAssistantShareScope } from '~/features/openai/interfaces/ai-assistant';
 import { useCurrentUser } from '~/stores-universal/context';
 import { useCurrentUser } from '~/stores-universal/context';
 
 
+import type { SelectedPage } from '../../../../interfaces/selected-page';
 import { useAiAssistantManagementModal, AiAssistantManagementModalPageMode } from '../../../stores/ai-assistant';
 import { useAiAssistantManagementModal, AiAssistantManagementModalPageMode } from '../../../stores/ai-assistant';
 
 
 import { ShareScopeWarningModal } from './ShareScopeWarningModal';
 import { ShareScopeWarningModal } from './ShareScopeWarningModal';
@@ -18,6 +19,7 @@ type Props = {
   description: string;
   description: string;
   instruction: string;
   instruction: string;
   shareScope: AiAssistantShareScope
   shareScope: AiAssistantShareScope
+  grantedPages: SelectedPage[]
   totalSelectedPageCount: number;
   totalSelectedPageCount: number;
   onNameChange: (value: string) => void;
   onNameChange: (value: string) => void;
   onDescriptionChange: (value: string) => void;
   onDescriptionChange: (value: string) => void;
@@ -31,6 +33,7 @@ export const AiAssistantManagementHome = (props: Props): JSX.Element => {
     description,
     description,
     instruction,
     instruction,
     shareScope,
     shareScope,
+    grantedPages,
     totalSelectedPageCount,
     totalSelectedPageCount,
     onNameChange,
     onNameChange,
     onDescriptionChange,
     onDescriptionChange,
@@ -51,15 +54,13 @@ export const AiAssistantManagementHome = (props: Props): JSX.Element => {
   }, [currentUser?.username, t]);
   }, [currentUser?.username, t]);
 
 
   const createAiAssistantHandler = useCallback(async() => {
   const createAiAssistantHandler = useCallback(async() => {
-    // TODO: Implement the logic to check if the assistant has a share scope that includes private pages
-    // task: https://redmine.weseek.co.jp/issues/161341
-    if (true) {
+    if (grantedPages.length !== 0) {
       setIsShareScopeWarningModalOpen(true);
       setIsShareScopeWarningModalOpen(true);
       return;
       return;
     }
     }
 
 
     await onCreateAiAssistant();
     await onCreateAiAssistant();
-  }, [onCreateAiAssistant]);
+  }, [grantedPages.length, onCreateAiAssistant]);
 
 
   return (
   return (
     <>
     <>
@@ -147,6 +148,7 @@ export const AiAssistantManagementHome = (props: Props): JSX.Element => {
 
 
       <ShareScopeWarningModal
       <ShareScopeWarningModal
         isOpen={isShareScopeWarningModalOpen}
         isOpen={isShareScopeWarningModalOpen}
+        grantedPages={grantedPages}
         closeModal={() => setIsShareScopeWarningModalOpen(false)}
         closeModal={() => setIsShareScopeWarningModalOpen(false)}
         onSubmit={onCreateAiAssistant}
         onSubmit={onCreateAiAssistant}
       />
       />

+ 9 - 2
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantManagementModal/AiAssistantManagementModal.tsx

@@ -2,8 +2,9 @@ import React, {
   useCallback, useState, useEffect, useMemo,
   useCallback, useState, useEffect, useMemo,
 } from 'react';
 } from 'react';
 
 
-import type { IPageHasId } from '@growi/core';
-import { type IGrantedGroup, isPopulated } from '@growi/core';
+import {
+  type IGrantedGroup, type IPageHasId, isPopulated, PageGrant,
+} 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';
 
 
@@ -116,6 +117,11 @@ const AiAssistantManagementModalSubstance = (): JSX.Element => {
   /*
   /*
   *  For AiAssistantManagementHome methods
   *  For AiAssistantManagementHome methods
   */
   */
+
+  const grantedPages = useMemo(() => {
+    return selectedPages.filter(selectedPage => selectedPage.page.grant !== PageGrant.GRANT_PUBLIC);
+  }, [selectedPages]);
+
   const totalSelectedPageCount = useMemo(() => {
   const totalSelectedPageCount = useMemo(() => {
     return selectedPages.reduce((total, selectedPage) => {
     return selectedPages.reduce((total, selectedPage) => {
       const descendantCount = selectedPage.isIncludeSubPage
       const descendantCount = selectedPage.isIncludeSubPage
@@ -250,6 +256,7 @@ const AiAssistantManagementModalSubstance = (): JSX.Element => {
             description={description}
             description={description}
             shareScope={selectedShareScope}
             shareScope={selectedShareScope}
             instruction={instruction}
             instruction={instruction}
+            grantedPages={grantedPages}
             totalSelectedPageCount={totalSelectedPageCount}
             totalSelectedPageCount={totalSelectedPageCount}
             onNameChange={changeNameHandler}
             onNameChange={changeNameHandler}
             onDescriptionChange={changeDescriptionHandler}
             onDescriptionChange={changeDescriptionHandler}

+ 9 - 3
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantManagementModal/ShareScopeWarningModal.tsx

@@ -4,8 +4,11 @@ import {
   Modal, ModalHeader, ModalBody, ModalFooter,
   Modal, ModalHeader, ModalBody, ModalFooter,
 } from 'reactstrap';
 } from 'reactstrap';
 
 
+import type { SelectedPage } from '../../../../interfaces/selected-page';
+
 type Props = {
 type Props = {
   isOpen: boolean,
   isOpen: boolean,
+  grantedPages: SelectedPage[],
   closeModal: () => void,
   closeModal: () => void,
   onSubmit: () => Promise<void>,
   onSubmit: () => Promise<void>,
 }
 }
@@ -13,6 +16,7 @@ type Props = {
 export const ShareScopeWarningModal = (props: Props): JSX.Element => {
 export const ShareScopeWarningModal = (props: Props): JSX.Element => {
   const {
   const {
     isOpen,
     isOpen,
+    grantedPages,
     closeModal,
     closeModal,
     onSubmit,
     onSubmit,
   } = props;
   } = props;
@@ -39,9 +43,11 @@ export const ShareScopeWarningModal = (props: Props): JSX.Element => {
 
 
         <div className="mb-4">
         <div className="mb-4">
           <p className="mb-2 text-secondary">含まれる限定公開ページ</p>
           <p className="mb-2 text-secondary">含まれる限定公開ページ</p>
-          <code>
-            /Project/GROWI/新機能/GROWI AI
-          </code>
+          {grantedPages.map(grantedPage => (
+            <code>
+              {grantedPage.page?.path}
+            </code>
+          ))}
         </div>
         </div>
 
 
         <p>
         <p>