|
| 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 | +// @flow |
| 5 | + |
| 6 | +import React from 'react'; |
| 7 | +import classNames from 'classnames'; |
| 8 | + |
| 9 | +import { |
| 10 | + getAssemblyViewCurrentNativeSymbolEntryIndex, |
| 11 | + getAssemblyViewNativeSymbolEntryCount, |
| 12 | +} from 'firefox-profiler/selectors/url-state'; |
| 13 | +import { changeAssemblyViewNativeSymbolEntryIndex } from 'firefox-profiler/actions/profile-view'; |
| 14 | +import explicitConnect from 'firefox-profiler/utils/connect'; |
| 15 | + |
| 16 | +import type { ConnectedProps } from 'firefox-profiler/utils/connect'; |
| 17 | + |
| 18 | +import { Localized } from '@fluent/react'; |
| 19 | + |
| 20 | +type StateProps = {| |
| 21 | + +assemblyViewCurrentNativeSymbolEntryIndex: number | null, |
| 22 | + +assemblyViewNativeSymbolEntryCount: number, |
| 23 | +|}; |
| 24 | + |
| 25 | +type DispatchProps = {| |
| 26 | + +changeAssemblyViewNativeSymbolEntryIndex: typeof changeAssemblyViewNativeSymbolEntryIndex, |
| 27 | +|}; |
| 28 | + |
| 29 | +type Props = ConnectedProps<{||}, StateProps, DispatchProps>; |
| 30 | + |
| 31 | +class AssemblyViewNativeSymbolNavigatorImpl extends React.PureComponent<Props> { |
| 32 | + _onPreviousClick = () => { |
| 33 | + this._changeIndexBy(-1); |
| 34 | + }; |
| 35 | + |
| 36 | + _onNextClick = () => { |
| 37 | + this._changeIndexBy(1); |
| 38 | + }; |
| 39 | + |
| 40 | + _changeIndexBy(delta: number) { |
| 41 | + const { |
| 42 | + assemblyViewCurrentNativeSymbolEntryIndex: index, |
| 43 | + assemblyViewNativeSymbolEntryCount: count, |
| 44 | + changeAssemblyViewNativeSymbolEntryIndex, |
| 45 | + } = this.props; |
| 46 | + const newIndex = index + delta; |
| 47 | + if (newIndex >= 0 && newIndex < count) { |
| 48 | + changeAssemblyViewNativeSymbolEntryIndex(newIndex); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + render() { |
| 53 | + const { |
| 54 | + assemblyViewCurrentNativeSymbolEntryIndex: index, |
| 55 | + assemblyViewNativeSymbolEntryCount: count, |
| 56 | + } = this.props; |
| 57 | + |
| 58 | + if (index === null || count <= 1) { |
| 59 | + return null; |
| 60 | + } |
| 61 | + |
| 62 | + return ( |
| 63 | + <> |
| 64 | + <h3 className="bottom-box-title-trailer"> |
| 65 | + {index !== null && count > 1 ? `${index + 1} of ${count}` : ''} |
| 66 | + </h3> |
| 67 | + <Localized id="AssemblyView--prev-button" attrs={{ title: true }}> |
| 68 | + <button |
| 69 | + className={classNames( |
| 70 | + 'bottom-prev-button', |
| 71 | + 'photon-button', |
| 72 | + 'photon-button-ghost' |
| 73 | + )} |
| 74 | + title="Previous" |
| 75 | + type="button" |
| 76 | + disabled={index === null || index <= 0} |
| 77 | + onClick={this._onPreviousClick} |
| 78 | + > |
| 79 | + ◀ |
| 80 | + </button> |
| 81 | + </Localized> |
| 82 | + <Localized id="AssemblyView--next-button" attrs={{ title: true }}> |
| 83 | + <button |
| 84 | + className={classNames( |
| 85 | + 'bottom-next-button', |
| 86 | + 'photon-button', |
| 87 | + 'photon-button-ghost' |
| 88 | + )} |
| 89 | + title="Next" |
| 90 | + type="button" |
| 91 | + disabled={index === null || index >= count - 1} |
| 92 | + onClick={this._onNextClick} |
| 93 | + > |
| 94 | + ▶ |
| 95 | + </button> |
| 96 | + </Localized> |
| 97 | + </> |
| 98 | + ); |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +export const AssemblyViewNativeSymbolNavigator = explicitConnect< |
| 103 | + {||}, |
| 104 | + StateProps, |
| 105 | + DispatchProps, |
| 106 | +>({ |
| 107 | + mapStateToProps: (state) => ({ |
| 108 | + assemblyViewCurrentNativeSymbolEntryIndex: |
| 109 | + getAssemblyViewCurrentNativeSymbolEntryIndex(state), |
| 110 | + assemblyViewNativeSymbolEntryCount: |
| 111 | + getAssemblyViewNativeSymbolEntryCount(state), |
| 112 | + }), |
| 113 | + mapDispatchToProps: { |
| 114 | + changeAssemblyViewNativeSymbolEntryIndex, |
| 115 | + }, |
| 116 | + component: AssemblyViewNativeSymbolNavigatorImpl, |
| 117 | +}); |
0 commit comments