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

download pageBulkExportJob attachment from inAppNotification

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

+ 10 - 4
apps/app/src/components/InAppNotification/InAppNotificationElm.tsx

@@ -23,8 +23,9 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
 
   const Notification = modelNotificationUtils?.Notification;
   const publishOpen = modelNotificationUtils?.publishOpen;
+  const clickLink = modelNotificationUtils?.clickLink;
 
-  if (Notification == null || publishOpen == null) {
+  if (Notification == null) {
     return <></>;
   }
 
@@ -35,7 +36,7 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
       onUnopenedNotificationOpend?.();
     }
 
-    publishOpen();
+    publishOpen?.();
   };
 
   const renderActionUserPictures = (): JSX.Element => {
@@ -58,7 +59,12 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
   };
 
   return (
-    <div className="list-group-item list-group-item-action" onClick={() => clickHandler(notification)} style={{ cursor: 'pointer' }}>
+    <a
+      className="list-group-item list-group-item-action"
+      href={clickLink}
+      onClick={() => clickHandler(notification)}
+      style={{ cursor: 'pointer' }}
+    >
       <div className="d-flex align-items-center">
         <span
           className={`${notification.status === InAppNotificationStatuses.STATUS_UNOPENED
@@ -73,7 +79,7 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
         <Notification />
 
       </div>
-    </div>
+    </a>
   );
 };
 

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

@@ -1,26 +1,27 @@
 import React from 'react';
 
-import type { HasObjectId } from '@growi/core';
-import { useRouter } from 'next/router';
+import { isPopulated, type HasObjectId } from '@growi/core';
+import { useTranslation } from 'react-i18next';
 
-import type { IPageBulkExportJob } from '~/features/page-bulk-export/interfaces/page-bulk-export';
+import type { IPageBulkExportJobHasId } 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';
 import { useActionMsgAndIconForModelNotification } from './useActionAndMsg';
 
+import type { ModelNotificationUtils } from '.';
+
 
 export const usePageBulkExportJobModelNotification = (notification: IInAppNotification & HasObjectId): ModelNotificationUtils | null => {
 
   const { actionMsg, actionIcon } = useActionMsgAndIconForModelNotification(notification);
-  const router = useRouter();
+  const { t } = useTranslation();
 
   const isPageBulkExportJobModelNotification = (
       notification: IInAppNotification & HasObjectId,
-  ): notification is IInAppNotification<IPageBulkExportJob> & HasObjectId => {
+  ): notification is IInAppNotification<IPageBulkExportJobHasId> & HasObjectId => {
     return notification.targetModel === SupportedTargetModel.MODEL_PAGE_BULK_EXPORT_JOB;
   };
 
@@ -43,13 +44,12 @@ export const usePageBulkExportJobModelNotification = (notification: IInAppNotifi
     );
   };
 
-  const publishOpen = () => {
-    router.push('/admin/users');
-  };
+  const clickLink = notification.target?.attachment != null && isPopulated(notification.target?.attachment)
+    ? notification.target.attachment.downloadPathProxied : undefined;
 
   return {
     Notification,
-    publishOpen,
+    clickLink,
   };
 
 };

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

@@ -1,4 +1,3 @@
-import type { FC } from 'react';
 import React, { useCallback } from 'react';
 
 import type { IPage, HasObjectId } from '@growi/core';
@@ -11,11 +10,7 @@ import * as pageSerializers from '~/models/serializers/in-app-notification-snaps
 import { ModelNotification } from './ModelNotification';
 import { useActionMsgAndIconForModelNotification } from './useActionAndMsg';
 
-
-export interface ModelNotificationUtils {
-  Notification: FC
-  publishOpen: () => void
-}
+import type { ModelNotificationUtils } from '.';
 
 export const usePageModelNotification = (notification: IInAppNotification & HasObjectId): ModelNotificationUtils | null => {
 

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

@@ -7,9 +7,10 @@ import { SupportedTargetModel } from '~/interfaces/activity';
 import type { IInAppNotification } from '~/interfaces/in-app-notification';
 
 import { ModelNotification } from './ModelNotification';
-import type { ModelNotificationUtils } from './PageModelNotification';
 import { useActionMsgAndIconForModelNotification } from './useActionAndMsg';
 
+import type { ModelNotificationUtils } from '.';
+
 
 export const useUserModelNotification = (notification: IInAppNotification & HasObjectId): ModelNotificationUtils | null => {
 

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

@@ -1,12 +1,19 @@
+import type { FC } from 'react';
+
 import type { HasObjectId } from '@growi/core';
 
 import type { IInAppNotification } from '~/interfaces/in-app-notification';
 
 
 import { usePageBulkExportJobModelNotification } from './PageBulkExportJobModelNotification';
-import { usePageModelNotification, type ModelNotificationUtils } from './PageModelNotification';
+import { usePageModelNotification } from './PageModelNotification';
 import { useUserModelNotification } from './UserModelNotification';
 
+export interface ModelNotificationUtils {
+  Notification: FC
+  publishOpen?: () => void
+  clickLink?: string
+}
 
 export const useModelNotification = (notification: IInAppNotification & HasObjectId): ModelNotificationUtils | null => {
 

+ 3 - 0
apps/app/src/features/page-bulk-export/interfaces/page-bulk-export.ts

@@ -1,4 +1,5 @@
 import type {
+  HasObjectId,
   IAttachment, IPage, IRevision, IUser, Ref,
 } from '@growi/core';
 
@@ -19,6 +20,8 @@ export interface IPageBulkExportJob {
   attachment?: Ref<IAttachment>,
 }
 
+export interface IPageBulkExportJobHasId extends IPageBulkExportJob, HasObjectId {}
+
 // snapshot of page info to upload
 export interface IPageBulkExportPageInfo {
   pageBulkExportJob: Ref<IPageBulkExportJob>,

+ 2 - 1
apps/app/src/features/page-bulk-export/server/routes/apiv3/page-bulk-export.ts

@@ -1,7 +1,7 @@
 import { ErrorV3 } from '@growi/core/dist/models';
 import type { Request } from 'express';
 import { Router } from 'express';
-import { body, validationResult } from 'express-validator';
+import { body, param, validationResult } from 'express-validator';
 
 import type Crowi from '~/server/crowi';
 import type { ApiV3Response } from '~/server/routes/apiv3/interfaces/apiv3-response';
@@ -25,6 +25,7 @@ module.exports = (crowi: Crowi): Router => {
       body('path').exists({ checkFalsy: true }).isString(),
       body('format').exists({ checkFalsy: true }).isString(),
     ],
+    downloadResult: param('jobId').isMongoId(),
   };
 
   router.post('/', loginRequiredStrictly, validators.pageBulkExport, async(req: AuthorizedRequest, res: ApiV3Response) => {

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

@@ -119,21 +119,26 @@ export default class InAppNotificationService {
     const { limit, offset, status } = queryOptions;
 
     try {
-      const pagenateOptions = { user: userId };
+      const paginateOptions = { user: userId };
       if (status != null) {
-        Object.assign(pagenateOptions, { status });
+        Object.assign(paginateOptions, { status });
       }
       // TODO: import @types/mongoose-paginate-v2 and use PaginateResult as a type after upgrading mongoose v6.0.0
       // eslint-disable-next-line @typescript-eslint/no-explicit-any
       const paginationResult = await (InAppNotification as any).paginate(
-        pagenateOptions,
+        paginateOptions,
         {
           sort: { createdAt: -1 },
           limit,
           offset,
           populate: [
             { path: 'user' },
-            { path: 'target' },
+            {
+              path: 'target',
+              populate: [
+                { path: 'attachment', strictPopulate: false },
+              ],
+            },
             { path: 'activities', populate: { path: 'user' } },
           ],
         },