-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathsession.tsx
More file actions
144 lines (137 loc) · 4.56 KB
/
session.tsx
File metadata and controls
144 lines (137 loc) · 4.56 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import {
Button,
Divider,
HTMLTable,
Pre,
Tab,
Tabs,
Tag
} from "@blueprintjs/core";
import { type FC, useEffect, useState } from "react";
import { useSelector } from "react-redux";
import { appSlice } from "../reducers/app";
import { sessionSlice } from "../reducers/session";
import { Xterm } from "./xterm";
export const Session: FC = () => {
const [activeId, setActiveId] = useState("");
const appStore = useSelector(appSlice.selectSlice);
const sessionStore = useSelector(sessionSlice.selectSlice);
useEffect(() => {
const sessionIds = Object.keys(sessionStore);
// Ensure there always be one tab active
if (!sessionIds.includes(activeId) && sessionIds[0]) {
setActiveId(sessionIds[0]);
}
}, [activeId, sessionStore]);
console.log(666644, appStore, sessionStore);
return (
<Tabs
selectedTabId={activeId}
onChange={(key) => {
setActiveId(key as string);
}}
>
{Object.entries(sessionStore).map(([id, session]) => {
const appInfo = appStore[session.appId];
return (
<Tab
style={{ overflowY: "auto" }}
id={id}
key={id}
title={appInfo?.name}
panel={
<div
style={{
display: "flex",
marginTop: -20,
overflow: "auto",
maxHeight: "calc(100vh - 100px)" // TODO:
}}
>
<div style={{ marginTop: 5, overflow: "auto", flexShrink: 0 }}>
<HTMLTable compact interactive>
<thead>
<tr>
<th>Type</th>
<th style={{ minWidth: 160, maxWidth: 160 }}>Title</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{Object.entries(session.page).map(([id, page]) => (
<tr key={id}>
<td>
<Tag
intent={
page.type === "node"
? "success"
: page.type === "page"
? "primary"
: "none"
}
>
{page.type}
</Tag>
</td>
<td
style={{
minWidth: 160,
maxWidth: 160,
wordWrap: "break-word"
}}
>
{page.title}
</td>
<td>
<Button
small
rightIcon="share"
onClick={() => {
const url = page.devtoolsFrontendUrl
.replace(
/^\/devtools/,
"devtools://devtools/bundled"
)
.replace(
/^chrome-devtools:\/\//,
"devtools://"
);
require("electron").ipcRenderer.send(
"open-window",
url
);
}}
>
Inspect
</Button>
</td>
</tr>
))}
</tbody>
</HTMLTable>
</div>
<Divider />
<div
style={{
marginTop: 5,
flexGrow: 1,
overflow: "auto"
}}
>
<Xterm
content={session.log}
options={{
fontFamily:
"SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace",
convertEol: true
}}
/>
</div>
</div>
}
/>
);
})}
</Tabs>
);
};