1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +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:
Thomas Heartman 2024-08-02 11:05:42 +02:00 committed by GitHub
parent 6458d461b9
commit 643cfeb5bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 14 additions and 29 deletions

View File

@ -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) => {
/>
</dl>
<ConditionallyRender
condition={entry.data || entry.preData}
condition={Boolean(entry.data || entry.preData)}
show={
<StyledCodeSection>
<StyledChangesTitle>Changes:</StyledChangesTitle>

View File

@ -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<IEvent>;
entry: { data?: unknown; preData?: unknown };
sort?: (a: IEventDiffResult, b: IEventDiffResult) => number;
}

View File

@ -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 }) => ({

View File

@ -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<IEvent[]>();
const [cache, setCache] = useState<EventSchema[]>();
useEffect(() => events && setCache(events), [events]);
const onShowData = () => {

View File

@ -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<IEvent[]>();
const [events, setEvents] = useState<EventSchema[]>();
const [totalEvents, setTotalEvents] = useState<number>(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 }));

View File

@ -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[];
}

View File

@ -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<string, unknown>;
};