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

Translate action names into readable text

arvid-e 5 месяцев назад
Родитель
Сommit
db1b188fd3

+ 9 - 6
apps/app/src/client/components/RecentActivity/ActivityListItem.tsx

@@ -1,19 +1,22 @@
-import type { ActivityWithPageTarget } from '~/interfaces/activity';
+import { ActivityActionTranslationMap } from '~/interfaces/activity';
+import type { ActivityWithPageTarget, SupportedActivityActionType } from '~/interfaces/activity';
 
 import { PageListItemS } from '../PageList/PageListItemS';
 
+const translateAction = (action: SupportedActivityActionType): string => {
+  return ActivityActionTranslationMap[action] || 'performed an unknown action';
+};
 
-export const ActivityListItem = ({ activity }: { activity: ActivityWithPageTarget }): JSX.Element => {
 
-  const username = activity.user?.username.trim();
-  const action = activity.action;
+export const ActivityListItem = ({ activity }: { activity: ActivityWithPageTarget }): JSX.Element => {
+  const username = activity.user?.username;
+  const action = activity.action as SupportedActivityActionType;
   const date = new Date(activity.createdAt).toLocaleString();
 
-
   return (
     <div className="activity-row">
       <p className="text-muted small mb-1">
-        {username} performed {action} on {date}
+        {username} {translateAction(action)} on {date}
       </p>
 
       <PageListItemS page={activity.target} />

+ 17 - 1
apps/app/src/interfaces/activity.ts

@@ -581,11 +581,26 @@ export const ActivityLogActions = {
   ACTION_PAGE_RENAME,
   ACTION_PAGE_DUPLICATE,
   ACTION_PAGE_DELETE,
+  ACTION_PAGE_REVERT,
   ACTION_COMMENT_CREATE,
   ACTION_COMMENT_UPDATE,
+  ACTION_COMMENT_REMOVE,
   ACTION_ATTACHMENT_ADD,
 } as const;
 
+export const ActivityActionTranslationMap: Record<SupportedActivityActionType, string> = {
+  [ACTION_PAGE_CREATE]: 'created a page',
+  [ACTION_PAGE_UPDATE]: 'updated a page',
+  [ACTION_PAGE_DELETE]: 'deleted a page',
+  [ACTION_PAGE_RENAME]: 'renamed a page',
+  [ACTION_PAGE_REVERT]: 'reverted a page',
+  [ACTION_PAGE_DUPLICATE]: 'duplicated a page',
+  [ACTION_COMMENT_CREATE]: 'posted a comment',
+  [ACTION_COMMENT_UPDATE]: 'edited a comment',
+  [ACTION_COMMENT_REMOVE]: 'deleted a comment',
+  [ACTION_ATTACHMENT_ADD]: 'added an attachment',
+};
+
 /*
  * Array
  */
@@ -663,7 +678,8 @@ export type SupportedActionType =
   (typeof SupportedAction)[keyof typeof SupportedAction];
 export type SupportedActionCategoryType =
   (typeof SupportedActionCategory)[keyof typeof SupportedActionCategory];
-
+export type SupportedActivityActionType =
+  (typeof ActivityLogActions)[keyof typeof ActivityLogActions];
 export type ISnapshot = Partial<Pick<IUser, 'username'>>;
 
 export type IActivity = {