Ver Fonte

Add next button functionality and selected pages handling in AiAssistantKeywordSearch

Shun Miyazawa há 8 meses atrás
pai
commit
c2bc496d8f

+ 16 - 3
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantManagementModal/AiAssistantManagementKeywordSearch.tsx

@@ -12,6 +12,7 @@ import {
 
 
 import { useSWRxSearch } from '~/stores/search';
 import { useSWRxSearch } from '~/stores/search';
 
 
+import type { SelectedPage } from '../../../../interfaces/selected-page';
 import {
 import {
   useAiAssistantManagementModal, AiAssistantManagementModalPageMode,
   useAiAssistantManagementModal, AiAssistantManagementModalPageMode,
 } from '../../../stores/ai-assistant';
 } from '../../../stores/ai-assistant';
@@ -32,7 +33,10 @@ const isSelectedSearchKeyword = (value: unknown): value is SelectedSearchKeyword
   return (value as SelectedSearchKeyword).label != null;
   return (value as SelectedSearchKeyword).label != null;
 };
 };
 
 
-export const AiAssistantKeywordSearch = (): JSX.Element => {
+
+export const AiAssistantKeywordSearch = (props: { updateBaseSelectedPages: (pages: IPageHasId[]) => void}): JSX.Element => {
+  const { updateBaseSelectedPages } = props;
+
   const [selectedSearchKeywords, setSelectedSearchKeywords] = useState<Array<SelectedSearchKeyword>>([]);
   const [selectedSearchKeywords, setSelectedSearchKeywords] = useState<Array<SelectedSearchKeyword>>([]);
   const [selectedPages, setSelectedPages] = useState<Array<IPageHasId>>([]);
   const [selectedPages, setSelectedPages] = useState<Array<IPageHasId>>([]);
 
 
@@ -73,7 +77,7 @@ export const AiAssistantKeywordSearch = (): JSX.Element => {
   }, [searchResult, selectedSearchKeywords.length]);
   }, [searchResult, selectedSearchKeywords.length]);
 
 
 
 
-  const { data: aiAssistantManagementModalData } = useAiAssistantManagementModal();
+  const { data: aiAssistantManagementModalData, changePageMode } = useAiAssistantManagementModal();
   const isNewAiAssistant = aiAssistantManagementModalData?.aiAssistantData == null;
   const isNewAiAssistant = aiAssistantManagementModalData?.aiAssistantData == null;
 
 
   const typeaheadRef = useRef<TypeaheadRef>(null);
   const typeaheadRef = useRef<TypeaheadRef>(null);
@@ -133,6 +137,11 @@ export const AiAssistantKeywordSearch = (): JSX.Element => {
     });
     });
   }, []);
   }, []);
 
 
+  const nextButtonClickHandler = useCallback(() => {
+    updateBaseSelectedPages(selectedPages);
+    changePageMode(AiAssistantManagementModalPageMode.HOME);
+  }, [changePageMode, selectedPages, updateBaseSelectedPages]);
+
   return (
   return (
     <div className={moduleClass}>
     <div className={moduleClass}>
       <AiAssistantManagementHeader
       <AiAssistantManagementHeader
@@ -208,7 +217,11 @@ export const AiAssistantKeywordSearch = (): JSX.Element => {
         </div>
         </div>
 
 
         <div className="d-flex justify-content-center mt-4">
         <div className="d-flex justify-content-center mt-4">
-          <button type="button" className="btn btn-primary rounded next-button">
+          <button
+            type="button"
+            className="btn btn-primary rounded next-button"
+            onClick={nextButtonClickHandler}
+          >
             {t('modal_ai_assistant.next')}
             {t('modal_ai_assistant.next')}
           </button>
           </button>
         </div>
         </div>

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

@@ -2,9 +2,11 @@ import React, {
   useCallback, useState, useEffect, type JSX,
   useCallback, useState, useEffect, type JSX,
 } from 'react';
 } from 'react';
 
 
+import type { IPageHasId } from '@growi/core';
 import {
 import {
   type IGrantedGroup, isPopulated,
   type IGrantedGroup, isPopulated,
 } from '@growi/core';
 } from '@growi/core';
+import { isGlobPatternPath } from '@growi/core/dist/utils/page-path-utils';
 import { useTranslation } from 'react-i18next';
 import { useTranslation } from 'react-i18next';
 import { Modal, TabContent, TabPane } from 'reactstrap';
 import { Modal, TabContent, TabPane } from 'reactstrap';
 
 
@@ -115,6 +117,28 @@ const AiAssistantManagementModalSubstance = (): JSX.Element => {
   }, [aiAssistant?.pagePathPatterns, pagePathsWithDescendantCount, shouldEdit]);
   }, [aiAssistant?.pagePathPatterns, pagePathsWithDescendantCount, shouldEdit]);
 
 
 
 
+  /*
+  *  For AiAssistantManagementKeywordSearch methods
+  */
+  const selectPageHandlerByKeywordSearch = useCallback((pages: IPageHasId[]) => {
+    if (pages.length === 0) {
+      return;
+    }
+
+    const convertedSelectedPages = pages.map((page) => {
+      const pagePath = page.path;
+      page.path = removeGlobPath([pagePath])[0];
+
+      return {
+        page,
+        isIncludeSubPage: isGlobPatternPath(pagePath),
+      };
+    });
+
+    setSelectedPages(convertedSelectedPages);
+  }, []);
+
+
   /*
   /*
   *  For AiAssistantManagementHome methods
   *  For AiAssistantManagementHome methods
   */
   */
@@ -246,7 +270,9 @@ const AiAssistantManagementModalSubstance = (): JSX.Element => {
         </TabPane>
         </TabPane>
 
 
         <TabPane tabId={AiAssistantManagementModalPageMode.KEYWORD_SEARCH}>
         <TabPane tabId={AiAssistantManagementModalPageMode.KEYWORD_SEARCH}>
-          <AiAssistantKeywordSearch />
+          <AiAssistantKeywordSearch
+            updateBaseSelectedPages={selectPageHandlerByKeywordSearch}
+          />
         </TabPane>
         </TabPane>
 
 
         <TabPane tabId={AiAssistantManagementModalPageMode.HOME}>
         <TabPane tabId={AiAssistantManagementModalPageMode.HOME}>

+ 3 - 1
apps/app/src/features/openai/interfaces/selected-page.ts

@@ -1,6 +1,8 @@
+import type { IPageHasId } from '@growi/core';
+
 import type { IPageForItem } from '~/interfaces/page';
 import type { IPageForItem } from '~/interfaces/page';
 
 
 export type SelectedPage = {
 export type SelectedPage = {
-  page: IPageForItem,
+  page: IPageForItem | IPageHasId,
   isIncludeSubPage: boolean,
   isIncludeSubPage: boolean,
 }
 }