-
Notifications
You must be signed in to change notification settings - Fork 131
Track metrics view explicitly so the segment indicator stays in sync #6463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Karakatiza666
wants to merge
3
commits into
main
Choose a base branch
from
issue-segment-indicator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
c295e39
[web-console] Track metrics view explicitly so the segment indicator …
Karakatiza666 2e411b1
[profiler-lib] Expose nodeId as a node attribute, export root node na…
Karakatiza666 251499f
[profiler-lib] Determine root node id dynamically instead of assuming…
Karakatiza666 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
36 changes: 36 additions & 0 deletions
36
js-packages/profiler-layout/src/lib/functions/metricsMode.test.ts
This file contains hidden or 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,36 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { type AnalysisView, isNodeView, metricsModeOf } from './metricsMode.js' | ||
|
|
||
| describe('metricsModeOf', () => { | ||
| it("returns 'overview' and 'top-nodes' unchanged", () => { | ||
| expect(metricsModeOf('overview')).toBe('overview') | ||
| expect(metricsModeOf('top-nodes')).toBe('top-nodes') | ||
| }) | ||
|
|
||
| it("maps any `{ node }` to 'node' regardless of the operator id", () => { | ||
| expect(metricsModeOf({ node: '42' })).toBe('node') | ||
| expect(metricsModeOf({ node: 'persistent-id-xyz' })).toBe('node') | ||
| }) | ||
|
|
||
| // Regression for the old title-based guess: the mode used to be inferred from | ||
| // `tooltipData.title === 'n region'`, so any profile whose root id wasn't `n` kept showing | ||
| // "Node" by mistake. Reading the mode straight from the `AnalysisView` removes that guesswork. | ||
| it('reads the mode from the `AnalysisView` for any root id', () => { | ||
| const seq: AnalysisView[] = ['overview', { node: 'root-42' }, 'top-nodes', 'overview'] | ||
| expect(seq.map(metricsModeOf)).toEqual(['overview', 'node', 'top-nodes', 'overview']) | ||
| }) | ||
| }) | ||
|
|
||
| describe('isNodeView', () => { | ||
| it('narrows to `{ node }` and returns false for string variants', () => { | ||
| const v: AnalysisView = { node: 'op-7' } | ||
| if (isNodeView(v)) { | ||
| expect(v.node).toBe('op-7') | ||
| } else { | ||
| throw new Error('expected isNodeView to narrow') | ||
| } | ||
| expect(isNodeView('overview')).toBe(false) | ||
| expect(isNodeView('top-nodes')).toBe(false) | ||
| expect(isNodeView(null)).toBe(false) | ||
| }) | ||
| }) |
18 changes: 18 additions & 0 deletions
18
js-packages/profiler-layout/src/lib/functions/metricsMode.ts
This file contains hidden or 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,18 @@ | ||
| // Describes which view the analysis panel is showing, so the segmented control stays in sync | ||
| // with what the diagram displays. | ||
|
|
||
| import type { MetricsMode } from '../components/MetricsView.svelte' | ||
|
|
||
| /** Which view the analysis panel is currently showing: the whole-circuit overview, the ranked | ||
| * top nodes, or a single operator's metrics. When one operator is selected, its id is stored so the | ||
| * panel can return to that same operator later. */ | ||
| export type AnalysisView = 'overview' | 'top-nodes' | { node: string } | ||
|
|
||
| export function metricsModeOf(view: AnalysisView): MetricsMode { | ||
| return typeof view === 'string' ? view : 'node' | ||
| } | ||
|
|
||
| /** Accepts `null` so "is there a node to restore?" is a single call. */ | ||
| export function isNodeView(view: AnalysisView | null): view is { node: string } { | ||
| return view !== null && typeof view === 'object' | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this commend makes no sense in this context. What is "restore?"