forked from deephaven/web-client-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCorePanel.tsx
More file actions
80 lines (66 loc) · 2.47 KB
/
CorePanel.tsx
File metadata and controls
80 lines (66 loc) · 2.47 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
import React, { PureComponent, type ReactElement } from 'react';
import { createXComponent } from '@deephaven/components';
import { type BasePanelProps, BasePanel } from '@deephaven/dashboard';
import type { dh } from '@deephaven/jsapi-types';
import { ConsoleEvent, InputFilterEvent } from '../events';
export type CorePanelProps = BasePanelProps & {
onClearAllFilters?: (...args: unknown[]) => void;
onSessionClose?: (session: dh.IdeSession) => void;
onSessionOpen?: (
session: dh.IdeSession,
{ language, sessionId }: { language: string; sessionId: string }
) => void;
};
/**
* Generic panel component that emits mount/unmount/focus events.
* Also wires up some triggers for common events:
* Focus, Resize, Show, Session open/close, client disconnect/reconnect.
*/
class CorePanel extends PureComponent<CorePanelProps> {
constructor(props: CorePanelProps) {
super(props);
this.handleClearAllFilters = this.handleClearAllFilters.bind(this);
this.handleSessionClosed = this.handleSessionClosed.bind(this);
this.handleSessionOpened = this.handleSessionOpened.bind(this);
}
componentDidMount(): void {
const { glEventHub } = this.props;
glEventHub.on(ConsoleEvent.SESSION_CLOSED, this.handleSessionClosed);
glEventHub.on(ConsoleEvent.SESSION_OPENED, this.handleSessionOpened);
glEventHub.on(
InputFilterEvent.CLEAR_ALL_FILTERS,
this.handleClearAllFilters
);
}
componentWillUnmount(): void {
const { glEventHub } = this.props;
glEventHub.off(ConsoleEvent.SESSION_CLOSED, this.handleSessionClosed);
glEventHub.off(ConsoleEvent.SESSION_OPENED, this.handleSessionOpened);
glEventHub.off(
InputFilterEvent.CLEAR_ALL_FILTERS,
this.handleClearAllFilters
);
}
handleClearAllFilters(...args: unknown[]): void {
const { onClearAllFilters } = this.props;
onClearAllFilters?.(...args);
}
handleSessionClosed(session: dh.IdeSession): void {
const { onSessionClose } = this.props;
onSessionClose?.(session);
}
handleSessionOpened(
session: dh.IdeSession,
params: { language: string; sessionId: string }
): void {
const { onSessionOpen } = this.props;
onSessionOpen?.(session, params);
}
render(): ReactElement {
const { children, ...otherProps } = this.props;
// eslint-disable-next-line react/jsx-props-no-spreading
return <BasePanel {...otherProps}>{children}</BasePanel>;
}
}
const XCorePanel = createXComponent(CorePanel);
export default XCorePanel;