Skip to content

Commit b14c70e

Browse files
authored
Merge pull request #297 from iceljc/features/refine-chat-window
Features/refine chat window
2 parents 2131b64 + 44d78f6 commit b14c70e

File tree

12 files changed

+252
-148
lines changed

12 files changed

+252
-148
lines changed

src/lib/common/MultiSelect.svelte

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
/** @type {string} */
2424
export let selectedText = '';
2525
26+
/** @type {string[]} */
27+
export let selectedKeys;
28+
2629
/** @type {string} */
2730
export let containerClasses = "";
2831
@@ -78,6 +81,43 @@
7881
});
7982
});
8083
84+
$: {
85+
innerOptions = innerOptions.map(x => {
86+
x.checked = !!selectedKeys?.includes(x.key);
87+
return {...x};
88+
});
89+
refOptions = refOptions.map(x => {
90+
x.checked = !!selectedKeys?.includes(x.key);
91+
return {...x};
92+
});
93+
changeDisplayText();
94+
}
95+
96+
$: {
97+
if (options.length > refOptions.length) {
98+
const curKeys = refOptions.map(x => x.key);
99+
const newOptions = options.filter(x => !curKeys.includes(x.key)).map(x => {
100+
return {
101+
key: x.key,
102+
value: x.value,
103+
checked: false
104+
};
105+
});
106+
107+
innerOptions = [
108+
...innerOptions,
109+
...newOptions
110+
];
111+
112+
refOptions = [
113+
...refOptions,
114+
...newOptions
115+
];
116+
117+
changeDisplayText();
118+
}
119+
}
120+
81121
82122
async function toggleOptionList() {
83123
showOptionList = !showOptionList;
@@ -226,31 +266,6 @@
226266
}
227267
}
228268
}
229-
230-
$: {
231-
if (options.length > refOptions.length) {
232-
const curKeys = refOptions.map(x => x.key);
233-
const newOptions = options.filter(x => !curKeys.includes(x.key)).map(x => {
234-
return {
235-
key: x.key,
236-
value: x.value,
237-
checked: false
238-
};
239-
});
240-
241-
innerOptions = [
242-
...innerOptions,
243-
...newOptions
244-
];
245-
246-
refOptions = [
247-
...refOptions,
248-
...newOptions
249-
];
250-
251-
changeDisplayText();
252-
}
253-
}
254269
</script>
255270
256271

src/lib/helpers/http.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ function skipLoader(config) {
8989
new RegExp('http(s*)://(.*?)/role/options', 'g'),
9090
new RegExp('http(s*)://(.*?)/role/(.*?)/details', 'g'),
9191
new RegExp('http(s*)://(.*?)/user/(.*?)/details', 'g'),
92+
new RegExp('http(s*)://(.*?)/agent/labels', 'g'),
9293
];
9394

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

src/lib/helpers/types/agentTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* @property {string[]?} [types]
3131
* @property {string[]?} [agentNames]
3232
* @property {string} [similarName]
33+
* @property {string[]?} [labels]
3334
* @property {boolean} [isPublic]
3435
* @property {boolean} [disabled]
3536
* @property {string[]?} [agentIds]

