Skip to content

Commit

Permalink
Moved event logger handler up the stack.
Browse files Browse the repository at this point in the history
  • Loading branch information
3coins committed Oct 31, 2023
1 parent 867d2ea commit 03ad172
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
31 changes: 27 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const advancedOptions: JupyterFrontEndPlugin<Scheduler.IAdvancedOptions> = {
const telemetryHandler = async (
eventLog: Scheduler.IEventLog
): Promise<void> => {
console.log(JSON.stringify(eventLog, undefined, 4));
// console.log(JSON.stringify(eventLog, undefined, 4));
};

const telemetry: JupyterFrontEndPlugin<Scheduler.TelemetryHandler> = {
Expand Down Expand Up @@ -182,13 +182,26 @@ async function activatePlugin(
let mainAreaWidget: MainAreaWidget<NotebookJobsPanel> | undefined;
let jobsPanel: NotebookJobsPanel | undefined;

const eventLogger: Scheduler.EventLogger = (eventName) => {
if (!eventName) {
return;
}
const eventLog = {
body: {
name: `org.jupyter.jupyter-scheduler.${eventName}`
},
timestamp: new Date()
};
telemetryHandler(eventLog).then();
}

const showJobsPanel = async (data: IJobsModel) => {
if (!mainAreaWidget || mainAreaWidget.isDisposed) {
// Create new jobs panel widget
jobsPanel = new NotebookJobsPanel({
app,
translator,
telemetryHandler,
eventLogger,
advancedOptions: advancedOptions
});
// Create new main area widget
Expand Down Expand Up @@ -223,13 +236,19 @@ async function activatePlugin(
// Commands

commands.addCommand(CommandIDs.showNotebookJobs, {
execute: async args => showJobsPanel(args as IJobsModel),
execute: async args => {
if(args['launcher']){
eventLogger("launcher.show-jobs")
}
showJobsPanel(args as IJobsModel)
},
label: trans.__('Notebook Jobs'),
icon: eventNoteIcon
});

commands.addCommand(CommandIDs.createJobFileBrowser, {
execute: async () => {
eventLogger("file-browser.create-job");
const widget = fileBrowserTracker.currentWidget;
const filePath = getSelectedFilePath(widget) ?? '';

Expand All @@ -252,6 +271,7 @@ async function activatePlugin(

commands.addCommand(CommandIDs.createJobCurrentNotebook, {
execute: async () => {
eventLogger("notebook-header.create-job");
// Get the current notebook's name and path
const contentsModel =
notebookTracker.currentWidget?.context?.contentsModel;
Expand Down Expand Up @@ -302,7 +322,10 @@ async function activatePlugin(
// Add to launcher
if (launcher) {
launcher.add({
command: CommandIDs.showNotebookJobs
command: CommandIDs.showNotebookJobs,
args: {
launcher: true
}
});
}
}
Expand Down
20 changes: 4 additions & 16 deletions src/notebook-jobs-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class NotebookJobsPanel extends VDomRenderer<JobsModel> {
readonly _translator: ITranslator;
readonly _trans: TranslationBundle;
readonly _advancedOptions: React.FunctionComponent<Scheduler.IAdvancedOptionsProps>;
readonly _telemetryHandler: Scheduler.TelemetryHandler;
readonly _eventLogger: Scheduler.EventLogger;
private _newlyCreatedId: string | undefined;
private _newlyCreatedName: string | undefined;
private _last_input_drop_target: Element | null;
Expand All @@ -68,7 +68,7 @@ export class NotebookJobsPanel extends VDomRenderer<JobsModel> {
this._translator = options.translator;
this._trans = this._translator.load('jupyterlab');
this._advancedOptions = options.advancedOptions;
this._telemetryHandler = options.telemetryHandler;
this._eventLogger = options.eventLogger;
this._last_input_drop_target = null;

this.node.setAttribute('role', 'region');
Expand Down Expand Up @@ -124,18 +124,6 @@ export class NotebookJobsPanel extends VDomRenderer<JobsModel> {
}
};

logEvent(eventName: string): void {
if (!eventName) {
return;
}
const eventLog = {
body: {
name: `org.jupyter.jupyter-scheduler.${eventName}`
},
timestamp: new Date()
};
this._telemetryHandler(eventLog).then();
}

/**
* Handle the DOM events for the directory listing.
Expand Down Expand Up @@ -235,7 +223,7 @@ export class NotebookJobsPanel extends VDomRenderer<JobsModel> {
return (
<ThemeProvider theme={getJupyterLabTheme()}>
<TranslatorContext.Provider value={this._translator}>
<LogContext.Provider value={this.logEvent.bind(this)}>
<LogContext.Provider value={this._eventLogger.bind(this)}>
<ErrorBoundary
alertTitle={this._trans.__('Internal error')}
alertMessage={this._trans.__(
Expand Down Expand Up @@ -325,7 +313,7 @@ namespace NotebookJobsPanel {
app: JupyterFrontEnd;
translator: ITranslator;
advancedOptions: Scheduler.IAdvancedOptions;
telemetryHandler: Scheduler.TelemetryHandler;
eventLogger: Scheduler.EventLogger;
model?: JobsModel;
}
}
2 changes: 2 additions & 0 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ export namespace Scheduler {
export const TelemetryHandler = new Token<TelemetryHandler>(
'@jupyterlab/scheduler:ITelemetryHandler'
);

export type EventLogger = (eventName: string) => void;
}

0 comments on commit 03ad172

Please sign in to comment.