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

Merge branch 'feat/gw7910-add-bookmark-from-sub-navigation' into feat/gw-7913-implement-drag-and-drop-to-bookmark-folder

Mudana-Grune 3 лет назад
Родитель
Сommit
38bf6da773

+ 1 - 1
packages/app/public/static/locales/en_US/commons.json

@@ -14,7 +14,7 @@
     "create_failed": "Failed to create {{target}}",
     "update_successed": "Succeeded to update {{target}}",
     "update_failed": "Failed to update {{target}}",
-
+    "delete_succeeded": "Succeeded to delete {{target}}",
     "remove_share_link_success": "Succeeded to remove {{shareLinkId}}",
     "remove_share_link": "Succeeded to remove {{count}} share links"
   },

+ 1 - 1
packages/app/public/static/locales/ja_JP/commons.json

@@ -14,7 +14,7 @@
     "create_failed": "{{target}}の作成に失敗しました",
     "update_successed": "{{target}}を更新しました",
     "update_failed": "{{target}}の更新に失敗しました",
-
+    "delete_succeeded": "{{target}} の削除に成功しました",
     "remove_share_link_success": "{{shareLinkId}}を削除しました",
     "remove_share_link": "共有リンクを{{count}}件削除しました"
   },

+ 1 - 1
packages/app/public/static/locales/zh_CN/commons.json

@@ -14,7 +14,7 @@
     "create_failed": "Failed to create {{target}}",
     "update_successed": "Succeeded to update {{target}}",
     "update_failed": "Failed to update {{target}}",
-
+    "delete_succeeded": "Succeeded to delete {{target}}",
     "remove_share_link_success": "Succeeded to remove {{shareLinkId}}",
     "remove_share_link": "Succeeded to remove {{count}} share links"
   },

+ 17 - 19
packages/app/src/components/Bookmarks/BookmarkFolderItem.tsx

@@ -6,9 +6,7 @@ import { useTranslation } from 'next-i18next';
 import { useDrag, useDrop } from 'react-dnd';
 import { DropdownToggle } from 'reactstrap';
 
-import {
-  apiv3Delete, apiv3Post, apiv3Put,
-} from '~/client/util/apiv3-client';
+import { apiv3Delete, apiv3Post, apiv3Put } from '~/client/util/apiv3-client';
 import { toastError, toastSuccess } from '~/client/util/toastr';
 import CountBadge from '~/components/Common/CountBadge';
 import FolderIcon from '~/components/Icons/FolderIcon';
@@ -75,12 +73,12 @@ const BookmarkFolderItem: FC<BookmarkFolderItemProps> = (props: BookmarkFolderIt
     return children.length > 0;
   }, [children.length, currentChildren]);
 
