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

move PageBulkExportJob logic to PageBulkExportJobModelNotification

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

+ 12 - 11
apps/app/src/components/InAppNotification/ModelNotification/ModelNotification.tsx

@@ -3,9 +3,7 @@ import React from 'react';
 
 
 import type { HasObjectId } from '@growi/core';
 import type { HasObjectId } from '@growi/core';
 import { PagePathLabel } from '@growi/ui/dist/components';
 import { PagePathLabel } from '@growi/ui/dist/components';
-import { useTranslation } from 'react-i18next';
 
 
-import { SupportedAction, SupportedTargetModel } from '~/interfaces/activity';
 import type { IInAppNotification } from '~/interfaces/in-app-notification';
 import type { IInAppNotification } from '~/interfaces/in-app-notification';
 
 
 import FormattedDistanceDate from '../../FormattedDistanceDate';
 import FormattedDistanceDate from '../../FormattedDistanceDate';
@@ -15,24 +13,27 @@ type Props = {
   actionMsg: string
   actionMsg: string
   actionIcon: string
   actionIcon: string
   actionUsers: string
   actionUsers: string
+  hideActionUsers?: boolean
+  subMsg?: JSX.Element
 };
 };
 
 
-export const ModelNotification: FC<Props> = (props) => {
-  const {
-    notification, actionMsg, actionIcon, actionUsers,
-  } = props;
-
-  const { t } = useTranslation();
+export const ModelNotification: FC<Props> = ({
+  notification,
+  actionMsg,
+  actionIcon,
+  actionUsers,
+  hideActionUsers = false,
+  subMsg,
+}: Props) => {
 
 
   return (
   return (
     <div className="p-2 overflow-hidden">
     <div className="p-2 overflow-hidden">
       <div className="text-truncate">
       <div className="text-truncate">
-        {notification.targetModel !== SupportedTargetModel.MODEL_PAGE_BULK_EXPORT_JOB ? <b>{actionUsers}</b> : <></>}
+        {hideActionUsers ? <></> : <b>{actionUsers}</b>}
         {` ${actionMsg}`}
         {` ${actionMsg}`}
         <PagePathLabel path={notification.parsedSnapshot?.path ?? ''} />
         <PagePathLabel path={notification.parsedSnapshot?.path ?? ''} />
       </div>
       </div>
-      { (notification.action === SupportedAction.ACTION_PAGE_BULK_EXPORT_COMPLETED && notification.target == null)
-        ? <div className="text-danger"><small>{t('page_export.bulk_export_download_expired')}</small></div> : <></> }
+      { subMsg }
       <span className="material-symbols-outlined me-2">{actionIcon}</span>
       <span className="material-symbols-outlined me-2">{actionIcon}</span>
       <FormattedDistanceDate
       <FormattedDistanceDate
         id={notification._id}
         id={notification._id}

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

@@ -1,6 +1,7 @@
 import React from 'react';
 import React from 'react';
 
 
 import { isPopulated, type HasObjectId } from '@growi/core';
 import { isPopulated, type HasObjectId } from '@growi/core';
+import { useTranslation } from 'react-i18next';
 
 
 import type { IPageBulkExportJobHasId } from '~/features/page-bulk-export/interfaces/page-bulk-export';
 import type { IPageBulkExportJobHasId } from '~/features/page-bulk-export/interfaces/page-bulk-export';
 import { SupportedAction, SupportedTargetModel } from '~/interfaces/activity';
 import { SupportedAction, SupportedTargetModel } from '~/interfaces/activity';
@@ -15,6 +16,7 @@ import type { ModelNotificationUtils } from '.';
 
 
 export const usePageBulkExportJobModelNotification = (notification: IInAppNotification & HasObjectId): ModelNotificationUtils | null => {
 export const usePageBulkExportJobModelNotification = (notification: IInAppNotification & HasObjectId): ModelNotificationUtils | null => {
 
 
+  const { t } = useTranslation();
   const { actionMsg, actionIcon } = useActionMsgAndIconForModelNotification(notification);
   const { actionMsg, actionIcon } = useActionMsgAndIconForModelNotification(notification);
 
 
   const isPageBulkExportJobModelNotification = (
   const isPageBulkExportJobModelNotification = (
@@ -31,6 +33,9 @@ export const usePageBulkExportJobModelNotification = (notification: IInAppNotifi
 
 
   notification.parsedSnapshot = pageBulkExportJobSerializers.parseSnapshot(notification.snapshot);
   notification.parsedSnapshot = pageBulkExportJobSerializers.parseSnapshot(notification.snapshot);
 
 
+  const subMsg = (notification.action === SupportedAction.ACTION_PAGE_BULK_EXPORT_COMPLETED && notification.target == null)
+    ? <div className="text-danger"><small>{t('page_export.bulk_export_download_expired')}</small></div> : <></>;
+
   const Notification = () => {
   const Notification = () => {
     return (
     return (
       <ModelNotification
       <ModelNotification
@@ -38,6 +43,8 @@ export const usePageBulkExportJobModelNotification = (notification: IInAppNotifi
         actionMsg={actionMsg}
         actionMsg={actionMsg}
         actionIcon={actionIcon}
         actionIcon={actionIcon}
         actionUsers={actionUsers}
         actionUsers={actionUsers}
+        hideActionUsers
+        subMsg={subMsg}
       />
       />
     );
     );
   };
   };