@@ -15,6 +15,7 @@ import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
15
15
import { useUiFlag } from 'hooks/useUiFlag' ;
16
16
import { EventLogFilters } from './EventLogFilters' ;
17
17
import type { EventSchema } from 'openapi' ;
18
+ import { useEventLogSearch } from './useEventLogSearch' ;
18
19
19
20
interface IEventLogProps {
20
21
title : string ;
@@ -41,7 +42,98 @@ const EventResultWrapper = styled('div')(({ theme }) => ({
41
42
gap : theme . spacing ( 1 ) ,
42
43
} ) ) ;
43
44
44
- export const EventLog = ( { title, project, feature } : IEventLogProps ) => {
45
+ const NewEventLog = ( { title, project, feature } : IEventLogProps ) => {
46
+ const { events, total, loading, tableState, setTableState, filterState } =
47
+ useEventLogSearch (
48
+ project
49
+ ? { type : 'project' , projectId : project }
50
+ : feature
51
+ ? { type : 'flag' , flagName : feature }
52
+ : { type : 'global' } ,
53
+ ) ;
54
+
55
+ const setSearchValue = ( query = '' ) => {
56
+ setTableState ( { query } ) ;
57
+ } ;
58
+ const { eventSettings, setEventSettings } = useEventSettings ( ) ;
59
+ const isSmallScreen = useMediaQuery ( theme . breakpoints . down ( 'md' ) ) ;
60
+
61
+ const onShowData = ( ) => {
62
+ setEventSettings ( ( prev ) => ( { showData : ! prev . showData } ) ) ;
63
+ } ;
64
+
65
+ const searchInputField = (
66
+ < Search
67
+ onChange = { setSearchValue }
68
+ initialValue = { tableState . query || '' }
69
+ debounceTime = { 500 }
70
+ />
71
+ ) ;
72
+
73
+ const showDataSwitch = (
74
+ < FormControlLabel
75
+ label = 'Full events'
76
+ control = {
77
+ < Switch
78
+ checked = { eventSettings . showData }
79
+ onChange = { onShowData }
80
+ color = 'primary'
81
+ />
82
+ }
83
+ />
84
+ ) ;
85
+
86
+ const resultComponent = ( ) => {
87
+ if ( loading ) {
88
+ return < p > Loading...</ p > ;
89
+ } else if ( events . length === 0 ) {
90
+ return < p > No events found.</ p > ;
91
+ } else {
92
+ return (
93
+ < StyledEventsList >
94
+ { events . map ( ( entry ) => (
95
+ < ConditionallyRender
96
+ key = { entry . id }
97
+ condition = { eventSettings . showData }
98
+ show = { ( ) => < EventJson entry = { entry } /> }
99
+ elseShow = { ( ) => < EventCard entry = { entry } /> }
100
+ />
101
+ ) ) }
102
+ </ StyledEventsList >
103
+ ) ;
104
+ }
105
+ } ;
106
+
107
+ return (
108
+ < PageContent
109
+ bodyClass = { 'no-padding' }
110
+ header = {
111
+ < PageHeader
112
+ title = { `${ title } (${ total } )` }
113
+ actions = {
114
+ < >
115
+ { showDataSwitch }
116
+ { ! isSmallScreen && searchInputField }
117
+ </ >
118
+ }
119
+ >
120
+ { isSmallScreen && searchInputField }
121
+ </ PageHeader >
122
+ }
123
+ >
124
+ < EventResultWrapper >
125
+ < StyledFilters
126
+ logType = { project ? 'project' : feature ? 'flag' : 'global' }
127
+ state = { filterState }
128
+ onChange = { setTableState }
129
+ />
130
+ { resultComponent ( ) }
131
+ </ EventResultWrapper >
132
+ </ PageContent >
133
+ ) ;
134
+ } ;
135
+
136
+ export const LegacyEventLog = ( { title, project, feature } : IEventLogProps ) => {
45
137
const [ query , setQuery ] = useState ( '' ) ;
46
138
const { events, totalEvents, fetchNextPage } = useLegacyEventSearch (
47
139
project ,
@@ -51,8 +143,6 @@ export const EventLog = ({ title, project, feature }: IEventLogProps) => {
51
143
const fetchNextPageRef = useOnVisible < HTMLDivElement > ( fetchNextPage ) ;
52
144
const { eventSettings, setEventSettings } = useEventSettings ( ) ;
53
145
const isSmallScreen = useMediaQuery ( theme . breakpoints . down ( 'md' ) ) ;
54
- const { isEnterprise } = useUiConfig ( ) ;
55
- const showFilters = useUiFlag ( 'newEventSearch' ) && isEnterprise ( ) ;
56
146
57
147
// Cache the previous search results so that we can show those while
58
148
// fetching new results for a new search query in the background.
@@ -82,33 +172,8 @@ export const EventLog = ({ title, project, feature }: IEventLogProps) => {
82
172
const totalCount = totalEvents || 0 ;
83
173
const countText = `${ count } of ${ totalCount } ` ;
84
174
85
- const EventResults = (
86
- < >
87
- < ConditionallyRender
88
- condition = { Boolean ( cache && cache . length === 0 ) }
89
- show = { < p > No events found.</ p > }
90
- />
91
- < ConditionallyRender
92
- condition = { Boolean ( cache && cache . length > 0 ) }
93
- show = {
94
- < StyledEventsList >
95
- { cache ?. map ( ( entry ) => (
96
- < ConditionallyRender
97
- key = { entry . id }
98
- condition = { eventSettings . showData }
99
- show = { ( ) => < EventJson entry = { entry } /> }
100
- elseShow = { ( ) => < EventCard entry = { entry } /> }
101
- />
102
- ) ) }
103
- </ StyledEventsList >
104
- }
105
- />
106
- </ >
107
- ) ;
108
-
109
175
return (
110
176
< PageContent
111
- bodyClass = { showFilters ? 'no-padding' : '' }
112
177
header = {
113
178
< PageHeader
114
179
title = { `${ title } (${ countText } )` }
@@ -124,25 +189,35 @@ export const EventLog = ({ title, project, feature }: IEventLogProps) => {
124
189
}
125
190
>
126
191
< ConditionallyRender
127
- condition = { showFilters }
192
+ condition = { Boolean ( cache && cache . length === 0 ) }
193
+ show = { < p > No events found.</ p > }
194
+ />
195
+ < ConditionallyRender
196
+ condition = { Boolean ( cache && cache . length > 0 ) }
128
197
show = {
129
- < EventResultWrapper >
130
- < StyledFilters
131
- logType = {
132
- project
133
- ? 'project'
134
- : feature
135
- ? 'flag'
136
- : 'global'
137
- }
138
- />
139
- { EventResults }
140
- </ EventResultWrapper >
198
+ < StyledEventsList >
199
+ { cache ?. map ( ( entry ) => (
200
+ < ConditionallyRender
201
+ key = { entry . id }
202
+ condition = { eventSettings . showData }
203
+ show = { ( ) => < EventJson entry = { entry } /> }
204
+ elseShow = { ( ) => < EventCard entry = { entry } /> }
205
+ />
206
+ ) ) }
207
+ </ StyledEventsList >
141
208
}
142
- elseShow = { EventResults }
143
209
/>
144
-
145
210
< div ref = { fetchNextPageRef } />
146
211
</ PageContent >
147
212
) ;
148
213
} ;
214
+
215
+ export const EventLog = ( props : IEventLogProps ) => {
216
+ const { isEnterprise } = useUiConfig ( ) ;
217
+ const showFilters = useUiFlag ( 'newEventSearch' ) && isEnterprise ( ) ;
218
+ if ( showFilters ) {
219
+ return < NewEventLog { ...props } /> ;
220
+ } else {
221
+ return < LegacyEventLog { ...props } /> ;
222
+ }
223
+ } ;
0 commit comments