From 7ea220633079d8f52e89a78e61400e15b839fcb0 Mon Sep 17 00:00:00 2001 From: Remko Date: Fri, 5 Jan 2024 14:11:33 +0100 Subject: [PATCH] added object and mapping to log table --- pwa/src/apiService/resources/mapping.ts | 7 ++ pwa/src/apiService/resources/object.ts | 6 ++ pwa/src/context/logs.ts | 6 +- pwa/src/context/tableColumns.ts | 3 +- pwa/src/hooks/mapping.ts | 9 ++- pwa/src/hooks/object.ts | 9 ++- pwa/src/services/getStatusTag.tsx | 27 ++++++- .../logsDetailTemplate/LogsDetailTemplate.tsx | 77 +++++++++++++++++-- .../logFilters/LogFiltersTemplate.tsx | 44 +++++++---- .../logsTable/LogsTableTemplate.tsx | 24 ++++-- 10 files changed, 180 insertions(+), 32 deletions(-) diff --git a/pwa/src/apiService/resources/mapping.ts b/pwa/src/apiService/resources/mapping.ts index fb294f36..d38cca03 100644 --- a/pwa/src/apiService/resources/mapping.ts +++ b/pwa/src/apiService/resources/mapping.ts @@ -22,6 +22,13 @@ export default class Mapping { return data; }; + public getAllSelectOptions = async (): Promise => { + const { data } = await this._send(this._instance, "GET", "/admin/mappings?limit=200"); + + return data?.map((mapping: any) => ({ label: mapping.name, value: mapping.id })); + }; + + public delete = async (variables: { id: string }): Promise => { const { id } = variables; diff --git a/pwa/src/apiService/resources/object.ts b/pwa/src/apiService/resources/object.ts index 3ae3dece..fad3c8df 100644 --- a/pwa/src/apiService/resources/object.ts +++ b/pwa/src/apiService/resources/object.ts @@ -69,6 +69,12 @@ export default class Sources { return data; }; + public getAllSelectOptions = async (): Promise => { + const { data } = await this._send(this._instance, "GET", "/admin/objects?limit=200"); + + return data?.results?.map((object: any) => ({ label: object.titel, value: object.id })); + }; + public getAllFromList = async (list: string): Promise => { const { data } = await this._send(this._instance, "GET", list); diff --git a/pwa/src/context/logs.ts b/pwa/src/context/logs.ts index 992b883e..74125129 100644 --- a/pwa/src/context/logs.ts +++ b/pwa/src/context/logs.ts @@ -18,7 +18,8 @@ export interface ILogFiltersContext { user?: string; organization?: string; application?: string; - template?: string; + object?: string; + mapping?: string; }; } @@ -65,6 +66,7 @@ export const channels = [ "organization", "user", "collection", - "template", + "object", + "mapping", ] as const; export type TLogChannel = (typeof channels)[number]; diff --git a/pwa/src/context/tableColumns.ts b/pwa/src/context/tableColumns.ts index ad8c7dbb..3d5361b7 100644 --- a/pwa/src/context/tableColumns.ts +++ b/pwa/src/context/tableColumns.ts @@ -26,7 +26,8 @@ const logColumns = { user: true, organization: true, application: true, - template: true, + object: true, + mapping: true, }; // Interface combining all above columns diff --git a/pwa/src/hooks/mapping.ts b/pwa/src/hooks/mapping.ts index be7adf48..164f0b25 100644 --- a/pwa/src/hooks/mapping.ts +++ b/pwa/src/hooks/mapping.ts @@ -26,6 +26,13 @@ export const useMapping = (queryClient: QueryClient) => { enabled: !!mappingId && !isDeleted(mappingId), }); + const getAllSelectOptions = () => + useQuery("mapping_select_options", API.Mapping.getAllSelectOptions, { + onError: (error) => { + console.warn(error.message); + }, + }); + const remove = () => useMutation(API.Mapping.delete, { onMutate: ({ id }) => addDeletedItem(id), @@ -62,5 +69,5 @@ export const useMapping = (queryClient: QueryClient) => { console.warn(error.message); }, }); - return { getAll, getOne, remove, createOrEdit, testMapping }; + return { getAll, getOne, remove, createOrEdit, testMapping, getAllSelectOptions }; }; diff --git a/pwa/src/hooks/object.ts b/pwa/src/hooks/object.ts index ae5cca7c..0850f1f3 100644 --- a/pwa/src/hooks/object.ts +++ b/pwa/src/hooks/object.ts @@ -60,6 +60,13 @@ export const useObject = () => { }, ); + const getAllSelectOptions = () => + useQuery("objects_select_options", API.Object.getAllSelectOptions, { + onError: (error) => { + console.warn(error.message); + }, + }); + const getAllFromList = (list: string) => useQuery(["objects", list], () => API.Object.getAllFromList(list), { onError: (error) => { @@ -114,5 +121,5 @@ export const useObject = () => { }, }); - return { getAll, getOne, getAllFromEntity, getAllFromList, getSchema, remove, createOrEdit, downloadPDF }; + return { getAll, getOne, getAllFromEntity, getAllFromList, getSchema, remove, createOrEdit, downloadPDF, getAllSelectOptions }; }; diff --git a/pwa/src/services/getStatusTag.tsx b/pwa/src/services/getStatusTag.tsx index 91f65542..40dd7596 100644 --- a/pwa/src/services/getStatusTag.tsx +++ b/pwa/src/services/getStatusTag.tsx @@ -1,8 +1,29 @@ +import _ from "lodash"; import { StatusTag } from "../components/statusTag/StatusTag"; export const getStatusTag = (value: unknown): JSX.Element => { - if (value === "200" || value === true) { - return ; + const isInInfoRange = (value: number): boolean => { + return _.inRange(value, 100, 200); + }; + + const isInSuccesRange = (value: number): boolean => { + return _.inRange(value, 200, 300); + }; + + const isInRedirectRange = (value: number): boolean => { + return _.inRange(value, 300, 400); + }; + + if (isInSuccesRange(_.toNumber(value)) || value === true) { + return ; + } + + if (isInInfoRange(_.toNumber(value))) { + return ; + } + + if (isInRedirectRange(_.toNumber(value))) { + return ; } if ( @@ -14,5 +35,5 @@ export const getStatusTag = (value: unknown): JSX.Element => { return ; } - return ; + return ; }; diff --git a/pwa/src/templates/logsDetailTemplate/LogsDetailTemplate.tsx b/pwa/src/templates/logsDetailTemplate/LogsDetailTemplate.tsx index de35b479..14feb4fb 100644 --- a/pwa/src/templates/logsDetailTemplate/LogsDetailTemplate.tsx +++ b/pwa/src/templates/logsDetailTemplate/LogsDetailTemplate.tsx @@ -21,6 +21,8 @@ import { useLog } from "../../hooks/log"; import { useLogFiltersContext } from "../../context/logs"; import { Button } from "../../components/button/Button"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { useMapping } from "../../hooks/mapping"; +import { useObject } from "../../hooks/object"; interface LogsDetailTemplateProps { logId: string; @@ -40,6 +42,8 @@ export const LogsDetailTemplate: React.FC = ({ logId }) const getAction = useAction(queryClient).getOne(getLog.data?.context?.action); const getUser = useUser(queryClient).getOne(getLog.data?.context?.user); const getOrganization = useOrganization(queryClient).getOne(getLog.data?.context?.organization); + const getMapping = useMapping(queryClient).getOne(getLog.data?.context?.mapping); + const getObject = useObject().getOne(getLog.data?.context?.object); const handleSetContextFilter = ( context: @@ -51,10 +55,17 @@ export const LogsDetailTemplate: React.FC = ({ logId }) | "action" | "user" | "organization" - | "application", + | "application" + | "mapping" + | "object", value: string, ) => { - setLogFilters({ context: { [context]: value } }); + setLogFilters({ + context: { [context]: value }, + "_order[datetime]": "asc", + "datetime[before]": "", + "datetime[after]": "", + }); navigate("/logs"); }; @@ -262,13 +273,36 @@ export const LogsDetailTemplate: React.FC = ({ logId }) Mapping {getLog.data.context?.mapping ? ( - {getLog.data.context?.mapping} + getMapping.isSuccess && ( + {getMapping.data.name ?? getLog.data.context?.mapping} + ) ) : ( - )} - - - - + {getMapping.isLoading && ( + + + + )} + +