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

Merge pull request #5945 from weseek/fix/show-modal-when-url-validated

fix/create new component that validate url has compare param
hirokei 3 лет назад
Родитель
Сommit
7680b72f4a

+ 0 - 8
packages/app/src/client/app.jsx

@@ -51,8 +51,6 @@ import TagPage from '../components/TagPage';
 import TrashPageList from '../components/TrashPageList';
 
 import { appContainer, componentMappings } from './base';
-import { toastError } from './util/apiNotification';
-
 
 const logger = loggerFactory('growi:cli:app');
 
@@ -136,12 +134,6 @@ if (pageContainer.state.pageId != null) {
 
     'recent-created-icon': <RecentlyCreatedIcon />,
   });
-
-  // show the Page accessory modal when query of "compare" is requested
-  if (revisionComparerContainer.getRevisionIDsToCompareAsParam().length > 0) {
-    toastError('Sorry, opening PageAccessoriesModal is not implemented yet in v5.');
-  //   pageAccessoriesContainer.openPageAccessoriesModal('pageHistory');
-  }
 }
 if (pageContainer.state.creator != null) {
   Object.assign(componentMappings, {

+ 3 - 0
packages/app/src/client/base.jsx

@@ -18,6 +18,8 @@ import PageDuplicateModal from '../components/PageDuplicateModal';
 import PagePresentationModal from '../components/PagePresentationModal';
 import PageRenameModal from '../components/PageRenameModal';
 
+import ShowPageAccessories from './services/ShowPageAccessories';
+
 const logger = loggerFactory('growi:cli:app');
 
 if (!window) {
@@ -58,6 +60,7 @@ const componentMappings = {
 
   'grw-hotkeys-manager': <HotkeysManager />,
 
+  'show-page-accessories': <ShowPageAccessories />,
 };
 
 export { appContainer, componentMappings };

+ 25 - 0
packages/app/src/client/services/ShowPageAccessories.tsx

@@ -0,0 +1,25 @@
+import React, { useEffect } from 'react';
+
+import { usePageAccessoriesModal, PageAccessoriesModalContents } from '~/stores/modal';
+
+function getURLQueryParamValue(key: string): string | null {
+// window.location.href is page URL;
+  const queryStr: URLSearchParams = new URL(window.location.href).searchParams;
+  return queryStr.get(key);
+}
+
+const ShowPageAccessoriesModal = (): JSX.Element => {
+  const { open: openPageAccessories } = usePageAccessoriesModal();
+  useEffect(() => {
+    const pageIdParams = getURLQueryParamValue('compare');
+    if (pageIdParams != null) {
+      if (/([a-z0-9]){24}...([a-z0-9]){24}/.test(pageIdParams)) {
+        openPageAccessories(PageAccessoriesModalContents.PageHistory);
+      }
+    }
+    // eslint-disable-next-line react-hooks/exhaustive-deps
+  }, []);
+  return <></>;
+};
+
+export default ShowPageAccessoriesModal;

+ 7 - 7
packages/app/src/components/PageAccessoriesModal.tsx

@@ -1,25 +1,25 @@
 import React, { useEffect, useMemo, useState } from 'react';
 
+import { useTranslation } from 'react-i18next';
 import {
   Modal, ModalBody, ModalHeader,
 } from 'reactstrap';
 
-import { useTranslation } from 'react-i18next';
 
+import AppContainer from '~/client/services/AppContainer';
 import { useIsGuestUser, useIsSharedUser } from '~/stores/context';
 import { usePageAccessoriesModal, PageAccessoriesModalContents } from '~/stores/modal';
-import AppContainer from '~/client/services/AppContainer';
 
-import HistoryIcon from './Icons/HistoryIcon';
+import { CustomNavTab } from './CustomNavigation/CustomNav';
+import CustomTabContent from './CustomNavigation/CustomTabContent';
+import ExpandOrContractButton from './ExpandOrContractButton';
 import AttachmentIcon from './Icons/AttachmentIcon';
+import HistoryIcon from './Icons/HistoryIcon';
 import ShareLinkIcon from './Icons/ShareLinkIcon';
-import { withUnstatedContainers } from './UnstatedUtils';
 import PageAttachment from './PageAttachment';
 import PageHistory from './PageHistory';
 import ShareLink from './ShareLink/ShareLink';
-import { CustomNavTab } from './CustomNavigation/CustomNav';
-import ExpandOrContractButton from './ExpandOrContractButton';
-import CustomTabContent from './CustomNavigation/CustomTabContent';
+import { withUnstatedContainers } from './UnstatedUtils';
 
 
 type Props = {

+ 1 - 0
packages/app/src/server/views/layout/layout.html

@@ -113,6 +113,7 @@
 <div id="page-accessories-modal"></div>
 <div id="descendants-page-list-modal"></div>
 <div id="page-put-back-modal"></div>
+<div id="show-page-accessories"></div>
 
 {% include '../modal/shortcuts.html' %}