/* eslint-disable no-nested-ternary */ import { Typography } from 'antd'; import LogItem from 'components/Logs/LogItem'; import Spinner from 'components/Spinner'; import { map } from 'lodash-es'; import React, { memo, useEffect } from 'react'; import { connect, useSelector } from 'react-redux'; import { bindActionCreators, Dispatch } from 'redux'; import { ThunkDispatch } from 'redux-thunk'; import { getLogs } from 'store/actions/logs/getLogs'; import { AppState } from 'store/reducers'; import AppActions from 'types/actions'; import { GlobalReducer } from 'types/reducer/globalTime'; import { ILogsReducer } from 'types/reducer/logs'; import { Container, Heading } from './styles'; function LogsTable({ getLogs }: LogsTableProps): JSX.Element { const { searchFilter: { queryString }, logs, logLinesPerPage, idEnd, idStart, isLoading, liveTail, } = useSelector((state) => state.logs); const { maxTime, minTime } = useSelector( (state) => state.globalTime, ); useEffect(() => { if (liveTail === 'STOPPED') getLogs({ q: queryString, limit: logLinesPerPage, orderBy: 'timestamp', order: 'desc', timestampStart: minTime, timestampEnd: maxTime, ...(idStart ? { idGt: idStart } : {}), ...(idEnd ? { idLt: idEnd } : {}), }); // eslint-disable-next-line react-hooks/exhaustive-deps }, [getLogs, idEnd, idStart, logLinesPerPage, maxTime, minTime, liveTail]); if (isLoading) { return ; } return ( Event {Array.isArray(logs) && logs.length > 0 ? ( map(logs, (log) => ) ) : liveTail === 'PLAYING' ? ( Getting live logs... ) : ( No log lines found )} ); } interface DispatchProps { getLogs: ( props: Parameters[0], ) => (dispatch: Dispatch) => void; } const mapDispatchToProps = ( dispatch: ThunkDispatch, ): DispatchProps => ({ getLogs: bindActionCreators(getLogs, dispatch), }); interface LogsTableProps { getLogs: (props: Parameters[0]) => ReturnType; } export default connect(null, mapDispatchToProps)(memo(LogsTable));