Skip to content

Don't render deleted messages #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
12 changes: 11 additions & 1 deletion packages/jupyter-chat/src/components/messages/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ export function ChatMessages(props: BaseMessageProps): JSX.Element {
const observer = new IntersectionObserver(entries => {
// Used on first rendering, to ensure all the message as been rendered once.
if (!allRendered) {
Promise.all(renderedPromise.current.map(p => p.promise)).then(() => {
const activePromises = renderedPromise.current
// Filter out nulls signifying deleted messages
.filter(p => p)
.map(p => p.promise);

Promise.all(activePromises).then(() => {
setAllRendered(true);
});
}
Expand Down Expand Up @@ -181,6 +186,11 @@ export function ChatMessages(props: BaseMessageProps): JSX.Element {
)}
<Box ref={refMsgBox} className={clsx(MESSAGES_BOX_CLASS)}>
{messages.map((message, i) => {
// Skip rendering deleted messages while preventing sparse array
if (message.deleted) {
listRef.current[i] = null;
return null;
}
renderedPromise.current[i] = new PromiseDelegate();
return (
// extra div needed to ensure each bubble is on a new line
Expand Down
23 changes: 15 additions & 8 deletions ui-tests/tests/message-toolbar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,27 @@
).not.toContain('(edited)');
});

test('should set the message as deleted', async ({ page }) => {
test('should not render deleted message', async ({ page }) => {
const chatPanel = await openChat(page, FILENAME);
const message = chatPanel
.locator('.jp-chat-messages-container .jp-chat-message')
.first();
const messagesContainer = chatPanel.locator('.jp-chat-messages-container');

const messageCountBefore = await messagesContainer
.locator('.jp-chat-message')
.count();
expect(messageCountBefore).toBe(1);

Check failure on line 139 in ui-tests/tests/message-toolbar.spec.ts

View workflow job for this annotation

GitHub Actions / jupyterlab

tests/message-toolbar.spec.ts:132:7 › #messageToolbar › should not render deleted message

2) tests/message-toolbar.spec.ts:132:7 › #messageToolbar › should not render deleted message ───── Error: expect(received).toBe(expected) // Object.is equality Expected: 1 Received: 0 137 | .locator('.jp-chat-message') 138 | .count(); > 139 | expect(messageCountBefore).toBe(1); | ^ 140 | 141 | const message = messagesContainer.locator('.jp-chat-message').first(); 142 | const messageContent = message.locator('.jp-chat-rendered-markdown'); at /home/runner/work/jupyter-chat/jupyter-chat/ui-tests/tests/message-toolbar.spec.ts:139:32

const message = messagesContainer.locator('.jp-chat-message').first();
const messageContent = message.locator('.jp-chat-rendered-markdown');

// Should display the message toolbar
await messageContent.hover({ position: { x: 5, y: 5 } });
await messageContent.locator('.jp-chat-toolbar jp-button').last().click();

await expect(messageContent).not.toBeVisible();
expect(
await message.locator('.jp-chat-message-header').textContent()
).toContain('(message deleted)');
await expect(message).not.toBeVisible();

const messageCountAfter = await messagesContainer
.locator('.jp-chat-message')
.count();
expect(messageCountAfter).toBe(0);
});
});
Loading