Skip to content

Commit 6150f1a

Browse files
kmerzdennisoelkers
authored andcommitted
Replace react-ace with react-ace-builds. (Graylog2#5984)
* Replace react-ace with react-ace-builds * Fix eslint warnings
1 parent 984c89b commit 6150f1a

File tree

5 files changed

+177
-95
lines changed

5 files changed

+177
-95
lines changed

graylog2-web-interface/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"numeral": "^1.5.3",
7171
"opensans-npm-webfont": "^1.0.0",
7272
"qs": "^6.3.0",
73-
"react-ace": "^5.9.0",
73+
"react-ace-builds": "^7.2.4",
7474
"react-color": "^2.14.0",
7575
"react-day-picker": "^5.0.0",
7676
"react-dnd": "^7.0.2",

graylog2-web-interface/src/components/common/SourceCodeEditor.jsx

+46-33
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,13 @@ import React from 'react';
22
import lodash from 'lodash';
33
import { PropTypes } from 'prop-types';
44
import { Resizable } from 'react-resizable';
5-
import 'brace';
6-
import AceEditor from 'react-ace';
5+
import AceEditor from 'react-ace-builds';
76
import { Button, ButtonGroup, ButtonToolbar, OverlayTrigger, Tooltip } from 'react-bootstrap';
87

98
import { ClipboardButton } from 'components/common';
109

11-
import 'brace/mode/json';
12-
import 'brace/mode/lua';
13-
import 'brace/mode/markdown';
14-
import 'brace/mode/text';
15-
import 'brace/mode/yaml';
16-
import 'brace/theme/tomorrow';
17-
import 'brace/theme/monokai';
1810
import style from './SourceCodeEditor.css';
11+
import './webpack-resolver';
1912

2013
/**
2114
* Component that renders a source code editor input. This is what powers the pipeline rules and collector
@@ -74,7 +67,7 @@ class SourceCodeEditor extends React.Component {
7467
toolbar: true,
7568
value: '',
7669
width: Infinity,
77-
}
70+
};
7871

7972
constructor(props) {
8073
super(props);
@@ -86,61 +79,81 @@ class SourceCodeEditor extends React.Component {
8679
}
8780

8881
componentDidUpdate(prevProps) {
89-
if (this.props.height !== prevProps.height || this.props.width !== prevProps.width) {
82+
const { height, width } = this.props;
83+
if (height !== prevProps.height || width !== prevProps.width) {
9084
this.reloadEditor();
9185
}
9286
}
9387

9488
handleResize = (event, { size }) => {
9589
const { height, width } = size;
9690
this.setState({ height: height, width: width }, this.reloadEditor);
97-
}
91+
};
9892

9993
reloadEditor = () => {
100-
if (this.props.resizable) {
94+
const { resizable } = this.props;
95+
if (resizable) {
10196
this.reactAce.editor.resize();
10297
}
103-
}
98+
};
10499

100+
/* eslint-disable-next-line react/destructuring-assignment */
105101
isCopyDisabled = () => this.props.readOnly || this.state.selectedText === '';
106102

103+
/* eslint-disable-next-line react/destructuring-assignment */
107104
isPasteDisabled = () => this.props.readOnly;
108105

106+
/* eslint-disable-next-line react/destructuring-assignment */
109107
isRedoDisabled = () => this.props.readOnly || !this.reactAce || !this.reactAce.editor.getSession().getUndoManager().hasRedo();
110108

109+
/* eslint-disable-next-line react/destructuring-assignment */
111110
isUndoDisabled = () => this.props.readOnly || !this.reactAce || !this.reactAce.editor.getSession().getUndoManager().hasUndo();
112111

113112
handleRedo = () => {
114113
this.reactAce.editor.redo();
115114
this.focusEditor();
116-
}
115+
};
117116

118117
handleUndo = () => {
119118
this.reactAce.editor.undo();
120119
this.focusEditor();
121-
}
120+
};
122121

123122
handleSelectionChange = (selection) => {
124-
if (!this.reactAce || !this.props.toolbar || this.props.readOnly) {
123+
const { toolbar, readOnly } = this.props;
124+
if (!this.reactAce || !toolbar || readOnly) {
125125
return;
126126
}
127127
const selectedText = this.reactAce.editor.getSession().getTextRange(selection.getRange());
128128
this.setState({ selectedText: selectedText });
129-
}
129+
};
130130

