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

Merge pull request #8222 from weseek/fix/134173-fix-tag-edit

fix: Show expected tags after update pages
Yuki Takei 2 лет назад
Родитель
Сommit
ee62737eee

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

@@ -30,14 +30,13 @@ export const useDrawioModalLauncherForView = (opts?: {
   const { data: shareLinkId } = useShareLinkId();
 
   const { data: currentPage } = useSWRxCurrentPage();
-  const { data: tagsInfo } = useSWRxTagsInfo(currentPage?._id);
 
   const { open: openDrawioModal } = useDrawioModal();
 
   const saveOrUpdate = useSaveOrUpdate();
 
   const saveByDrawioModal = useCallback(async(drawioMxFile: string, bol: number, eol: number) => {
-    if (currentPage == null || tagsInfo == null || shareLinkId != null) {
+    if (currentPage == null || shareLinkId != null) {
       return;
     }
 
@@ -50,7 +49,6 @@ export const useDrawioModalLauncherForView = (opts?: {
       grant: currentPage.grant,
       grantUserGroupId: currentPage.grantedGroup?._id,
       grantUserGroupName: currentPage.grantedGroup?.name,
-      pageTags: tagsInfo.tags,
     };
 
     try {
@@ -67,7 +65,7 @@ export const useDrawioModalLauncherForView = (opts?: {
       logger.error('failed to save', error);
       opts?.onSaveError?.(error);
     }
-  }, [currentPage, opts, saveOrUpdate, shareLinkId, tagsInfo]);
+  }, [currentPage, opts, saveOrUpdate, shareLinkId]);
 
 
   // set handler to open DrawioModal

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

@@ -29,14 +29,13 @@ export const useHandsontableModalLauncherForView = (opts?: {
   const { data: shareLinkId } = useShareLinkId();
 
   const { data: currentPage } = useSWRxCurrentPage();
-  const { data: tagsInfo } = useSWRxTagsInfo(currentPage?._id);
 
   const { open: openHandsontableModal } = useHandsontableModal();
 
   const saveOrUpdate = useSaveOrUpdate();
 
   const saveByHandsontableModal = useCallback(async(table: MarkdownTable, bol: number, eol: number) => {
-    if (currentPage == null || tagsInfo == null || shareLinkId != null) {
+    if (currentPage == null || shareLinkId != null) {
       return;
     }
 
@@ -49,7 +48,6 @@ export const useHandsontableModalLauncherForView = (opts?: {
       grant: currentPage.grant,
       grantUserGroupId: currentPage.grantedGroup?._id,
       grantUserGroupName: currentPage.grantedGroup?.name,
-      pageTags: tagsInfo.tags,
     };
 
     try {
@@ -66,7 +64,7 @@ export const useHandsontableModalLauncherForView = (opts?: {
       logger.error('failed to save', error);
       opts?.onSaveError?.(error);
     }
-  }, [currentPage, opts, saveOrUpdate, shareLinkId, tagsInfo]);
+  }, [currentPage, opts, saveOrUpdate, shareLinkId]);
 
 
   // set handler to open HandsonTableModal

+ 0 - 1
apps/app/src/components/Navbar/hooks.tsx

@@ -35,7 +35,6 @@ export const useOnPageEditorModeButtonClicked = (
           isSlackEnabled: false,
           slackChannels: '',
           grant,
-          pageTags: [],
           grantUserGroupId,
         };
 

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

@@ -98,7 +98,7 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
   const { data: currentPage } = useSWRxCurrentPage();
   const { trigger: mutateCurrentPage } = useSWRMUTxCurrentPage();
   const { data: grantData } = useSelectedGrant();
-  const { data: pageTags, sync: syncTagsInfoForEditor } = usePageTagsForEditors(pageId);
+  const { sync: syncTagsInfoForEditor } = usePageTagsForEditors(pageId);
   const { mutate: mutateTagsInfo } = useSWRxTagsInfo(pageId);
   const { data: editingMarkdown, mutate: mutateEditingMarkdown } = useEditingMarkdown();
   const { data: isEnabledAttachTitleHeader } = useIsEnabledAttachTitleHeader();
@@ -218,12 +218,11 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
       isSlackEnabled: isSlackEnabled ?? false,
       slackChannels: '', // set in save method by opts in SavePageControlls.tsx
       grant: grantData.grant,
-      pageTags: pageTags ?? [],
       grantUserGroupId: grantData.grantedGroup?.id,
       grantUserGroupName: grantData.grantedGroup?.name,
     };
     return optionsToSave;
-  }, [grantData, isSlackEnabled, pageTags]);
+  }, [grantData, isSlackEnabled]);
 
 
   const save = useCallback(async(opts?: {slackChannels: string, overwriteScopesOfDescendants?: boolean}): Promise<IPageHasId | null> => {

+ 1 - 5
apps/app/src/components/Sidebar/PageCreateButton/PageCreateButton.tsx

@@ -10,8 +10,8 @@ import { useCurrentUser } from '~/stores/context';
 import { useSWRxCurrentPage } from '~/stores/page';
 import loggerFactory from '~/utils/logger';
 
-import { DropendMenu } from './DropendMenu';
 import { CreateButton } from './CreateButton';
+import { DropendMenu } from './DropendMenu';
 import { DropendToggle } from './DropendToggle';
 
 const logger = loggerFactory('growi:cli:PageCreateButton');
@@ -50,7 +50,6 @@ export const PageCreateButton = React.memo((): JSX.Element => {
         isSlackEnabled: false,
         slackChannels: '',
         grant: currentPage?.grant || 1,
-        pageTags: [],
         grantUserGroupId: currentPage?.grantedGroup?._id,
         shouldGeneratePath: true,
       };
@@ -82,7 +81,6 @@ export const PageCreateButton = React.memo((): JSX.Element => {
         isSlackEnabled: false,
         slackChannels: '',
         grant: 1,
-        pageTags: [],
       };
 
       const res = await exist(JSON.stringify([todaysPath]));
@@ -115,7 +113,6 @@ export const PageCreateButton = React.memo((): JSX.Element => {
         isSlackEnabled: false,
         slackChannels: '',
         grant: currentPage?.grant || 1,
-        pageTags: [],
         grantUserGroupId: currentPage?.grantedGroup?._id,
       };
 
@@ -149,7 +146,6 @@ export const PageCreateButton = React.memo((): JSX.Element => {
         isSlackEnabled: false,
         slackChannels: '',
         grant: currentPage?.grant || 1,
-        pageTags: [],
         grantUserGroupId: currentPage?.grantedGroup?._id,
       };
 

+ 0 - 1
apps/app/src/interfaces/page-operation.ts

@@ -31,7 +31,6 @@ export type OptionsToSave = {
   isSlackEnabled: boolean;
   slackChannels: string;
   grant: number;
-  pageTags: string[] | null;
   grantUserGroupId?: string | null;
   grantUserGroupName?: string | null;
   shouldGeneratePath?: boolean | null;

+ 0 - 17
apps/app/src/server/routes/page.js

@@ -328,7 +328,6 @@ module.exports = function(crowi, app) {
     const overwriteScopesOfDescendants = req.body.overwriteScopesOfDescendants || null;
     const isSlackEnabled = !!req.body.isSlackEnabled; // cast to boolean
     const slackChannels = req.body.slackChannels || null;
-    const pageTags = req.body.pageTags || undefined;
 
     if (body === null || pagePath === null) {
       return res.json(ApiResponse.error('Parameters body and path are required.'));
@@ -351,16 +350,9 @@ module.exports = function(crowi, app) {
 
     const createdPage = await crowi.pageService.create(pagePath, body, req.user, options);
 
-    let savedTags;
-    if (pageTags != null) {
-      await PageTagRelation.updatePageTags(createdPage.id, pageTags);
-      savedTags = await PageTagRelation.listTagNamesByPage(createdPage.id);
-    }
-
     const result = {
       page: serializePageSecurely(createdPage),
       revision: serializeRevisionSecurely(createdPage.revision),
-      tags: savedTags,
     };
     res.json(ApiResponse.success(result));
 
@@ -455,7 +447,6 @@ module.exports = function(crowi, app) {
     const overwriteScopesOfDescendants = req.body.overwriteScopesOfDescendants || null;
     const isSlackEnabled = !!req.body.isSlackEnabled; // cast to boolean
     const slackChannels = req.body.slackChannels || null;
-    const pageTags = req.body.pageTags || undefined;
 
     if (pageId === null || pageBody === null || revisionId === null) {
       return res.json(ApiResponse.error('page_id, body and revision_id are required.'));
@@ -496,18 +487,10 @@ module.exports = function(crowi, app) {
       return res.json(ApiResponse.error(err));
     }
 
-    let savedTags;
-    if (pageTags != null) {
-      const tagEvent = crowi.event('tag');
-      await PageTagRelation.updatePageTags(pageId, pageTags);
-      savedTags = await PageTagRelation.listTagNamesByPage(pageId);
-      tagEvent.emit('update', page, savedTags);
-    }
 
     const result = {
       page: serializePageSecurely(page),
       revision: serializeRevisionSecurely(page.revision),
-      tags: savedTags,
     };
     res.json(ApiResponse.success(result));