mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-10 05:15:35 +08:00
feat(connections): show connection detail on click of a button
This commit is contained in:
parent
4341a4b8ee
commit
daf168208e
@ -95,9 +95,7 @@ export const ConnectionsTableOrderingModal = (props: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<dialog id="connections-table-ordering-modal" class="modal">
|
||||||
<input type="checkbox" id="connection-modal" class="modal-toggle" />
|
|
||||||
<div class="modal">
|
|
||||||
<div class="modal-box w-80">
|
<div class="modal-box w-80">
|
||||||
<DragDropProvider
|
<DragDropProvider
|
||||||
onDragStart={onDragStart}
|
onDragStart={onDragStart}
|
||||||
@ -128,8 +126,9 @@ export const ConnectionsTableOrderingModal = (props: {
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<label class="modal-backdrop" for="connection-modal" />
|
<form method="dialog" class="modal-backdrop">
|
||||||
</div>
|
<button />
|
||||||
</>
|
</form>
|
||||||
|
</dialog>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -110,6 +110,7 @@ export enum LANG {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum CONNECTIONS_TABLE_ACCESSOR_KEY {
|
export enum CONNECTIONS_TABLE_ACCESSOR_KEY {
|
||||||
|
Details = 'details',
|
||||||
Close = 'close',
|
Close = 'close',
|
||||||
ID = 'ID',
|
ID = 'ID',
|
||||||
Type = 'type',
|
Type = 'type',
|
||||||
|
@ -74,4 +74,5 @@ export default {
|
|||||||
all: 'All',
|
all: 'All',
|
||||||
sequence: 'Sequence',
|
sequence: 'Sequence',
|
||||||
payload: 'Payload',
|
payload: 'Payload',
|
||||||
|
details: 'Details',
|
||||||
}
|
}
|
||||||
|
@ -73,4 +73,5 @@ export default {
|
|||||||
all: '全部',
|
all: '全部',
|
||||||
sequence: '序列号',
|
sequence: '序列号',
|
||||||
payload: '内容',
|
payload: '内容',
|
||||||
|
details: '详情',
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import { useI18n } from '@solid-primitives/i18n'
|
|||||||
import { makePersisted } from '@solid-primitives/storage'
|
import { makePersisted } from '@solid-primitives/storage'
|
||||||
import {
|
import {
|
||||||
IconCircleX,
|
IconCircleX,
|
||||||
|
IconInfoCircle,
|
||||||
IconPlayerPause,
|
IconPlayerPause,
|
||||||
IconPlayerPlay,
|
IconPlayerPlay,
|
||||||
IconSettings,
|
IconSettings,
|
||||||
@ -25,7 +26,7 @@ import {
|
|||||||
} from '@tanstack/solid-table'
|
} from '@tanstack/solid-table'
|
||||||
import byteSize from 'byte-size'
|
import byteSize from 'byte-size'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { For, createMemo, createSignal } from 'solid-js'
|
import { Component, For, Show, createMemo, createSignal } from 'solid-js'
|
||||||
import { twMerge } from 'tailwind-merge'
|
import { twMerge } from 'tailwind-merge'
|
||||||
import { Button, ConnectionsTableOrderingModal } from '~/components'
|
import { Button, ConnectionsTableOrderingModal } from '~/components'
|
||||||
import {
|
import {
|
||||||
@ -35,6 +36,7 @@ import {
|
|||||||
} from '~/constants'
|
} from '~/constants'
|
||||||
import { formatTimeFromNow } from '~/helpers'
|
import { formatTimeFromNow } from '~/helpers'
|
||||||
import {
|
import {
|
||||||
|
allConnections,
|
||||||
tableSize,
|
tableSize,
|
||||||
tableSizeClassName,
|
tableSizeClassName,
|
||||||
useConnections,
|
useConnections,
|
||||||
@ -50,6 +52,34 @@ enum ActiveTab {
|
|||||||
closedConnections = 'closedConnections',
|
closedConnections = 'closedConnections',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ConnectionDetailsModal: Component<{
|
||||||
|
selectedConnectionID?: string
|
||||||
|
}> = (props) => {
|
||||||
|
return (
|
||||||
|
<dialog id="connections-table-details-modal" class="modal">
|
||||||
|
<div class="modal-box">
|
||||||
|
<Show when={props.selectedConnectionID}>
|
||||||
|
<pre>
|
||||||
|
<code>
|
||||||
|
{JSON.stringify(
|
||||||
|
allConnections.find(
|
||||||
|
({ id }) => id === props.selectedConnectionID,
|
||||||
|
),
|
||||||
|
null,
|
||||||
|
2,
|
||||||
|
)}
|
||||||
|
</code>
|
||||||
|
</pre>
|
||||||
|
</Show>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form method="dialog" class="modal-backdrop">
|
||||||
|
<button />
|
||||||
|
</form>
|
||||||
|
</dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const [t] = useI18n()
|
const [t] = useI18n()
|
||||||
const request = useRequest()
|
const request = useRequest()
|
||||||
@ -75,7 +105,33 @@ export default () => {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const [selectedConnectionID, setSelectedConnectionID] = createSignal<string>()
|
||||||
|
|
||||||
const columns = createMemo<ColumnDef<Connection>[]>(() => [
|
const columns = createMemo<ColumnDef<Connection>[]>(() => [
|
||||||
|
{
|
||||||
|
header: () => t('details'),
|
||||||
|
enableGrouping: false,
|
||||||
|
enableSorting: false,
|
||||||
|
accessorKey: CONNECTIONS_TABLE_ACCESSOR_KEY.Details,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div class="flex h-4 items-center">
|
||||||
|
<Button
|
||||||
|
class="btn-circle btn-xs"
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedConnectionID(row.original.id)
|
||||||
|
|
||||||
|
const modal = document.querySelector(
|
||||||
|
'#connections-table-details-modal',
|
||||||
|
) as HTMLDialogElement | null
|
||||||
|
|
||||||
|
modal?.showModal()
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IconInfoCircle size="16" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
header: () => t('close'),
|
header: () => t('close'),
|
||||||
enableGrouping: false,
|
enableGrouping: false,
|
||||||
@ -293,21 +349,19 @@ export default () => {
|
|||||||
<IconCircleX />
|
<IconCircleX />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<label for="connection-modal" class="btn btn-circle btn-sm sm:btn-md">
|
<Button
|
||||||
<IconSettings />
|
class="btn btn-circle btn-sm sm:btn-md"
|
||||||
</label>
|
onClick={() => {
|
||||||
</div>
|
const modal = document.querySelector(
|
||||||
|
'#connections-table-ordering-modal',
|
||||||
|
) as HTMLDialogElement | null
|
||||||
|
|
||||||
<ConnectionsTableOrderingModal
|
modal?.showModal()
|
||||||
order={columnOrder()}
|
|
||||||
visible={columnVisibility()}
|
|
||||||
onOrderChange={(data: ColumnOrder) => {
|
|
||||||
setColumnOrder([...data])
|
|
||||||
}}
|
}}
|
||||||
onVisibleChange={(data: ColumnVisibility) =>
|
>
|
||||||
setColumnVisibility({ ...data })
|
<IconSettings />
|
||||||
}
|
</Button>
|
||||||
/>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="overflow-x-auto whitespace-nowrap rounded-md bg-base-300">
|
<div class="overflow-x-auto whitespace-nowrap rounded-md bg-base-300">
|
||||||
@ -427,6 +481,17 @@ export default () => {
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<ConnectionsTableOrderingModal
|
||||||
|
order={columnOrder()}
|
||||||
|
visible={columnVisibility()}
|
||||||
|
onOrderChange={(data: ColumnOrder) => setColumnOrder(data)}
|
||||||
|
onVisibleChange={(data: ColumnVisibility) =>
|
||||||
|
setColumnVisibility({ ...data })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ConnectionDetailsModal selectedConnectionID={selectedConnectionID()} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ export type WsMsg = {
|
|||||||
// we make connections global, so we can keep track of connections when user in proxy page
|
// we make connections global, so we can keep track of connections when user in proxy page
|
||||||
// when user selects proxy and close some connections they can back and check connections
|
// when user selects proxy and close some connections they can back and check connections
|
||||||
// they closed
|
// they closed
|
||||||
let allConnections: Connection[] = []
|
export let allConnections: Connection[] = []
|
||||||
|
|
||||||
export const setAllConnections = (allConns: Connection[]) => {
|
export const setAllConnections = (allConns: Connection[]) => {
|
||||||
allConnections = allConns
|
allConnections = allConns
|
||||||
|
Loading…
Reference in New Issue
Block a user