Skip to content
Open
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
74 changes: 74 additions & 0 deletions src/helpers/notificationAugmentor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Notification, showDialog, Dialog } from '@jupyterlab/apputils';
import { Widget } from '@lumino/widgets';

const MAX_VISIBLE_CHARS = 140;
const VIEW_DETAILS_LABEL = 'View details';

function toPlainText(value: unknown): string {
try {
return typeof value === 'string' ? value : JSON.stringify(value, null, 2);
} catch {
return String(value ?? '');
}
}

function createViewDetailsAction(fullMessage: string, dialogTitle = 'Details'): Notification.IAction {
return {
label: VIEW_DETAILS_LABEL,
caption: 'Show full message',
callback: async () => {
const dialogBody = new Widget();
dialogBody.addClass('xircuits-notification-details');

const pre = document.createElement('pre');
pre.textContent = fullMessage;
dialogBody.node.appendChild(pre);

const copyButton = Dialog.createButton({ label: 'Copy' });
const closeButton = Dialog.okButton({ label: 'Close' });

const result = await showDialog({
title: dialogTitle,
body: dialogBody,
buttons: [copyButton, closeButton]
});

if (result.button.label === 'Copy') {
await navigator.clipboard.writeText(fullMessage);
}
}
};
}

function ensureViewDetailsAction(
messageText: string,
options: any = {},
title?: string
): any {
if (messageText.length <= MAX_VISIBLE_CHARS) return options;
const actions = [...(options.actions ?? [])];
if (!actions.some((a: any) => a?.label === VIEW_DETAILS_LABEL)) {
actions.push(createViewDetailsAction(messageText, title));
}
return { ...options, actions };
}

export function augmentNotifications(): void {
const NotificationObj: any = Notification as any;
if (NotificationObj.__xircuitsAugmented) return;

const wrap = (method: 'error' | 'warning' | 'info' | 'success') => {
const original = NotificationObj[method]?.bind(Notification);
if (!original) return;

NotificationObj[method] = (...args: any[]) => {
const [rawMessage, rawOptions] = args;
const text = toPlainText(rawMessage);
const options = ensureViewDetailsAction(text, rawOptions);
return original(text, options);
};
};

['error', 'warning', 'info', 'success'].forEach(wrap);
NotificationObj.__xircuitsAugmented = true;
}
4 changes: 3 additions & 1 deletion src/helpers/notificationEffects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ export async function resolveLibraryForNode(
const candidateId = pathToLibraryId(extras.path);
if (!candidateId) return { libId: null, status: 'unknown' };

const cleanLibId = candidateId.replace(/^xai_components[\/\\]/i, '');

const idx = await loadLibraryIndex();
const entry = idx.get(candidateId);
return computeStatusFromEntry(entry, candidateId);
return computeStatusFromEntry(entry, cleanLibId);
}

export async function showInstallForRemoteLibrary(args: {
Expand Down
8 changes: 6 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ import type { Signal } from "@lumino/signaling";
import { commandIDs } from "./commands/CommandIDs";
import { IEditorTracker } from '@jupyterlab/fileeditor';
import { IMainMenu } from '@jupyterlab/mainmenu';
import { installLibrarySilently } from './context-menu/TrayContextMenu';
import { normalizeLibraryName } from './tray_library/ComponentLibraryConfig';
import { handleInstall, installLibrarySilently } from './context-menu/TrayContextMenu';
import { augmentNotifications } from './helpers/notificationAugmentor';
import { loadLibraryIndex } from './helpers/notificationEffects';
import { normalizeLibraryName } from './tray_library/ComponentLibraryConfig';
import { installComponentPreview } from './component_info_sidebar/previewHelper';
const FACTORY = 'Xircuits editor';

Expand Down Expand Up @@ -81,6 +82,9 @@ const xircuits: JupyterFrontEndPlugin<void> = {

console.log('Xircuits is activated!');

// Add "View details" to long notifications
augmentNotifications();

// Creating the widget factory to register it so the document manager knows about
// our new DocumentWidget
const widgetFactory = new XircuitsFactory({
Expand Down
16 changes: 13 additions & 3 deletions style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ body.light-mode jp-button[title="Toggle Light/Dark Mode"] .moon { visibility:

body.light-mode jp-button[title="Toggle Light/Dark Mode"] .sun { visibility: visible; }




.xircuits-notification-details {
max-height: 60vh;
overflow: auto;
padding: 0.25rem;
}

.xircuits-notification-details pre {
white-space: pre-wrap;
word-break: break-word;
margin: 0;
font-family: var(--jp-code-font-family);
font-size: var(--jp-code-font-size);
}