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

Adjust props and remove unused method

https://youtrack.weseek.co.jp/issue/GW-7908
- Add and adjust props of PageRevisionTable in PageHistory component
- Update RevisionComparer component props
- Remove useSWRxPageRevisions method
Mudana-Grune 3 лет назад
Родитель
Сommit
2efd8fcf22

+ 11 - 3
packages/app/src/components/PageHistory.tsx

@@ -1,5 +1,7 @@
 import React from 'react';
 
+import { useCurrentPageId } from '~/stores/context';
+import { useCurrentPagePath } from '~/stores/page';
 import loggerFactory from '~/utils/logger';
 
 import { PageRevisionTable } from './PageHistory/PageRevisionTable';
@@ -7,11 +9,17 @@ import { PageRevisionTable } from './PageHistory/PageRevisionTable';
 const logger = loggerFactory('growi:PageHistory');
 
 export const PageHistory: React.FC<{ onClose: () => void }> = ({ onClose }) => {
+  const { data: currentPageId } = useCurrentPageId();
+  const { data: currentPagePath } = useCurrentPagePath();
   return (
     <div className="revision-history" data-testid="page-history">
-      <PageRevisionTable
-        onClose={onClose}
-      />
+      { currentPageId && currentPagePath && (
+        <PageRevisionTable
+          currentPageId={currentPageId}
+          currentPagePath = {currentPagePath}
+          onClose={onClose}
+        />
+      )}
     </div>
   );
 };

+ 5 - 6
packages/app/src/components/PageHistory/PageRevisionTable.tsx

@@ -5,8 +5,7 @@ import React, {
 import { IRevisionHasId, IRevisionHasPageId } from '@growi/core';
 import { useTranslation } from 'next-i18next';
 
-import { useCurrentPageId } from '~/stores/context';
-import { useCurrentPagePath, useSWRxInfinitePageRevisions } from '~/stores/page';
+import { useSWRxInfinitePageRevisions } from '~/stores/page';
 
 import { RevisionComparer } from '../RevisionComparer/RevisionComparer';
 
@@ -15,7 +14,9 @@ import { Revision } from './Revision';
 import styles from './PageRevisionTable.module.scss';
 
 type PageRevisionTableProps = {
-  onClose: () => void,
+  currentPageId: string
+  currentPagePath: string
+  onClose: () => void
 }
 
 export const PageRevisionTable = (props: PageRevisionTableProps): JSX.Element => {
@@ -24,11 +25,9 @@ export const PageRevisionTable = (props: PageRevisionTableProps): JSX.Element =>
   const REVISIONS_PER_PAGE = 10;
 
   const {
-    onClose,
+    onClose, currentPageId, currentPagePath,
   } = props;
 
-  const { data: currentPageId } = useCurrentPageId();
-  const { data: currentPagePath } = useCurrentPagePath();
   const swrInifiniteResponse = useSWRxInfinitePageRevisions(currentPageId, REVISIONS_PER_PAGE);
 
   const {

+ 2 - 2
packages/app/src/components/RevisionComparer/RevisionComparer.tsx

@@ -23,8 +23,8 @@ const DropdownItemContents = ({ title, contents }) => (
 type RevisionComparerProps = {
   sourceRevision: IRevisionHasPageId
   targetRevision: IRevisionHasPageId
-  currentPageId: Nullable<string> | undefined
-  currentPagePath: Nullable<string> | undefined
+  currentPageId?: string
+  currentPagePath: string
   onClose: () => void
 }
 

+ 1 - 22
packages/app/src/stores/page.tsx

@@ -15,7 +15,7 @@ import {
   IPageInfo, IPageInfoForOperation,
 } from '~/interfaces/page';
 import { IRecordApplicableGrant, IResIsGrantNormalized } from '~/interfaces/page-grant';
-import { IRevision, IRevisionHasId, IRevisionsForPagination } from '~/interfaces/revision';
+import { IRevision, IRevisionHasId } from '~/interfaces/revision';
 
 import { IPageTagsInfo } from '../interfaces/tag';
 
@@ -144,27 +144,6 @@ export const useSWRxPageRevision = (pageId: string, revisionId: Ref<IRevision>):
   );
 };
 
-export const useSWRxPageRevisions = (
-    page: number, // page number of pagination
-    limit: number, // max number of pages in one paginate
-    pageId: string | null | undefined,
-): SWRResponse<IRevisionsForPagination, Error> => {
-
-  return useSWRImmutable(
-    ['/revisions/list', pageId, page, limit],
-    ([endpoint, pageId, page, limit]) => {
-      return apiv3Get(endpoint, { pageId, page, limit }).then((response) => {
-        const revisions = {
-          revisions: response.data.docs,
-          totalCounts: response.data.totalDocs,
-        };
-        return revisions;
-      });
-    },
-  );
-};
-
-
 /*
  * SWR Infinite for page revision list
  */