forked from deephaven/web-client-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogPanel.tsx
More file actions
136 lines (112 loc) · 3.44 KB
/
LogPanel.tsx
File metadata and controls
136 lines (112 loc) · 3.44 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
// Wrapper for the Console for use in a golden layout container
// Will probably need to handle window popping out from golden layout here.
import React, { PureComponent } from 'react';
import { connect } from 'react-redux';
import { LogView } from '@deephaven/console';
import type { dh } from '@deephaven/jsapi-types';
import { type DashboardPanelProps } from '@deephaven/dashboard';
import Log from '@deephaven/log';
import { type RootState } from '@deephaven/redux';
import './LogPanel.scss';
import Panel from './CorePanel';
import { getDashboardSessionWrapper } from '../redux';
const log = Log.module('LogPanel');
interface LogPanelProps extends DashboardPanelProps {
session?: dh.IdeSession;
}
interface LogPanelState {
session?: dh.IdeSession;
}
class LogPanel extends PureComponent<LogPanelProps, LogPanelState> {
static defaultProps = {
session: null,
};
static COMPONENT = 'LogPanel';
static TITLE = 'Log';
constructor(props: LogPanelProps) {
super(props);
this.handleResize = this.handleResize.bind(this);
this.handleShow = this.handleShow.bind(this);
this.handleHide = this.handleHide.bind(this);
this.handleSessionOpened = this.handleSessionOpened.bind(this);
this.handleSessionClosed = this.handleSessionClosed.bind(this);
this.isBottomVisible = true;
this.logView = null;
const { session } = this.props;
this.state = { session };
}
isBottomVisible: boolean;
logView: LogView | null;
handleResize(): void {
this.updateDimensions();
}
handleShow(): void {
this.updateDimensions();
if (this.logView) {
this.logView.triggerFindWidget();
if (this.isBottomVisible) {
this.logView.scrollToBottom();
}
}
}
handleHide(): void {
if (this.logView) {
this.isBottomVisible = this.logView.isBottomVisible();
}
}
handleSessionOpened(session: dh.IdeSession): void {
log.debug('Session opened', [session]);
this.setState({ session });
}
// eslint-disable-next-line class-methods-use-this
handleSessionClosed(session: dh.IdeSession): void {
log.debug('Session closed', session);
// Keep the session reference in state unchanged until the session is re-connected
}
updateDimensions(): void {
if (this.logView) {
this.logView.updateDimensions();
}
}
render(): JSX.Element {
const { glContainer, glEventHub } = this.props;
const { session } = this.state;
return (
<Panel
componentPanel={this}
glContainer={glContainer}
glEventHub={glEventHub}
onResize={this.handleResize}
onHide={this.handleHide}
onShow={this.handleShow}
onSessionOpen={this.handleSessionOpened}
onSessionClose={this.handleSessionClosed}
>
{session == null && (
<div className="log-panel-disconnected-message">
Waiting for session connection
</div>
)}
{session != null && (
<LogView
session={session}
ref={logView => {
this.logView = logView;
}}
/>
)}
</Panel>
);
}
}
const mapStateToProps = (
state: RootState,
ownProps: { localDashboardId: string }
): Pick<LogPanelProps, 'session'> => ({
session: getDashboardSessionWrapper(state, ownProps.localDashboardId)
?.session,
});
const ConnectedLogPanel = connect(mapStateToProps, null, null, {
forwardRef: true,
})(LogPanel);
export default ConnectedLogPanel;