131131
focusEditor = () => {
132132
this.reactAce.editor.focus();
133-
}
133+
};
134134

135135
render() {
136-
const { height, width } = this.state;
137-
const { theme, resizable } = this.props;
136+
const { height, width, selectedText } = this.state;
137+
const {
138+
theme,
139+
resizable,
140+
toolbar,
141+
annotations,
142+
focus,
143+
fontSize,
144+
mode,
145+
id,
146+
onLoad,
147+
onChange,
148+
readOnly,
149+
value,
150+
} = this.props;
138151
const validCssWidth = lodash.isFinite(width) ? width : '100%';
139152
const containerStyle = `${style.sourceCodeEditor} ${theme !== 'light' && style.darkMode} ${!resizable && style.static}`;
140153
const overlay = <Tooltip id="paste-button-tooltip">Press Ctrl+V (&#8984;V in macOS) or select Edit&thinsp;&rarr;&thinsp;Paste to paste from clipboard.</Tooltip>;
141154
return (
142155
<div>
143-
{this.props.toolbar
156+
{toolbar
144157
&& (
145158
<div className={style.toolbar} style={{ width: validCssWidth }}>
146159
<ButtonToolbar>
@@ -149,7 +162,7 @@ class SourceCodeEditor extends React.Component {
149162
bsStyle="link"
150163
bsSize="sm"
151164
onSuccess={this.focusEditor}
152-
text={this.state.selectedText}
165+
text={selectedText}
153166
buttonTitle="Copy (Ctrl+C / &#8984;C)"
154167
disabled={this.isCopyDisabled()} />
155168
<OverlayTrigger placement="top" trigger="click" overlay={overlay} rootClose>
@@ -184,19 +197,19 @@ class SourceCodeEditor extends React.Component {
184197
onResize={this.handleResize}>
185198
<div className={containerStyle} style={{ height: height, width: validCssWidth }}>
186199
<AceEditor ref={(c) => { this.reactAce = c; }}
187-
annotations={this.props.annotations}
200+
annotations={annotations}
188201
editorProps={{ $blockScrolling: 'Infinity' }}
189-
focus={this.props.focus}
190-
fontSize={this.props.fontSize}
191-
mode={this.props.mode}
192-
theme={this.props.theme === 'light' ? 'tomorrow' : 'monokai'}
193-
name={this.props.id}
202+
focus={focus}
203+
fontSize={fontSize}
204+
mode={mode}
205+
theme={theme === 'light' ? 'tomorrow' : 'monokai'}
206+
name={id}
194207
height="100%"
195-
onLoad={this.props.onLoad}
196-
onChange={this.props.onChange}
208+
onLoad={onLoad}
209+
onChange={onChange}
197210
onSelectionChange={this.handleSelectionChange}
198-
readOnly={this.props.readOnly}
199-
value={this.props.value}
211+
readOnly={readOnly}
212+
value={value}
200213
width="100%" />
201214
</div>
202215
</Resizable>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* eslint-disable */
2+
const modes = [
3+
'json',
4+
'lua',
5+
'markdown',
6+
'text',
7+
'yaml',
8+
];
9+
10+
modes.forEach((mode) => {
11+
ace.config.setModuleUrl(
12+
`ace/mode/${mode}`, require(`file-loader!ace-builds/src-min-noconflict/mode-${mode}.js`)
13+
);
14+
});
15+
16+
const themes = [
17+
'tomorrow',
18+
'monokai',
19+
];
20+
21+
themes.forEach((theme) => {
22+
ace.config.setModuleUrl(
23+
`ace/theme/${theme}`, require(`file-loader!ace-builds/src-min-noconflict/theme-${theme}.js`)
24+
);
25+
});

graylog2-web-interface/webpack/vendor-module-ids.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,9 @@
892892
"node_modules/moment/locale/mn.js": 13,
893893
"node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js": 18,
894894
"node_modules/scheduler/index.js": 20,
895-
"node_modules/scheduler/cjs/scheduler.production.min.js": 29
895+
"node_modules/scheduler/cjs/scheduler.production.min.js": 29,
896+
"node_modules/react-dom/node_modules/scheduler/index.js": 20,
897+
"node_modules/react-dom/node_modules/scheduler/cjs/scheduler.production.min.js": 29
896898
},
897899
"usedIds": {
898900
"0": 0,

0 commit comments

Comments
 (0)