Skip to content

Commit

Permalink
fix: enable removing tasklists and avatars (Chainlit#296)
Browse files Browse the repository at this point in the history
- When splitting the frontend state for tasklists and avatars away from other elements, we introduced a but where it wouldn't be possible to remove the tasklist and avatars.
- Attempting to remove an element across the three existing element states (elements, tasklists, avatars) restores the feature.
  • Loading branch information
tpatel authored Aug 21, 2023
1 parent fb8853a commit 41228cc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
13 changes: 13 additions & 0 deletions cypress/e2e/tasklist/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,22 @@
"Preparing for shutdown",
]

# Not a good practice in a normal chainlit server as it's global to all users
# However it work in a testing scenario where we have just one user
task_list = None


@cl.on_message
async def on_message():
# Waiting on a message to remove the tasklist to make sure
# all checks are successful before we remove it
await task_list.remove()


@cl.on_chat_start
async def main():
global task_list

task_list = cl.TaskList()
task_list.status = "Running..."
for i in range(17):
Expand Down
8 changes: 6 additions & 2 deletions cypress/e2e/tasklist/spec.cy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { runTestServer } from "../../support/testUtils";
import { runTestServer, submitMessage } from "../../support/testUtils";

describe("tasklist", () => {
before(() => {
runTestServer()
runTestServer();
});

it("should display the tasklist ", () => {
Expand Down Expand Up @@ -32,5 +32,9 @@ describe("tasklist", () => {
"have.length",
9
);

submitMessage("ok");

cy.get(".tasklist").should("not.exist");
});
});
6 changes: 6 additions & 0 deletions src/chainlit/frontend/src/components/socket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ export default memo(function Socket() {
setElements((old) => {
return old.filter((e) => e.id !== remove.id);
});
setTasklists((old) => {
return old.filter((e) => e.id !== remove.id);
});
setAvatars((old) => {
return old.filter((e) => e.id !== remove.id);
});
});

socket.on('action', (action: IAction) => {
Expand Down

0 comments on commit 41228cc

Please sign in to comment.