mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	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.
This commit is contained in:
		
							parent
							
								
									6458d461b9
								
							
						
					
					
						commit
						643cfeb5bb
					
				| @ -1,13 +1,13 @@ | |||||||
| import EventDiff from 'component/events/EventDiff/EventDiff'; | import EventDiff from 'component/events/EventDiff/EventDiff'; | ||||||
| import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; | import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; | ||||||
| import type { IEvent } from 'interfaces/event'; |  | ||||||
| import { useLocationSettings } from 'hooks/useLocationSettings'; | import { useLocationSettings } from 'hooks/useLocationSettings'; | ||||||
| import { formatDateYMDHMS } from 'utils/formatDate'; | import { formatDateYMDHMS } from 'utils/formatDate'; | ||||||
| import { Link } from 'react-router-dom'; | import { Link } from 'react-router-dom'; | ||||||
| import { styled } from '@mui/material'; | import { styled } from '@mui/material'; | ||||||
|  | import type { EventSchema } from 'openapi'; | ||||||
| 
 | 
 | ||||||
| interface IEventCardProps { | interface IEventCardProps { | ||||||
|     entry: IEvent; |     entry: EventSchema; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const StyledDefinitionTerm = styled('dt')(({ theme }) => ({ | const StyledDefinitionTerm = styled('dt')(({ theme }) => ({ | ||||||
| @ -134,7 +134,7 @@ const EventCard = ({ entry }: IEventCardProps) => { | |||||||
|                 /> |                 /> | ||||||
|             </dl> |             </dl> | ||||||
|             <ConditionallyRender |             <ConditionallyRender | ||||||
|                 condition={entry.data || entry.preData} |                 condition={Boolean(entry.data || entry.preData)} | ||||||
|                 show={ |                 show={ | ||||||
|                     <StyledCodeSection> |                     <StyledCodeSection> | ||||||
|                         <StyledChangesTitle>Changes:</StyledChangesTitle> |                         <StyledChangesTitle>Changes:</StyledChangesTitle> | ||||||
|  | |||||||
| @ -1,5 +1,4 @@ | |||||||
| import { diff } from 'deep-diff'; | import { diff } from 'deep-diff'; | ||||||
| import type { IEvent } from 'interfaces/event'; |  | ||||||
| import { useTheme } from '@mui/system'; | import { useTheme } from '@mui/system'; | ||||||
| import type { JSX, CSSProperties } from 'react'; | import type { JSX, CSSProperties } from 'react'; | ||||||
| 
 | 
 | ||||||
| @ -17,7 +16,7 @@ interface IEventDiffResult { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| interface IEventDiffProps { | interface IEventDiffProps { | ||||||
|     entry: Partial<IEvent>; |     entry: { data?: unknown; preData?: unknown }; | ||||||
|     sort?: (a: IEventDiffResult, b: IEventDiffResult) => number; |     sort?: (a: IEventDiffResult, b: IEventDiffResult) => number; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,8 +1,8 @@ | |||||||
| import type { IEvent } from 'interfaces/event'; |  | ||||||
| import { styled } from '@mui/material'; | import { styled } from '@mui/material'; | ||||||
|  | import type { EventSchema } from 'openapi'; | ||||||
| 
 | 
 | ||||||
| interface IEventJsonProps { | interface IEventJsonProps { | ||||||
|     entry: IEvent; |     entry: EventSchema; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export const StyledJsonListItem = styled('li')(({ theme }) => ({ | export const StyledJsonListItem = styled('li')(({ theme }) => ({ | ||||||
|  | |||||||
| @ -10,11 +10,11 @@ import theme from 'themes/theme'; | |||||||
| import { useEventSearch } from 'hooks/api/getters/useEventSearch/useEventSearch'; | import { useEventSearch } from 'hooks/api/getters/useEventSearch/useEventSearch'; | ||||||
| import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; | import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; | ||||||
| import { useOnVisible } from 'hooks/useOnVisible'; | import { useOnVisible } from 'hooks/useOnVisible'; | ||||||
| import type { IEvent } from 'interfaces/event'; |  | ||||||
| import { styled } from '@mui/system'; | import { styled } from '@mui/system'; | ||||||
| import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; | import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; | ||||||
| import { useUiFlag } from 'hooks/useUiFlag'; | import { useUiFlag } from 'hooks/useUiFlag'; | ||||||
| import { EventLogFilters } from './EventLogFilters'; | import { EventLogFilters } from './EventLogFilters'; | ||||||
|  | import type { EventSchema } from 'openapi'; | ||||||
| 
 | 
 | ||||||
| interface IEventLogProps { | interface IEventLogProps { | ||||||
|     title: string; |     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
 |     // Cache the previous search results so that we can show those while
 | ||||||
|     // fetching new results for a new search query in the background.
 |     // fetching new results for a new search query in the background.
 | ||||||
|     const [cache, setCache] = useState<IEvent[]>(); |     const [cache, setCache] = useState<EventSchema[]>(); | ||||||
|     useEffect(() => events && setCache(events), [events]); |     useEffect(() => events && setCache(events), [events]); | ||||||
| 
 | 
 | ||||||
|     const onShowData = () => { |     const onShowData = () => { | ||||||
|  | |||||||
| @ -2,12 +2,12 @@ import useSWR from 'swr'; | |||||||
| import { useCallback, useState, useEffect, useMemo } from 'react'; | import { useCallback, useState, useEffect, useMemo } from 'react'; | ||||||
| import { formatApiPath } from 'utils/formatPath'; | import { formatApiPath } from 'utils/formatPath'; | ||||||
| import handleErrorResponses from '../httpErrorResponseHandler'; | import handleErrorResponses from '../httpErrorResponseHandler'; | ||||||
| import type { IEvent } from 'interfaces/event'; | import type { EventSchema } from 'openapi'; | ||||||
| 
 | 
 | ||||||
| const PATH = formatApiPath('api/admin/events/search'); | const PATH = formatApiPath('api/admin/events/search'); | ||||||
| 
 | 
 | ||||||
| export interface IUseEventSearchOutput { | export interface IUseEventSearchOutput { | ||||||
|     events?: IEvent[]; |     events?: EventSchema[]; | ||||||
|     fetchNextPage: () => void; |     fetchNextPage: () => void; | ||||||
|     loading: boolean; |     loading: boolean; | ||||||
|     totalEvents?: number; |     totalEvents?: number; | ||||||
| @ -28,7 +28,7 @@ export const useEventSearch = ( | |||||||
|     feature?: string, |     feature?: string, | ||||||
|     query?: string, |     query?: string, | ||||||
| ): IUseEventSearchOutput => { | ): IUseEventSearchOutput => { | ||||||
|     const [events, setEvents] = useState<IEvent[]>(); |     const [events, setEvents] = useState<EventSchema[]>(); | ||||||
|     const [totalEvents, setTotalEvents] = useState<number>(0); |     const [totalEvents, setTotalEvents] = useState<number>(0); | ||||||
|     const [offset, setOffset] = useState(0); |     const [offset, setOffset] = useState(0); | ||||||
| 
 | 
 | ||||||
| @ -38,7 +38,7 @@ export const useEventSearch = ( | |||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|     const { data, error, isValidating } = useSWR<{ |     const { data, error, isValidating } = useSWR<{ | ||||||
|         events: IEvent[]; |         events: EventSchema[]; | ||||||
|         totalEvents?: number; |         totalEvents?: number; | ||||||
|     }>([PATH, search, offset], () => searchEvents(PATH, { ...search, offset })); |     }>([PATH, search, offset], () => searchEvents(PATH, { ...search, offset })); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -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[]; |  | ||||||
| } |  | ||||||
| @ -1,4 +1,4 @@ | |||||||
| import type { IEvent } from './event'; | import type { EventSchema } from 'openapi'; | ||||||
| 
 | 
 | ||||||
| export type IntegrationEvent = { | export type IntegrationEvent = { | ||||||
|     id: string; |     id: string; | ||||||
| @ -6,7 +6,7 @@ export type IntegrationEvent = { | |||||||
|     createdAt: string; |     createdAt: string; | ||||||
|     state: 'success' | 'failed' | 'successWithErrors'; |     state: 'success' | 'failed' | 'successWithErrors'; | ||||||
|     stateDetails: string; |     stateDetails: string; | ||||||
|     event: IEvent; |     event: EventSchema; | ||||||
|     details: Record<string, unknown>; |     details: Record<string, unknown>; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user