Explorar o código

refactor: replace isCreatablePageWithGlob with isCreatablePagePathPattern for improved page path validation

Shun Miyazawa hai 8 meses
pai
achega
80daed8e38

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

@@ -3,7 +3,7 @@ import React, {
 } from 'react';
 
 import { pathUtils } from '@growi/core/dist/utils';
-import { isCreatablePageWithGlob } from '../../../../utils/is-creatable-page-with-glob'
+import { isCreatablePagePathPattern } from '../../../../utils/is-creatable-page-path-pattern'
 import { useRect } from '@growi/ui/dist/utils';
 import { useTranslation } from 'react-i18next';
 import AutosizeInput from 'react-input-autosize';
@@ -123,7 +123,7 @@ const EditablePagePath = memo((props: EditablePagePathProps): JSX.Element => {
 
       // Validate page path
       const pagePathWithSlash = pathUtils.addHeadingSlash(inputValue);
-      if (inputValue === '' || disablePagePaths.includes(pagePathWithSlash) || !isCreatablePageWithGlob(pagePathWithSlash)) {
+      if (inputValue === '' || disablePagePaths.includes(pagePathWithSlash) || !isCreatablePagePathPattern(pagePathWithSlash)) {
         handleInputBlur();
         return;
       }

+ 2 - 2
apps/app/src/features/openai/server/routes/middlewares/upsert-ai-assistant-validator.ts

@@ -1,7 +1,7 @@
 import { GroupType } from '@growi/core';
 // import { isGlobPatternPath, isCreatablePage } from '@growi/core/dist/utils/page-path-utils';
 import { type ValidationChain, body } from 'express-validator';
-import { isCreatablePageWithGlob } from '../../../utils/is-creatable-page-with-glob'
+import { isCreatablePagePathPattern } from '../../../utils/is-creatable-page-path-pattern'
 
 import { AiAssistantShareScope, AiAssistantAccessScope } from '../../../interfaces/ai-assistant';
 
@@ -43,7 +43,7 @@ export const upsertAiAssistantValidator: ValidationChain[] = [
     .notEmpty()
     .withMessage('pagePathPatterns must not be empty')
     .custom((value: string) => {
-      return isCreatablePageWithGlob(value);
+      return isCreatablePagePathPattern(value);
     }),
 
   body('grantedGroupsForShareScope')

+ 1 - 1
apps/app/src/features/openai/utils/is-creatable-page-with-glob.ts → apps/app/src/features/openai/utils/is-creatable-page-path-pattern.ts

@@ -1,7 +1,7 @@
 import { pagePathUtils } from '@growi/core/dist/utils';
 import { removeGlobPath } from './remove-glob-path';
 
-export const isCreatablePageWithGlob = (pagePath: string): boolean => {
+export const isCreatablePagePathPattern = (pagePath: string): boolean => {
 const isGlobPattern = pagePathUtils.isGlobPatternPath(pagePath);
   if (isGlobPattern) {
     // Remove glob pattern since glob paths are non-creatable in GROWI