Skip to content

Commit c839807

Browse files
author
Jicheng Lu
committed
add user update api
1 parent 71a9959 commit c839807

File tree

10 files changed

+128
-48
lines changed

10 files changed

+128
-48
lines changed

src/lib/helpers/http.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ function skipLoader(config) {
6767
new RegExp('http(s*)://(.*?)/knowledge/vector/(.*?)/update', 'g'),
6868
new RegExp('http(s*)://(.*?)/conversation/(.*?)/update-message', 'g'),
6969
new RegExp('http(s*)://(.*?)/conversation/(.*?)/update-tags', 'g'),
70+
new RegExp('http(s*)://(.*?)/users', 'g'),
7071
];
7172

7273
const deleteRegexes = [
@@ -83,7 +84,8 @@ function skipLoader(config) {
8384
new RegExp('http(s*)://(.*?)/conversation/(.*?)/files/(.*?)', 'g'),
8485
new RegExp('http(s*)://(.*?)/llm-provider/(.*?)/models', 'g'),
8586
new RegExp('http(s*)://(.*?)/knowledge/vector/collections', 'g'),
86-
new RegExp('http(s*)://(.*?)/knowledge/vector/(.*?)/exist', 'g')
87+
new RegExp('http(s*)://(.*?)/knowledge/vector/(.*?)/exist', 'g'),
88+
new RegExp('http(s*)://(.*?)/users', 'g')
8789
];
8890

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

src/lib/helpers/types/userTypes.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
* @property {string[]} actions - The actions
2828
*/
2929

30+
/**
31+
* @typedef {Object} UserAgentInnerAction
32+
* @property {string?} [id] - The id
33+
* @property {string} agent_id - The agent id
34+
* @property {string} [agent_name] - The agent name
35+
* @property {import('$agentTypes').AgentModel} [agent] - The agent details
36+
* @property {{ key: string, value: string, checked: boolean }[]} actions - The actions
37+
*/
38+
3039
/**
3140
* @typedef {Object} UserFilter
3241
* @property {number} page - The page number

src/lib/scss/custom/common/_common.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ button:focus {
157157
justify-content:center;
158158
}
159159

160+
.div-center {
161+
display: flex;
162+
justify-content:center;
163+
}
164+
160165
.ellipsis {
161166
white-space: nowrap;
162167
overflow: hidden;
@@ -171,6 +176,10 @@ button:focus {
171176
.danger-background {
172177
background-color: $danger !important;
173178
}
179+
180+
.thin-scrollbar {
181+
scrollbar-width: thin;
182+
}
174183

175184
.markdown-container {
176185
overflow-x: auto;

src/lib/scss/custom/pages/_users.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
}
66

77
.user-permission-col {
8-
width: 10%;
8+
width: 20%;
99
max-width: 300px;
1010
}
1111

@@ -88,6 +88,7 @@
8888
display: flex;
8989
justify-content: flex-end;
9090
font-size: 16px;
91+
margin-top: 10px;
9192
}
9293
}
9394
}

src/lib/services/api-endpoints.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const endpoints = {
66
tokenUrl: `${host}/token`,
77
myInfoUrl: `${host}/user/me`,
88
usersUrl: `${host}/users`,
9+
userUpdateUrl: `${host}/user`,
910
usrCreationUrl: `${host}/user`,
1011
userAvatarUrl: `${host}/user/avatar`,
1112

src/lib/services/user-service.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,15 @@ import axios from 'axios';
99
export async function getUsers(filter) {
1010
const response = await axios.post(endpoints.usersUrl, { ...filter });
1111
return response.data;
12+
}
13+
14+
15+
/**
16+
* Get user list
17+
* @param {import('$userTypes').UserModel} model
18+
* @returns {Promise<boolean>}
19+
*/
20+
export async function updateUser(model) {
21+
const response = await axios.put(endpoints.userUpdateUrl, { ...model });
22+
return response.data;
1223
}

src/routes/page/agent/[agentId]/agent-overview.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
</Button>
8686
{/if}
8787
</div>
88-
<h5 class="mt-1 mb-1"><InPlaceEdit bind:value={agent.name} /></h5>
88+
<h5 class="mt-1 mb-1 div-center"><InPlaceEdit bind:value={agent.name} /></h5>
8989
<p class="text-muted mb-0">Updated at {format(agent.updated_datetime, 'time')}</p>
9090
</div>
9191
</CardHeader>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@
440440
{/if}
441441
</CardBody>
442442
<CardBody>
443-
<div class="table-responsive">
443+
<div class="table-responsive thin-scrollbar">
444444
<Table class="align-middle nowrap" bordered>
445445
<thead>
446446
<tr>

src/routes/page/users/+page.svelte

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
CardBody,
77
Col,
88
Dropdown,
9-
DropdownItem,
10-
DropdownMenu,
119
DropdownToggle,
1210
Input,
1311
Row,
@@ -19,21 +17,21 @@
1917
import Breadcrumb from '$lib/common/Breadcrumb.svelte';
2018
import TablePagination from '$lib/common/TablePagination.svelte';
2119
import LoadingToComplete from '$lib/common/LoadingToComplete.svelte';
22-
import { getUsers } from '$lib/services/user-service';
20+
import { getUsers, updateUser } from '$lib/services/user-service';
2321
import UserItem from './user-item.svelte';
2422
import { getAgents } from '$lib/services/agent-service';
2523
2624
const duration = 3000;
2725
const firstPage = 1;
28-
const pageSize = 5;
26+
const pageSize = 15;
2927
3028
const initPager = { page: firstPage, size: pageSize };
3129
3230
let isLoading = false;
3331
let isComplete = false;
3432
let isError = false;
35-
let successText = '';
36-
let errorText = '';
33+
let successText = 'User has been updated!';
34+
let errorText = 'Failed to update user!';
3735
3836
/** @type {import('$commonTypes').Pagination} */
3937
let pager = { ...initPager, count: 0 };
@@ -60,8 +58,18 @@
6058
});
6159
6260
async function getPagedUsers() {
63-
users = await getUsers(filter);
64-
refresh();
61+
isLoading = true;
62+
return new Promise((resolve, reject) => {
63+
getUsers(filter).then(res => {
64+
users = res;
65+
refresh();
66+
resolve(res);
67+
}).finally(() => {
68+
setTimeout(() => {
69+
isLoading = false;
70+
}, 200);
71+
});
72+
});
6573
}
6674
6775
async function getPagedAgents() {
@@ -123,9 +131,43 @@
123131
page: pageNum,
124132
size: pageSize
125133
};
126-
127134
getPagedUsers();
128135
}
136+
137+
/** @param {any} e */
138+
function saveUser(e) {
139+
const data = e.detail.updatedData;
140+
isLoading = true;
141+
updateUser(data).then(() => {
142+
isLoading = false;
143+
isComplete = true;
144+
postUpdateUser(data);
145+
setTimeout(() => {
146+
isComplete = false;
147+
}, duration);
148+
}).catch(() => {
149+
isLoading = false;
150+
isComplete = false;
151+
isError = true;
152+
setTimeout(() => {
153+
isError = false;
154+
}, duration);
155+
});
156+
}
157+
158+
/** @param {import('$userTypes').UserModel} data */
159+
function postUpdateUser(data) {
160+
const newItems = users?.items?.map(x => {
161+
if (x.id === data.id) {
162+
return { ...data };
163+
}
164+
return x;
165+
}) || [];
166+
users = {
167+
...users,
168+
items: newItems
169+
};
170+
}
129171
</script>
130172
131173
@@ -183,23 +225,22 @@
183225
</Row>
184226
</CardBody>
185227
<CardBody>
186-
<div class="table-responsive">
228+
<div class="table-responsive thin-scrollbar">
187229
<Table class="align-middle nowrap users-table" bordered>
188230
<thead>
189231
<tr>
190232
<th scope="col">{$_('User Name')}</th>
191233
<th scope="col">{$_('Full Name')}</th>
192234
<th scope="col">{$_('External Id')}</th>
193-
<th scope="col">{$_('Role')}</th>
235+
<th scope="col" class="user-plain-col">{$_('Role')}</th>
194236
<th scope="col">{$_('Source')}</th>
195237
<th scope="col" class="user-permission-col">{$_('Permissions')}</th>
196-
<th scope="col" class="user-agent-col">{$_('Agents')}</th>
197238
<th scope="col">{$_('')}</th>
198239
</tr>
199240
</thead>
200241
<tbody>
201242
{#each users.items as item, idx (idx)}
202-
<UserItem item={item} agents={agents} />
243+
<UserItem item={item} agents={agents} on:save={e => saveUser(e)} />
203244
{/each}
204245
</tbody>
205246
</Table>

0 commit comments

Comments
 (0)