Skip to content

Commit 8a7005f

Browse files
brichetandrii-i
andauthored
Improve file event handling in side panel (#260)
* Dispose of the chat widget in side panel if the file is deleted * Fix ui tests * lint --------- Co-authored-by: Andrii Ieroshenko <[email protected]>
1 parent 8621f2a commit 8a7005f

File tree

5 files changed

+28
-25
lines changed

5 files changed

+28
-25
lines changed

packages/jupyter-chat/style/chat.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
}
2020

2121
/*
22-
*
2322
* Selectors must be nested in `.jp-ThemedContainer` to have a higher
2423
* specificity than selectors in rules provided by JupyterLab.
2524
*
@@ -147,7 +146,6 @@
147146
}
148147

149148
/* Keyframe animations */
150-
151149
@keyframes jp-chat-typing-bounce {
152150
0%,
153151
80%,

packages/jupyter-chat/style/input.css

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,15 @@
4141
padding: 8px 0;
4242
}
4343

44+
/* stylelint-disable-next-line selector-class-pattern */
4445
.jp-chat-input-container .MuiTextField-root {
4546
padding-bottom: 8px;
4647
}
4748

4849
.jp-chat-input-container.jp-chat-drag-hover::after {
4950
content: '';
5051
position: absolute;
51-
top: 0;
52-
left: 0;
53-
right: 0;
54-
bottom: 0;
52+
inset: 0;
5553
background: rgb(33 150 243 / 10%);
5654
border: 2px dashed var(--jp-brand-color1);
5755
border-radius: 4px;

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -760,23 +760,6 @@ const chatPanel: JupyterFrontEndPlugin<ChatPanel> = {
760760
restorer.add(chatPanel, 'jupyter-chat');
761761
}
762762

763-
// Use events system to watch changes on files, and update the chat list if a chat
764-
// file has been created, deleted or renamed.
765-
const schemaID =
766-
'https://events.jupyter.org/jupyter_server/contents_service/v1';
767-
const actions = ['create', 'delete', 'rename'];
768-
app.serviceManager.events.stream.connect((_, emission) => {
769-
if (emission.schema_id === schemaID) {
770-
const action = emission.action as string;
771-
if (
772-
actions.includes(action) &&
773-
(emission.path as string).endsWith(chatFileType.extensions[0])
774-
) {
775-
chatPanel.updateChatList();
776-
}
777-
}
778-
});
779-
780763
/*
781764
* Command to move a chat from the main area to the side panel.
782765
*/

packages/jupyterlab-chat/src/widget.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,24 @@ export class ChatPanel extends SidePanel {
137137

138138
const content = this.content as AccordionPanel;
139139
content.expansionToggled.connect(this._onExpansionToggled, this);
140+
141+
this._contentsManager.fileChanged.connect((_, args) => {
142+
if (args.type === 'delete') {
143+
this.widgets.forEach(widget => {
144+
if ((widget as ChatSection).path === args.oldValue?.path) {
145+
widget.dispose();
146+
}
147+
});
148+
this.updateChatList();
149+
}
150+
const updateActions = ['new', 'rename'];
151+
if (
152+
updateActions.includes(args.type) &&
153+
args.newValue?.path?.endsWith(chatFileType.extensions[0])
154+
) {
155+
this.updateChatList();
156+
}
157+
});
140158
}
141159

142160
/**
@@ -236,9 +254,9 @@ export class ChatPanel extends SidePanel {
236254
}
237255

238256
/**
239-
* A message handler invoked on an `'after-show'` message.
257+
* A message handler invoked on an `'after-attach'` message.
240258
*/
241-
protected onAfterShow(msg: Message): void {
259+
protected onAfterAttach(msg: Message): void {
242260
// Wait for the component to be rendered.
243261
this._openChat.renderPromise?.then(() => this.updateChatList());
244262
}

ui-tests/tests/side-panel.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,19 @@ test.describe('#sidepanel', () => {
142142
});
143143

144144
test.describe('#openingClosing', () => {
145+
test.use({ autoGoto: false });
146+
145147
const name = FILENAME.replace('.chat', '');
146148
const NEW_DIR = 'chats_dir';
147149
let panel: Locator;
148150
let select: Locator;
149151

150152
test.beforeEach(async ({ page }) => {
151153
await page.filebrowser.contents.uploadContent('{}', 'text', FILENAME);
154+
await page.waitForCondition(
155+
async () => await page.filebrowser.contents.fileExists(FILENAME)
156+
);
157+
await page.goto();
152158
});
153159

154160
test.afterEach(async ({ page }) => {

0 commit comments

Comments
 (0)