mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-10-13 07:11:30 +08:00

* feat: add list and table views for logs * chore: some of the changes are updated * chore: some of the refactoring is done * chore: px to updated to rem * chore: constant is moved to local storage * refactor: some of the refactoring is updated * chore: some of the changes are updated * fix: resize log table issue * chore: logs is updated * chore: resize header is updated * chore: font observer is added in package json and hook is added for same * chore: no logs text is updated * chore: no logs text is updated * chore: updated some feedback in raw logs line * chore: types is added --------- Co-authored-by: Palash Gupta <palashgdev@gmail.com> Co-authored-by: Pranay Prateek <pranay@signoz.io> Co-authored-by: Vishal Sharma <makeavish786@gmail.com> Co-authored-by: Chintan Sudani <csudani7@gmail.com>
143 lines
3.2 KiB
TypeScript
143 lines
3.2 KiB
TypeScript
import {
|
|
FastBackwardOutlined,
|
|
LeftOutlined,
|
|
RightOutlined,
|
|
} from '@ant-design/icons';
|
|
import { Button, Divider, Select } from 'antd';
|
|
import { getGlobalTime } from 'container/LogsSearchFilter/utils';
|
|
import { getMinMax } from 'container/TopNav/AutoRefresh/config';
|
|
import { defaultSelectStyle } from 'pages/Logs/config';
|
|
import React, { memo, useMemo } from 'react';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import { Dispatch } from 'redux';
|
|
import { AppState } from 'store/reducers';
|
|
import AppActions from 'types/actions';
|
|
import {
|
|
GET_NEXT_LOG_LINES,
|
|
GET_PREVIOUS_LOG_LINES,
|
|
RESET_ID_START_AND_END,
|
|
SET_LOG_LINES_PER_PAGE,
|
|
} from 'types/actions/logs';
|
|
import { GlobalReducer } from 'types/reducer/globalTime';
|
|
import { ILogsReducer } from 'types/reducer/logs';
|
|
|
|
import { ITEMS_PER_PAGE_OPTIONS } from './config';
|
|
import { Container } from './styles';
|
|
|
|
function LogControls(): JSX.Element | null {
|
|
const {
|
|
logLinesPerPage,
|
|
liveTail,
|
|
isLoading: isLogsLoading,
|
|
isLoadingAggregate,
|
|
logs,
|
|
} = useSelector<AppState, ILogsReducer>((state) => state.logs);
|
|
const globalTime = useSelector<AppState, GlobalReducer>(
|
|
(state) => state.globalTime,
|
|
);
|
|
|
|
const dispatch = useDispatch<Dispatch<AppActions>>();
|
|
|
|
const handleLogLinesPerPageChange = (e: number): void => {
|
|
dispatch({
|
|
type: SET_LOG_LINES_PER_PAGE,
|
|
payload: {
|
|
logsLinesPerPage: e,
|
|
},
|
|
});
|
|
};
|
|
|
|
const handleGoToLatest = (): void => {
|
|
const { maxTime, minTime } = getMinMax(
|
|
globalTime.selectedTime,
|
|
globalTime.minTime,
|
|
globalTime.maxTime,
|
|
);
|
|
|
|
const updatedGlobalTime = getGlobalTime(globalTime.selectedTime, {
|
|
maxTime,
|
|
minTime,
|
|
});
|
|
|
|
if (updatedGlobalTime) {
|
|
dispatch({
|
|
type: RESET_ID_START_AND_END,
|
|
payload: updatedGlobalTime,
|
|
});
|
|
}
|
|
};
|
|
|
|
const handleNavigatePrevious = (): void => {
|
|
dispatch({
|
|
type: GET_PREVIOUS_LOG_LINES,
|
|
});
|
|
};
|
|
const handleNavigateNext = (): void => {
|
|
dispatch({
|
|
type: GET_NEXT_LOG_LINES,
|
|
});
|
|
};
|
|
|
|
const isLoading = isLogsLoading || isLoadingAggregate;
|
|
|
|
const isNextAndPreviousDisabled = useMemo(
|
|
() =>
|
|
isLoading ||
|
|
logLinesPerPage === 0 ||
|
|
logs.length === 0 ||
|
|
logs.length < logLinesPerPage,
|
|
[isLoading, logLinesPerPage, logs.length],
|
|
);
|
|
|
|
if (liveTail !== 'STOPPED') {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<Container>
|
|
<Button
|
|
loading={isLoading}
|
|
size="small"
|
|
type="link"
|
|
onClick={handleGoToLatest}
|
|
>
|
|
<FastBackwardOutlined /> Go to latest
|
|
</Button>
|
|
<Divider type="vertical" />
|
|
<Button
|
|
loading={isLoading}
|
|
size="small"
|
|
type="link"
|
|
disabled={isNextAndPreviousDisabled}
|
|
onClick={handleNavigatePrevious}
|
|
>
|
|
<LeftOutlined /> Previous
|
|
</Button>
|
|
<Button
|
|
loading={isLoading}
|
|
size="small"
|
|
type="link"
|
|
disabled={isNextAndPreviousDisabled}
|
|
onClick={handleNavigateNext}
|
|
>
|
|
Next <RightOutlined />
|
|
</Button>
|
|
<Select
|
|
style={defaultSelectStyle}
|
|
loading={isLoading}
|
|
value={logLinesPerPage}
|
|
onChange={handleLogLinesPerPageChange}
|
|
>
|
|
{ITEMS_PER_PAGE_OPTIONS.map((count) => (
|
|
<Select.Option
|
|
key={count}
|
|
value={count}
|
|
>{`${count} / page`}</Select.Option>
|
|
))}
|
|
</Select>
|
|
</Container>
|
|
);
|
|
}
|
|
|
|
export default memo(LogControls);
|