Skip to content

Commit

Permalink
Merge "ui: Add discriminating type to {,Legacy}DetailsPanel" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
primiano authored and Gerrit Code Review committed Sep 23, 2024
2 parents f0d6bcb + f79657e commit f1480b4
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 5 deletions.
12 changes: 9 additions & 3 deletions ui/src/core/app_trace_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {TimeSpan} from '../base/time';
import {TimelineImpl} from '../core/timeline';
import {App} from '../public/app';
import {Command} from '../public/command';
import {LegacyDetailsPanel} from '../public/details_panel';
import {DetailsPanel, LegacyDetailsPanel} from '../public/details_panel';
import {Trace} from '../public/trace';
import {setScrollToFunction} from '../public/scroll_helper';
import {ScrollToArgs} from 'src/public/scroll_helper';
Expand Down Expand Up @@ -304,8 +304,14 @@ export class TraceImpl implements Trace {
return new TraceImpl(this.appImpl.forkForPlugin(pluginId), this.traceCtx);
}

registerDetailsPanel(detailsPanel: LegacyDetailsPanel): Disposable {
return this.traceCtx.tabMgr.registerLegacyDetailsPanel(detailsPanel);
registerDetailsPanel(
detailsPanel: DetailsPanel | LegacyDetailsPanel,
): Disposable {
if (detailsPanel.panelType === 'LegacyDetailsPanel') {
return this.traceCtx.tabMgr.registerLegacyDetailsPanel(detailsPanel);
} else {
return this.traceCtx.tabMgr.registerDetailsPanel(detailsPanel);
}
}

// TODO(primiano): there are two things here:
Expand Down
1 change: 1 addition & 0 deletions ui/src/core_plugins/cpu_profile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class CpuProfile implements PerfettoPlugin {
}

class CpuProfileSampleFlamegraphDetailsPanel implements LegacyDetailsPanel {
readonly panelType = 'LegacyDetailsPanel';
private sel?: CpuProfileSampleSelection;
private selMonitor = new Monitor([() => this.sel?.ts, () => this.sel?.utid]);
private flamegraphAttrs?: QueryFlamegraphAttrs;
Expand Down
1 change: 1 addition & 0 deletions ui/src/core_plugins/heap_profile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class HeapProfilePlugin implements PerfettoPlugin {
}

class HeapProfileFlamegraphDetailsPanel implements LegacyDetailsPanel {
readonly panelType = 'LegacyDetailsPanel';
private sel?: HeapProfileSelection;
private selMonitor = new Monitor([
() => this.sel?.ts,
Expand Down
1 change: 1 addition & 0 deletions ui/src/core_plugins/perf_samples_profile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class PerfSamplesProfilePlugin implements PerfettoPlugin {
}

class PerfSamplesFlamegraphDetailsPanel implements LegacyDetailsPanel {
readonly panelType = 'LegacyDetailsPanel';
private sel?: PerfSamplesSelection;
private selMonitor = new Monitor([
() => this.sel?.leftTs,
Expand Down
1 change: 1 addition & 0 deletions ui/src/frontend/aggregation_tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ export class AggregationsTabs implements Disposable {

constructor() {
const unregister = globals.tabManager.registerDetailsPanel({
panelType: 'DetailsPanel',
render(selection) {
if (selection.kind === 'area') {
return m(AreaDetailsPanel);
Expand Down
2 changes: 2 additions & 0 deletions ui/src/frontend/notes_panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ export class NotesPanel implements Panel {
}

export class NotesEditorTab implements DetailsPanel {
readonly panelType = 'DetailsPanel';

render(selection: Selection) {
if (selection.kind !== 'note') {
return undefined;
Expand Down
2 changes: 2 additions & 0 deletions ui/src/public/details_panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import m from 'mithril';
import {LegacySelection, Selection} from './selection';

export interface LegacyDetailsPanel {
readonly panelType: 'LegacyDetailsPanel';
render(selection: LegacySelection): m.Children;
isLoading?(): boolean;
}

export interface DetailsPanel {
readonly panelType: 'DetailsPanel';
render(selection: Selection): m.Children;
isLoading?(): boolean;
}
Expand Down
4 changes: 2 additions & 2 deletions ui/src/public/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {TabManager} from './tab';
import {TrackManager} from './track';
import {Timeline} from './timeline';
import {Workspace, WorkspaceManager} from './workspace';
import {LegacyDetailsPanel} from './details_panel';
import {DetailsPanel, LegacyDetailsPanel} from './details_panel';
import {SelectionManager} from './selection';
import {ScrollToArgs} from './scroll_helper';

Expand Down Expand Up @@ -50,7 +50,7 @@ export interface Trace extends App {
// gone. This method is particularly problematic because the method called
// registerDetailsPanel in TabManagerImpl takes a non-Legacy DetailsPanel, but
// all plugins use a Legacy one. Keeping this as a bridge for now.
registerDetailsPanel(detailsPanel: LegacyDetailsPanel): void;
registerDetailsPanel(detailsPanel: DetailsPanel | LegacyDetailsPanel): void;

// Creates and shows a tab with a tabular result for the given query.
// TODO(primiano): I am not convinced this belongs here, this should probably
Expand Down
1 change: 1 addition & 0 deletions ui/src/public/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export interface BottomTabAdapterAttrs {
})
*/
export class BottomTabToSCSAdapter implements LegacyDetailsPanel {
readonly panelType = 'LegacyDetailsPanel';
private oldSelection?: LegacySelection;
private bottomTab?: BottomTab;
private attrs: BottomTabAdapterAttrs;
Expand Down

0 comments on commit f1480b4

Please sign in to comment.