Shun Miyazawa 2 лет назад
Родитель
Сommit
43aa6a7a63

+ 2 - 1
apps/app/src/client/services/side-effects/drawio-modal-launcher-for-view.ts

@@ -5,6 +5,7 @@ import type EventEmitter from 'events';
 import type { DrawioEditByViewerProps } from '@growi/remark-drawio';
 
 import { replaceDrawioInMarkdown } from '~/components/Page/markdown-drawio-util-for-view';
+import { Origin } from '~/interfaces/apiv3';
 import { useShareLinkId } from '~/stores/context';
 import { useDrawioModal } from '~/stores/modal';
 import { useSWRxCurrentPage } from '~/stores/page';
@@ -47,7 +48,7 @@ export const useDrawioModalLauncherForView = (opts?: {
         pageId: currentPage._id,
         revisionId: currentRevisionId,
         body: newMarkdown,
-        origin: 'view',
+        origin: Origin.View,
       });
 
       opts?.onSaveSuccess?.();

+ 2 - 1
apps/app/src/client/services/side-effects/handsontable-modal-launcher-for-view.ts

@@ -4,6 +4,7 @@ import type EventEmitter from 'events';
 
 import type MarkdownTable from '~/client/models/MarkdownTable';
 import { getMarkdownTableFromLine, replaceMarkdownTableInMarkdown } from '~/components/Page/markdown-table-util-for-view';
+import { Origin } from '~/interfaces/apiv3';
 import { useShareLinkId } from '~/stores/context';
 import { useHandsontableModal } from '~/stores/modal';
 import { useSWRxCurrentPage } from '~/stores/page';
@@ -46,7 +47,7 @@ export const useHandsontableModalLauncherForView = (opts?: {
         pageId: currentPage._id,
         revisionId: currentRevisionId,
         body: newMarkdown,
-        origin: 'view',
+        origin: Origin.View,
       });
 
       opts?.onSaveSuccess?.();

+ 2 - 1
apps/app/src/components/PageEditor/PageEditor.tsx

@@ -65,6 +65,7 @@ import Preview from './Preview';
 import { scrollEditor, scrollPreview } from './ScrollSyncHelper';
 
 import '@growi/editor/dist/style.css';
+import { Origin } from '~/interfaces/apiv3';
 
 
 const logger = loggerFactory('growi:PageEditor');
@@ -215,7 +216,7 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
         revisionId: currentRevisionId,
         body: codeMirrorEditor?.getDoc() ?? '',
         grant: grantData?.grant,
-        origin: 'editor',
+        origin: Origin.Editor,
         userRelatedGrantUserGroupIds: grantData?.userRelatedGrantedGroups?.map((group) => {
           return { item: group.id, type: group.type };
         }),

+ 8 - 1
apps/app/src/interfaces/apiv3/page.ts

@@ -22,12 +22,19 @@ export type IApiv3PageCreateResponse = {
   revision: IRevisionHasId,
 };
 
+export const Origin = {
+  View: 'view',
+  Editor: 'editor',
+} as const;
+
+export type Origin = typeof Origin[keyof typeof Origin];
+
 export type IApiv3PageUpdateParams = IOptionsForUpdate & {
   pageId: string,
   revisionId: string,
   body: string,
 
-  origin?: 'view' | 'editor',
+  origin?: Origin,
   isSlackEnabled?: boolean,
   slackChannels?: string,
 };

+ 3 - 3
apps/app/src/server/routes/apiv3/page/update-page.ts

@@ -8,7 +8,7 @@ import { body } from 'express-validator';
 import mongoose from 'mongoose';
 
 import { SupportedAction, SupportedTargetModel } from '~/interfaces/activity';
-import type { IApiv3PageUpdateParams } from '~/interfaces/apiv3';
+import { type IApiv3PageUpdateParams, Origin } from '~/interfaces/apiv3';
 import type { IOptionsForUpdate } from '~/interfaces/page';
 import { RehypeSanitizeOption } from '~/interfaces/rehype';
 import type Crowi from '~/server/crowi';
@@ -59,8 +59,8 @@ export const updatePageHandlersFactory: UpdatePageHandlersFactory = (crowi) => {
     return new Xss(xssOption);
   })();
 
-  const validateOrigin = (value: string) => {
-    if (value === 'view' || value === 'editor') {
+  const validateOrigin = (origin: string) => {
+    if (origin === Origin.View || origin === Origin.Editor) {
       return true;
     }
     return false;