From 643cfeb5bb5bd9224fd51fa546df74630e4b4773 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Fri, 2 Aug 2024 11:05:42 +0200 Subject: [PATCH] chore: use EventSchema instead of IEvent (#7732) Changes the type used by the useEventSearch hook to be `EventSchema` from OpenAPI instead. This is more accurate with what we're actually getting. And crucially for the event log search, it contains the `createdByUserId` property that we need to filter out events. It's mostly a straightforward find and replace except for one instance where we need to do some extra fiddling. There's an inline comment explaining that. --- .../src/component/events/EventCard/EventCard.tsx | 6 +++--- .../src/component/events/EventDiff/EventDiff.tsx | 3 +-- .../src/component/events/EventJson/EventJson.tsx | 4 ++-- .../src/component/events/EventLog/EventLog.tsx | 4 ++-- .../api/getters/useEventSearch/useEventSearch.ts | 8 ++++---- frontend/src/interfaces/event.ts | 14 -------------- frontend/src/interfaces/integrationEvent.ts | 4 ++-- 7 files changed, 14 insertions(+), 29 deletions(-) delete mode 100644 frontend/src/interfaces/event.ts diff --git a/frontend/src/component/events/EventCard/EventCard.tsx b/frontend/src/component/events/EventCard/EventCard.tsx index 9c25c9a799..60d6cf0be3 100644 --- a/frontend/src/component/events/EventCard/EventCard.tsx +++ b/frontend/src/component/events/EventCard/EventCard.tsx @@ -1,13 +1,13 @@ import EventDiff from 'component/events/EventDiff/EventDiff'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; -import type { IEvent } from 'interfaces/event'; import { useLocationSettings } from 'hooks/useLocationSettings'; import { formatDateYMDHMS } from 'utils/formatDate'; import { Link } from 'react-router-dom'; import { styled } from '@mui/material'; +import type { EventSchema } from 'openapi'; interface IEventCardProps { - entry: IEvent; + entry: EventSchema; } const StyledDefinitionTerm = styled('dt')(({ theme }) => ({ @@ -134,7 +134,7 @@ const EventCard = ({ entry }: IEventCardProps) => { /> Changes: diff --git a/frontend/src/component/events/EventDiff/EventDiff.tsx b/frontend/src/component/events/EventDiff/EventDiff.tsx index bdf0fb4b11..a65f7e1591 100644 --- a/frontend/src/component/events/EventDiff/EventDiff.tsx +++ b/frontend/src/component/events/EventDiff/EventDiff.tsx @@ -1,5 +1,4 @@ import { diff } from 'deep-diff'; -import type { IEvent } from 'interfaces/event'; import { useTheme } from '@mui/system'; import type { JSX, CSSProperties } from 'react'; @@ -17,7 +16,7 @@ interface IEventDiffResult { } interface IEventDiffProps { - entry: Partial; + entry: { data?: unknown; preData?: unknown }; sort?: (a: IEventDiffResult, b: IEventDiffResult) => number; } diff --git a/frontend/src/component/events/EventJson/EventJson.tsx b/frontend/src/component/events/EventJson/EventJson.tsx index f83bda9692..5e6c5d3dd0 100644 --- a/frontend/src/component/events/EventJson/EventJson.tsx +++ b/frontend/src/component/events/EventJson/EventJson.tsx @@ -1,8 +1,8 @@ -import type { IEvent } from 'interfaces/event'; import { styled } from '@mui/material'; +import type { EventSchema } from 'openapi'; interface IEventJsonProps { - entry: IEvent; + entry: EventSchema; } export const StyledJsonListItem = styled('li')(({ theme }) => ({ diff --git a/frontend/src/component/events/EventLog/EventLog.tsx b/frontend/src/component/events/EventLog/EventLog.tsx index 03243d4d94..052affc315 100644 --- a/frontend/src/component/events/EventLog/EventLog.tsx +++ b/frontend/src/component/events/EventLog/EventLog.tsx @@ -10,11 +10,11 @@ import theme from 'themes/theme'; import { useEventSearch } from 'hooks/api/getters/useEventSearch/useEventSearch'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; import { useOnVisible } from 'hooks/useOnVisible'; -import type { IEvent } from 'interfaces/event'; import { styled } from '@mui/system'; import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; import { useUiFlag } from 'hooks/useUiFlag'; import { EventLogFilters } from './EventLogFilters'; +import type { EventSchema } from 'openapi'; interface IEventLogProps { title: string; @@ -45,7 +45,7 @@ export const EventLog = ({ title, project, feature }: IEventLogProps) => { // Cache the previous search results so that we can show those while // fetching new results for a new search query in the background. - const [cache, setCache] = useState(); + const [cache, setCache] = useState(); useEffect(() => events && setCache(events), [events]); const onShowData = () => { diff --git a/frontend/src/hooks/api/getters/useEventSearch/useEventSearch.ts b/frontend/src/hooks/api/getters/useEventSearch/useEventSearch.ts index a63311456e..d9796fd334 100644 --- a/frontend/src/hooks/api/getters/useEventSearch/useEventSearch.ts +++ b/frontend/src/hooks/api/getters/useEventSearch/useEventSearch.ts @@ -2,12 +2,12 @@ import useSWR from 'swr'; import { useCallback, useState, useEffect, useMemo } from 'react'; import { formatApiPath } from 'utils/formatPath'; import handleErrorResponses from '../httpErrorResponseHandler'; -import type { IEvent } from 'interfaces/event'; +import type { EventSchema } from 'openapi'; const PATH = formatApiPath('api/admin/events/search'); export interface IUseEventSearchOutput { - events?: IEvent[]; + events?: EventSchema[]; fetchNextPage: () => void; loading: boolean; totalEvents?: number; @@ -28,7 +28,7 @@ export const useEventSearch = ( feature?: string, query?: string, ): IUseEventSearchOutput => { - const [events, setEvents] = useState(); + const [events, setEvents] = useState(); const [totalEvents, setTotalEvents] = useState(0); const [offset, setOffset] = useState(0); @@ -38,7 +38,7 @@ export const useEventSearch = ( ); const { data, error, isValidating } = useSWR<{ - events: IEvent[]; + events: EventSchema[]; totalEvents?: number; }>([PATH, search, offset], () => searchEvents(PATH, { ...search, offset })); diff --git a/frontend/src/interfaces/event.ts b/frontend/src/interfaces/event.ts deleted file mode 100644 index 0b1d4b2634..0000000000 --- a/frontend/src/interfaces/event.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { ITag } from './tags'; - -export interface IEvent { - id: number; - createdAt: string; - type: string; - createdBy: string; - project?: string; - environment?: string; - featureName?: string; - data?: any; - preData?: any; - tags?: ITag[]; -} diff --git a/frontend/src/interfaces/integrationEvent.ts b/frontend/src/interfaces/integrationEvent.ts index fcbe5894e7..0aef0fd606 100644 --- a/frontend/src/interfaces/integrationEvent.ts +++ b/frontend/src/interfaces/integrationEvent.ts @@ -1,4 +1,4 @@ -import type { IEvent } from './event'; +import type { EventSchema } from 'openapi'; export type IntegrationEvent = { id: string; @@ -6,7 +6,7 @@ export type IntegrationEvent = { createdAt: string; state: 'success' | 'failed' | 'successWithErrors'; stateDetails: string; - event: IEvent; + event: EventSchema; details: Record; };