-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessDebugger.tsx
More file actions
104 lines (94 loc) · 2.48 KB
/
ProcessDebugger.tsx
File metadata and controls
104 lines (94 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { z } from 'zod';
import React from 'react';
import { runRpcQuery, useRpcQuery } from '../hooks/useRpcQuery';
import { useTopic } from '../../toolkit/react/stream';
import { ScrollWindow } from './ScrollWindow';
import toast from 'react-hot-toast';
type ProcessInfo = z.infer<typeof ProcessInfo>;
const ProcessInfo = z.object({});
type Process = z.infer<typeof Process>;
const Process = z.object({
id: z.object({
category: z.string(),
key: z.string(),
}),
command: z.string(),
args: z.array(z.string()),
});
// This is a temporary bit of code to just display what's in the processes DB
// to make writing other features easier
export function ProcessDebugger() {
const { data: processes = [], error } = useRpcQuery({
method: 'ListProcesses',
data: {},
result: z.array(Process),
});
const [currentProcess, setCurrentProcess] = React.useState<Process>();
const { state } = useTopic({
topicId: currentProcess && {
category: `/logs${currentProcess.id.category}`,
key: currentProcess.id.key,
},
resultType: z.string(),
fetchState: () =>
runRpcQuery({
method: 'GetProcessLogs',
data: { processId: currentProcess?.id },
result: z.object({
counter: z.number(),
text: z.string(),
}),
}).then(({ counter, text }) => ({ counter, state: text })),
reducer: (prev, message) => {
return prev + '\n' + message;
},
});
React.useEffect(() => {
if (error) {
toast.error(`${String(error)}`);
}
}, [error]);
return (
<div
className={'full col robin-rounded robin-gap robin-pad'}
style={{ backgroundColor: 'DarkSlateGray', maxHeight: '100%' }}
>
<div>Processes</div>
<ScrollWindow className={'full'} innerClassName={'col robin-gap'}>
{processes?.map((value) => {
const key = `${value.id.category} ${value.id.key}`;
return (
<div
key={key}
className={'robin-rounded robin-pad'}
style={{ backgroundColor: 'Coral', width: '100%' }}
>
{key}
<button onClick={() => setCurrentProcess(value)}>Select</button>
<pre
style={{
width: '100%',
whiteSpace: 'pre-wrap',
wordWrap: 'break-word',
}}
>
{JSON.stringify(value, null, 2)}
</pre>
</div>
);
})}
</ScrollWindow>
<ScrollWindow className={'full'} innerClassName={'col robin-gap'}>
<pre
style={{
width: '100%',
whiteSpace: 'pre-wrap',
wordWrap: 'break-word',
}}
>
{state}
</pre>
</ScrollWindow>
</div>
);
}