Skip to content

Commit b77c714

Browse files
authored
Wait for the chat to be opened in main before disposing of the widget (#287)
1 parent 55c2ca4 commit b77c714

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

packages/jupyter-chat/src/widgets/multichat-panel.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export class MultiChatPanel extends SidePanel {
279279
name?: string
280280
) => Promise<MultiChatPanel.IAddChatArgs>;
281281
private _getChatNames?: () => Promise<{ [name: string]: string }>;
282-
private _openInMain?: (name: string) => void;
282+
private _openInMain?: (name: string) => Promise<boolean>;
283283
private _renameChat?: (oldName: string, newName: string) => Promise<boolean>;
284284

285285
private _openChatWidget?: ReactWidget;
@@ -317,7 +317,7 @@ export namespace MultiChatPanel {
317317
*
318318
* @param name - the name of the chat to move.
319319
*/
320-
openInMain?: (name: string) => void;
320+
openInMain?: (name: string) => Promise<boolean>;
321321
/**
322322
* An optional callback to rename a chat.
323323
*
@@ -406,11 +406,12 @@ export class ChatSection extends PanelWithToolbar {
406406
icon: launchIcon,
407407
iconLabel: 'Move the chat to the main area',
408408
className: 'jp-mod-styled',
409-
onClick: () => {
409+
onClick: async () => {
410410
const name = this.model.name;
411-
this.model.dispose();
412-
options.openInMain?.(name);
413-
this.dispose();
411+
if (await options.openInMain?.(name)) {
412+
this.model.dispose();
413+
this.dispose();
414+
}
414415
}
415416
});
416417
this.toolbar.addItem('moveMain', moveToMain);
@@ -521,7 +522,7 @@ export namespace ChatSection {
521522
*
522523
* @param name - the name of the chat to move.
523524
*/
524-
openInMain?: (name: string) => void;
525+
openInMain?: (name: string) => Promise<boolean>;
525526
/**
526527
* An optional callback to rename a chat.
527528
*

packages/jupyterlab-chat-extension/src/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ const chatCommands: JupyterFrontEndPlugin<void> = {
595595
*/
596596
commands.addCommand(CommandIDs.openChat, {
597597
label: 'Open a chat',
598-
execute: async args => {
598+
execute: async (args): Promise<any> => {
599599
const inSidePanel: boolean = (args.inSidePanel as boolean) ?? false;
600600
const startup: boolean = (args.startup as boolean) ?? false;
601601
let filepath: string | null = (args.filepath as string) ?? null;
@@ -610,7 +610,7 @@ const chatCommands: JupyterFrontEndPlugin<void> = {
610610
}
611611

612612
if (!filepath) {
613-
return;
613+
return false;
614614
}
615615

616616
let fileExist = true;
@@ -631,7 +631,7 @@ const chatCommands: JupyterFrontEndPlugin<void> = {
631631
`'${filepath}' is not a valid path`
632632
);
633633
}
634-
return;
634+
return false;
635635
}
636636

637637
if (inSidePanel && chatPanel) {
@@ -655,7 +655,7 @@ const chatCommands: JupyterFrontEndPlugin<void> = {
655655
}
656656

657657
if (chatPanel.openIfExists(filepath)) {
658-
return;
658+
return true;
659659
}
660660

661661
const addChatArgs = await createChatModel(app, drive, filepath);
@@ -670,6 +670,7 @@ const chatCommands: JupyterFrontEndPlugin<void> = {
670670
factory: FACTORY
671671
});
672672
}
673+
return false;
673674
}
674675
});
675676

@@ -835,7 +836,9 @@ const chatPanel: JupyterFrontEndPlugin<MultiChatPanel> = {
835836
);
836837
},
837838
openInMain: path => {
838-
commands.execute(CommandIDs.openChat, { filepath: path });
839+
return commands.execute(CommandIDs.openChat, {
840+
filepath: path
841+
}) as Promise<boolean>;
839842
},
840843
renameChat: (oldPath, newPath) => {
841844
return commands.execute(CommandIDs.renameChat, {

0 commit comments

Comments
 (0)