Topic消息查询支持Timestamp排序,接口支持按指定日期查询

This commit is contained in:
superspeedone
2022-09-09 15:45:31 +08:00
parent 8e50d145d5
commit 0e49002f42
6 changed files with 50 additions and 21 deletions

View File

@@ -32,8 +32,8 @@ const TopicMessages = (props: any) => {
// 获取消息开始位置
const offsetResetList = [
{ 'label': 'latest', value: '0' },
{ 'label': 'earliest', value: '1' }
{ 'label': 'latest', value: 0 },
{ 'label': 'earliest', value: 1 }
];
// 默认排序
@@ -42,6 +42,8 @@ const TopicMessages = (props: any) => {
sortType: 'desc',
};
const [sorter, setSorter] = useState<any>(defaultSorter);
// 请求接口获取数据
const genData = async () => {
if (urlParams?.clusterId === undefined || hashData?.topicName === undefined) return;
@@ -56,7 +58,7 @@ const TopicMessages = (props: any) => {
});
setPartitionIdList(newPartitionIdList || []);
});
request(Api.getTopicMessagesList(hashData?.topicName, urlParams?.clusterId), { data: { ...params, ...defaultSorter }, method: 'POST' })
request(Api.getTopicMessagesList(hashData?.topicName, urlParams?.clusterId), { data: { ...params, ...sorter }, method: 'POST' })
.then((res: any) => {
// setPagination({
// current: res.pagination?.pageNo,
@@ -94,11 +96,16 @@ const TopicMessages = (props: any) => {
history.push(`/cluster/${urlParams?.clusterId}/testing/consumer`);
};
const onTableChange = (pagination: any, filters: any, sorter: any) => {
defaultSorter.sortField = sorter.field || '';
defaultSorter.sortType = sorter.order ? sorter.order.substring(0, sorter.order.indexOf('end')) : '';
const onTableChange = (pagination: any, filters: any, sorter: any, extra: any) => {
setPagination(pagination);
genData();
// 只有排序事件时,触发重新请求后端数据
if(extra.action === 'sort') {
setSorter({
sortField: sorter.field || '',
sortType: sorter.order ? sorter.order.substring(0, sorter.order.indexOf('end')) : ''
});
genData();
}
// const asc = sorter?.order && sorter?.order === 'ascend' ? true : false;
// const sortColumn = sorter.field && toLine(sorter.field);
// genData({ pageNo: pagination.current, pageSize: pagination.pageSize, filters, asc, sortColumn, queryTerm: searchResult, ...allParams });
@@ -106,7 +113,7 @@ const TopicMessages = (props: any) => {
useEffect(() => {
props.positionType === 'Messages' && genData();
}, [props, params]);
}, [props, params, sorter]);
return (
<>

View File

@@ -85,7 +85,8 @@ export const getTopicMessagesColmns = () => {
title: 'Timestamp',
dataIndex: 'timestampUnitMs',
key: 'timestampUnitMs',
render: (t: number) => (t ? moment(t).format(timeFormat) : '-'),
sorter: true,
render: (t: number) => (t ? moment(t).format(timeFormat) + '.' + moment(t).millisecond() : '-'),
},
{
title: 'Key',