-  const loadChildFolder = useCallback(async() => {
+  const loadChildFolder = useCallback(async () => {
     setIsOpen(!isOpen);
     setTargetFolder(folderId);
   }, [folderId, isOpen]);
 
-  const loadParent = useCallback(async() => {
+  const loadParent = useCallback(async () => {
     if (!isRenameAction) {
       if (parent != null) {
         await mutateParentBookmarkFolder();
@@ -95,12 +93,12 @@ const BookmarkFolderItem: FC<BookmarkFolderItemProps> = (props: BookmarkFolderIt
   }, [isRenameAction, mutateParentBookmarkFolder, parent]);
 
   // Rename  for bookmark folder handler
-  const onPressEnterHandlerForRename = useCallback(async(folderName: string) => {
+  const onPressEnterHandlerForRename = useCallback(async (folderName: string) => {
     try {
       await apiv3Put('/bookmark-folder', { bookmarkFolderId: folderId, name: folderName, parent });
       loadParent();
       setIsRenameAction(false);
-      toastSuccess(t('toaster.update_successed', { target: t('bookmark_folder.bookmark_folder') }));
+      toastSuccess(t('toaster.update_successed', { target: t('bookmark_folder.bookmark_folder'), ns: 'commons' }));
     }
     catch (err) {
       toastError(err);
@@ -108,13 +106,13 @@ const BookmarkFolderItem: FC<BookmarkFolderItemProps> = (props: BookmarkFolderIt
   }, [folderId, loadParent, parent, t]);
 
   // Create new folder / subfolder handler
-  const onPressEnterHandlerForCreate = useCallback(async(folderName: string) => {
+  const onPressEnterHandlerForCreate = useCallback(async (folderName: string) => {
     try {
       await apiv3Post('/bookmark-folder', { name: folderName, parent: targetFolder });
       setIsOpen(true);
       setIsCreateAction(false);
       mutateChildBookmarkData();
-      toastSuccess(t('toaster.create_succeeded', { target: t('bookmark_folder.bookmark_folder') }));
+      toastSuccess(t('toaster.create_succeeded', { target: t('bookmark_folder.bookmark_folder'), ns: 'commons' }));
 
     }
     catch (err) {
@@ -124,20 +122,20 @@ const BookmarkFolderItem: FC<BookmarkFolderItemProps> = (props: BookmarkFolderIt
   }, [mutateChildBookmarkData, t, targetFolder]);
 
   // Delete Fodler handler
-  const onClickDeleteButtonHandler = useCallback(async() => {
+  const onClickDeleteButtonHandler = useCallback(async () => {
     try {
       await apiv3Delete(`/bookmark-folder/${folderId}`);
       setIsDeleteFolderModalShown(false);
       loadParent();
       mutateBookmarkInfo();
-      toastSuccess(t('toaster.delete_succeeded', { target: t('bookmark_folder.bookmark_folder') }));
+      toastSuccess(t('toaster.delete_succeeded', { target: t('bookmark_folder.bookmark_folder'), ns: 'commons' }));
     }
     catch (err) {
       toastError(err);
     }
   }, [folderId, loadParent, mutateBookmarkInfo, t]);
 
-  const onClickPlusButton = useCallback(async(e) => {
+  const onClickPlusButton = useCallback(async (e) => {
     e.stopPropagation();
     if (!isOpen && hasChildren()) {
       setIsOpen(true);
@@ -146,7 +144,7 @@ const BookmarkFolderItem: FC<BookmarkFolderItemProps> = (props: BookmarkFolderIt
   }, [hasChildren, isOpen]);
 
   const onClickDeleteBookmarkHandler = useCallback((pageToDelete: IPageToDeleteWithMeta) => {
-    const pageDeletedHandler : OnDeletedFunction = (pathOrPathsToDelete, _isRecursively, isCompletely) => {
+    const pageDeletedHandler: OnDeletedFunction = (pathOrPathsToDelete, _isRecursively, isCompletely) => {
       if (typeof pathOrPathsToDelete !== 'string') {
         return;
       }
@@ -171,7 +169,7 @@ const BookmarkFolderItem: FC<BookmarkFolderItemProps> = (props: BookmarkFolderIt
 
   const [, bookmarkFolderDragRef] = useDrag({
     type: 'FOLDER',
-    item:  props,
+    item: props,
     end: (item, monitor) => {
       const dropResult = monitor.getDropResult();
       if (dropResult != null) {
@@ -185,7 +183,7 @@ const BookmarkFolderItem: FC<BookmarkFolderItemProps> = (props: BookmarkFolderIt
   });
 
 
-  const folderItemDropHandler = async(item: BookmarkFolderItemProps) => {
+  const folderItemDropHandler = async (item: BookmarkFolderItemProps) => {
     try {
       await apiv3Put('/bookmark-folder', { bookmarkFolderId: item.bookmarkFolder._id, name: item.bookmarkFolder.name, parent: bookmarkFolder._id });
       await mutateChildBookmarkData();
@@ -196,7 +194,7 @@ const BookmarkFolderItem: FC<BookmarkFolderItemProps> = (props: BookmarkFolderIt
     }
   };
 
-  const bookmarkItemDropHandler = useCallback(async(item: IPageHasId) => {
+  const bookmarkItemDropHandler = useCallback(async (item: IPageHasId) => {
     try {
       await apiv3Post('/bookmark-folder/add-boookmark-to-folder', { pageId: item._id, folderId: bookmarkFolder._id });
       mutateParentBookmarkFolder();
@@ -308,7 +306,7 @@ const BookmarkFolderItem: FC<BookmarkFolderItemProps> = (props: BookmarkFolderIt
             <FolderIcon isOpen={isOpen} />
           </div>
         }
-        { isRenameAction ? (
+        {isRenameAction ? (
           <BookmarkFolderNameInput
             onClickOutside={() => setIsRenameAction(false)}
             onPressEnter={onPressEnterHandlerForRename}
@@ -321,7 +319,7 @@ const BookmarkFolderItem: FC<BookmarkFolderItemProps> = (props: BookmarkFolderIt
             </div>
             {hasChildren() && (
               <div className="grw-foldertree-count-wrapper">
-                <CountBadge count={ childCount } />
+                <CountBadge count={childCount} />
               </div>
             )}
           </>
@@ -368,7 +366,7 @@ const BookmarkFolderItem: FC<BookmarkFolderItemProps> = (props: BookmarkFolderIt
         bookmarkFolder={bookmarkFolder}
         isOpen={isDeleteFolderModalShown}
         onClickDeleteButton={onClickDeleteButtonHandler}
-        onModalClose={onDeleteFolderModalClose}/>
+        onModalClose={onDeleteFolderModalClose} />
     </div>
   );
 };

+ 0 - 3
packages/app/src/components/Bookmarks/BookmarkFolderTree.tsx

@@ -1,6 +1,4 @@
 
-import { useTranslation } from 'next-i18next';
-
 import { useSWRxBookamrkFolderAndChild } from '~/stores/bookmark-folder';
 
 import BookmarkFolderItem from './BookmarkFolderItem';
@@ -9,7 +7,6 @@ import styles from './BookmarkFolderTree.module.scss';
 
 
 const BookmarkFolderTree = (): JSX.Element => {
-  const { t } = useTranslation();
   const { data: bookmarkFolderData } = useSWRxBookamrkFolderAndChild();
 
   return (

+ 7 - 8
packages/app/src/components/Bookmarks/BookmarkItem.tsx

@@ -8,9 +8,8 @@ import { useTranslation } from 'react-i18next';
 import { UncontrolledTooltip, DropdownToggle } from 'reactstrap';
 
 import { unbookmark } from '~/client/services/page-operation';
-import { toastError, toastSuccess } from '~/client/util/apiNotification';
 import { apiv3Put } from '~/client/util/apiv3-client';
-import { BookmarkFolderItems } from '~/interfaces/bookmark-info';
+import { toastError, toastSuccess } from '~/client/util/toastr';
 import { IPageHasId, IPageInfoAll, IPageToDeleteWithMeta } from '~/interfaces/page';
 import { useSWRxBookamrkFolderAndChild } from '~/stores/bookmark-folder';
 
@@ -46,7 +45,7 @@ const BookmarkItem = (props: Props): JSX.Element => {
     }
   }, [parentId, mutateChildFolderData]);
 
-  const bookmarkMenuItemClickHandler = useCallback(async() => {
+  const bookmarkMenuItemClickHandler = useCallback(async () => {
     await unbookmark(bookmarkedPage._id);
     onUnbookmarked();
   }, [onUnbookmarked, bookmarkedPage]);
@@ -66,7 +65,7 @@ const BookmarkItem = (props: Props): JSX.Element => {
     return null;
   };
 
-  const pressEnterForRenameHandler = useCallback(async(inputText: string) => {
+  const pressEnterForRenameHandler = useCallback(async (inputText: string) => {
     const parentPath = pathUtils.addTrailingSlash(nodePath.dirname(bookmarkedPage.path ?? ''));
     const newPagePath = nodePath.resolve(parentPath, inputText);
     if (newPagePath === bookmarkedPage.path) {
@@ -90,7 +89,7 @@ const BookmarkItem = (props: Props): JSX.Element => {
     }
   }, [bookmarkedPage, onRenamed, t]);
 
-  const deleteMenuItemClickHandler = useCallback(async(_pageId: string, pageInfo: IPageInfoAll | undefined): Promise<void> => {
+  const deleteMenuItemClickHandler = useCallback(async (_pageId: string, pageInfo: IPageInfoAll | undefined): Promise<void> => {
     if (bookmarkedPage._id == null || bookmarkedPage.path == null) {
       throw Error('_id and path must not be null.');
     }
@@ -109,7 +108,7 @@ const BookmarkItem = (props: Props): JSX.Element => {
 
   const [, bookmarkItemDragRef] = useDrag({
     type: 'BOOKMARK',
-    item:  bookmarkedPage,
+    item: bookmarkedPage,
     end: (item) => {
       if (parentFolder.parent == null) {
         mutateParentBookmarkData();
@@ -132,7 +131,7 @@ const BookmarkItem = (props: Props): JSX.Element => {
       key={bookmarkedPage._id} ref={(c) => { bookmarkItemDragRef(c) }}
       id={bookmarkItemId}
     >
-      { isRenameInputShown ? (
+      {isRenameInputShown ? (
         <ClosableTextInput
           value={nodePath.basename(bookmarkedPage.path ?? '')}
           placeholder={t('Input page name')}
@@ -164,7 +163,7 @@ const BookmarkItem = (props: Props): JSX.Element => {
         target={bookmarkItemId}
         fade={false}
       >
-        { formerPagePath !== null ? `${formerPagePath}/` : '/' }
+        {formerPagePath !== null ? `${formerPagePath}/` : '/'}
       </UncontrolledTooltip>
     </li>
   );

+ 1 - 1
packages/app/src/components/Bookmarks/BookmarkItemList.tsx

@@ -2,7 +2,7 @@ import React, { useCallback } from 'react';
 
 import { useTranslation } from 'next-i18next';
 
-import { toastSuccess } from '~/client/util/apiNotification';
+import { toastSuccess } from '~/client/util/toastr';
 import { IPageToDeleteWithMeta } from '~/interfaces/page';
 import { OnDeletedFunction } from '~/interfaces/ui';
 import { useSWRxCurrentUserBookmarks } from '~/stores/bookmark';

+ 2 - 2
packages/app/src/components/Sidebar/Bookmarks/BookmarkContents.tsx

@@ -2,8 +2,8 @@ import React, { useCallback, useState } from 'react';
 
 import { useTranslation } from 'next-i18next';
 
-import { toastError, toastSuccess } from '~/client/util/apiNotification';
 import { apiv3Post } from '~/client/util/apiv3-client';
+import { toastError, toastSuccess } from '~/client/util/toastr';
 import BookmarkFolderNameInput from '~/components/Bookmarks/BookmarkFolderNameInput';
 import BookmarkFolderTree from '~/components/Bookmarks/BookmarkFolderTree';
 import FolderPlusIcon from '~/components/Icons/FolderPlusIcon';
@@ -27,7 +27,7 @@ const BookmarkContents = (): JSX.Element => {
       await apiv3Post('/bookmark-folder', { name: folderName, parent: null });
       await mutateChildBookmarkData();
       setIsCreateAction(false);
-      toastSuccess(t('toaster.create_succeeded', { target: t('bookmark_folder.bookmark_folder') }));
+      toastSuccess(t('toaster.create_succeeded', { target: t('bookmark_folder.bookmark_folder'), ns: 'commons' }));
     }
     catch (err) {
       toastError(err);

+ 3 - 10
packages/app/src/server/models/bookmark-folder.ts

@@ -28,8 +28,7 @@ export interface BookmarkFolderDocument extends Document {
 
 export interface BookmarkFolderModel extends Model<BookmarkFolderDocument>{
   createByParameters(params: IBookmarkFolder): Promise<BookmarkFolderDocument>
-  findFolderAndChildren(user: Types.ObjectId | string, parentId?: Types.ObjectId | string): Promise<BookmarkFolderItems[] | null>
-  findChildFolderById(parentBookmarkFolder: Types.ObjectId | string): Promise<BookmarkFolderDocument[]>
+  findFolderAndChildren(user: Types.ObjectId | string, parentId?: Types.ObjectId | string): Promise<BookmarkFolderItems[]>
   deleteFolderAndChildren(bookmarkFolderId: Types.ObjectId | string): Promise<{deletedCount: number}>
   updateBookmarkFolder(bookmarkFolderId: string, name: string, parent: string): Promise<BookmarkFolderDocument>
   insertOrUpdateBookmarkedPage(pageId: IPageHasId, userId: Types.ObjectId | string, folderId: string): Promise<BookmarkFolderDocument>
@@ -114,12 +113,6 @@ bookmarkFolderSchema.statics.findFolderAndChildren = async function(
   return bookmarkFolders;
 };
 
-bookmarkFolderSchema.statics.findChildFolderById = async function(parentFolderId: Types.ObjectId | string): Promise<BookmarkFolderDocument[]> {
-  const parentFolder = await this.findById(parentFolderId) as unknown as BookmarkFolderDocument;
-  const childFolders = await this.find({ parent: parentFolder });
-  return childFolders;
-};
-
 bookmarkFolderSchema.statics.deleteFolderAndChildren = async function(bookmarkFolderId: Types.ObjectId | string): Promise<{deletedCount: number}> {
   const bookmarkFolder = await this.findById(bookmarkFolderId);
   // Delete parent and all children folder
@@ -143,9 +136,9 @@ bookmarkFolderSchema.statics.deleteFolderAndChildren = async function(bookmarkFo
   return { deletedCount };
 };
 
-bookmarkFolderSchema.statics.updateBookmarkFolder = async function(bookmarkFolderId: string, name: string, parent: string):
+bookmarkFolderSchema.statics.updateBookmarkFolder = async function(bookmarkFolderId: string, name: string, parentId: string):
  Promise<BookmarkFolderDocument> {
-  const parentFolder = await this.findById(parent);
+  const parentFolder = await this.findById(parentId);
   const updateFields = {
     name, parent: parentFolder?._id || null,
   };

+ 1 - 1
packages/app/src/server/routes/apiv3/bookmark-folder.ts

@@ -55,7 +55,7 @@ module.exports = (crowi) => {
     const _parentId = parentId ?? null;
     try {
       const bookmarkFolders = await BookmarkFolder.findFolderAndChildren(req.user?._id, _parentId);
-      const bookmarkFolderItems = bookmarkFolders?.map(bookmarkFolder => ({
+      const bookmarkFolderItems = bookmarkFolders.map(bookmarkFolder => ({
         _id: bookmarkFolder._id,
         name: bookmarkFolder.name,
         parent: bookmarkFolder.parent,