Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
e3016611
Unverified
Commit
e3016611
authored
May 15, 2024
by
Timothy Jaeryang Baek
Committed by
GitHub
May 15, 2024
Browse files
Merge pull request #2264 from iits-jonathan-rohde/fix/share-chat-reactive-loop
fix: prevent loop when fetching shared chat id
parents
ea812a3b
9381113f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
27 deletions
+51
-27
cypress/e2e/chat.cy.ts
cypress/e2e/chat.cy.ts
+33
-0
src/lib/components/chat/ShareChatModal.svelte
src/lib/components/chat/ShareChatModal.svelte
+15
-1
src/lib/components/layout/Navbar.svelte
src/lib/components/layout/Navbar.svelte
+2
-1
src/lib/components/layout/Navbar/Menu.svelte
src/lib/components/layout/Navbar/Menu.svelte
+1
-25
No files found.
cypress/e2e/chat.cy.ts
View file @
e3016611
...
@@ -42,5 +42,38 @@ describe('Settings', () => {
...
@@ -42,5 +42,38 @@ describe('Settings', () => {
.
find
(
'
div[aria-label="Generation Info"]
'
,
{
timeout
:
120
_000
})
// Generation Info is created after the stop token is received
.
find
(
'
div[aria-label="Generation Info"]
'
,
{
timeout
:
120
_000
})
// Generation Info is created after the stop token is received
.
should
(
'
exist
'
);
.
should
(
'
exist
'
);
});
});
it
(
'
user can share chat
'
,
()
=>
{
// Click on the model selector
cy
.
get
(
'
button[aria-label="Select a model"]
'
).
click
();
// Select the first model
cy
.
get
(
'
button[aria-label="model-item"]
'
).
first
().
click
();
// Type a message
cy
.
get
(
'
#chat-textarea
'
).
type
(
'
Hi, what can you do? A single sentence only please.
'
,
{
force
:
true
});
// Send the message
cy
.
get
(
'
button[type="submit"]
'
).
click
();
// User's message should be visible
cy
.
get
(
'
.chat-user
'
).
should
(
'
exist
'
);
// Wait for the response
cy
.
get
(
'
.chat-assistant
'
,
{
timeout
:
120
_000
})
// .chat-assistant is created after the first token is received
.
find
(
'
div[aria-label="Generation Info"]
'
,
{
timeout
:
120
_000
})
// Generation Info is created after the stop token is received
.
should
(
'
exist
'
);
// spy on requests
const
spy
=
cy
.
spy
();
cy
.
intercept
(
"
GET
"
,
"
/api/v1/chats/*
"
,
spy
);
// Open context menu
cy
.
get
(
'
#chat-context-menu-button
'
).
click
();
// Click share button
cy
.
get
(
'
#chat-share-button
'
).
click
();
// Check if the share dialog is visible
cy
.
get
(
'
#copy-and-share-chat-button
'
).
should
(
'
exist
'
);
cy
.
wrap
({},
{
timeout
:
5000
})
.
should
(()
=>
{
// Check if the request was made twice (once for to replace chat object and once more due to change event)
expect
(
spy
).
to
.
be
.
callCount
(
2
);
});
});
});
});
});
});
src/lib/components/chat/ShareChatModal.svelte
View file @
e3016611
...
@@ -57,10 +57,23 @@
...
@@ -57,10 +57,23 @@
export let show = false;
export let show = false;
const isDifferentChat = (_chat) => {
if (!chat) {
return true;
}
if (!_chat) {
return false;
}
return chat.id !== _chat.id || chat.share_id !== _chat.share_id;
}
$: if (show) {
$: if (show) {
(async () => {
(async () => {
if (chatId) {
if (chatId) {
chat = await getChatById(localStorage.token, chatId);
const _chat = await getChatById(localStorage.token, chatId);
if (isDifferentChat(_chat)) {
chat = _chat;
}
} else {
} else {
chat = null;
chat = null;
console.log(chat);
console.log(chat);
...
@@ -137,6 +150,7 @@
...
@@ -137,6 +150,7 @@
<button
<button
class=" self-center flex items-center gap-1 px-3.5 py-2 rounded-xl text-sm font-medium bg-emerald-600 hover:bg-emerald-500 text-white"
class=" self-center flex items-center gap-1 px-3.5 py-2 rounded-xl text-sm font-medium bg-emerald-600 hover:bg-emerald-500 text-white"
type="button"
type="button"
id="copy-and-share-chat-button"
on:click={async () => {
on:click={async () => {
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
...
...
src/lib/components/layout/Navbar.svelte
View file @
e3016611
...
@@ -81,7 +81,8 @@
...
@@ -81,7 +81,8 @@
>
>
<button
<button
class="hidden md:flex cursor-pointer px-2 py-2 rounded-xl hover:bg-gray-100 dark:hover:bg-gray-850 transition"
class="hidden md:flex cursor-pointer px-2 py-2 rounded-xl hover:bg-gray-100 dark:hover:bg-gray-850 transition"
>
id="chat-context-menu-button"
>
<div class=" m-auto self-center">
<div class=" m-auto self-center">
<svg
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
...
...
src/lib/components/layout/Navbar/Menu.svelte
View file @
e3016611
...
@@ -112,6 +112,7 @@
...
@@ -112,6 +112,7 @@
<DropdownMenu.Item
<DropdownMenu.Item
class="flex gap-2 items-center px-3 py-2 text-sm cursor-pointer dark:hover:bg-gray-800 rounded-md"
class="flex gap-2 items-center px-3 py-2 text-sm cursor-pointer dark:hover:bg-gray-800 rounded-md"
id="chat-share-button"
on:click={() => {
on:click={() => {
shareHandler();
shareHandler();
}}
}}
...
@@ -188,31 +189,6 @@
...
@@ -188,31 +189,6 @@
<div class="flex p-1">
<div class="flex p-1">
<Tags chatId={chat.id} />
<Tags chatId={chat.id} />
</div>
</div>
<!-- <DropdownMenu.Item
class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer"
on:click={() => {
tagHandler();
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2"
stroke="currentColor"
class="size-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M9.568 3H5.25A2.25 2.25 0 0 0 3 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581c.699.699 1.78.872 2.607.33a18.095 18.095 0 0 0 5.223-5.223c.542-.827.369-1.908-.33-2.607L11.16 3.66A2.25 2.25 0 0 0 9.568 3Z"
/>
<path stroke-linecap="round" stroke-linejoin="round" d="M6 6h.008v.008H6V6Z" />
</svg>
<div class="flex items-center">Tag</div>
</DropdownMenu.Item> -->
</DropdownMenu.Content>
</DropdownMenu.Content>
</div>
</div>
</Dropdown>
</Dropdown>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment