Skip to content

Commit 7ec1394

Browse files
author
Jicheng Lu
committed
refine state search
1 parent e322aa7 commit 7ec1394

File tree

7 files changed

+68
-52
lines changed

7 files changed

+68
-52
lines changed

src/lib/common/RemoteSearchInput.svelte

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@
1111
1212
/** @type {string} */
1313
export let value;
14+
/** @type {string} */
15+
export let placeholder = '';
16+
/** @type {boolean} */
1417
export let disabled = false;
15-
export let placeholder = '';
16-
/**
17-
* @type {(query: string) => Promise<({id: string; name: string} | string)[]>}
18-
*/
19-
export let onSearch;
18+
/** @type {boolean} */
2019
export let loading = false;
20+
/** @type {(query: string) => Promise<string[]>} */
21+
export let onSearch = query => Promise.resolve([]);
22+
23+
export const clearSearchResults = () => {
24+
searchResults = [];
25+
};
2126
22-
/** @type {({id: string; name: string} | string)[]} */
27+
/** @type {string[]} */
2328
let searchResults = [];
2429
let isOpen = false;
2530
@@ -46,15 +51,13 @@
4651
}
4752
4853
/**
49-
* @param { {id: string; name: string} | string } result
54+
* @param { string } result
5055
*/
5156
function selectResult(result) {
52-
value = typeof result === 'string' ? result : result?.id;
57+
value = result;
5358
}
5459
55-
export function clearSearchResults() {
56-
searchResults = [];
57-
}
60+
5861
</script>
5962

