/
appSettingsEditor.tsx
255 lines (237 loc) · 9.02 KB
/
appSettingsEditor.tsx
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license.
//
// Microsoft Bot Framework: http://botframework.com
//
// Bot Framework Emulator Github:
// https://github.com/Microsoft/BotFramwork-Emulator
//
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// MIT License:
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
import { FrameworkSettings } from '@bfemulator/app-shared';
import {
Checkbox,
Column,
PrimaryButton,
Row,
RowAlignment,
RowJustification,
SmallHeader,
TextField,
} from '@bfemulator/ui-react';
import * as React from 'react';
import { ChangeEvent } from 'react';
import { GenericDocument } from '../../layout';
import * as styles from './appSettingsEditor.scss';
export interface AppSettingsEditorProps {
documentId?: string;
dirty?: boolean;
framework?: FrameworkSettings;
discardChanges?: () => void;
getFrameworkSettings?: () => void;
openBrowseForNgrok: () => Promise<string>;
saveFrameworkSettings?: (framework: FrameworkSettings) => void;
setDirtyFlag?: (dirty: boolean) => void;
}
export interface AppSettingsEditorState extends Partial<FrameworkSettings> {
dirty?: boolean;
pendingUpdate?: boolean;
}
function shallowEqual(x: any, y: any) {
return Object.keys(x).length === Object.keys(y).length && Object.keys(x).every(key => key in y && x[key] === y[key]);
}
export class AppSettingsEditor extends React.Component<AppSettingsEditorProps, AppSettingsEditorState> {
public state = {} as AppSettingsEditorState;
public static getDerivedStateFromProps(
newProps: AppSettingsEditorProps,
prevState: AppSettingsEditorState
): AppSettingsEditorState {
if (newProps.framework.hash === prevState.hash) {
return prevState;
}
return {
...newProps.framework,
dirty: newProps.dirty,
pendingUpdate: false,
};
}
public componentDidMount(): void {
this.props.getFrameworkSettings();
}
public render(): JSX.Element {
const { state } = this;
return (
<GenericDocument className={styles.appSettingsEditor}>
<Row>
<Column className={styles.spacing}>
<SmallHeader>Service</SmallHeader>
<p>
<a href="https://ngrok.com/" target="_blank" rel="noopener noreferrer">
ngrok
</a>{' '}
is network tunneling software. The Bot Framework Emulator works with ngrok to communicate with bots hosted
remotely. Read the{' '}
<a
href="https://github.com/Microsoft/BotFramework-Emulator/wiki/Tunneling-(ngrok)"
target="_blank"
rel="noopener noreferrer"
>
wiki page
</a>{' '}
to learn more about using ngrok and to download it.
</p>
<Row align={RowAlignment.Center} className={styles.marginBottomRow}>
<TextField
className={styles.appSettingsInput}
inputContainerClassName={styles.inputContainer}
readOnly={false}
value={state.ngrokPath}
onChange={this.onInputChange}
name="ngrokPath"
label={'Path to ngrok'}
/>
<PrimaryButton onClick={this.onClickBrowse} text="Browse" className={styles.browseButton} />
</Row>
<Checkbox
className={styles.checkboxOverrides}
checked={state.bypassNgrokLocalhost}
onChange={this.onChangeCheckBox}
id="ngrok-bypass"
label="Bypass ngrok for local addresses"
name="bypassNgrokLocalhost"
/>
<Checkbox
className={styles.checkboxOverrides}
checked={state.runNgrokAtStartup}
onChange={this.onChangeCheckBox}
id="ngrok-startup"
label="Run ngrok when the Emulator starts up"
name="runNgrokAtStartup"
/>
<Row align={RowAlignment.Center} className={styles.marginBottomRow}>
<TextField
className={styles.appSettingsInput}
inputContainerClassName={styles.inputContainer}
readOnly={false}
value={state.localhost}
onChange={this.onInputChange}
name="localhost"
label="localhost override"
/>
</Row>
<Row align={RowAlignment.Center}>
<TextField
className={styles.appSettingsInput}
inputContainerClassName={styles.inputContainer}
readOnly={false}
value={state.locale}
name="locale"
onChange={this.onInputChange}
label="Locale"
/>
</Row>
</Column>
<Column className={[styles.rightColumn, styles.spacing].join(' ')}>
<SmallHeader>Auth</SmallHeader>
<Checkbox
className={styles.checkboxOverrides}
checked={state.use10Tokens}
onChange={this.onChangeCheckBox}
id="auth-token-version"
label="Use version 1.0 authentication tokens"
name="use10Tokens"
/>
<SmallHeader>Sign-in</SmallHeader>
<Checkbox
className={styles.checkboxOverrides}
checked={state.useCodeValidation}
onChange={this.onChangeCheckBox}
id="use-validation-code"
label="Use a sign-in verification code for OAuthCards"
name="useCodeValidation"
/>
<SmallHeader>Application Updates</SmallHeader>
<Checkbox
className={styles.checkboxOverrides}
checked={state.autoUpdate}
onChange={this.onChangeCheckBox}
label="Automatically download and install updates"
name="autoUpdate"
/>
<Checkbox
className={styles.checkboxOverrides}
checked={state.usePrereleases}
onChange={this.onChangeCheckBox}
label="Use pre-release versions"
name="usePrereleases"
/>
<SmallHeader>Data Collection</SmallHeader>
<Checkbox
className={styles.checkboxOverrides}
checked={false}
onChange={this.onChangeCheckBox}
label="Help improve the Emulator by allowing us to collect usage data."
name="collectUsageData"
disabled={true}
/>
<a target="_blank" href="https://aka.ms/bot-framework-emulator-data-collection" rel="noopener noreferrer">
Learn more.
</a>
</Column>
</Row>
<Row className={styles.buttonRow} justify={RowJustification.Right}>
<PrimaryButton text="Cancel" onClick={this.props.discardChanges} className={styles.cancelButton} />
<PrimaryButton text="Save" onClick={this.onSaveClick} className={styles.saveButton} disabled={!state.dirty} />
</Row>
</GenericDocument>
);
}
private onChangeCheckBox = (event: ChangeEvent<HTMLInputElement>) => {
const { name, checked } = event.target;
const change = { [name]: checked };
this.setState(change);
this.updateDirtyFlag(change);
};
private onClickBrowse = async (): Promise<void> => {
const ngrokPath = await this.props.openBrowseForNgrok();
const change = { ngrokPath };
this.setState(change);
this.updateDirtyFlag(change);
};
private onInputChange = (event: ChangeEvent<HTMLInputElement>): void => {
const { value, name } = event.target;
const change = { [name]: value };
this.setState(change);
this.updateDirtyFlag(change);
};
private onSaveClick = () => {
this.props.saveFrameworkSettings(this.state);
};
private updateDirtyFlag(change: { [prop: string]: any }) {
const dirty = !shallowEqual({ ...this.state, ...change }, this.props.framework);
this.setState({ dirty });
this.props.setDirtyFlag(dirty);
}
}