Skip to content

Commit

Permalink
fix(chat): fix blinking on click "New conversation" (Issue #2676) (#2677
Browse files Browse the repository at this point in the history
)

Co-authored-by: Irina_Kartun <[email protected]>
  • Loading branch information
IlyaBondar and irinakartun authored Nov 26, 2024
1 parent 7a0ac6d commit 55ec50e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
},
"selectedAddons": [],
"assistantModelId": ""
},
{
"id": "bc66971f-fd89-44db-8d3b-3efa893cc587",
"name": "New Conversation",
"messages": [],
"model": {
"id": "gpt-4",
"name": "GPT-4"
},
"prompt": "",
"temperature": 1,
"folderId": null
}
],
"folders": [
Expand Down
44 changes: 20 additions & 24 deletions apps/chat-e2e/src/tests/monitoring/createNewConversation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ dialTest(
'Create new conversation and send new message',
async ({
dialHomePage,
header,
conversations,
talkToEntities,
entitySettings,
Expand All @@ -34,33 +33,14 @@ dialTest(
addons,
}) => {
const expectedAddons = ModelsUtil.getAddons();
const request = 'test request';

await dialTest.step(
'Create new conversation and verify it is moved under Today section in chat bar',
'Verify the list of recent entities and default settings for default model',
async () => {
await dialHomePage.openHomePage();
await dialHomePage.waitForPageLoaded();
await header.createNewConversation();

const todayConversations = await conversations.getTodayConversations();
expect
.soft(
todayConversations.length,
ExpectedMessages.newConversationCreated,
)
.toBe(2);
for (const todayConversation of todayConversations) {
expect
.soft(todayConversation, ExpectedMessages.conversationOfToday)
.toEqual(
expect.stringContaining(ExpectedConstants.newConversationTitle),
);
}
},
);

await dialTest.step(
'Verify the list of recent entities and default settings for default model',
async () => {
const expectedDefaultRecentEntities = [];
for (const entity of recentModelIds) {
expectedDefaultRecentEntities.push(
Expand Down Expand Up @@ -110,13 +90,29 @@ dialTest(
await dialHomePage.mockChatTextResponse(
MockedChatApiResponseBodies.simpleTextBody,
);
await chat.sendRequestWithKeyboard('test request');
await chat.sendRequestWithKeyboard(request);
const messagesCount =
await chatMessages.chatMessages.getElementsCount();
expect
.soft(messagesCount, ExpectedMessages.messageCountIsCorrect)
.toBe(2);
},
);

await dialTest.step(
'Verify new conversation is moved under Today section in chat bar',
async () => {
const todayConversations = await conversations.getTodayConversations();
expect
.soft(
todayConversations.length,
ExpectedMessages.newConversationCreated,
)
.toBe(1);
expect
.soft(todayConversations[0], ExpectedMessages.conversationOfToday)
.toBe(request);
},
);
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ dialTest(
'hidden',
);

const todayConversations = await conversations.getTodayConversations();
const todayConversationsCount = await conversations.getEntitiesCount();
expect
.soft(
todayConversations.includes(conversationInFolder.conversations[0].name),
ExpectedMessages.conversationOfToday,
)
.toBeFalsy();
.soft(todayConversationsCount, ExpectedMessages.entitiesCountIsValid)
.toBe(0);
},
);
11 changes: 7 additions & 4 deletions apps/chat/src/store/conversations/conversations.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,6 @@ export const conversationsSlice = createSlice({
}>,
) => {
state.isActiveNewConversationRequest = true;
state.conversations = state.conversations.filter(
(conv) => !isEntityIdLocal(conv),
);
},
deleteConversations: (
state,
Expand Down Expand Up @@ -350,9 +347,15 @@ export const conversationsSlice = createSlice({
suspendHideSidebar?: boolean;
}>,
) => {
const hasNew = payload.conversations.some((conv) =>
isEntityIdLocal(conv),
);
const existedConversation = hasNew
? state.conversations.filter((conv) => !isEntityIdLocal(conv))
: state.conversations;
state.conversations = combineEntities(
payload.conversations,
state.conversations,
existedConversation,
);
},
clearConversations: (state) => {
Expand Down
5 changes: 4 additions & 1 deletion apps/chat/src/store/models/models.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ export const modelsSlice = createSlice({
const rootSelector = (state: RootState): ModelsState => state.models;

const selectModelsIsLoading = createSelector([rootSelector], (state) => {
return state.status === UploadStatus.LOADING;
return (
state.status === UploadStatus.LOADING ||
state.status === UploadStatus.UNINITIALIZED
);
});

const selectIsModelsLoaded = createSelector([rootSelector], (state) => {
Expand Down

0 comments on commit 55ec50e

Please sign in to comment.