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

Merge pull request #6135 from weseek/imprv/adjust-variable-names

imprv: Adjust variable names
Shun Miyazawa 3 лет назад
Родитель
Сommit
08d22bebf1

+ 2 - 2
packages/app/src/components/Admin/AuditLogManagement.tsx

@@ -4,7 +4,7 @@ import { format } from 'date-fns';
 import { useTranslation } from 'react-i18next';
 
 import {
-  SupportedActionType, AllSupportedAction, PageActions, CommentActions,
+  SupportedActionType, AllSupportedActions, PageActions, CommentActions,
 } from '~/interfaces/activity';
 import { useSWRxActivity } from '~/stores/activity';
 
@@ -39,7 +39,7 @@ export const AuditLogManagement: FC = () => {
   const [endDate, setEndDate] = useState<Date | null>(null);
   const [selectedUsernames, setSelectedUsernames] = useState<string[]>([]);
   const [actionMap, setActionMap] = useState(
-    new Map<SupportedActionType, boolean>(AllSupportedAction.map(action => [action, true])),
+    new Map<SupportedActionType, boolean>(AllSupportedActions.map(action => [action, true])),
   );
 
   /*

+ 17 - 16
packages/app/src/interfaces/activity.ts

@@ -110,6 +110,19 @@ export const SupportedAction = {
   ACTION_ADMIN_SEARCH_INDICES_REBUILD,
 } as const;
 
+// Action required for notification
+export const EssentialActionGroup = {
+  ACTION_PAGE_LIKE,
+  ACTION_PAGE_BOOKMARK,
+  ACTION_PAGE_UPDATE,
+  ACTION_PAGE_RENAME,
+  ACTION_PAGE_DUPLICATE,
+  ACTION_PAGE_DELETE,
+  ACTION_PAGE_DELETE_COMPLETELY,
+  ACTION_PAGE_REVERT,
+  ACTION_COMMENT_CREATE,
+} as const;
+
 export const ActionGroupSize = {
   Small: 'SMALL',
   Medium: 'MEDIUM',
@@ -173,18 +186,6 @@ export const LargeActionGroup = {
   ACTION_ADMIN_SEARCH_INDICES_REBUILD,
 } as const;
 
-export const SupportedActionToNotified = {
-  ACTION_PAGE_LIKE,
-  ACTION_PAGE_BOOKMARK,
-  ACTION_PAGE_UPDATE,
-  ACTION_PAGE_RENAME,
-  ACTION_PAGE_DUPLICATE,
-  ACTION_PAGE_DELETE,
-  ACTION_PAGE_DELETE_COMPLETELY,
-  ACTION_PAGE_REVERT,
-  ACTION_COMMENT_CREATE,
-} as const;
-
 /*
  * For AuditLogManagement.tsx
  */
@@ -208,10 +209,10 @@ export const CommentActions = Object.values({
 /*
  * Array
  */
-export const AllSupportedTargetModel = Object.values(SupportedTargetModel);
-export const AllSupportedEventModel = Object.values(SupportedEventModel);
-export const AllSupportedAction = Object.values(SupportedAction);
-export const AllSupportedActionToNotified = Object.values(SupportedActionToNotified);
+export const AllSupportedTargetModels = Object.values(SupportedTargetModel);
+export const AllSupportedEventModels = Object.values(SupportedEventModel);
+export const AllSupportedActions = Object.values(SupportedAction);
+export const AllEssentialActions = Object.values(EssentialActionGroup);
 export const AllSmallGroupActions = Object.values(SmallActionGroup);
 export const AllMediumGroupActions = Object.values(MediumActionGroup);
 export const AllLargeGroupActions = Object.values(LargeActionGroup);

+ 6 - 6
packages/app/src/server/models/activity.ts

@@ -5,9 +5,9 @@ import {
 import mongoosePaginate from 'mongoose-paginate-v2';
 
 import {
-  IActivity, ISnapshot, AllSupportedAction, SupportedActionType,
-  AllSupportedTargetModel, SupportedTargetModelType,
-  AllSupportedEventModel, SupportedEventModelType,
+  IActivity, ISnapshot, AllSupportedActions, SupportedActionType,
+  AllSupportedTargetModels, SupportedTargetModelType,
+  AllSupportedEventModels, SupportedEventModelType,
 } from '~/interfaces/activity';
 
 import loggerFactory from '../../utils/logger';
@@ -56,7 +56,7 @@ const activitySchema = new Schema<ActivityDocument, ActivityModel>({
   },
   targetModel: {
     type: String,
-    enum: AllSupportedTargetModel,
+    enum: AllSupportedTargetModels,
   },
   target: {
     type: Schema.Types.ObjectId,
@@ -64,14 +64,14 @@ const activitySchema = new Schema<ActivityDocument, ActivityModel>({
   },
   eventModel: {
     type: String,
-    enum: AllSupportedEventModel,
+    enum: AllSupportedEventModels,
   },
   event: {
     type: Schema.Types.ObjectId,
   },
   action: {
     type: String,
-    enum: AllSupportedAction,
+    enum: AllSupportedActions,
     required: true,
   },
   snapshot: snapshotSchema,

+ 3 - 3
packages/app/src/server/models/in-app-notification.ts

@@ -4,7 +4,7 @@ import {
 } from 'mongoose';
 import mongoosePaginate from 'mongoose-paginate-v2';
 
-import { AllSupportedTargetModel, AllSupportedAction } from '~/interfaces/activity';
+import { AllSupportedTargetModels, AllSupportedActions } from '~/interfaces/activity';
 import { InAppNotificationStatuses } from '~/interfaces/in-app-notification';
 
 import { ActivityDocument } from './activity';
@@ -46,7 +46,7 @@ const inAppNotificationSchema = new Schema<InAppNotificationDocument, InAppNotif
   targetModel: {
     type: String,
     required: true,
-    enum: AllSupportedTargetModel,
+    enum: AllSupportedTargetModels,
   },
   target: {
     type: Schema.Types.ObjectId,
@@ -56,7 +56,7 @@ const inAppNotificationSchema = new Schema<InAppNotificationDocument, InAppNotif
   action: {
     type: String,
     required: true,
-    enum: AllSupportedAction,
+    enum: AllSupportedActions,
   },
   activities: [
     {

+ 2 - 2
packages/app/src/server/models/subscription.ts

@@ -3,7 +3,7 @@ import {
   Types, Document, Model, Schema,
 } from 'mongoose';
 
-import { AllSupportedTargetModel } from '~/interfaces/activity';
+import { AllSupportedTargetModels } from '~/interfaces/activity';
 import { SubscriptionStatusType, AllSubscriptionStatusType } from '~/interfaces/subscription';
 
 
@@ -38,7 +38,7 @@ const subscriptionSchema = new Schema<SubscriptionDocument, SubscriptionModel>({
   targetModel: {
     type: String,
     required: true,
-    enum: AllSupportedTargetModel,
+    enum: AllSupportedTargetModels,
   },
   target: {
     type: Schema.Types.ObjectId,

+ 4 - 4
packages/app/src/server/service/activity.ts

@@ -1,8 +1,8 @@
 import mongoose from 'mongoose';
 
 import {
-  IActivity, SupportedActionType, ActionGroupSize, AllSupportedAction,
-  AllSmallGroupActions, AllMediumGroupActions, AllLargeGroupActions, AllSupportedActionToNotified,
+  IActivity, SupportedActionType, AllSupportedActions, ActionGroupSize,
+  AllEssentialActions, AllSmallGroupActions, AllMediumGroupActions, AllLargeGroupActions,
 } from '~/interfaces/activity';
 import { IPage } from '~/interfaces/page';
 import Activity from '~/server/models/activity';
@@ -19,7 +19,7 @@ const parseActionString = (actionsString: string): SupportedActionType[] => {
   }
 
   const actions = actionsString.split(',').map(value => value.trim());
-  return actions.filter(action => (AllSupportedAction as string[]).includes(action)) as SupportedActionType[];
+  return actions.filter(action => (AllSupportedActions as string[]).includes(action)) as SupportedActionType[];
 };
 
 class ActivityService {
@@ -87,7 +87,7 @@ class ActivityService {
 
     // Add essentialActions
     if (isIncludeEssentialActions) {
-      AllSupportedActionToNotified.forEach(action => availableActionsSet.add(action));
+      AllEssentialActions.forEach(action => availableActionsSet.add(action));
     }
 
     return Array.from(availableActionsSet);

+ 3 - 3
packages/app/src/server/service/in-app-notification.ts

@@ -1,7 +1,7 @@
 import { subDays } from 'date-fns';
 import { Types } from 'mongoose';
 
-import { AllSupportedActionToNotified, SupportedAction } from '~/interfaces/activity';
+import { AllEssentialActions, SupportedAction } from '~/interfaces/activity';
 import { HasObjectId } from '~/interfaces/has-object-id';
 import { InAppNotificationStatuses, PaginateResult } from '~/interfaces/in-app-notification';
 import { IPage } from '~/interfaces/page';
@@ -53,7 +53,7 @@ export default class InAppNotificationService {
   initActivityEventListeners(): void {
     this.activityEvent.on('updated', async(activity: ActivityDocument, target: IPage) => {
       try {
-        const shouldNotification = activity != null && target != null && (AllSupportedActionToNotified as ReadonlyArray<string>).includes(activity.action);
+        const shouldNotification = activity != null && target != null && (AllEssentialActions as ReadonlyArray<string>).includes(activity.action);
         if (shouldNotification) {
           await this.createInAppNotification(activity, target);
         }
@@ -200,7 +200,7 @@ export default class InAppNotificationService {
   };
 
   createInAppNotification = async function(activity: ActivityDocument, target: IPage): Promise<void> {
-    const shouldNotification = activity != null && target != null && (AllSupportedActionToNotified as ReadonlyArray<string>).includes(activity.action);
+    const shouldNotification = activity != null && target != null && (AllEssentialActions as ReadonlyArray<string>).includes(activity.action);
     if (shouldNotification) {
       let mentionedUsers: IUser[] = [];
       if (activity.action === SupportedAction.ACTION_COMMENT_CREATE) {