forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the getVisibleTabs selector to the threadSelectors so that we ca…
…n compute it for any thread (Merge PR firefox-devtools#2111)
- Loading branch information
Showing
7 changed files
with
148 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
// @flow | ||
import { createSelector } from 'reselect'; | ||
|
||
import { tabSlugs, type TabSlug } from '../../app-logic/tabs-handling'; | ||
|
||
import type { Selector } from '../../types/store'; | ||
import type { $ReturnType } from '../../types/utils'; | ||
import type { Thread, JsTracerTable } from '../../types/profile'; | ||
|
||
/** | ||
* Infer the return type from the getStackAndSampleSelectorsPerThread function. This | ||
* is done that so that the local type definition with `Selector<T>` is the canonical | ||
* definition for the type of the selector. | ||
*/ | ||
export type ComposedSelectorsPerThread = $ReturnType< | ||
typeof getComposedSelectorsPerThread | ||
>; | ||
|
||
/** | ||
* This type contains the selectors needed for the extra selectors defined in | ||
* this file. It's non-exact because the passed object _will_ contain more | ||
* elements that we don't use here, and that's OK. | ||
*/ | ||
type NeededThreadSelectors = { | ||
getThread: Selector<Thread>, | ||
getIsNetworkChartEmptyInFullRange: Selector<boolean>, | ||
getJsTracerTable: Selector<JsTracerTable | null>, | ||
}; | ||
|
||
/** | ||
* Create the selectors for a thread that have to do with either stacks or samples. | ||
*/ | ||
export function getComposedSelectorsPerThread( | ||
threadSelectors: NeededThreadSelectors | ||
): * { | ||
/** | ||
* Visible tabs are computed based on the current state of the profile. Some | ||
* effort is made to not show a tab when there is no data available for it or | ||
* when it's absurd. | ||
*/ | ||
const getUsefulTabs: Selector<$ReadOnlyArray<TabSlug>> = createSelector( | ||
threadSelectors.getIsNetworkChartEmptyInFullRange, | ||
threadSelectors.getJsTracerTable, | ||
(isNetworkChartEmpty, jsTracerTable) => { | ||
let visibleTabs = tabSlugs; | ||
if (isNetworkChartEmpty) { | ||
visibleTabs = visibleTabs.filter( | ||
tabSlug => tabSlug !== 'network-chart' | ||
); | ||
} | ||
if (!jsTracerTable) { | ||
visibleTabs = visibleTabs.filter(tabSlug => tabSlug !== 'js-tracer'); | ||
} | ||
return visibleTabs; | ||
} | ||
); | ||
|
||
return { | ||
getUsefulTabs, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
// @flow | ||
|
||
import { selectedThreadSelectors } from '../../selectors/per-thread'; | ||
|
||
import { storeWithProfile } from '../fixtures/stores'; | ||
import { | ||
getProfileFromTextSamples, | ||
getProfileWithMarkers, | ||
getNetworkMarkers, | ||
getProfileWithJsTracerEvents, | ||
} from '../fixtures/profiles/processed-profile'; | ||
|
||
describe('getUsefulTabs', function() { | ||
it('hides the network chart and JS tracer when no data is in the thread', function() { | ||
const { profile } = getProfileFromTextSamples('A'); | ||
const { getState } = storeWithProfile(profile); | ||
expect(selectedThreadSelectors.getUsefulTabs(getState())).toEqual([ | ||
'calltree', | ||
'flame-graph', | ||
'stack-chart', | ||
'marker-chart', | ||
'marker-table', | ||
]); | ||
}); | ||
|
||
it('shows the network chart when network markers are present in the thread', function() { | ||
const profile = getProfileWithMarkers(getNetworkMarkers()); | ||
const { getState } = storeWithProfile(profile); | ||
expect(selectedThreadSelectors.getUsefulTabs(getState())).toEqual([ | ||
'calltree', | ||
'flame-graph', | ||
'stack-chart', | ||
'marker-chart', | ||
'marker-table', | ||
'network-chart', | ||
]); | ||
}); | ||
|
||
it('shows the js tracer when it is available in a thread', function() { | ||
const profile = getProfileWithJsTracerEvents([['A', 0, 10]]); | ||
const { getState } = storeWithProfile(profile); | ||
expect(selectedThreadSelectors.getUsefulTabs(getState())).toEqual([ | ||
'calltree', | ||
'flame-graph', | ||
'stack-chart', | ||
'marker-chart', | ||
'marker-table', | ||
'js-tracer', | ||
]); | ||
}); | ||
}); |