From d70c279d3d6e996412cb21170de55e30c51f8a85 Mon Sep 17 00:00:00 2001
From: Thomas Heartman
Date: Wed, 7 Aug 2024 08:48:59 +0200
Subject: [PATCH] refactor: split EventLog into separate components and hook up
new Event search (#7777)
Hooks up the new Event search and filtering capabilities to the new
Event Log component. In doing so, it also splits the existing EventLog
component into two: `LegacyEventLog` and `NewEventLog`. The naming is
probably temporary, as the old EventLog isn't really legacy yet. But we
can rename them later.
The other half of #7768 .
---
.../component/events/EventLog/EventLog.tsx | 161 +++++++++++++-----
.../events/EventLog/EventLogFilters.tsx | 27 +--
2 files changed, 135 insertions(+), 53 deletions(-)
diff --git a/frontend/src/component/events/EventLog/EventLog.tsx b/frontend/src/component/events/EventLog/EventLog.tsx
index 693a970f6af6..937228c0d51f 100644
--- a/frontend/src/component/events/EventLog/EventLog.tsx
+++ b/frontend/src/component/events/EventLog/EventLog.tsx
@@ -15,6 +15,7 @@ import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { useUiFlag } from 'hooks/useUiFlag';
import { EventLogFilters } from './EventLogFilters';
import type { EventSchema } from 'openapi';
+import { useEventLogSearch } from './useEventLogSearch';
interface IEventLogProps {
title: string;
@@ -41,7 +42,98 @@ const EventResultWrapper = styled('div')(({ theme }) => ({
gap: theme.spacing(1),
}));
-export const EventLog = ({ title, project, feature }: IEventLogProps) => {
+const NewEventLog = ({ title, project, feature }: IEventLogProps) => {
+ const { events, total, loading, tableState, setTableState, filterState } =
+ useEventLogSearch(
+ project
+ ? { type: 'project', projectId: project }
+ : feature
+ ? { type: 'flag', flagName: feature }
+ : { type: 'global' },
+ );
+
+ const setSearchValue = (query = '') => {
+ setTableState({ query });
+ };
+ const { eventSettings, setEventSettings } = useEventSettings();
+ const isSmallScreen = useMediaQuery(theme.breakpoints.down('md'));
+
+ const onShowData = () => {
+ setEventSettings((prev) => ({ showData: !prev.showData }));
+ };
+
+ const searchInputField = (
+
+ );
+
+ const showDataSwitch = (
+
+ }
+ />
+ );
+
+ const resultComponent = () => {
+ if (loading) {
+ return Loading...
;
+ } else if (events.length === 0) {
+ return No events found.
;
+ } else {
+ return (
+
+ {events.map((entry) => (
+ }
+ elseShow={() => }
+ />
+ ))}
+
+ );
+ }
+ };
+
+ return (
+
+ {showDataSwitch}
+ {!isSmallScreen && searchInputField}
+ >
+ }
+ >
+ {isSmallScreen && searchInputField}
+
+ }
+ >
+
+
+ {resultComponent()}
+
+
+ );
+};
+
+export const LegacyEventLog = ({ title, project, feature }: IEventLogProps) => {
const [query, setQuery] = useState('');
const { events, totalEvents, fetchNextPage } = useLegacyEventSearch(
project,
@@ -51,8 +143,6 @@ export const EventLog = ({ title, project, feature }: IEventLogProps) => {
const fetchNextPageRef = useOnVisible(fetchNextPage);
const { eventSettings, setEventSettings } = useEventSettings();
const isSmallScreen = useMediaQuery(theme.breakpoints.down('md'));
- const { isEnterprise } = useUiConfig();
- const showFilters = useUiFlag('newEventSearch') && isEnterprise();
// Cache the previous search results so that we can show those while
// fetching new results for a new search query in the background.
@@ -82,33 +172,8 @@ export const EventLog = ({ title, project, feature }: IEventLogProps) => {
const totalCount = totalEvents || 0;
const countText = `${count} of ${totalCount}`;
- const EventResults = (
- <>
- No events found.
}
- />
- 0)}
- show={
-
- {cache?.map((entry) => (
- }
- elseShow={() => }
- />
- ))}
-
- }
- />
- >
- );
-
return (
{
}
>
No events found.}
+ />
+ 0)}
show={
-
-
- {EventResults}
-
+
+ {cache?.map((entry) => (
+ }
+ elseShow={() => }
+ />
+ ))}
+
}
- elseShow={EventResults}
/>
-
);
};
+
+export const EventLog = (props: IEventLogProps) => {
+ const { isEnterprise } = useUiConfig();
+ const showFilters = useUiFlag('newEventSearch') && isEnterprise();
+ if (showFilters) {
+ return ;
+ } else {
+ return ;
+ }
+};
diff --git a/frontend/src/component/events/EventLog/EventLogFilters.tsx b/frontend/src/component/events/EventLog/EventLogFilters.tsx
index b3a27bc4d72e..80437afb3145 100644
--- a/frontend/src/component/events/EventLog/EventLogFilters.tsx
+++ b/frontend/src/component/events/EventLog/EventLogFilters.tsx
@@ -1,5 +1,9 @@
import { useState, useEffect, type FC } from 'react';
-import { Filters, type IFilterItem } from 'component/filter/Filters/Filters';
+import {
+ type FilterItemParamHolder,
+ Filters,
+ type IFilterItem,
+} from 'component/filter/Filters/Filters';
import useProjects from 'hooks/api/getters/useProjects/useProjects';
import { useFeatureSearch } from 'hooks/api/getters/useFeatureSearch/useFeatureSearch';
import { EventSchemaType } from 'openapi';
@@ -30,14 +34,13 @@ const sharedFilters: IFilterItem[] = [
pluralOperators: ['IS_ANY_OF'],
},
{
- // todo fill this in with actual values
label: 'Event type',
icon: 'announcement',
options: Object.entries(EventSchemaType).map(([key, value]) => ({
label: key,
value: value,
})),
- filterKey: 'eventType',
+ filterKey: 'type',
singularOperators: ['IS'],
pluralOperators: ['IS_ANY_OF'],
},
@@ -46,11 +49,15 @@ const sharedFilters: IFilterItem[] = [
type EventLogFiltersProps = {
logType: 'flag' | 'project' | 'global';
className?: string;
+ state: FilterItemParamHolder;
+ onChange: (value: FilterItemParamHolder) => void;
};
-export const EventLogFilters: FC = (
- { logType, className },
- // {state, onChange,} // these are to fill in later to make the filters work
-) => {
+export const EventLogFilters: FC = ({
+ logType,
+ className,
+ state,
+ onChange,
+}) => {
const { projects } = useProjects();
const { features } = useFeatureSearch({});
@@ -90,7 +97,7 @@ export const EventLogFilters: FC = (
label: 'Feature Flag',
icon: 'flag',
options: flagOptions,
- filterKey: 'flag',
+ filterKey: 'feature',
singularOperators: ['IS'],
pluralOperators: ['IS_ANY_OF'],
},
@@ -105,8 +112,8 @@ export const EventLogFilters: FC = (
console.log(v)}
+ state={state}
+ onChange={onChange}
/>
);
};