import { Switch, FormControlLabel, useMediaQuery } from '@mui/material'; import EventJson from 'component/events/EventJson/EventJson'; import { PageContent } from 'component/common/PageContent/PageContent'; import { PageHeader } from 'component/common/PageHeader/PageHeader'; import EventCard from 'component/events/EventCard/EventCard'; import { useEventSettings } from 'hooks/useEventSettings'; import { useState, useEffect } from 'react'; import { Search } from 'component/common/Search/Search'; import theme from 'themes/theme'; import { useLegacyEventSearch } from 'hooks/api/getters/useEventSearch/useLegacyEventSearch'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; import { useOnVisible } from 'hooks/useOnVisible'; 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'; import { useEventLogSearch } from './useEventLogSearch'; import { StickyPaginationBar } from 'component/common/Table/StickyPaginationBar/StickyPaginationBar'; interface IEventLogProps { title: string; project?: string; feature?: string; } const StyledEventsList = styled('ul')(({ theme }) => ({ listStyleType: 'none', margin: 0, padding: 0, display: 'grid', gap: theme.spacing(2), })); const StyledFilters = styled(EventLogFilters)({ padding: 0, }); const EventResultWrapper = styled('div')(({ theme }) => ({ padding: theme.spacing(2, 4, 4, 4), display: 'flex', flexFlow: 'column', gap: theme.spacing(1), })); const NewEventLog = ({ title, project, feature }: IEventLogProps) => { const { events, total, loading, tableState, setTableState, filterState, pagination, } = 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()} 25} show={ } /> ); }; export const LegacyEventLog = ({ title, project, feature }: IEventLogProps) => { const [query, setQuery] = useState(''); const { events, totalEvents, fetchNextPage } = useLegacyEventSearch( project, feature, query, ); const fetchNextPageRef = useOnVisible(fetchNextPage); const { eventSettings, setEventSettings } = useEventSettings(); const isSmallScreen = useMediaQuery(theme.breakpoints.down('md')); // 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(); useEffect(() => events && setCache(events), [events]); const onShowData = () => { setEventSettings((prev) => ({ showData: !prev.showData })); }; const searchInputField = ; const showDataSwitch = ( } /> ); const count = events?.length || 0; const totalCount = totalEvents || 0; const countText = `${count} of ${totalCount}`; return ( {showDataSwitch} {!isSmallScreen && searchInputField} } > {isSmallScreen && searchInputField} } > No events found.

} /> 0)} show={ {cache?.map((entry) => ( } elseShow={() => } /> ))} } />
); }; export const EventLog = (props: IEventLogProps) => { const { isEnterprise } = useUiConfig(); const showFilters = useUiFlag('newEventSearch') && isEnterprise(); if (showFilters) { return ; } else { return ; } };