Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 494ecde

Browse files
authored
Zhiqing bugfix (#26)
* Fix Bug #1059554:[Firefox][1366*768][Ja]the layout of link area is out of boarder on wizard page * Point to different language docs page when set to different languages * Fix Bug #1037246:[Chrome][1280*1024][ProdSide]Reset button is enable after click run button * When language menu is unfold, click any place will close the menu * Add react router to have different url when select languages * Track pageview after language is set * Use react route V3 for handling query string * Fix language name to automatically match languages
1 parent 87639aa commit 494ecde

File tree

8 files changed

+79
-15
lines changed

8 files changed

+79
-15
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"react-dom": "^15.5.4",
1717
"react-ga": "^2.2.0",
1818
"react-localization": "^0.1.0",
19+
"react-router": "3.0.5",
1920
"sass-loader": "^6.0.6",
2021
"uuid": "^3.0.1"
2122
},

src/component/controlBar/controlBar.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@
2121
.rightBtn {
2222
float: right;
2323
height: 24px;
24+
}
25+
26+
.reset-disable {
27+
color: grey !important;
2428
}

src/component/controlBar/controlBar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ControlBar extends Component {
88
return (
99
<div className='controlBar'>
1010
<span onClick={this.props.isRunning ? this.props.onStop : this.props.onStart}>{this.props.isRunning ? Localization.getLocalizedString().buttonStop : Localization.getLocalizedString().buttonRun}</span>
11-
<span onClick={this.props.onReset}>{Localization.getLocalizedString().buttonReset}</span>
11+
<span className={`${this.props.isRunning && 'reset-disable'}`} onClick={!this.props.isRunning && this.props.onReset}>{Localization.getLocalizedString().buttonReset}</span>
1212
<span className='rightBtn' onClick={this.props.toggleConsole}><Glyphicon glyph={this.props.consoleHide ? 'chevron-up' : 'chevron-down'} /></span>
1313
</div>
1414
);

src/component/helpOverlay/helpOverlay.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class HelpOverlay extends Component {
241241
</div>
242242
</div>
243243
<div className="link-container">
244-
<a target="_blank" href="https://docs.microsoft.com/azure/iot-hub/iot-hub-raspberry-pi-web-simulator-get-started">{Localization.getLocalizedString().helpLinkSeeDoc}</a>
244+
<a target="_blank" href={Localization.getLocalizedString().helpDocsLink}>{Localization.getLocalizedString().helpLinkSeeDoc}</a>
245245
<a target="_blank" href="https://github.com/Azure-Samples/raspberry-pi-web-simulator">{Localization.getLocalizedString().helpLinkViewSource}</a>
246246
</div>
247247
</div>

src/component/helpOverlay/helpOverlay.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $break-small: 768px;
2121
.instruction {
2222
width: 50%;
2323
height: 60%;
24-
min-height: 450px;
24+
min-height: 500px;
2525
@media screen and (max-width : 768px) {
2626
width: 90%;
2727
height: 90%;

src/component/language/language.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Component } from 'react';
22
import { traceEvent } from '../../lib/telemetry.js';
33
import './language.scss';
44
import Localization from '../../localization/localization';
5+
import { browserHistory } from 'react-router';
56

67
class Language extends Component {
78
constructor(props) {
@@ -12,6 +13,23 @@ class Language extends Component {
1213
}
1314

1415
onButtonClick = (e) => {
16+
e.stopPropagation();
17+
if(this.state.showList === false) {
18+
this.toggleShowList();
19+
document.body.addEventListener('mousedown',this.onBodyClick);
20+
this.listener = true;
21+
}
22+
}
23+
24+
onBodyClick = () => {
25+
setTimeout(this.toggleShowList,100);
26+
}
27+
28+
toggleShowList = () => {
29+
if(this.listener) {
30+
document.body.removeEventListener('mousedown',this.onBodyClick);
31+
this.listener = false;
32+
}
1533
this.setState((prev) => {
1634
return {
1735
showList: !prev.showList
@@ -21,13 +39,15 @@ class Language extends Component {
2139

2240
onLanguageClick = (key, e) => {
2341
Localization.getLocalizedString().setLanguage(key);
24-
this.setState((prev) => {
25-
return {
26-
showList: !prev.showList
27-
}
28-
});
2942
e.stopPropagation();
3043
this.props.reloadMain();
44+
let location = Object.assign({},
45+
browserHistory.getCurrentLocation());
46+
Object.assign(location.query, {
47+
lang: key,
48+
});
49+
browserHistory.push(location);
50+
window.localStorage.setItem('lang', key);
3151
}
3252

3353
render() {

src/index.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ import Localization from './localization/localization';
88
import { traceEvent } from './lib/telemetry.js';
99
import 'bootstrap/dist/css/bootstrap.css';
1010
import './index.css';
11-
import ErrorMap from './data/errorMap'
11+
import ErrorMap from './data/errorMap';
12+
import { Router, Route, Link, browserHistory } from 'react-router';
1213

1314
import Sample from './lib/sample.js';
1415
import { tracePageView,tracePageViewAI } from './lib/telemetry.js';
1516

1617
class Index extends Component {
1718
constructor(props) {
1819
super(props);
19-
tracePageView();
20-
tracePageViewAI();
2120
this.state = {
2221
console: {
2322
consoleMsg: '',
@@ -44,6 +43,40 @@ class Index extends Component {
4443
this.onFinish = this.onFinish.bind(this);
4544
}
4645

46+
componentDidMount() {
47+
let needUpdateUrl = false;
48+
let useDefault = true;
49+
let lang;
50+
if (this.props.location && this.props.location.query && this.props.location.query.lang) {
51+
useDefault = false;
52+
lang = this.props.location.query.lang;
53+
} else if (window.localStorage.getItem('lang')) {
54+
needUpdateUrl = true;
55+
useDefault = false;
56+
lang = window.localStorage.getItem('lang')
57+
}
58+
59+
if (!useDefault) {
60+
for (let key of Object.keys(Localization.localizedStringList)) {
61+
if (lang === key) {
62+
Localization.getLocalizedString().setLanguage(key);
63+
this.forceUpdate();
64+
}
65+
}
66+
if (needUpdateUrl) {
67+
let location = Object.assign({},
68+
browserHistory.getCurrentLocation());
69+
Object.assign(location.query, {
70+
lang
71+
});
72+
browserHistory.push(location);
73+
}
74+
}
75+
tracePageView();
76+
tracePageViewAI();
77+
}
78+
79+
4780
runApp() {
4881
if (this.state.isRunning) { return; }
4982

@@ -148,6 +181,7 @@ class Index extends Component {
148181
}
149182

150183
ReactDOM.render(
151-
<Index />,
152-
document.getElementById('root')
184+
<Router history={browserHistory} >
185+
<Route path="/*" component={Index} />
186+
</Router>, document.getElementById('root')
153187
);

src/localization/localization.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Localization.localizedStringList = {
6363
helpContent9: "with the Azure IoT hub",
6464
helpContent10: "device connection string",
6565
helpContent11: "button or type \"npm start\" in the console window to run the application",
66+
helpDocsLink: "https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-raspberry-pi-web-simulator-get-started",
6667
altRaspberryPiLogo: "Raspberry Pi logo"
6768
},
6869
"ja": {
@@ -108,9 +109,10 @@ Localization.localizedStringList = {
108109
helpContent9: "のプレースホルダをAzure IoTハブデバイスの",
109110
helpContent10: "接続文字列に置き換えます。",
110111
helpContent11: "[Run] をクリックまたは npm start と入力してアプリケーションを実行します。",
112+
helpDocsLink: "https://docs.microsoft.com/ja-jp/azure/iot-hub/iot-hub-raspberry-pi-web-simulator-get-started",
111113
altRaspberryPiLogo: "Raspberry Pi logo"
112114
},
113-
"zh-cn": {
115+
"zh-CN": {
114116
_displayName: "简体中文",
115117
pageTitle: "Raspberry Pi Azure IoT Online Simulator",
116118
pageTitleMobile: "Raspberry Pi Simulator",
@@ -153,9 +155,10 @@ Localization.localizedStringList = {
153155
helpContent9: "替换的内容是Azure IoT中心内",
154156
helpContent10: "设备连接字符串",
155157
helpContent11: "按钮或者输入 \"npm start\" 以运行应用程序",
158+
helpDocsLink: "https://docs.microsoft.com/zh-cn/azure/iot-hub/iot-hub-raspberry-pi-web-simulator-get-started",
156159
altRaspberryPiLogo: "Raspberry Pi logo"
157160
},
158-
"zh-tw": {
161+
"zh-HK": {
159162
_displayName: "繁体中文",
160163
pageTitle: "Raspberry Pi Azure IoT Online Simulator",
161164
pageTitleMobile: "Raspberry Pi Simulator",
@@ -198,6 +201,7 @@ Localization.localizedStringList = {
198201
helpContent9: "替換為",
199202
helpContent10: "連接字串的主索引鍵",
200203
helpContent11: "按鈕或在控制台窗口中鍵入“npm start”來運行應用程序",
204+
helpDocsLink: "https://docs.microsoft.com/zh-hk/azure/iot-hub/iot-hub-raspberry-pi-web-simulator-get-started",
201205
altRaspberryPiLogo: "Raspberry Pi logo"
202206
},
203207
"es": {
@@ -243,6 +247,7 @@ Localization.localizedStringList = {
243247
helpContent9: "con la cadena de conexión del dispositivo de Azure IoT Hub.",
244248
helpContent10: "cadena de la cadena de conexión",
245249
helpContent11: "Haga clic en Ejecutar o escriba \"npm start\" para ejecutar la aplicación",
250+
helpDocsLink: "https://docs.microsoft.com/es-es/azure/iot-hub/iot-hub-raspberry-pi-web-simulator-get-started",
246251
altRaspberryPiLogo: "Raspberry Pi logo"
247252
}
248253
};

0 commit comments

Comments
 (0)