GitStart 64d4532a6b
feat: sort logs in ascending order (#2895)
* feat: sort logs in ascending order

Co-authored-by: gitstart <gitstart@gitstart.com>
Co-authored-by: Rubens Rafael <70234898+RubensRafael@users.noreply.github.com>
Co-authored-by: RubensRafael <rubensrafael2@live.com>

* refactor: requested changes

Co-authored-by: Nitesh Singh <nitesh.singh@gitstart.dev>
Co-authored-by: niteshsingh1357 <niteshsingh1357@gmail.com>
Co-authored-by: RubensRafael <rubensrafael2@live.com>

* fix: lint

Co-authored-by: niteshsingh1357 <niteshsingh1357@gmail.com>
Co-authored-by: Nitesh Singh <nitesh.singh@gitstart.dev>
Co-authored-by: RubensRafael <rubensrafael2@live.com>

* chore: removed the magic string

---------

Co-authored-by: gitstart <gitstart@users.noreply.github.com>
Co-authored-by: gitstart <gitstart@gitstart.com>
Co-authored-by: Nitesh Singh <nitesh.singh@gitstart.dev>
Co-authored-by: Rubens Rafael <70234898+RubensRafael@users.noreply.github.com>
Co-authored-by: Palash Gupta <palashgdev@gmail.com>
Co-authored-by: RubensRafael <rubensrafael2@live.com>
Co-authored-by: Vishal Sharma <makeavish786@gmail.com>
Co-authored-by: niteshsingh1357 <niteshsingh1357@gmail.com>
2023-06-29 14:11:49 +05:30

158 lines
3.9 KiB
TypeScript

import { Button, Col, Divider, Popover, Row, Select, Space } from 'antd';
import { QueryParams } from 'constants/query';
import LogControls from 'container/LogControls';
import LogDetailedView from 'container/LogDetailedView';
import LogLiveTail from 'container/LogLiveTail';
import LogsAggregate from 'container/LogsAggregate';
import LogsFilters from 'container/LogsFilters';
import LogsSearchFilter from 'container/LogsSearchFilter';
import LogsTable from 'container/LogsTable';
import history from 'lib/history';
import { useCallback, useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useLocation } from 'react-router-dom';
import { Dispatch } from 'redux';
import { AppState } from 'store/reducers';
import AppActions from 'types/actions';
import { SET_DETAILED_LOG_DATA, SET_LOGS_ORDER } from 'types/actions/logs';
import { ILog } from 'types/api/logs/log';
import { ILogsReducer } from 'types/reducer/logs';
import {
defaultSelectStyle,
logsOptions,
orderItems,
OrderPreferenceItems,
} from './config';
import { useSelectedLogView } from './hooks';
import PopoverContent from './PopoverContent';
import SpaceContainer from './styles';
function Logs(): JSX.Element {
const dispatch = useDispatch<Dispatch<AppActions>>();
const { order } = useSelector<AppState, ILogsReducer>((store) => store.logs);
const location = useLocation();
const showExpandedLog = useCallback(
(logData: ILog) => {
dispatch({
type: SET_DETAILED_LOG_DATA,
payload: logData,
});
},
[dispatch],
);
const {
viewModeOptionList,
viewModeOption,
viewMode,
handleViewModeOptionChange,
linesPerRow,
handleLinesPerRowChange,
} = useSelectedLogView();
const renderPopoverContent = useCallback(
() => (
<PopoverContent
linesPerRow={linesPerRow}
handleLinesPerRowChange={handleLinesPerRowChange}
/>
),
[linesPerRow, handleLinesPerRowChange],
);
const isFormatButtonVisible = useMemo(() => logsOptions.includes(viewMode), [
viewMode,
]);
const selectedViewModeOption = useMemo(() => viewModeOption.value.toString(), [
viewModeOption.value,
]);
const onChangeVeiwMode = useCallback(
(key: string) => {
handleViewModeOptionChange({
key,
});
},
[handleViewModeOptionChange],
);
const handleChangeOrder = (value: OrderPreferenceItems): void => {
dispatch({
type: SET_LOGS_ORDER,
payload: value,
});
const params = new URLSearchParams(location.search);
params.set(QueryParams.order, value);
history.push({ search: params.toString() });
};
return (
<>
<SpaceContainer
split={<Divider type="vertical" />}
align="center"
direction="horizontal"
>
<LogsSearchFilter />
<LogLiveTail />
</SpaceContainer>
<LogsAggregate />
<Row gutter={20} wrap={false}>
<LogsFilters />
<Col flex={1}>
<Row>
<Col flex={1}>
<Space align="baseline" direction="horizontal">
<Select
style={defaultSelectStyle}
value={selectedViewModeOption}
onChange={onChangeVeiwMode}
>
{viewModeOptionList.map((option) => (
<Select.Option key={option.value}>{option.label}</Select.Option>
))}
</Select>
{isFormatButtonVisible && (
<Popover placement="right" content={renderPopoverContent}>
<Button>Format</Button>
</Popover>
)}
<Select
style={defaultSelectStyle}
defaultValue={order}
onChange={handleChangeOrder}
>
{orderItems.map((item) => (
<Select.Option key={item.enum}>{item.name}</Select.Option>
))}
</Select>
</Space>
</Col>
<Col>
<LogControls />
</Col>
</Row>
<LogsTable
viewMode={viewMode}
linesPerRow={linesPerRow}
onClickExpand={showExpandedLog}
/>
</Col>
</Row>
<LogDetailedView />
</>
);
}
export default Logs;