From b128c9b17c23e5181e8bd55b859128e47750022e Mon Sep 17 00:00:00 2001 From: shamsmosowi Date: Wed, 3 Nov 2021 09:10:24 +1100 Subject: [PATCH] update cell audit logs --- src/constants/runRoutes.ts | 1 + src/contexts/ProjectContext.tsx | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/constants/runRoutes.ts b/src/constants/runRoutes.ts index 3bfc40eb..f6d7c2fa 100644 --- a/src/constants/runRoutes.ts +++ b/src/constants/runRoutes.ts @@ -53,4 +53,5 @@ export const runRoutes = { algoliaSearchKey: { path: `/algoliaSearchKey`, method: "GET" } as RunRoute, algoliaAppId: { path: `/algoliaAppId`, method: "GET" } as RunRoute, functionLogs: { path: `/functionLogs`, method: "GET" } as RunRoute, + auditChange: { path: `/auditChange`, method: "POST" } as RunRoute, } as const; diff --git a/src/contexts/ProjectContext.tsx b/src/contexts/ProjectContext.tsx index f298aebe..9f5769bd 100644 --- a/src/contexts/ProjectContext.tsx +++ b/src/contexts/ProjectContext.tsx @@ -19,6 +19,7 @@ import { rowyRun, IRowyRunRequestProps } from "@src/utils/rowyRun"; import { FieldType } from "@src/constants/fields"; import { rowyUser } from "@src/utils/fns"; import { WIKI_LINKS } from "@src/constants/externalLinks"; +import { runRoutes } from "@src/constants/runRoutes"; export type Table = { id: string; @@ -169,6 +170,14 @@ export const ProjectContextProvider: React.FC = ({ children }) => { initialData[table?.auditFieldUpdatedBy || "_updatedBy"] = rowyUser( currentUser! ); + // _rowyRun({route:runRoutes.auditChange,body:{ + // rowyUser, + // eventType:"ADD_ROW", + // eventData:{ + // rowPath:ref.path, + // tableId:table?.id, + // } + // }}) } tableActions.row.add( @@ -188,10 +197,20 @@ export const ProjectContextProvider: React.FC = ({ children }) => { const update = { [fieldName]: value }; if (table?.audit !== false) { - update[table?.auditFieldUpdatedBy || "_updatedBy"] = rowyUser( - currentUser!, - { updatedField: fieldName } - ); + const _rowyUser = rowyUser(currentUser!, { updatedField: fieldName }); + update[table?.auditFieldUpdatedBy || "_updatedBy"] = _rowyUser; + _rowyRun({ + route: runRoutes.auditChange, + body: { + rowyUser: _rowyUser, + eventType: "UPDATE_CELL", + eventData: { + rowPath: ref.path, + tableId: table?.id, + updatedField: fieldName, + }, + }, + }); } tableActions.row.update(