Преглед изворни кода

Merge pull request #4898 from weseek/fix/show-delete-modal-even-when-empty

fix: Improve delete modal when top page or empty page
Yuki Takei пре 4 година
родитељ
комит
ef91762602

+ 5 - 2
packages/app/src/components/Common/Dropdown/PageItemControl.tsx

@@ -8,12 +8,15 @@ import { IPageHasId } from '~/interfaces/page';
 type PageItemControlProps = {
 type PageItemControlProps = {
   page: Partial<IPageHasId>
   page: Partial<IPageHasId>
   isEnableActions: boolean
   isEnableActions: boolean
+  isDeletable: boolean
   onClickDeleteButton?: (pageId: string) => void
   onClickDeleteButton?: (pageId: string) => void
 }
 }
 
 
 const PageItemControl: FC<PageItemControlProps> = (props: PageItemControlProps) => {
 const PageItemControl: FC<PageItemControlProps> = (props: PageItemControlProps) => {
 
 
-  const { page, isEnableActions, onClickDeleteButton } = props;
+  const {
+    page, isEnableActions, onClickDeleteButton, isDeletable,
+  } = props;
   const { t } = useTranslation('');
   const { t } = useTranslation('');
 
 
   const deleteButtonHandler = () => {
   const deleteButtonHandler = () => {
@@ -74,7 +77,7 @@ const PageItemControl: FC<PageItemControlProps> = (props: PageItemControlProps)
             {t('Move/Rename')}
             {t('Move/Rename')}
           </button>
           </button>
         )}
         )}
-        {isEnableActions && (
+        {isDeletable && isEnableActions && (
           <>
           <>
             <div className="dropdown-divider"></div>
             <div className="dropdown-divider"></div>
             <button className="dropdown-item text-danger pt-2" type="button" onClick={deleteButtonHandler}>
             <button className="dropdown-item text-danger pt-2" type="button" onClick={deleteButtonHandler}>

+ 8 - 1
packages/app/src/components/SearchPage/SearchResultListItem.tsx

@@ -3,10 +3,12 @@ import React, { FC, memo } from 'react';
 import Clamp from 'react-multiline-clamp';
 import Clamp from 'react-multiline-clamp';
 
 
 import { UserPicture, PageListMeta, PagePathLabel } from '@growi/ui';
 import { UserPicture, PageListMeta, PagePathLabel } from '@growi/ui';
+import { pagePathUtils } from '@growi/core';
 
 
 import { IPageSearchResultData } from '../../interfaces/search';
 import { IPageSearchResultData } from '../../interfaces/search';
 import PageItemControl from '../Common/Dropdown/PageItemControl';
 import PageItemControl from '../Common/Dropdown/PageItemControl';
 
 
+const { isTopPage } = pagePathUtils;
 
 
 type Props = {
 type Props = {
   page: IPageSearchResultData,
   page: IPageSearchResultData,
@@ -84,7 +86,12 @@ const SearchResultListItem: FC<Props> = memo((props:Props) => {
               </div>
               </div>
               {/* doropdown icon includes page control buttons */}
               {/* doropdown icon includes page control buttons */}
               <div className="ml-auto">
               <div className="ml-auto">
-                <PageItemControl page={pageData} onClickDeleteButton={props.onClickDeleteButton} isEnableActions={isEnableActions} />
+                <PageItemControl
+                  page={pageData}
+                  onClickDeleteButton={props.onClickDeleteButton}
+                  isEnableActions={isEnableActions}
+                  isDeletable={!isTopPage(pageData.path)}
+                />
               </div>
               </div>
             </div>
             </div>
             <div className="my-2 search-result-list-snippet">
             <div className="my-2 search-result-list-snippet">

+ 6 - 1
packages/app/src/components/Sidebar/PageTree/Item.tsx

@@ -3,6 +3,7 @@ import React, {
 } from 'react';
 } from 'react';
 import nodePath from 'path';
 import nodePath from 'path';
 import { useTranslation } from 'react-i18next';
 import { useTranslation } from 'react-i18next';
+import { pagePathUtils } from '@growi/core';
 
 
 import { ItemNode } from './ItemNode';
 import { ItemNode } from './ItemNode';
 import { IPageHasId } from '~/interfaces/page';
 import { IPageHasId } from '~/interfaces/page';
@@ -13,6 +14,8 @@ import { IPageForPageDeleteModal } from '~/components/PageDeleteModal';
 
 
 import TriangleIcon from '~/components/Icons/TriangleIcon';
 import TriangleIcon from '~/components/Icons/TriangleIcon';
 
 
+const { isTopPage } = pagePathUtils;
+
 
 
 interface ItemProps {
 interface ItemProps {
   isEnableActions: boolean
   isEnableActions: boolean
@@ -39,6 +42,7 @@ const markTarget = (children: ItemNode[], targetId?: string): void => {
 type ItemControlProps = {
 type ItemControlProps = {
   page: Partial<IPageHasId>
   page: Partial<IPageHasId>
   isEnableActions: boolean
   isEnableActions: boolean
+  isDeletable: boolean
   onClickDeleteButtonHandler?(): void
   onClickDeleteButtonHandler?(): void
   onClickPlusButtonHandler?(): void
   onClickPlusButtonHandler?(): void
 }
 }
@@ -66,7 +70,7 @@ const ItemControl: FC<ItemControlProps> = memo((props: ItemControlProps) => {
 
 
   return (
   return (
     <>
     <>
-      <PageItemControl page={props.page} onClickDeleteButton={onClickDeleteButton} isEnableActions={props.isEnableActions} />
+      <PageItemControl page={props.page} onClickDeleteButton={onClickDeleteButton} isEnableActions={props.isEnableActions} isDeletable={props.isDeletable} />
       <button
       <button
         type="button"
         type="button"
         className="btn-link nav-link border-0 rounded grw-btn-page-management py-0"
         className="btn-link nav-link border-0 rounded grw-btn-page-management py-0"
@@ -197,6 +201,7 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
             onClickDeleteButtonHandler={onClickDeleteButtonHandler}
             onClickDeleteButtonHandler={onClickDeleteButtonHandler}
             onClickPlusButtonHandler={() => { setNewPageInputShown(true) }}
             onClickPlusButtonHandler={() => { setNewPageInputShown(true) }}
             isEnableActions={isEnableActions}
             isEnableActions={isEnableActions}
+            isDeletable={!page.isEmpty && !isTopPage(page.path as string)}
           />
           />
         </div>
         </div>
       </div>
       </div>