|
| 1 | +/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | + |
| 5 | +// @flow |
| 6 | + |
| 7 | +import React, { PureComponent } from 'react'; |
| 8 | +import { Localized } from '@fluent/react'; |
| 9 | + |
| 10 | +import { changeImplementationFilter } from 'firefox-profiler/actions/profile-view'; |
| 11 | +import { getImplementationFilter } from 'firefox-profiler/selectors/url-state'; |
| 12 | + |
| 13 | +import { toValidImplementationFilter } from 'firefox-profiler/profile-logic/profile-data'; |
| 14 | +import explicitConnect, { |
| 15 | + type ConnectedProps, |
| 16 | +} from 'firefox-profiler/utils/connect'; |
| 17 | + |
| 18 | +import { getProfileUsesMultipleStackTypes } from 'firefox-profiler/selectors/profile'; |
| 19 | + |
| 20 | +import './PanelSettingsList.css'; |
| 21 | + |
| 22 | +import type { ImplementationFilter } from 'firefox-profiler/types'; |
| 23 | + |
| 24 | +type OwnProps = {| |
| 25 | + labelL10nId?: string, |
| 26 | +|}; |
| 27 | + |
| 28 | +type StateProps = {| |
| 29 | + +implementationFilter: ImplementationFilter, |
| 30 | + +allowSwitchingStackType: boolean, |
| 31 | +|}; |
| 32 | + |
| 33 | +type DispatchProps = {| |
| 34 | + +changeImplementationFilter: typeof changeImplementationFilter, |
| 35 | +|}; |
| 36 | + |
| 37 | +type Props = ConnectedProps<OwnProps, StateProps, DispatchProps>; |
| 38 | + |
| 39 | +class StackImplementationSettingImpl extends PureComponent<Props> { |
| 40 | + _onImplementationFilterChange = (e: SyntheticEvent<HTMLInputElement>) => { |
| 41 | + this.props.changeImplementationFilter( |
| 42 | + // This function is here to satisfy Flow that we are getting a valid |
| 43 | + // implementation filter. |
| 44 | + toValidImplementationFilter(e.currentTarget.value) |
| 45 | + ); |
| 46 | + }; |
| 47 | + |
| 48 | + _renderImplementationRadioButton( |
| 49 | + labelL10nId: string, |
| 50 | + implementationFilter: ImplementationFilter |
| 51 | + ) { |
| 52 | + const htmlId = `implementation-radio-${implementationFilter}`; |
| 53 | + return ( |
| 54 | + <> |
| 55 | + <Localized id={labelL10nId} attrs={{ title: true }}> |
| 56 | + <input |
| 57 | + type="radio" |
| 58 | + className="photon-radio photon-radio-micro" |
| 59 | + value={implementationFilter} |
| 60 | + id={htmlId} |
| 61 | + onChange={this._onImplementationFilterChange} |
| 62 | + checked={this.props.implementationFilter === implementationFilter} |
| 63 | + /> |
| 64 | + </Localized> |
| 65 | + <Localized id={labelL10nId} attrs={{ title: true }}> |
| 66 | + <label |
| 67 | + className="photon-label photon-label-micro photon-label-horiz-padding" |
| 68 | + htmlFor={htmlId} |
| 69 | + ></label> |
| 70 | + </Localized> |
| 71 | + </> |
| 72 | + ); |
| 73 | + } |
| 74 | + |
| 75 | + render() { |
| 76 | + const { allowSwitchingStackType, labelL10nId } = this.props; |
| 77 | + |
| 78 | + return allowSwitchingStackType ? ( |
| 79 | + <li className="panelSettingsListItem"> |
| 80 | + {labelL10nId ? <Localized id={labelL10nId} /> : null} |
| 81 | + {this._renderImplementationRadioButton( |
| 82 | + 'StackSettings--implementation-all-frames', |
| 83 | + 'combined' |
| 84 | + )} |
| 85 | + {this._renderImplementationRadioButton( |
| 86 | + 'StackSettings--implementation-javascript2', |
| 87 | + 'js' |
| 88 | + )} |
| 89 | + {this._renderImplementationRadioButton( |
| 90 | + 'StackSettings--implementation-native2', |
| 91 | + 'cpp' |
| 92 | + )} |
| 93 | + </li> |
| 94 | + ) : null; |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +export const StackImplementationSetting = explicitConnect< |
| 99 | + OwnProps, |
| 100 | + StateProps, |
| 101 | + DispatchProps |
| 102 | +>({ |
| 103 | + mapStateToProps: (state) => ({ |
| 104 | + implementationFilter: getImplementationFilter(state), |
| 105 | + allowSwitchingStackType: getProfileUsesMultipleStackTypes(state), |
| 106 | + }), |
| 107 | + mapDispatchToProps: { |
| 108 | + changeImplementationFilter, |
| 109 | + }, |
| 110 | + component: StackImplementationSettingImpl, |
| 111 | +}); |
0 commit comments