From 9ff766e81b6786eda15d7408fe5dee084213a48f Mon Sep 17 00:00:00 2001 From: Alexander Timin Date: Thu, 12 Oct 2023 14:18:10 -0700 Subject: [PATCH] Unify getTrackShellButtons and getContextMenu. There is no need to have both and current approach has limitations: e.g. context menu is always going to be the last button, and not being able to add more buttons with context menus. Allow getTrackShellButtons to return any mithril vnode instead of requiring TrackButtonAttrs and fold getContextMenu into it. Change-Id: Ib8337260b44d3b4928574a2b6c63eee86f75c026 --- ui/src/common/basic_async_track.ts | 7 +------ ui/src/common/track_adapter.ts | 2 +- ui/src/frontend/base_counter_track.ts | 8 +++++++- ui/src/frontend/track.ts | 7 +------ ui/src/frontend/track_panel.ts | 1 - ui/src/public/index.ts | 4 +--- ui/src/tracks/counter/index.ts | 6 +++--- ui/src/tracks/debug/counter_track.ts | 23 +++++++++++++---------- ui/src/tracks/debug/slice_track.ts | 4 ++-- ui/src/tracks/visualised_args/index.ts | 2 +- 10 files changed, 30 insertions(+), 34 deletions(-) diff --git a/ui/src/common/basic_async_track.ts b/ui/src/common/basic_async_track.ts index 2faf829235..2f62dc64f9 100644 --- a/ui/src/common/basic_async_track.ts +++ b/ui/src/common/basic_async_track.ts @@ -19,7 +19,6 @@ import {raf} from '../core/raf_scheduler'; import {globals} from '../frontend/globals'; import {PxSpan, TimeScale} from '../frontend/time_scale'; import {SliceRect} from '../frontend/track'; -import {TrackButtonAttrs} from '../frontend/track_panel'; import {Track} from '../public'; import {TrackData} from './track_data'; @@ -67,14 +66,10 @@ export abstract class BasicAsyncTrack implements Track { abstract getHeight(): number; - getTrackShellButtons(): m.Vnode[] { + getTrackShellButtons(): m.Children { return []; } - getContextMenu(): m.Vnode|null { - return null; - } - onMouseMove(_position: {x: number; y: number;}): void {} onMouseClick(_position: {x: number; y: number;}): boolean { diff --git a/ui/src/common/track_adapter.ts b/ui/src/common/track_adapter.ts index 1c145d3df8..ba7b31c4eb 100644 --- a/ui/src/common/track_adapter.ts +++ b/ui/src/common/track_adapter.ts @@ -76,7 +76,7 @@ export class TrackWithControllerAdapter extends return this.track.getHeight(); } - getTrackShellButtons(): m.Vnode[] { + getTrackShellButtons(): m.Children { return this.track.getTrackShellButtons(); } diff --git a/ui/src/frontend/base_counter_track.ts b/ui/src/frontend/base_counter_track.ts index 66e221c68d..e6897ca990 100644 --- a/ui/src/frontend/base_counter_track.ts +++ b/ui/src/frontend/base_counter_track.ts @@ -121,7 +121,7 @@ export abstract class BaseCounterTrack extends TrackBase { }); } - getContextMenu(): m.Vnode { + getCounterContextMenu(): m.Child { return m( PopupMenu2, { @@ -131,6 +131,12 @@ export abstract class BaseCounterTrack extends TrackBase { ); } + getTrackShellButtons(): m.Children { + return [ + this.getCounterContextMenu(), + ]; + } + renderCanvas(ctx: CanvasRenderingContext2D) { const { visibleTimeScale: timeScale, diff --git a/ui/src/frontend/track.ts b/ui/src/frontend/track.ts index 6ddbc51ed2..7f01eddf62 100644 --- a/ui/src/frontend/track.ts +++ b/ui/src/frontend/track.ts @@ -24,7 +24,6 @@ import {Track} from '../public'; import {checkerboard} from './checkerboard'; import {globals} from './globals'; import {PxSpan, TimeScale} from './time_scale'; -import {TrackButtonAttrs} from './track_panel'; // Args passed to the track constructors when creating a new track. export interface NewTrackArgs { @@ -113,14 +112,10 @@ export abstract class TrackBase return 40; } - getTrackShellButtons(): Array> { + getTrackShellButtons(): m.Children { return []; } - getContextMenu(): m.Vnode|null { - return null; - } - onMouseMove(_position: {x: number, y: number}) {} // Returns whether the mouse click has selected something. diff --git a/ui/src/frontend/track_panel.ts b/ui/src/frontend/track_panel.ts index c280ced40a..6cbfb03472 100644 --- a/ui/src/frontend/track_panel.ts +++ b/ui/src/frontend/track_panel.ts @@ -152,7 +152,6 @@ class TrackShell implements m.ClassComponent { ), m('.track-buttons', attrs.track.getTrackShellButtons(), - attrs.track.getContextMenu(), m(TrackButton, { action: () => { globals.dispatch( diff --git a/ui/src/public/index.ts b/ui/src/public/index.ts index 283449df1c..eb87a3a1fd 100644 --- a/ui/src/public/index.ts +++ b/ui/src/public/index.ts @@ -21,7 +21,6 @@ import {TrackControllerFactory} from '../controller/track_controller'; import {Store} from '../frontend/store'; import {PxSpan, TimeScale} from '../frontend/time_scale'; import {SliceRect, TrackCreator} from '../frontend/track'; -import {TrackButtonAttrs} from '../frontend/track_panel'; export {EngineProxy} from '../common/engine'; export { @@ -196,8 +195,7 @@ export interface Track { windowSpan: PxSpan, tStart: time, tEnd: time, depth: number): SliceRect |undefined; getHeight(): number; - getTrackShellButtons(): Array>; - getContextMenu(): m.Vnode|null; + getTrackShellButtons(): m.Children; onMouseMove(position: {x: number, y: number}): void; onMouseClick(position: {x: number, y: number}): boolean; onMouseOut(): void; diff --git a/ui/src/tracks/counter/index.ts b/ui/src/tracks/counter/index.ts index 1fbc53f6b3..c963d3b67f 100644 --- a/ui/src/tracks/counter/index.ts +++ b/ui/src/tracks/counter/index.ts @@ -318,7 +318,7 @@ export class CounterTrack extends BasicAsyncTrack { return MARGIN_TOP + RECT_HEIGHT; } - getContextMenu(): m.Vnode { + getTrackShellButtons(): m.Children { const currentScale = this.store.state.scale; const scales: {name: CounterScaleOptions, humanName: string}[] = [ {name: 'ZERO_BASED', humanName: 'Zero based'}, @@ -338,13 +338,13 @@ export class CounterTrack extends BasicAsyncTrack { }); }); - return m( + return [m( PopupMenu2, { trigger: m(Button, {icon: 'show_chart', minimal: true}), }, menuItems, - ); + )]; } renderCanvas(ctx: CanvasRenderingContext2D): void { diff --git a/ui/src/tracks/debug/counter_track.ts b/ui/src/tracks/debug/counter_track.ts index 4879f270df..3ab87819fd 100644 --- a/ui/src/tracks/debug/counter_track.ts +++ b/ui/src/tracks/debug/counter_track.ts @@ -19,7 +19,7 @@ import {EngineProxy} from '../../common/engine'; import {BaseCounterTrack} from '../../frontend/base_counter_track'; import {globals} from '../../frontend/globals'; import {NewTrackArgs} from '../../frontend/track'; -import {TrackButton, TrackButtonAttrs} from '../../frontend/track_panel'; +import {TrackButton} from '../../frontend/track_panel'; // Names of the columns of the underlying view to be used as ts / dur / name. export interface CounterColumns { @@ -44,15 +44,18 @@ export class DebugCounterTrack extends super(args); } - getTrackShellButtons(): Array> { - return [m(TrackButton, { - action: () => { - globals.dispatch(Actions.removeDebugTrack({trackId: this.trackId})); - }, - i: 'close', - tooltip: 'Close', - showButton: true, - })]; + getTrackShellButtons(): m.Children { + return [ + this.getCounterContextMenu(), + m(TrackButton, { + action: () => { + globals.dispatch(Actions.removeDebugTrack({trackId: this.trackId})); + }, + i: 'close', + tooltip: 'Close', + showButton: true, + }), + ]; } async initSqlTable(tableName: string): Promise { diff --git a/ui/src/tracks/debug/slice_track.ts b/ui/src/tracks/debug/slice_track.ts index 3b18788f9d..93f7e3d703 100644 --- a/ui/src/tracks/debug/slice_track.ts +++ b/ui/src/tracks/debug/slice_track.ts @@ -21,7 +21,7 @@ import { NamedSliceTrackTypes, } from '../../frontend/named_slice_track'; import {NewTrackArgs} from '../../frontend/track'; -import {TrackButton, TrackButtonAttrs} from '../../frontend/track_panel'; +import {TrackButton} from '../../frontend/track_panel'; import { CustomSqlDetailsPanelConfig, CustomSqlTableDefConfig, @@ -78,7 +78,7 @@ export class DebugTrackV2 extends CustomSqlTableSliceTrack { super.initSqlTable(tableName); } - getTrackShellButtons(): Array> { + getTrackShellButtons(): m.Children { return [m(TrackButton, { action: () => { globals.dispatch(Actions.removeDebugTrack({trackId: this.trackId})); diff --git a/ui/src/tracks/visualised_args/index.ts b/ui/src/tracks/visualised_args/index.ts index 3385bf9f5f..2c5610a6c1 100644 --- a/ui/src/tracks/visualised_args/index.ts +++ b/ui/src/tracks/visualised_args/index.ts @@ -49,7 +49,7 @@ export class VisualisedArgsTrack extends ChromeSliceTrack { return 'italic 11px Roboto'; } - getTrackShellButtons(): Array> { + getTrackShellButtons(): m.Children { const config = this.config as Config; const buttons: Array> = []; buttons.push(m(TrackButton, {