2
0
Эх сурвалжийг харах

implement latest revision alert

yohei0125 3 жил өмнө
parent
commit
4b615ebc3e

+ 22 - 0
packages/app/src/components/PageAlert/OldRevisionAlert.tsx

@@ -0,0 +1,22 @@
+import React from 'react';
+import { useTranslation } from 'react-i18next';
+import { useCurrentPageId } from '~/stores/context';
+import { useSWRxPageInfo } from '~/stores/page';
+
+export const OldRevisionAlert = (): JSX.Element => {
+
+  const { t } = useTranslation()
+  const { data: currentPageId } = useCurrentPageId();
+  const { data: pageInfo } = useSWRxPageInfo(currentPageId);
+
+  if (pageInfo == null || pageInfo.isLatestRevision) {
+    return <></>
+  }
+
+  return (
+    <div className="alert alert-warning">
+      <strong>{ t('Warning') }: </strong> { t('page_page.notice.version') }
+      <a href="{ encodeURI(page.path) }"><i className="icon-fw icon-arrow-right-circle"></i>{ t('Show latest') }</a>
+    </div>
+  );
+};

+ 11 - 7
packages/app/src/components/PageAlert/PageAlerts.tsx

@@ -1,6 +1,9 @@
-import { FixPageGrantAlert } from "./FixPageGrantAlert";
-import { PageGrantAlert } from "./PageGrantAlert";
-import { PageStaleAlert } from "./PageStaleAlert";
+import React from 'react';
+
+import { FixPageGrantAlert } from './FixPageGrantAlert';
+import { OldRevisionAlert } from './OldRevisionAlert';
+import { PageGrantAlert } from './PageGrantAlert';
+import { PageStaleAlert } from './PageStaleAlert';
 
 export const PageAlerts = (): JSX.Element => {
 
@@ -9,10 +12,11 @@ export const PageAlerts = (): JSX.Element => {
     <div className="row d-edit-none">
       <div className="col-sm-12">
         {/* alerts */}
-        <FixPageGrantAlert/>
-        <PageGrantAlert/>
-        <PageStaleAlert/>
+        <FixPageGrantAlert />
+        <PageGrantAlert />
+        <PageStaleAlert />
+        <OldRevisionAlert />
       </div>
     </div>
   );
-}
+};

+ 1 - 0
packages/app/src/interfaces/page.ts

@@ -54,6 +54,7 @@ export type IPageInfo = {
   isAbleToDeleteCompletely: boolean,
   isRevertible: boolean,
   contentAge?: number,
+  isLatestRevision?: boolean,
 }
 
 export type IPageInfoForEntity = IPageInfo & {

+ 1 - 0
packages/app/src/server/service/page.ts

@@ -2205,6 +2205,7 @@ class PageService {
       isAbleToDeleteCompletely: false,
       isRevertible: isTrashPage(page.path),
       contentAge: page.getContentAge(),
+      isLatestRevision: page.isLatestRevision(),
     };
 
   }