Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ui/src/common/plugin_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {TrackControllerFactory} from '../controller/track_controller';
import {TrackCreator} from '../frontend/track';
import {Selection} from './state';
import {CustomButtonArgs} from '../frontend/button_registry';
import {AnyAttrsVnode} from '../frontend/panel_container';

export {EngineProxy} from '../common/engine';
export {
Expand Down Expand Up @@ -116,6 +117,14 @@ export interface PluginContext {
onDetailsPanelSelectionChange: (newSelection?: Selection) => void): void;
// Register a custom button on the timeline
registerCustomButton(button: CustomButtonArgs): void;

detailsPanelRenderOverride(
onDetailsPanelRender:
(detailsPanels: {
key: string;
name: string;
vnode: AnyAttrsVnode;
}[]) => void): void;
}

export interface PluginInfo {
Expand Down
27 changes: 27 additions & 0 deletions ui/src/common/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,29 @@ import {
import {Registry} from './registry';
import {Selection} from './state';
import {CustomButton, CustomButtonArgs, customButtonRegistry} from '../frontend/button_registry';
import {AnyAttrsVnode} from 'src/frontend/panel_container';

// Every plugin gets its own PluginContext. This is how we keep track
// what each plugin is doing and how we can blame issues on particular
// plugins.
export class PluginContextImpl implements PluginContext {
readonly pluginId: string;
onDetailsPanelSelectionChange?: (newSelection?: Selection) => void;
onDetailsPanelRender?:
(detailsPanels:
{ key: string; name: string; vnode: AnyAttrsVnode; }[]) => void;
private trackProviders: TrackProvider[];

constructor(pluginId: string) {
this.pluginId = pluginId;
this.trackProviders = [];
}
detailsPanelRenderOverride(
onDetailsPanelHijack: (detailsPanels:
{ key: string; name: string; vnode: AnyAttrsVnode; }[]
) => void): void {
this.onDetailsPanelRender = onDetailsPanelHijack;
}

// ==================================================================
// The plugin facing API of PluginContext:
Expand Down Expand Up @@ -148,6 +158,23 @@ export class PluginManager {
pluginContext.onDetailsPanelSelectionChange(newSelection);
}
}

isDetailsPanelRenderOverride(): boolean {
const overrides = Array.from(this.contexts.values()).filter((context)=>{
return !!context.onDetailsPanelRender;
});
return overrides.length>0;
}

onDetailsPanelRender(detailsPanel?:
{ key: string; name: string; vnode: AnyAttrsVnode; }[]) {
this.contexts.forEach((context)=>{
if (context === undefined) return;
if (context.onDetailsPanelRender) {
context.onDetailsPanelRender(detailsPanel || []);
}
});
}
}

// TODO(hjd): Sort out the story for global singletons like these:
Expand Down
9 changes: 6 additions & 3 deletions ui/src/frontend/details_panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ function getDetailsHeight() {
}

function getFullScreenHeight(dom?: Element) {
for(const selector of globals.frontendLocalState.detailsFullScreenSelectors) {
for (const selector of globals.frontendLocalState.detailsFullScreenSelectors) {
const element = dom?.closest(selector) || document.querySelector(selector);
if(element != null) {
if (element != null) {
return element.clientHeight;
}
}
Expand Down Expand Up @@ -393,7 +393,10 @@ export class DetailsPanel implements m.ClassComponent {

const panel = currentTabDetails?.vnode;
const panels = panel ? [panel] : [];

if (pluginManager.isDetailsPanelRenderOverride()) {
pluginManager.onDetailsPanelRender(detailsPanels);
return;
}
return m(
'.details-content',
{
Expand Down