Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 8 additions & 3 deletions src/context-menu/TrayContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ import { normalizeLibraryName } from '../tray_library/ComponentLibraryConfig';
export async function handleInstall(
app,
libraryName: string,
refreshTrigger: () => void
refreshTrigger: () => void,
opts?: { silent?: boolean }

): Promise<boolean> {
const { silent = false } = opts ?? {};
const originalName = libraryName;
const normalizedLibName = normalizeLibraryName(originalName);

const proceed = confirm(`Do you want to proceed with installing "${originalName}" library?`);
if (!proceed) return false;
if (!silent) {
const proceed = confirm(`Do you want to proceed with installing "${originalName}" library?`);
if (!proceed) return false;
}

const installPromise = requestAPI<any>('library/install', {
method: 'POST',
Expand Down
30 changes: 19 additions & 11 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,10 @@ const xircuits: JupyterFrontEndPlugin<void> = {
});
}

function canon(name: string): string {
return name.toLowerCase().replace(/^xai[_-]?/, '');
}

async function getInstalledLibraries(): Promise<Set<string>> {
try {
const result = await requestAPI<any>('library/get_config', {
Expand All @@ -592,7 +596,7 @@ const xircuits: JupyterFrontEndPlugin<void> = {
return new Set<string>(
result.config.libraries
.filter((lib: any) => lib.status === 'installed' && typeof lib.name === 'string')
.map((lib: any) => lib.name)
.map((lib: any) => canon(lib.name))
);
} catch (err) {
console.error('Failed to load library config via API:', err);
Expand Down Expand Up @@ -622,23 +626,27 @@ const xircuits: JupyterFrontEndPlugin<void> = {
const currentPath = browserFactory.tracker.currentWidget?.model.path ?? '';
const installedLibs = await getInstalledLibraries();

for (const lib of libraries) {
if (installedLibs.has(lib)) {
console.log(`Library ${lib} already installed. Skipping.`);
continue;
const pairs = libraries.map(lib => ({ lib, want: canon(lib) }));
const missing = pairs.filter(p => !installedLibs.has(p.want));
if (missing.length) {
const list = missing.map(p => p.lib).join(', ');
const ok = window.confirm(`This template requires: ${list}. Install now?`);
if (!ok) {
console.warn('User cancelled installation.');
return;
}

const ok = await handleInstall(app, lib, () =>
app.commands.execute(commandIDs.refreshComponentList)
);

for (const { lib, want } of missing) {
const ok = await handleInstall(app, lib, () =>{},
{ silent: true }
);
if (!ok) {
console.warn(`Aborted: ${lib} not installed.`);
return;
}
installedLibs.add(lib);
installedLibs.add(want);
}

}
// Currently the templates are stored at the `examples` dir
await app.commands.execute(commandIDs.fetchExamples);

Expand Down