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

display detail in page bulk export notification

Futa Arai 1 год назад
Родитель
Сommit
1cdf78cadb

+ 1 - 1
apps/app/src/components/InAppNotification/ModelNotification/ModelNotification.tsx

@@ -24,7 +24,7 @@ export const ModelNotification: FC<Props> = (props) => {
     <div className="p-2 overflow-hidden">
       <div className="text-truncate">
         <b>{actionUsers}</b>
-        {actionMsg}
+        {` ${actionMsg}`}
         <PagePathLabel path={notification.parsedSnapshot?.path ?? ''} />
       </div>
       <span className="material-symbols-outlined me-2">{actionIcon}</span>

+ 3 - 0
apps/app/src/components/InAppNotification/ModelNotification/PageBulkExportJobModelNotification.tsx

@@ -6,6 +6,7 @@ import { useRouter } from 'next/router';
 import type { IPageBulkExportJob } from '~/features/page-bulk-export/interfaces/page-bulk-export';
 import { SupportedTargetModel } from '~/interfaces/activity';
 import type { IInAppNotification } from '~/interfaces/in-app-notification';
+import * as pageBulkExportJobSerializers from '~/models/serializers/in-app-notification-snapshot/page-bulk-export-job';
 
 import { ModelNotification } from './ModelNotification';
 import type { ModelNotificationUtils } from './PageModelNotification';
@@ -29,6 +30,8 @@ export const usePageBulkExportJobModelNotification = (notification: IInAppNotifi
 
   const actionUsers = notification.user.username;
 
+  notification.parsedSnapshot = pageBulkExportJobSerializers.parseSnapshot(notification.snapshot);
+
   const Notification = () => {
     return (
       <ModelNotification

+ 8 - 0
apps/app/src/components/InAppNotification/ModelNotification/useActionAndMsg.ts

@@ -70,6 +70,14 @@ export const useActionMsgAndIconForModelNotification = (notification: IInAppNoti
       actionMsg = 'requested registration approval';
       actionIcon = 'add_comment';
       break;
+    case SupportedAction.ACTION_PAGE_BULK_EXPORT_COMPLETED:
+      actionMsg = 'export completed for';
+      actionIcon = 'download';
+      break;
+    case SupportedAction.ACTION_PAGE_BULK_EXPORT_FAILED:
+      actionMsg = 'export failed for';
+      actionIcon = 'error';
+      break;
     default:
       actionMsg = '';
       actionIcon = '';

+ 25 - 0
apps/app/src/models/serializers/in-app-notification-snapshot/page-bulk-export-job.ts

@@ -0,0 +1,25 @@
+import { isPopulated } from '@growi/core';
+import type { IPage } from '@growi/core';
+import mongoose from 'mongoose';
+
+import type { IPageBulkExportJob } from '~/features/page-bulk-export/interfaces/page-bulk-export';
+import type { PageModel } from '~/server/models/page';
+
+export interface IPageBulkExportJobSnapshot {
+  path: string
+}
+
+export const stringifySnapshot = async(exportJob: IPageBulkExportJob): Promise<string | undefined> => {
+  const Page = mongoose.model<IPage, PageModel>('Page');
+  const page = isPopulated(exportJob.page) ? exportJob.page : (await Page.findById(exportJob.page));
+
+  if (page != null) {
+    return JSON.stringify({
+      path: page.path,
+    });
+  }
+};
+
+export const parseSnapshot = (snapshot: string): IPageBulkExportJobSnapshot => {
+  return JSON.parse(snapshot);
+};

+ 1 - 1
apps/app/src/server/service/in-app-notification.ts

@@ -205,7 +205,7 @@ export default class InAppNotificationService {
 
     const targetModel = activity.targetModel;
 
-    const snapshot = generateSnapshot(targetModel, target);
+    const snapshot = await generateSnapshot(targetModel, target);
 
     if (shouldNotification) {
       const props = preNotifyService.generateInitialPreNotifyProps();

+ 10 - 1
apps/app/src/server/service/in-app-notification/in-app-notification-utils.ts

@@ -3,18 +3,27 @@ import type { IUser, IPage } from '@growi/core';
 import type { IPageBulkExportJob } from '~/features/page-bulk-export/interfaces/page-bulk-export';
 import { SupportedTargetModel } from '~/interfaces/activity';
 import * as pageSerializers from '~/models/serializers/in-app-notification-snapshot/page';
+import * as pageBulkExportJobSerializers from '~/models/serializers/in-app-notification-snapshot/page-bulk-export-job';
 
 const isIPage = (targetModel: string, target: IUser | IPage | IPageBulkExportJob): target is IPage => {
   return targetModel === SupportedTargetModel.MODEL_PAGE;
 };
 
-export const generateSnapshot = (targetModel: string, target: IUser | IPage | IPageBulkExportJob): string | undefined => {
+const isIPageBulkExportJob = (targetModel: string, target: IUser | IPage | IPageBulkExportJob): target is IPageBulkExportJob => {
+  return targetModel === SupportedTargetModel.MODEL_PAGE_BULK_EXPORT_JOB;
+};
+
+// snapshots are infos about the target that are displayed in the notification, which should not change on target update
+export const generateSnapshot = async(targetModel: string, target: IUser | IPage | IPageBulkExportJob): Promise<string | undefined> => {
 
   let snapshot: string | undefined;
 
   if (isIPage(targetModel, target)) {
     snapshot = pageSerializers.stringifySnapshot(target);
   }
+  else if (isIPageBulkExportJob(targetModel, target)) {
+    snapshot = await pageBulkExportJobSerializers.stringifySnapshot(target);
+  }
 
   return snapshot;
 };