src/lib/services/agent-service.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,9 @@ export async function getSettings() {
1919
*/
2020
export async function getAgents(filter, checkAuth = false) {
2121
let url = endpoints.agentListUrl;
22-
const response = await axios.get(url, {
23-
params: {
24-
...filter,
25-
checkAuth : checkAuth
26-
},
27-
paramsSerializer: {
28-
dots: true,
29-
indexes: null,
30-
}
22+
const response = await axios.post(url, {
23+
filter: filter,
24+
checkAuth : checkAuth
3125
});
3226
return response.data;
3327
}
@@ -100,4 +94,14 @@ export async function getAgentRuleOptions() {
10094
const url = endpoints.agentRuleOptionsUrl;
10195
const response = await axios.get(url);
10296
return response.data;
97+
}
98+
99+
/**
100+
* Get agent labels
101+
* @returns {Promise<string[]>}
102+
*/
103+
export async function getAgentLabels() {
104+
const url = endpoints.agentLabelsUrl;
105+
const response = await axios.get(url);
106+
return response.data;
103107
}

src/lib/services/api-endpoints.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const endpoints = {
3535
agentCreateUrl: `${host}/agent`,
3636
agentUtilityOptionsUrl: `${host}/agent/utility/options`,
3737
agentRuleOptionsUrl: `${host}/rule/triggers`,
38+
agentLabelsUrl: `${host}/agent/labels`,
3839

3940
// agent task
4041
agentTaskListUrl: `${host}/agent/tasks`,
@@ -97,7 +98,7 @@ export const endpoints = {
9798

9899
// dashboard
99100
dashboardSettingUrl: `${host}/dashboard/components`,
100-
dashConversationInstructionUrl: `${host}/dashboard/component/conversation?userId={userId}`,
101+
dashConversationInstructionUrl: `${host}/dashboard/component/conversation`,
101102

102103
// Google geocode api
103104
addressUrl: `${host}/address/options`

src/lib/services/conversation-service.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,10 @@ export async function unpinConversationFromDashboard(agentId, conversationId) {
135135

136136
/**
137137
* update a dashboard conversation instuction
138-
* @param {string} userId - The conversation id
139138
* @param {import('$userTypes').DashboardConversation} dashConv - The instruction
140139
*/
141-
export async function updateDashboardConversation(userId, dashConv) {
142-
let url = replaceUrl(endpoints.dashConversationInstructionUrl, {
143-
userId: userId
144-
});
140+
export async function updateDashboardConversation(dashConv) {
141+
let url = endpoints.dashConversationInstructionUrl;
145142
const response = await axios.post(url, dashConv);
146143
return response.data;
147144
}

src/lib/services/dashboard-service.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,10 @@ import axios from 'axios';
33

44
/**
55
* Get dashboard settings
6-
* @param {string} userId - The user id
76
* @returns {Promise<import('$userTypes').DashboardModel>}
87
*/
9-
export async function getDashboardSettings(userId) {
10-
let userIdParam = userId;
11-
let url = endpoints.dashboardSettingUrl;
12-
console.log(url);
13-
const response = await axios.get(url, {
14-
params: {
15-
"userId" : userId
16-
}
17-
});
8+
export async function getDashboardSettings() {
9+
const url = endpoints.dashboardSettingUrl;
10+
const response = await axios.get(url);
1811
return response.data;
1912
}

src/routes/page/agent/+page.svelte

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import HeadTitle from '$lib/common/HeadTitle.svelte';
66
import CardAgent from './card-agent.svelte';
77
import LoadingToComplete from '$lib/common/LoadingToComplete.svelte';
8-
import { createAgent, getAgents } from '$lib/services/agent-service.js';
8+
import { createAgent, getAgentLabels, getAgents } from '$lib/services/agent-service.js';
99
import { myInfo } from '$lib/services/auth-service';
1010
import PlainPagination from '$lib/common/PlainPagination.svelte';
1111
import { _ } from 'svelte-i18n'
@@ -43,16 +43,22 @@
4343
/** @type {any} */
4444
let unsubscriber;
4545
46-
let agentTypeOptions = Object.entries(AgentType).map(([k, v]) => (
47-
{ key: k, value: v }
46+
const agentTypeOptions = Object.entries(AgentType).map(([k, v]) => (
47+
{ key: v, value: v }
4848
));
4949
50+
/** @type {{ key: string, value: string }[]} */
51+
let agentLabelOptions = [];
52+
5053
/** @type {string[]} */
5154
let selectedAgentTypes = [];
55+
/** @type {string[]} */
56+
let selectedAgentLabels = [];
5257
5358
onMount(async () => {
5459
user = await myInfo();
5560
getPagedAgents();
61+
getAgentLabelOptions();
5662
5763
unsubscriber = globalEventStore.subscribe((/** @type {import('$commonTypes').GlobalEvent} */ event) => {
5864
if (event.name !== GlobalEvent.Search) return;
@@ -82,6 +88,14 @@
8288
});
8389
}
8490
91+
function getAgentLabelOptions() {
92+
return getAgentLabels().then(res => {
93+
agentLabelOptions = res?.map(x => ({ key: x, value: x })) || [];
94+
}).catch(() => {
95+
agentLabelOptions = [];
96+
});
97+
}
98+
8599
function createNewAgent() {
86100
// @ts-ignore
87101
Swal.fire({
@@ -147,23 +161,44 @@
147161
148162
getPagedAgents();
149163
}
150-
151164
152-
/**
153-
* @param {any} e
154-
*/
165+
/** @param {any} e */
155166
function selectAgentTypeOption(e) {
156167
// @ts-ignore
157-
selectedAgentTypes = e.detail.selecteds?.map(x => x.value) || [];
168+
selectedAgentTypes = e.detail.selecteds?.map(x => x.key) || [];
169+
}
170+
171+
/** @param {any} e */
172+
function selectAgentLabelOption(e) {
173+
// @ts-ignore
174+
selectedAgentLabels = e.detail.selecteds?.map(x => x.key) || [];
175+
}
176+
177+
function search() {
178+
refreshFilter();
179+
initFilterPager();
180+
getPagedAgents();
181+
}
182+
183+
function reset() {
184+
selectedAgentTypes = [];
185+
selectedAgentLabels = [];
158186
}
159187
160-
function searchAgents() {
188+
function refreshFilter() {
161189
filter = {
162190
...filter,
163191
types: selectedAgentTypes?.length > 0 ? selectedAgentTypes : null,
192+
labels: selectedAgentLabels?.length > 0 ? selectedAgentLabels : null,
164193
pager: initFilter.pager
165194
};
166-
getPagedAgents();
195+
}
196+
197+
function initFilterPager() {
198+
filter = {
199+
...filter,
200+
pager: { page: firstPage, size: pageSize, count: 0 },
201+
};
167202
}
168203
</script>
169204
@@ -182,24 +217,39 @@
182217
<div class="agent-filter">
183218
<MultiSelect
184219
tag={'agent-label-select'}
185-
placeholder={'Select agent labels'}
220+
placeholder={'Select labels'}
186221
selectedText={'labels'}
187-
options={[]}
188-
on:select={e => {}}
222+
searchMode
223+
selectedKeys={selectedAgentLabels}
224+
options={agentLabelOptions}
225+
on:select={e => selectAgentLabelOption(e)}
189226
/>
190227
<MultiSelect
191228
tag={'agent-type-select'}
192-
placeholder={'Select agent types'}
229+
placeholder={'Select types'}
193230
selectedText={'types'}
231+
selectedKeys={selectedAgentTypes}
194232
options={agentTypeOptions}
195233
on:select={e => selectAgentTypeOption(e)}
196234
/>
197235
<Button
198-
class="btn btn-light"
199-
on:click={(e) => searchAgents()}
236+
class="btn btn-info"
237+
data-bs-toggle="tooltip"
238+
data-bs-placement="bottom"
239+
title="Search"
240+
on:click={(e) => search()}
200241
>
201242
<i class="mdi mdi-magnify" />
202243
</Button>
244+
<Button
245+
class="btn btn-light"
246+
data-bs-toggle="tooltip"
247+
data-bs-placement="bottom"
248+
title="Reset filters"
249+
on:click={(e) => reset()}
250+
>
251+
<i class="mdi mdi-restore" />
252+
</Button>
203253
</div>
204254
</div>
205255

src/routes/page/agent/router/+page.svelte

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import Breadcrumb from '$lib/common/Breadcrumb.svelte';
77
import HeadTitle from '$lib/common/HeadTitle.svelte';
88
import { getAgents } from '$lib/services/agent-service.js';
9+
import { AgentType } from '$lib/helpers/enums';
910
import RoutingFlow from './routing-flow.svelte'
1011
1112
const params = $page.url.searchParams;
@@ -22,7 +23,7 @@
2223
const filter = {
2324
pager: { page: 1, size: 10, count: 0 },
2425
disabled: false,
25-
types: ["routing"]
26+
types: [AgentType.Routing]
2627
};
2728
2829
onMount(async () => {
@@ -31,9 +32,9 @@
3132
});
3233
3334
async function getRouter() {
34-
// if (!!targetAgentId) {
35-
// filter.agentIds = [targetAgentId];
36-
// }
35+
if (!!targetAgentId) {
36+
filter.agentIds = [targetAgentId];
37+
}
3738
const response = await getAgents(filter);
3839
if (response.items?.length > 0) {
3940
routers = response.items;
@@ -66,7 +67,7 @@
6667
<Col>
6768
<RoutingFlow
6869
routers={routers}
69-
targetAgentId={targetAgentId}
70+
viewOnlyMode={!!targetAgentId}
7071
on:userNodeSelected={(e) => handleUserNodeSelected()}
7172
on:routerNodeSelected={(e) => handleRouterNodeSelected(e.detail.agent)}
7273
on:agentNodeSelected={(e) => handleAgentNodeSelected(e.detail.agent)}/>

0 commit comments

Comments
 (0)