From 81b71352dd18120a851d957d9c99a77b668c5761 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Thu, 27 Jun 2019 06:53:11 -0700 Subject: [PATCH] Fix the bug related to the crash selection Summary: Fixes the bug when the crash options had same title. Selection was broken in that case. Look at the video. {F163450316} Reviewed By: jknoxville Differential Revision: D15985919 fbshipit-source-id: 7366c8f5f33bbddc15c058b7d20d78d295161404 --- src/plugins/crash_reporter/index.js | 9 +++------ src/ui/components/Select.js | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/plugins/crash_reporter/index.js b/src/plugins/crash_reporter/index.js index d485d3350..c63e7ddce 100644 --- a/src/plugins/crash_reporter/index.js +++ b/src/plugins/crash_reporter/index.js @@ -431,12 +431,9 @@ class CrashSelector extends Component { grow={true} selected={selectedCrashID || 'NoCrashID'} options={crashes || {NoCrashID: 'No Crash'}} - onChange={(title: string) => { - for (const key in crashes) { - if (crashes[key] === title && onCrashChange) { - onCrashChange(key); - return; - } + onChangeWithKey={(key: string) => { + if (onCrashChange) { + onCrashChange(key); } }} /> diff --git a/src/ui/components/Select.js b/src/ui/components/Select.js index 8fb65f20b..91049e5c9 100644 --- a/src/ui/components/Select.js +++ b/src/ui/components/Select.js @@ -33,8 +33,12 @@ export default class Select extends Component<{ options: { [key: string]: string, }, - /** Callback when the selected value changes */ - onChange: (key: string) => void, + /** DEPRECATED: Callback when the selected value changes. The callback is called with the displayed value. */ + onChange?: (value: string) => void, + + /** Callback when the selected value changes. The callback is called with the key for the displayed value */ + onChangeWithKey?: (key: string) => void, + /** Selected key */ selected?: ?string, /** Label shown next to the dropdown */ @@ -45,7 +49,12 @@ export default class Select extends Component<{ selectID: string = Math.random().toString(36); onChange = (event: Object) => { - this.props.onChange(event.target.value); + if (this.props.onChangeWithKey) { + this.props.onChangeWithKey(event.target.value); + } + if (this.props.onChange) { + this.props.onChange(this.props.options[event.target.value]); + } }; render() { @@ -59,7 +68,7 @@ export default class Select extends Component<{ className={className} value={selected || ''}> {Object.keys(options).map((key, index) => ( - ))}