Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions src/components/shared/FilterNavigatorBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,43 @@ import classNames from 'classnames';
import { CSSTransition, TransitionGroup } from 'react-transition-group';
import './FilterNavigatorBar.css';

type FilterNavigatorBarButtonProps = {|
onClick: (number) => mixed,
index: number,
children: React.Node,
|};

class FilterNavigatorBarButton extends React.PureComponent<FilterNavigatorBarButtonProps> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_onClick = () => {
const { index, onClick } = this.props;
onClick(index);
};

render() {
return (
<button
type="button"
className="filterNavigatorBarItemContent"
onClick={this._onClick}
>
{this.props.children}
</button>
);
}
}

type Props = {|
+className: string,
+items: $ReadOnlyArray<React.Node | string>,
+items: $ReadOnlyArray<React.Node>,
+onPop: (number) => mixed,
+selectedItem: number,
+uncommittedItem?: string,
|};

export class FilterNavigatorBar extends React.PureComponent<Props> {
_onLiClick = (e: SyntheticMouseEvent<HTMLLIElement>) => {
const element = e.currentTarget;
const index = parseInt(element.dataset.index, 10) || 0;
this.props.onPop(index);
};

render() {
const { className, items, selectedItem, uncommittedItem } = this.props;
const { className, items, selectedItem, uncommittedItem, onPop } =
this.props;
return (
<TransitionGroup
component="ol"
Expand All @@ -38,21 +58,19 @@ export class FilterNavigatorBar extends React.PureComponent<Props> {
timeout={250}
>
<li
data-index={i}
className={classNames('filterNavigatorBarItem', {
filterNavigatorBarRootItem: i === 0,
filterNavigatorBarBeforeSelectedItem: i === selectedItem - 1,
filterNavigatorBarSelectedItem: i === selectedItem,
filterNavigatorBarLeafItem: i === items.length - 1,
})}
onClick={this._onLiClick}
>
{i === items.length - 1 ? (
{i === items.length - 1 && !uncommittedItem ? (
<span className="filterNavigatorBarItemContent">{item}</span>
) : (
<button type="button" className="filterNavigatorBarItemContent">
<FilterNavigatorBarButton index={i} onClick={onPop}>
{item}
</button>
</FilterNavigatorBarButton>
)}
</li>
</CSSTransition>
Expand Down
48 changes: 47 additions & 1 deletion src/test/components/FilterNavigatorBar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,59 @@
import * as React from 'react';
import { Provider } from 'react-redux';

import { render } from 'firefox-profiler/test/fixtures/testing-library';
import {
render,
fireEvent,
screen,
} from 'firefox-profiler/test/fixtures/testing-library';
import { FilterNavigatorBar } from 'firefox-profiler/components/shared/FilterNavigatorBar';
import { ProfileFilterNavigator } from '../../components/app/ProfileFilterNavigator';
import * as ProfileView from '../../actions/profile-view';
import * as ReceiveProfile from '../../actions/receive-profile';
import { storeWithProfile } from '../fixtures/stores';
import { getProfileFromTextSamples } from '../fixtures/profiles/processed-profile';

describe('shared/FilterNavigatorBar', () => {
it(`pops the item unless the last one is clicked`, () => {
const onPop = jest.fn();
render(
<FilterNavigatorBar
className=""
items={['foo', 'bar']}
selectedItem={2}
onPop={onPop}
/>
);

// We don't use getByRole because this isn't a button.
const lastElement = screen.getByText('bar');
fireEvent.click(lastElement);
expect(onPop).not.toHaveBeenCalled();

const firstElement = screen.getByRole('button', { name: 'foo' });
fireEvent.click(firstElement);
expect(onPop).toHaveBeenCalledWith(0);
});

it(`pops the last item if there's an uncommited item`, () => {
const onPop = jest.fn();
render(
<FilterNavigatorBar
className=""
items={['foo', 'bar']}
selectedItem={2}
uncommittedItem="baz"
onPop={onPop}
/>
);

// We don't use getByRole because this isn't a button.
const lastElement = screen.getByText('bar');
fireEvent.click(lastElement);
expect(onPop).toHaveBeenCalledWith(1);
});
});

describe('app/ProfileFilterNavigator', () => {
const tabID = 123123;
function setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ exports[`app/ProfileFilterNavigator renders ProfileFilterNavigator properly 1`]
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand All @@ -23,7 +22,6 @@ exports[`app/ProfileFilterNavigator renders ProfileFilterNavigator properly 2`]
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarBeforeSelectedItem"
data-index="0"
>
<button
class="filterNavigatorBarItemContent"
Expand All @@ -34,7 +32,6 @@ exports[`app/ProfileFilterNavigator renders ProfileFilterNavigator properly 2`]
</li>
<li
class="filterNavigatorBarItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem filterNavigatorBarTransition-enter filterNavigatorBarTransition-enter-active"
data-index="1"
>
<span
class="filterNavigatorBarItemContent"
Expand All @@ -51,7 +48,6 @@ exports[`app/ProfileFilterNavigator renders ProfileFilterNavigator properly 3`]
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarBeforeSelectedItem"
data-index="0"
>
<button
class="filterNavigatorBarItemContent"
Expand All @@ -62,13 +58,13 @@ exports[`app/ProfileFilterNavigator renders ProfileFilterNavigator properly 3`]
</li>
<li
class="filterNavigatorBarItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem filterNavigatorBarTransition-enter filterNavigatorBarTransition-enter-active"
data-index="1"
>
<span
<button
class="filterNavigatorBarItemContent"
type="button"
>
40ms
</span>
</button>
</li>
<li
class="filterNavigatorBarItem filterNavigatorBarLeafItem filterNavigatorBarUncommittedItem filterNavigatorBarUncommittedTransition-enter filterNavigatorBarUncommittedTransition-enter-active"
Expand All @@ -89,7 +85,6 @@ exports[`app/ProfileFilterNavigator renders the site hostname as its first eleme
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down
1 change: 0 additions & 1 deletion src/test/components/__snapshots__/FlameGraph.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ exports[`FlameGraph matches the snapshot 1`] = `
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down
21 changes: 0 additions & 21 deletions src/test/components/__snapshots__/ProfileCallTreeView.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ exports[`ProfileCallTreeView with JS Allocations matches the snapshot for JS all
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -806,7 +805,6 @@ exports[`ProfileCallTreeView with balanced native allocations matches the snapsh
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -1478,7 +1476,6 @@ exports[`ProfileCallTreeView with balanced native allocations matches the snapsh
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -2138,7 +2135,6 @@ exports[`ProfileCallTreeView with unbalanced native allocations matches the snap
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -2798,7 +2794,6 @@ exports[`ProfileCallTreeView with unbalanced native allocations matches the snap
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -3302,7 +3297,6 @@ exports[`calltree/ProfileCallTreeView EmptyReasons shows a reason for a call tre
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -3438,7 +3432,6 @@ exports[`calltree/ProfileCallTreeView EmptyReasons shows reasons for being out o
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -3574,7 +3567,6 @@ exports[`calltree/ProfileCallTreeView EmptyReasons shows reasons for when sample
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -3606,7 +3598,6 @@ exports[`calltree/ProfileCallTreeView TransformNavigator renders with multiple t
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem"
data-index="0"
>
<button
class="filterNavigatorBarItemContent"
Expand All @@ -3617,7 +3608,6 @@ exports[`calltree/ProfileCallTreeView TransformNavigator renders with multiple t
</li>
<li
class="filterNavigatorBarItem"
data-index="1"
>
<button
class="filterNavigatorBarItemContent"
Expand All @@ -3628,7 +3618,6 @@ exports[`calltree/ProfileCallTreeView TransformNavigator renders with multiple t
</li>
<li
class="filterNavigatorBarItem filterNavigatorBarBeforeSelectedItem"
data-index="2"
>
<button
class="filterNavigatorBarItemContent"
Expand All @@ -3639,7 +3628,6 @@ exports[`calltree/ProfileCallTreeView TransformNavigator renders with multiple t
</li>
<li
class="filterNavigatorBarItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="3"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -3761,7 +3749,6 @@ exports[`calltree/ProfileCallTreeView renders an inverted call tree 1`] = `
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -4388,7 +4375,6 @@ exports[`calltree/ProfileCallTreeView renders an unfiltered call tree 1`] = `
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -5015,7 +5001,6 @@ exports[`calltree/ProfileCallTreeView renders an unfiltered call tree with filen
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -5465,7 +5450,6 @@ exports[`calltree/ProfileCallTreeView renders call tree with some search strings
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -6092,7 +6076,6 @@ exports[`calltree/ProfileCallTreeView renders call tree with some search strings
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -6674,7 +6657,6 @@ exports[`calltree/ProfileCallTreeView renders call tree with some search strings
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -7256,7 +7238,6 @@ exports[`calltree/ProfileCallTreeView renders call tree with some search strings
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -7719,7 +7700,6 @@ exports[`calltree/ProfileCallTreeView renders call tree with some search strings
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -8182,7 +8162,6 @@ exports[`calltree/ProfileCallTreeView renders call tree with some search strings
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down
3 changes: 0 additions & 3 deletions src/test/components/__snapshots__/StackChart.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ exports[`CombinedChart renders combined stack chart 1`] = `
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -641,7 +640,6 @@ exports[`MarkerChart matches the snapshots for the component and draw log 1`] =
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down Expand Up @@ -1106,7 +1104,6 @@ exports[`StackChart matches the snapshot 1`] = `
>
<li
class="filterNavigatorBarItem filterNavigatorBarRootItem filterNavigatorBarSelectedItem filterNavigatorBarLeafItem"
data-index="0"
>
<span
class="filterNavigatorBarItemContent"
Expand Down