diff --git a/frontend/src/container/Trace/TraceTable/index.tsx b/frontend/src/container/Trace/TraceTable/index.tsx index d66dd37592..aa9fc1cf6b 100644 --- a/frontend/src/container/Trace/TraceTable/index.tsx +++ b/frontend/src/container/Trace/TraceTable/index.tsx @@ -1,6 +1,10 @@ import { TableProps, Tag, Typography } from 'antd'; import Table, { ColumnsType } from 'antd/lib/table'; import ROUTES from 'constants/routes'; +import { + getSpanOrder, + getSpanOrderParam, +} from 'container/Trace/TraceTable/util'; import dayjs from 'dayjs'; import duration from 'dayjs/plugin/duration'; import history from 'lib/history'; @@ -111,16 +115,6 @@ function TraceTable(): JSX.Element { }, ]; - const getSortKey = (key: string): string => { - if (key === 'durationNano') { - return 'duration'; - } - if (key === 'timestamp') { - return 'timestamp'; - } - return ''; - }; - const onChangeHandler: TableProps['onChange'] = ( props, _, @@ -129,8 +123,8 @@ function TraceTable(): JSX.Element { if (!Array.isArray(sort)) { const { order = spansAggregateOrder } = sort; if (props.current && props.pageSize) { - const spanOrder = order === 'ascend' ? 'ascending' : 'descending'; - const orderParam = getSortKey(sort.field as string); + const spanOrder = getSpanOrder(order || ''); + const orderParam = getSpanOrderParam(sort.field as string); dispatch({ type: UPDATE_SPAN_ORDER, diff --git a/frontend/src/container/Trace/TraceTable/util.ts b/frontend/src/container/Trace/TraceTable/util.ts new file mode 100644 index 0000000000..08276636c1 --- /dev/null +++ b/frontend/src/container/Trace/TraceTable/util.ts @@ -0,0 +1,19 @@ +export const getSpanOrderParam = (key: string): string => { + if (key === 'durationNano') { + return 'duration'; + } + if (key === 'timestamp') { + return 'timestamp'; + } + return ''; +}; + +export const getSpanOrder = (order: string): string => { + if (order === 'ascend') { + return 'ascending'; + } + if (order === 'descend') { + return 'descending'; + } + return ''; +};