6063
<div class="position-relative">
@@ -66,17 +69,17 @@
6669
<DropdownToggle tag="div">
6770
<Input type="text" {value} on:input={handleInput} {disabled} {placeholder} />
6871
</DropdownToggle>
69-
<DropdownMenu class="w-100">
72+
<DropdownMenu class="w-100 thin-scrollbar">
7073
{#if loading}
7174
<li class="text-center"><Spinner size="sm" /></li>
7275
{:else}
73-
{#each searchResults as result, index}
76+
{#each searchResults as item, index}
7477
<DropdownItem
75-
active={value === (typeof result === 'string' ? result : result?.id)}
76-
on:click={() => selectResult(result)}
77-
title={typeof result === 'string' ? result : result?.name}
78+
active={value === item}
79+
title={item}
80+
on:click={() => selectResult(item)}
7881
>
79-
{typeof result === 'string' ? result : result?.name}
82+
{item}
8083
</DropdownItem>
8184
{/each}
8285
{/if}

src/lib/helpers/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function skipLoader(config) {
9090
new RegExp('http(s*)://(.*?)/role/(.*?)/details', 'g'),
9191
new RegExp('http(s*)://(.*?)/user/(.*?)/details', 'g'),
9292
new RegExp('http(s*)://(.*?)/agent/labels', 'g'),
93-
new RegExp('http(s*)://(.*?)/conversation/state-key', 'g'),
93+
new RegExp('http(s*)://(.*?)/conversation/state/keys', 'g'),
9494
];
9595

9696
if (config.method === 'post' && postRegexes.some(regex => regex.test(config.url || ''))) {

src/lib/helpers/types/conversationTypes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@
3737
*/
3838

3939

40+
/**
41+
* @typedef {Object} StateSearchQuery
42+
* @property {string} query - The search query.
43+
* @property {number?} [keyLimit] - The key limit.
44+
* @property {boolean?} [preLoad] - Whether it is preloading or not.
45+
*/
46+
47+
4048
/**
4149
* @interface
4250
* @class

src/lib/scss/custom/pages/_conversation.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
.list-title {
99
width: 40%;
10+
white-space: nowrap;
11+
overflow: hidden;
12+
text-overflow: ellipsis;
1013
}
1114

1215
.conv-state-search-menu {

src/lib/services/api-endpoints.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const endpoints = {
6767
conversationTagsUpdateUrl: `${host}/conversation/{conversationId}/update-tags`,
6868
fileUploadUrl: `${host}/agent/{agentId}/conversation/{conversationId}/upload`,
6969
pinConversationUrl: `${host}/agent/{agentId}/conversation/{conversationId}/dashboard`,
70-
conversationStateKeyListUrl: `${host}/conversation/state-key`,
70+
conversationStateSearchKeysUrl: `${host}/conversation/state/keys`,
7171

7272
// LLM provider
7373
llmProvidersUrl: `${host}/llm-providers`,

src/lib/services/conversation-service.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,24 +290,21 @@ export async function getAddressOptions(text) {
290290
return response.data;
291291
}
292292

293-
/** @type {import('axios').CancelTokenSource | null} */
294-
let getConversationStatKeyCancelToken = null;
293+
/** @type {AbortController} */
294+
let controller = new AbortController();
295+
295296
/**
296-
* get conversation state key list
297-
* @param {string} query
298-
* @returns {Promise<{id: string, name: string}[]>}
297+
* get conversation state search keys
298+
* @param {import('$conversationTypes').StateSearchQuery} request
299+
* @returns {Promise<string[]>}
299300
*/
300-
export async function getConversationStateKey(query) {
301-
let url = endpoints.conversationStateKeyListUrl;
302-
if (getConversationStatKeyCancelToken) {
303-
getConversationStatKeyCancelToken.cancel();
304-
}
305-
getConversationStatKeyCancelToken = axios.CancelToken.source();
301+
export async function getConversationStateSearchKeys(request) {
302+
let url = endpoints.conversationStateSearchKeysUrl;
306303
const response = await axios.get(url, {
307304
params: {
308-
searchKey: query
305+
...request
309306
},
310-
cancelToken: getConversationStatKeyCancelToken.token
307+
signal: controller.signal
311308
});
312309
return response.data;
313310
}

src/routes/page/conversation/+page.svelte

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<script>
2-
import { _ } from 'svelte-i18n'
2+
import { onMount } from 'svelte';
3+
import { _ } from 'svelte-i18n';
4+
import Swal from 'sweetalert2';
5+
import lodash from "lodash";
36
import {
47
Button,
58
Card,
@@ -13,13 +16,10 @@
1316
import HeadTitle from '$lib/common/HeadTitle.svelte';
1417
import TablePagination from '$lib/common/TablePagination.svelte';
1518
import LoadingToComplete from '$lib/common/LoadingToComplete.svelte';
16-
import { onMount } from 'svelte';
1719
import { getAgents } from '$lib/services/agent-service';
18-
import { getConversations, deleteConversation, getConversationStateKey } from '$lib/services/conversation-service.js';
20+
import { getConversations, deleteConversation, getConversationStateSearchKeys } from '$lib/services/conversation-service.js';
1921
import { utcToLocal } from '$lib/helpers/datetime';
20-
import Swal from 'sweetalert2';
21-
import lodash from "lodash";
22-
import { ConversationChannel, ConversationTag } from '$lib/helpers/enums';
22+
import { ConversationChannel } from '$lib/helpers/enums';
2323
import RemoteSearchInput from '$lib/common/RemoteSearchInput.svelte';
2424
2525
let isLoading = false;
@@ -219,11 +219,11 @@
219219
* @param {any} e
220220
*/
221221
function handleConfirmStateModal(e) {
222-
if (stateKey && stateValue) {
222+
if (stateKey) {
223223
searchOption.states = [
224224
{
225225
key: { data: stateKey, isValid: true },
226-
value: {data: stateValue, isValid: true },
226+
value: { data: stateValue || '', isValid: true },
227227
active_rounds: {data: -1, isValid: true},
228228
}
229229
];
@@ -338,13 +338,16 @@
338338
}
339339
}
340340
341-
/**
342-
* @param {any} query
343-
*/
344-
async function handleStateSearch(query) {
345-
const response = await getConversationStateKey(query);
346-
return response || [];
347-
}
341+
/** @param {string} query */
342+
function handleStateSearch(query) {
343+
return new Promise((resolve) => {
344+
getConversationStateSearchKeys({
345+
query: query
346+
}).then(res => {
347+
resolve(res || []);
348+
}).catch(() => resolve([]));
349+
});
350+
}
348351
</script>
349352
350353
<HeadTitle title="{$_('Conversation List')}" />
@@ -355,14 +358,16 @@
355358
<Col lg="12">
356359
<Card>
357360
<CardBody class="border-bottom">
358-
<div class="d-flex align-items-center">
359-
<h5 class="mb-0 card-title flex-grow-0" style="width: 100%;">{$_('Conversation List')}</h5>
360-
<div style="width: 100%;">
361+
<div class="d-flex align-items-center" style="flex-wrap: wrap; justify-content: space-between;">
362+
<div class="mb-0 card-title flex-grow-0">
363+
<h5 class="mb-0">{$_('Conversation List')}</h5>
364+
</div>
365+
<div>
361366
<div class="state-search-container">
362367
<div>
363368
<RemoteSearchInput
364369
bind:value={stateKey}
365-
onSearch={handleStateSearch}
370+
onSearch={e => handleStateSearch(e)}
366371
placeholder="Search States"
367372
/>
368373
</div>
@@ -435,7 +440,7 @@
435440
</CardBody>
436441
<CardBody>
437442
<div class="table-responsive thin-scrollbar">
438-
<Table class="align-middle nowrap" bordered>
443+
<Table class="align-middle nowrap" style="table-layout: fixed;" bordered>
439444
<thead>
440445
<tr>
441446
<th scope="col" class="list-title">{$_('Title')}</th>

0 commit comments

Comments
 (0)