Skip to content

Commit

Permalink
Merge pull request #1455 from mito-ds/no-focus-on-smart-debug
Browse files Browse the repository at this point in the history
No focus on smart debug
  • Loading branch information
ngafar authored Jan 2, 2025
2 parents 0dfa01e + 22da430 commit 21cbd60
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
11 changes: 10 additions & 1 deletion mito-ai/src/Extensions/AiChat/AiChatPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import { IVariableManager } from '../VariableManager/VariableManagerPlugin';
import { COMMAND_MITO_AI_OPEN_CHAT } from '../../commands';
import { IChatTracker } from './token';
import { ReadonlyPartialJSONObject } from '@lumino/coreutils';


/**
Expand Down Expand Up @@ -53,7 +54,7 @@ const AiChatPlugin: JupyterFrontEndPlugin<WidgetTracker> = {
// Add an application command
app.commands.addCommand(COMMAND_MITO_AI_OPEN_CHAT, {
label: 'Your friendly Python Expert chat bot',
execute: () => {
execute: (args?: ReadonlyPartialJSONObject) => {
// In order for the widget to be accessible, the widget must be:
// 1. Created
// 2. Added to the widget tracker
Expand All @@ -80,6 +81,14 @@ const AiChatPlugin: JupyterFrontEndPlugin<WidgetTracker> = {
// widget opens the taskpane
app.shell.activateById(widget.id);


// If the command is called with focus on chat input set to false,
// don't focus. This is useful when we don't want to active cell
// preview to be displayed when using the smart debugger.
if (args?.focusChatInput === false) {
return;
}

// Set focus on the chat input
const chatInput: HTMLTextAreaElement | null =
widget.node.querySelector('.chat-input');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ class AugmentedStderrRenderer extends Widget implements IRenderMime.IRenderer {
}
}



// Append the original error/warning rendered node
this.node.appendChild(originalNode);
}
Expand All @@ -110,7 +108,7 @@ class AugmentedStderrRenderer extends Widget implements IRenderMime.IRenderer {
*/
openChatInterfaceWithError(model: IRenderMime.IMimeModel): void {
const conciseErrorMessage = this.getErrorString(model);
this.app.commands.execute(COMMAND_MITO_AI_OPEN_CHAT)
this.app.commands.execute(COMMAND_MITO_AI_OPEN_CHAT, { focusChatInput: false });
this.app.commands.execute(COMMAND_MITO_AI_SEND_DEBUG_ERROR_MESSAGE, { input: conciseErrorMessage });
}

Expand Down
9 changes: 6 additions & 3 deletions tests/mitoai_ui_tests/mitoai.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ test.describe('Mito AI Chat', () => {
expect(codeMessagePartContainersCount).toBe(1);
});

test('Test fix error button', async ({ page }) => {
test('Fix error button', async ({ page }) => {
await createAndRunNotebookWithCells(page, ['print(1']);
await waitForIdle(page);

Expand All @@ -229,6 +229,9 @@ test.describe('Mito AI Chat', () => {

await waitForMitoAILoadingToDisappear(page);

// Ensure the chat input is not focussed on
await expect(page.locator('.chat-input')).not.toBeFocused();

// No code diffs should be visible before the user clicks preview
await expect(page.locator('.cm-codeDiffRemovedStripe')).not.toBeVisible();
await expect(page.locator('.cm-codeDiffInsertedStripe')).not.toBeVisible();
Expand All @@ -242,15 +245,15 @@ test.describe('Mito AI Chat', () => {
expect(code).toContain('print(1)');
});

test('Test no fix error button for warnings', async ({ page }) => {
test('No fix error button for warnings', async ({ page }) => {
await createAndRunNotebookWithCells(page, ['import warnings', 'warnings.warn("This is a warning")']);
await waitForIdle(page);

// Ensure that the "Fix Error in AI Chat" button is not visible
expect(page.getByRole('button', { name: 'Fix Error in AI Chat' })).not.toBeVisible();
});

test('Test explain code button', async ({ page }) => {
test('Explain code button', async ({ page }) => {
await createAndRunNotebookWithCells(page, ['print(1)']);
await waitForIdle(page);

Expand Down

0 comments on commit 21cbd60

Please sign in to comment.