|
| 1 | +import { useMemo } from 'react'; |
1 | 2 | import { MultipleStatisticProvider } from '../../StatisticProvider'; |
2 | 3 | import { TabPrefab, TabPrefabDataSource } from '../TabPrefab'; |
3 | 4 | import MinecraftMultiColumnStatisticTable from '../../controls/MinecraftMultiColumnStatisticTable'; |
4 | 5 | import { createStatResolver, StatisticType, YAxisType } from '../../StatisticResolver'; |
5 | 6 |
|
| 7 | +function EditorNetworkStatsContent(props: { onRunCommand: (command: string) => void }) { |
| 8 | + const actions = useMemo( |
| 9 | + () => [ |
| 10 | + { label: 'Reset', onClick: () => props.onRunCommand(getPayloadMetricsCommandStr('clear')) }, |
| 11 | + { label: 'Pause', onClick: () => props.onRunCommand(getPayloadMetricsCommandStr('pause')) }, |
| 12 | + { |
| 13 | + label: 'Resume', |
| 14 | + onClick: () => props.onRunCommand(getPayloadMetricsCommandStr('resume')), |
| 15 | + }, |
| 16 | + ], |
| 17 | + [props.onRunCommand], |
| 18 | + ); |
| 19 | + |
| 20 | + return ( |
| 21 | + <div> |
| 22 | + <MinecraftMultiColumnStatisticTable |
| 23 | + title="Editor Network Packet Statistics" |
| 24 | + statisticDataProvider={ |
| 25 | + new MultipleStatisticProvider({ |
| 26 | + statisticParentId: 'editor_network_stats', |
| 27 | + statisticIds: ['consolidated_data'], |
| 28 | + }) |
| 29 | + } |
| 30 | + statisticResolver={createStatResolver({ |
| 31 | + type: StatisticType.Absolute, |
| 32 | + yAxisType: YAxisType.Absolute, |
| 33 | + tickRange: 20 * 15, // About 15 seconds |
| 34 | + })} |
| 35 | + actions={actions} |
| 36 | + keyLabel="Packet Type" |
| 37 | + valueLabels={[ |
| 38 | + 'Sent Count', |
| 39 | + 'Received Count', |
| 40 | + 'Sent Total Size', |
| 41 | + 'Received Total Size', |
| 42 | + 'Min Size', |
| 43 | + 'Max Size', |
| 44 | + ]} |
| 45 | + prettifyNames={false} // Keep original packet name format |
| 46 | + defaultSortColumn="value_0" // Sort by "Sent Count" column by default |
| 47 | + columnWidths={['400px', '80px', '80px', '80px', '80px', '80px', '80px']} // Custom column widths |
| 48 | + /> |
| 49 | + </div> |
| 50 | + ); |
| 51 | +} |
| 52 | + |
| 53 | +function getPayloadMetricsCommandStr(command: 'clear' | 'pause' | 'resume'): string { |
| 54 | + return `/editorservertest payloadmetrics ${command}`; |
| 55 | +} |
| 56 | + |
6 | 57 | const statsTab: TabPrefab = { |
7 | 58 | name: 'Editor Network Stats', |
8 | 59 | dataSource: TabPrefabDataSource.Server, |
9 | | - content: () => { |
10 | | - return ( |
11 | | - <div> |
12 | | - <MinecraftMultiColumnStatisticTable |
13 | | - title="Editor Network Packet Statistics" |
14 | | - statisticDataProvider={ |
15 | | - new MultipleStatisticProvider({ |
16 | | - statisticParentId: 'editor_network_stats', |
17 | | - statisticIds: ['consolidated_data'], |
18 | | - }) |
19 | | - } |
20 | | - statisticResolver={createStatResolver({ |
21 | | - type: StatisticType.Absolute, |
22 | | - yAxisType: YAxisType.Absolute, |
23 | | - tickRange: 20 * 15, // About 15 seconds |
24 | | - })} |
25 | | - keyLabel="Packet Type" |
26 | | - valueLabels={['Sent Count', 'Received Count', 'Min Size', 'Max Size']} |
27 | | - prettifyNames={false} // Keep original packet name format |
28 | | - defaultSortColumn="value_0" // Sort by "Sent Count" column by default |
29 | | - columnWidths={['400px', '80px', '80px', '80px', '80px']} // Custom column widths |
30 | | - /> |
31 | | - </div> |
32 | | - ); |
33 | | - }, |
| 60 | + content: props => <EditorNetworkStatsContent onRunCommand={props.onRunCommand} />, |
34 | 61 | }; |
35 | 62 |
|
36 | 63 | export default statsTab; |
0 commit comments