feat: time column in conns

This commit is contained in:
Zephyruso 2023-09-04 18:48:39 +08:00
parent 16cb0debb9
commit 98f6293290
6 changed files with 15 additions and 0 deletions

View File

@ -118,6 +118,7 @@ export enum CONNECTIONS_TABLE_ACCESSOR_KEY {
Chains = 'chains', Chains = 'chains',
DlSpeed = 'dlSpeed', DlSpeed = 'dlSpeed',
ULSpeed = 'ulSpeed', ULSpeed = 'ulSpeed',
ConnectTime = 'connectTime',
Download = 'dl', Download = 'dl',
Upload = 'ul', Upload = 'ul',
Source = 'source', Source = 'source',

View File

@ -25,6 +25,7 @@ export default {
process: 'Process', process: 'Process',
host: 'Host', host: 'Host',
chains: 'Chains', chains: 'Chains',
connectTime: 'Time',
dlSpeed: 'DL Speed', dlSpeed: 'DL Speed',
ulSpeed: 'UL Speed', ulSpeed: 'UL Speed',
dl: 'DL', dl: 'DL',

View File

@ -1,5 +1,6 @@
import { I18nContext, createI18nContext, useI18n } from '@solid-primitives/i18n' import { I18nContext, createI18nContext, useI18n } from '@solid-primitives/i18n'
import { makePersisted } from '@solid-primitives/storage' import { makePersisted } from '@solid-primitives/storage'
import dayjs from 'dayjs'
import { ParentComponent, createEffect, createSignal } from 'solid-js' import { ParentComponent, createEffect, createSignal } from 'solid-js'
import { LANG } from '~/constants' import { LANG } from '~/constants'
import dict from './dict' import dict from './dict'
@ -24,6 +25,7 @@ const I18nUpdator: ParentComponent = (props) => {
createEffect(() => { createEffect(() => {
setLang(locale()) setLang(locale())
dayjs.locale(locale())
}) })
return props.children return props.children

View File

@ -25,6 +25,7 @@ export default {
process: '进程', process: '进程',
host: '主机', host: '主机',
chains: '链路', chains: '链路',
connectTime: '连接时间',
dlSpeed: '下载速度', dlSpeed: '下载速度',
ulSpeed: '上传速度', ulSpeed: '上传速度',
dl: '下载量', dl: '下载量',

View File

@ -3,6 +3,7 @@ import '~/index.css'
import { Router, hashIntegration } from '@solidjs/router' import { Router, hashIntegration } from '@solidjs/router'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'
import relativeTime from 'dayjs/plugin/relativeTime' import relativeTime from 'dayjs/plugin/relativeTime'
import { render } from 'solid-js/web' import { render } from 'solid-js/web'
import { App } from '~/App' import { App } from '~/App'

View File

@ -18,6 +18,7 @@ import {
getSortedRowModel, getSortedRowModel,
} from '@tanstack/solid-table' } from '@tanstack/solid-table'
import byteSize from 'byte-size' import byteSize from 'byte-size'
import dayjs from 'dayjs'
import { isIPv6 } from 'is-ip' import { isIPv6 } from 'is-ip'
import { For, createEffect, createSignal } from 'solid-js' import { For, createEffect, createSignal } from 'solid-js'
import { twMerge } from 'tailwind-merge' import { twMerge } from 'tailwind-merge'
@ -27,6 +28,7 @@ import {
CONNECTIONS_TABLE_INITIAL_COLUMN_ORDER, CONNECTIONS_TABLE_INITIAL_COLUMN_ORDER,
CONNECTIONS_TABLE_INITIAL_COLUMN_VISIBILITY, CONNECTIONS_TABLE_INITIAL_COLUMN_VISIBILITY,
} from '~/constants' } from '~/constants'
import { formatTimeFromNow } from '~/helpers'
import { secret, useRequest, wsEndpointURL } from '~/signals' import { secret, useRequest, wsEndpointURL } from '~/signals'
import type { Connection } from '~/types' import type { Connection } from '~/types'
@ -154,6 +156,13 @@ export default () => {
accessorKey: CONNECTIONS_TABLE_ACCESSOR_KEY.Chains, accessorKey: CONNECTIONS_TABLE_ACCESSOR_KEY.Chains,
accessorFn: (row) => row.chains.slice().reverse().join(' :: '), accessorFn: (row) => row.chains.slice().reverse().join(' :: '),
}, },
{
accessorKey: CONNECTIONS_TABLE_ACCESSOR_KEY.ConnectTime,
accessorFn: (row) => formatTimeFromNow(row.start),
sortingFn: (prev, next) =>
dayjs(prev.original.start).valueOf() -
dayjs(next.original.start).valueOf(),
},
{ {
accessorKey: CONNECTIONS_TABLE_ACCESSOR_KEY.DlSpeed, accessorKey: CONNECTIONS_TABLE_ACCESSOR_KEY.DlSpeed,
accessorFn: (row) => `${byteSize(row.downloadSpeed)}/s`, accessorFn: (row) => `${byteSize(row.downloadSpeed)}/s`,