PanelMonacoEditor.tsx 2.64 KB
Newer Older
1
2
3
import * as React from 'react';
import { Stack, Panel, PrimaryButton } from '@fluentui/react';
import MonacoEditor from 'react-monaco-editor';
4
5
import { caclMonacoEditorHeight } from '@static/function';
import '@style/logPanel.scss';
6

7
interface LogPanelProps {
8
9
10
11
12
    hideConfigPanel: () => void;
    panelName: string;
    panelContent: string;
}

13
interface LogPanelState {
14
15
16
17
18
19
20
21
22
23
    panelInnerHeight: number;
}

/**
 * search space
 * config
 * retiarii parameter
 * panel
 */

24
25
class PanelMonacoEditor extends React.Component<LogPanelProps, LogPanelState> {
    constructor(props: LogPanelProps) {
26
27
28
29
30
31
32
33
        super(props);

        this.state = {
            panelInnerHeight: window.innerHeight
        };
    }

    // use arrow function for change window size met error: this.setState is not a function
34
    setLogPanelHeight = (): void => {
35
36
37
38
        this.setState(() => ({ panelInnerHeight: window.innerHeight, innerWidth: window.innerWidth }));
    };

    async componentDidMount(): Promise<void> {
39
        window.addEventListener('resize', this.setLogPanelHeight);
40
41
42
    }

    componentWillUnmount(): void {
43
        window.removeEventListener('resize', this.setLogPanelHeight);
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
    }

    render(): React.ReactNode {
        const { hideConfigPanel, panelName, panelContent } = this.props;
        const { panelInnerHeight } = this.state;
        const monacoEditorHeight = caclMonacoEditorHeight(panelInnerHeight);
        return (
            <Stack>
                <Panel
                    isOpen={true}
                    hasCloseButton={false}
                    isFooterAtBottom={true}
                    isLightDismiss={true}
                    onLightDismissClick={hideConfigPanel}
                >
                    <div className='panel'>
                        <div>
                            <div className='panelName'>{panelName}</div>
                            <MonacoEditor
                                height={monacoEditorHeight}
                                language='json'
                                theme='vs-light'
                                value={panelContent}
                                options={{
                                    minimap: { enabled: false },
                                    readOnly: true,
                                    automaticLayout: true,
                                    wordWrap: 'on'
                                }}
                            />
                        </div>
                        <PrimaryButton text='Close' className='configClose' onClick={hideConfigPanel} />
                    </div>
                </Panel>
            </Stack>
        );
    }
}

export default PanelMonacoEditor;