Skip to content

Commit

Permalink
[ui] Clean up getTrackShellButtons().
Browse files Browse the repository at this point in the history
- Since `getTrackShellButtons()` now returns `m.Children`, we can
  simplify the return values in a few places.
- Also, removed getContextMenu() from TrackAdapter and
  TrackWithControllerAdapter.

Change-Id: I01669341253c8a298d8a494cea47d91a6050abdf
  • Loading branch information
stevegolton committed Oct 16, 2023
1 parent b5a3d01 commit dfcc389
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 22 deletions.
11 changes: 1 addition & 10 deletions ui/src/common/track_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {duration, Span, time} from '../base/time';
import {EngineProxy} from '../common/engine';
import {PxSpan, TimeScale} from '../frontend/time_scale';
import {NewTrackArgs, SliceRect} from '../frontend/track';
import {TrackButtonAttrs} from '../frontend/track_panel';

import {BasicAsyncTrack} from './basic_async_track';

Expand Down Expand Up @@ -80,10 +79,6 @@ export class TrackWithControllerAdapter<Config, Data> extends
return this.track.getTrackShellButtons();
}

getContextMenu(): m.Vnode<any, {}>|null {
return this.track.getContextMenu();
}

onMouseMove(position: {x: number; y: number;}): void {
this.track.onMouseMove(position);
}
Expand Down Expand Up @@ -155,14 +150,10 @@ export abstract class TrackAdapter<Config, Data> {
return 40;
}

getTrackShellButtons(): Array<m.Vnode<TrackButtonAttrs>> {
getTrackShellButtons(): m.Children {
return [];
}

getContextMenu(): m.Vnode<any>|null {
return null;
}

onMouseMove(_position: {x: number, y: number}) {}

// Returns whether the mouse click has selected something.
Expand Down
4 changes: 1 addition & 3 deletions ui/src/frontend/base_counter_track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ export abstract class BaseCounterTrack<Config> extends TrackBase<Config> {
}

getTrackShellButtons(): m.Children {
return [
this.getCounterContextMenu(),
];
return this.getCounterContextMenu();
}

renderCanvas(ctx: CanvasRenderingContext2D) {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/tracks/counter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,13 @@ export class CounterTrack extends BasicAsyncTrack<Data> {
});
});

return [m(
return m(
PopupMenu2,
{
trigger: m(Button, {icon: 'show_chart', minimal: true}),
},
menuItems,
)];
);
}

renderCanvas(ctx: CanvasRenderingContext2D): void {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/tracks/debug/slice_track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ export class DebugTrackV2 extends CustomSqlTableSliceTrack<DebugTrackV2Types> {
}

getTrackShellButtons(): m.Children {
return [m(TrackButton, {
return m(TrackButton, {
action: () => {
globals.dispatch(Actions.removeDebugTrack({trackId: this.trackId}));
},
i: 'close',
tooltip: 'Close',
showButton: true,
})];
});
}
}

Expand Down
8 changes: 3 additions & 5 deletions ui/src/tracks/visualised_args/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import m from 'mithril';
import {Actions} from '../../common/actions';
import {globals} from '../../frontend/globals';
import {NewTrackArgs, TrackBase} from '../../frontend/track';
import {TrackButton, TrackButtonAttrs} from '../../frontend/track_panel';
import {TrackButton} from '../../frontend/track_panel';
import {Plugin, PluginContext, PluginDescriptor} from '../../public';
import {
ChromeSliceTrack,
Expand Down Expand Up @@ -51,17 +51,15 @@ export class VisualisedArgsTrack extends ChromeSliceTrack {

getTrackShellButtons(): m.Children {
const config = this.config as Config;
const buttons: Array<m.Vnode<TrackButtonAttrs>> = [];
buttons.push(m(TrackButton, {
return m(TrackButton, {
action: () => {
globals.dispatch(
Actions.removeVisualisedArg({argName: config.argName}));
},
i: 'close',
tooltip: 'Close',
showButton: true,
}));
return buttons;
});
}
}

Expand Down

0 comments on commit dfcc389

Please sign in to comment.