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,41 +95,40 @@ 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-box w-80">
|
||||||
<div class="modal">
|
<DragDropProvider
|
||||||
<div class="modal-box w-80">
|
onDragStart={onDragStart}
|
||||||
<DragDropProvider
|
onDragEnd={onDragEnd as DragEventHandler}
|
||||||
onDragStart={onDragStart}
|
collisionDetector={closestCenter}
|
||||||
onDragEnd={onDragEnd as DragEventHandler}
|
>
|
||||||
collisionDetector={closestCenter}
|
<DragDropSensors />
|
||||||
>
|
<div class="column self-stretch">
|
||||||
<DragDropSensors />
|
<SortableProvider ids={props.order}>
|
||||||
<div class="column self-stretch">
|
<For each={props.order}>{(key) => <FormRow key={key} />}</For>
|
||||||
<SortableProvider ids={props.order}>
|
</SortableProvider>
|
||||||
<For each={props.order}>{(key) => <FormRow key={key} />}</For>
|
</div>
|
||||||
</SortableProvider>
|
<DragOverlay>
|
||||||
</div>
|
<Show when={activeKey()}>
|
||||||
<DragOverlay>
|
<div class="sortable">{t(activeKey()!)}</div>
|
||||||
<Show when={activeKey()}>
|
</Show>
|
||||||
<div class="sortable">{t(activeKey()!)}</div>
|
</DragOverlay>
|
||||||
</Show>
|
</DragDropProvider>
|
||||||
</DragOverlay>
|
|
||||||
</DragDropProvider>
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
class="btn-neutral btn-sm ml-auto mt-4 block"
|
class="btn-neutral btn-sm ml-auto mt-4 block"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
props.onOrderChange(CONNECTIONS_TABLE_INITIAL_COLUMN_ORDER)
|
props.onOrderChange(CONNECTIONS_TABLE_INITIAL_COLUMN_ORDER)
|
||||||
props.onVisibleChange(CONNECTIONS_TABLE_INITIAL_COLUMN_VISIBILITY)
|
props.onVisibleChange(CONNECTIONS_TABLE_INITIAL_COLUMN_VISIBILITY)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t('reset')}
|
{t('reset')}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
|
||||||
|
|
||||||
<label class="modal-backdrop" for="connection-modal" />
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
|
||||||
|
<form method="dialog" class="modal-backdrop">
|
||||||
|
<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) => {
|
<IconSettings />
|
||||||
setColumnOrder([...data])
|
</Button>
|
||||||
}}
|
</div>
|
||||||
onVisibleChange={(data: ColumnVisibility) =>
|
|
||||||
setColumnVisibility({ ...data })
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</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