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

Merge pull request #5202 from weseek/feat/not-display-delete-btn

not display delete btn for /user
Yuki Takei 4 лет назад
Родитель
Сommit
77c62ffc7d

+ 2 - 3
packages/app/src/components/PageList/PageListItemL.tsx

@@ -10,7 +10,7 @@ import { IPageSearchMeta, isIPageSearchMeta } from '~/interfaces/search';
 
 
 import PageItemControl from '../Common/Dropdown/PageItemControl';
 import PageItemControl from '../Common/Dropdown/PageItemControl';
 
 
-const { isTopPage } = pagePathUtils;
+const { isTopPage, isUserNamePage } = pagePathUtils;
 
 
 type Props = {
 type Props = {
   page: IPageWithMeta | IPageWithMeta<IPageSearchMeta>,
   page: IPageWithMeta | IPageWithMeta<IPageSearchMeta>,
@@ -124,8 +124,7 @@ export const PageListItemL: FC<Props> = memo((props:Props) => {
                   page={pageData}
                   page={pageData}
                   onClickDeleteButtonHandler={props.onClickDeleteButton}
                   onClickDeleteButtonHandler={props.onClickDeleteButton}
                   isEnableActions={isEnableActions}
                   isEnableActions={isEnableActions}
-                  isDeletable={!isTopPage(pageData.path)}
-                  // Todo: add onClickRenameButtonHandler
+                  isDeletable={!isTopPage(pageData.path) && !isUserNamePage(pageData.path)}
                 />
                 />
               </div>
               </div>
             </div>
             </div>

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

@@ -16,7 +16,7 @@ import { IPageForPageDeleteModal } from '~/components/PageDeleteModal';
 
 
 import TriangleIcon from '~/components/Icons/TriangleIcon';
 import TriangleIcon from '~/components/Icons/TriangleIcon';
 
 
-const { isTopPage, isUserPage } = pagePathUtils;
+const { isTopPage, isUserNamePage } = pagePathUtils;
 
 
 
 
 interface ItemProps {
 interface ItemProps {
@@ -132,7 +132,7 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
 
 
   const hasDescendants = (page.descendantCount != null && page?.descendantCount > 0);
   const hasDescendants = (page.descendantCount != null && page?.descendantCount > 0);
 
 
-  const isDeletable = !page.isEmpty && !isTopPage(page.path as string) && !isUserPage(page.path as string);
+  const isDeletable = !page.isEmpty && !isTopPage(page.path as string) && !isUserNamePage(page.path as string);
 
 
   const [{ isDragging }, drag] = useDrag(() => ({
   const [{ isDragging }, drag] = useDrag(() => ({
     type: 'PAGE_TREE',
     type: 'PAGE_TREE',

+ 13 - 0
packages/core/src/utils/page-path-utils.ts

@@ -36,6 +36,19 @@ export const isUserPage = (path: string): boolean => {
   return false;
   return false;
 };
 };
 
 
+/**
+ * Whether path is right under the path '/user'
+ * @param path
+ */
+export const isUserNamePage = (path: string): boolean => {
+  // https://regex101.com/r/GUZntH/1
+  if (path.match(/^\/user\/[^/]+$/)) {
+    return true;
+  }
+
+  return false;
+};
+
 /**
 /**
  * Whether path belongs to the shared page
  * Whether path belongs to the shared page
  * @param path
  * @param path