Răsfoiți Sursa

refactor: include subordinate pages in selected pages with glob path formatting

Shun Miyazawa 8 luni în urmă
părinte
comite
6e84eefec4

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

@@ -1,5 +1,5 @@
 import React, {
 import React, {
-  Suspense, useCallback, memo,
+  Suspense, useCallback, memo, useMemo,
 } from 'react';
 } from 'react';
 
 
 import type { IPageHasId } from '@growi/core';
 import type { IPageHasId } from '@growi/core';
@@ -98,6 +98,24 @@ export const AiAssistantManagementPageTreeSelection = (props: { updateBaseSelect
 
 
   const { selectedPages, addPageHandler, removePageHandler } = useSelectedPages();
   const { selectedPages, addPageHandler, removePageHandler } = useSelectedPages();
 
 
+  // SelectedPages will include subordinate pages by default
+  const pagesWithGlobPath = useMemo((): IPageHasId[] | undefined => {
+    if (selectedPages.size === 0) {
+      return;
+    }
+    return Array.from(selectedPages.values()).map((page) => {
+      if (page.path === '/') {
+        page.path = '/*';
+      }
+
+      if (!page.path.endsWith('/*')) {
+        page.path = `${page.path}/*`;
+      }
+
+      return page;
+    });
+  }, [selectedPages]);
+
   const nextButtonClickHandler = useCallback(() => {
   const nextButtonClickHandler = useCallback(() => {
     updateBaseSelectedPages(Array.from(selectedPages.values()));
     updateBaseSelectedPages(Array.from(selectedPages.values()));
     changePageMode(AiAssistantManagementModalPageMode.HOME);
     changePageMode(AiAssistantManagementModalPageMode.HOME);
@@ -128,9 +146,9 @@ export const AiAssistantManagementPageTreeSelection = (props: { updateBaseSelect
 
 
         <div className="px-4">
         <div className="px-4">
           <SelectablePagePageList
           <SelectablePagePageList
-            pages={Array.from(selectedPages.values())}
             method="remove"
             method="remove"
             methodButtonPosition="right"
             methodButtonPosition="right"
+            pages={pagesWithGlobPath ?? []}
             onClickMethodButton={removePageHandler}
             onClickMethodButton={removePageHandler}
           />
           />
           <label className="form-text text-muted mt-2">
           <label className="form-text text-muted mt-2">