Skip to content

Commit e93b773

Browse files
committed
Merge branch 'master' into issue-2542-clean-schema-update-table
2 parents f95bbcb + 7a68332 commit e93b773

File tree

5 files changed

+281
-211
lines changed

5 files changed

+281
-211
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
.jsonNormalInput {
1+
.normalInput {
22
padding-right: 30px;
33
}
44

5-
.jsonToggleButton {
5+
.modeToggleButton {
66
position: absolute;
77
top: 10px;
88
right: 10px;
@@ -11,4 +11,12 @@
1111
&:hover {
1212
opacity: 1.0;
1313
}
14+
}
15+
16+
.modeType {
17+
position: absolute;
18+
top: 6px;
19+
right: 28px;
20+
z-index: 100;
21+
font-style: italic;
1422
}

console/src/components/Common/CustomInputTypes/JsonInput.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import React, { useState } from 'react';
22
import AceEditor from 'react-ace';
33

4-
const styles = require('./JsonInput.scss');
4+
import 'brace/mode/markdown';
5+
import 'brace/theme/github';
6+
7+
const styles = require('./CustomInput.scss');
58

69
const NORMALKEY = 'normal';
710
const JSONKEY = 'json';
@@ -112,7 +115,7 @@ const JsonInput = props => {
112115
value={data}
113116
onChange={handleInputChangeAndPropagate}
114117
onKeyUp={handleKeyUpEvent}
115-
className={allProps.className + ' ' + styles.jsonNormalInput}
118+
className={allProps.className + ' ' + styles.normalInput}
116119
/>
117120
);
118121
};
@@ -126,12 +129,12 @@ const JsonInput = props => {
126129
key="icon_json_editor"
127130
className={
128131
'fa ' +
129-
styles.jsonToggleButton +
132+
styles.modeToggleButton +
130133
(editorType === JSONKEY ? ' fa-compress' : ' fa-expand')
131134
}
132135
onClick={() => updateState(toggleEditorType)}
133136
title={
134-
(editorType === JSONKEY ? 'Collapse' : 'Expand') + '(Ctrl + Space)'
137+
(editorType === JSONKEY ? 'Collapse' : 'Expand') + ' (Ctrl + Space)'
135138
}
136139
/>
137140
</span>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
import React, { useState } from 'react';
2+
import AceEditor from 'react-ace';
3+
4+
import 'brace/mode/html';
5+
import 'brace/mode/markdown';
6+
import 'brace/theme/github';
7+
import 'brace/theme/chrome';
8+
9+
const styles = require('./CustomInput.scss');
10+
11+
// editorType is what sort of editor. All are ACE Editor
12+
// modes except 0, which is text input
13+
14+
// ACE editor mode names
15+
const EDITORTYPES = [
16+
'normal', // must be first
17+
'text',
18+
'markdown',
19+
'html',
20+
];
21+
22+
// human readable editor names
23+
const EDITORTYPENAMES = [
24+
'single line input',
25+
'multi-line text input',
26+
'markdown',
27+
'html',
28+
];
29+
30+
// short human readable editor names
31+
// for the visible label
32+
const SHORTEDITORTYPENAMES = ['', 'multi-line', 'markdown', 'html'];
33+
34+
const NORMALKEY = 0;
35+
36+
const createInitialState = data => {
37+
const initialState = {
38+
editorType: NORMALKEY,
39+
data: data,
40+
};
41+
return initialState;
42+
};
43+
44+
const TextInput = props => {
45+
const { standardProps, placeholderProp } = props;
46+
const { defaultValue, onChange } = standardProps;
47+
const allProps = { ...standardProps };
48+
delete allProps.defaultValue;
49+
const [state, updateState] = useState(createInitialState(defaultValue));
50+
const { editorType, data } = state;
51+
52+
const updateData = (newData, currentState) => {
53+
return {
54+
...currentState,
55+
data: newData,
56+
};
57+
};
58+
59+
const cycleEditorType = currentState => {
60+
const nextEditorType = (currentState.editorType + 1) % EDITORTYPES.length;
61+
62+
return {
63+
...currentState,
64+
editorType: nextEditorType,
65+
};
66+
};
67+
68+
const handleKeyUpEvent = e => {
69+
if ((e.ctrlKey || event.metaKey) && e.which === 32) {
70+
updateState(cycleEditorType);
71+
}
72+
};
73+
74+
const handleEditorExec = () => {
75+
updateState(cycleEditorType);
76+
};
77+
78+
const handleInputChangeAndPropagate = e => {
79+
const val = e.target.value;
80+
updateState(currentState => updateData(val, currentState));
81+
if (onChange) {
82+
onChange(e);
83+
}
84+
};
85+
86+
const handleTextAreaChangeAndPropagate = (value, e) => {
87+
const val = value;
88+
updateState(currentState => updateData(val, currentState));
89+
if (onChange) {
90+
onChange(e, value);
91+
}
92+
};
93+
94+
const getAceEditor = curmode => {
95+
return (
96+
<AceEditor
97+
key="ace_text_editor"
98+
{...allProps}
99+
mode={curmode}
100+
theme="chrome"
101+
name="texttoggler"
102+
minLines={10}
103+
maxLines={100}
104+
width="100%"
105+
value={data}
106+
showPrintMargin={false}
107+
onChange={handleTextAreaChangeAndPropagate}
108+
showGutter={false}
109+
focus
110+
commands={[
111+
{
112+
name: 'toggleEditor',
113+
bindKey: { win: 'Ctrl-Space', mac: 'Command-Space' },
114+
exec: handleEditorExec,
115+
},
116+
]}
117+
/>
118+
);
119+
};
120+
121+
const getNormalEditor = () => {
122+
return (
123+
<input
124+
key="input_text_editor"
125+
{...allProps}
126+
placeholder={placeholderProp}
127+
value={data}
128+
onChange={handleInputChangeAndPropagate}
129+
onKeyUp={handleKeyUpEvent}
130+
className={allProps.className + ' ' + styles.normalInput}
131+
/>
132+
);
133+
};
134+
135+
const editor =
136+
editorType === NORMALKEY
137+
? getNormalEditor()
138+
: getAceEditor(EDITORTYPES[editorType]);
139+
140+
return (
141+
<span className="text_input_editor">
142+
<label>{editor}</label>
143+
<span
144+
onClick={() => updateState(cycleEditorType)}
145+
title={
146+
'Change to ' +
147+
EDITORTYPENAMES[(editorType + 1) % EDITORTYPES.length] +
148+
' (Ctrl + Space)'
149+
}
150+
>
151+
<span className={styles.modeType}>
152+
{SHORTEDITORTYPENAMES[editorType]}
153+
</span>
154+
<i
155+
key="icon_text_editor"
156+
className={
157+
'fa ' +
158+
styles.modeToggleButton +
159+
(editorType === NORMALKEY ? ' fa-expand' : ' fa-chevron-right')
160+
}
161+
/>
162+
</span>
163+
</span>
164+
);
165+
};
166+
export default TextInput;

0 commit comments

Comments
 (0)