Skip to content

Commit a9a2bd6

Browse files
author
Jicheng Lu
committed
refine scrolling
1 parent 3160259 commit a9a2bd6

File tree

5 files changed

+44
-35
lines changed

5 files changed

+44
-35
lines changed

src/lib/scss/custom/pages/_knowledgebase.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
display: flex;
259259
flex-direction: column;
260260
gap: 10px;
261-
max-height: 230px;
261+
max-height: 280px;
262262
overflow-y: auto;
263263
scrollbar-width: none;
264264

@@ -388,7 +388,7 @@
388388
gap: 10px;
389389
max-height: 300px;
390390
overflow-y: auto;
391-
scrollbar-width: thin;
391+
scrollbar-width: none;
392392

393393
.knowledge-adv-search-item {
394394
display: flex;

src/routes/page/knowledge-base/common/search/advanced-search.svelte

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,25 @@
7171
}
7272
}
7373
74-
async function addItem() {
74+
/** @param {any} e */
75+
async function addItem(e) {
76+
e.preventDefault();
77+
e.stopPropagation();
78+
7579
items = [
7680
...items,
7781
{ uuid: uuidv4(), key: '', value: '', checked: true }
7882
];
7983
8084
// Wait for DOM to update, then scroll to bottom
81-
await tick();
8285
if (scrollContainer) {
83-
scrollContainer.scrollTop = scrollContainer.scrollHeight;
86+
await tick();
87+
setTimeout(() => {
88+
scrollContainer.scrollTo({
89+
top: scrollContainer.scrollHeight,
90+
behavior: 'smooth'
91+
});
92+
}, 0);
8493
}
8594
}
8695
@@ -223,7 +232,7 @@
223232
<Button
224233
color="link"
225234
style="width: fit-content"
226-
on:click={() => addItem()}
235+
on:click={e => addItem(e)}
227236
>
228237
{'Add +'}
229238
</Button>

src/routes/page/knowledge-base/common/vector-table/vector-item-edit-modal.svelte

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,21 @@
105105
});
106106
}
107107
108-
async function addPayloadItem() {
108+
/** @param {any} e */
109+
async function addPayloadItem(e) {
110+
e.preventDefault();
111+
e.stopPropagation();
112+
109113
innerPayloads = [...innerPayloads, { uuid: uuidv4(), key: '', value: ''}];
110114
111-
await tick();
112-
if (scrollContainer) {
113-
scrollContainer.scrollTop = scrollContainer.scrollHeight;
115+
if (allowPayload && scrollContainer) {
116+
await tick();
117+
setTimeout(() => {
118+
scrollContainer.scrollTo({
119+
top: scrollContainer.scrollHeight,
120+
behavior: 'smooth'
121+
});
122+
}, 0);
114123
}
115124
}
116125
@@ -147,7 +156,7 @@
147156
}
148157
149158
const validPayloads = innerPayloads.map(x => ({ key: util.trim(x.key), value: util.trim(x.value) }))
150-
.filter(x => !!x.key && !!x.value && !excludedPayloads.includes(x.key));
159+
.filter(x => !!x.key && !!x.value && !excludedPayloads.includes(x.key));
151160
152161
const obj = validPayloads.reduce((acc, cur) => {
153162
// @ts-ignore
@@ -300,7 +309,7 @@
300309
<Button
301310
color="link"
302311
style="width: fit-content"
303-
on:click={() => addPayloadItem()}
312+
on:click={e => addPayloadItem(e)}
304313
>
305314
{'Add Payload +'}
306315
</Button>

src/routes/page/knowledge-base/documents/+page.svelte

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -497,19 +497,17 @@
497497
function confirmEdit(e) {
498498
isLoading = true;
499499
isOpenEditKnowledge = false;
500-
const dataSource = e.data?.dataSource || VectorDataSource.User;
501-
e.data.dataSource = dataSource;
500+
e.payload = {
501+
...e.payload || {},
502+
dataSource: e.payload?.dataSource || VectorDataSource.User
503+
};
502504
503505
if (!!editItem) {
504-
const {
505-
text,
506-
...payload
507-
} = e.data;
508506
updateVectorKnowledgeData(
509507
e.id,
510508
editCollection,
511509
e.data?.text,
512-
e.data?.dataSource,
510+
e.payload?.dataSource,
513511
e.payload
514512
).then(res => {
515513
if (res) {
@@ -537,7 +535,7 @@
537535
createVectorKnowledgeData(
538536
editCollection,
539537
e.data?.text,
540-
e.data.dataSource,
538+
e.payload?.dataSource,
541539
e.payload
542540
).then(res => {
543541
if (res) {
@@ -571,7 +569,6 @@
571569
if (found) {
572570
const newData = {
573571
text: newItem.data?.text || '',
574-
dataSource: newItem.data?.dataSource,
575572
...newItem.payload
576573
};
577574
@@ -746,8 +743,7 @@
746743
allowPayload
747744
payloadLimit={10}
748745
excludedPayloads={[
749-
KnowledgePayloadName.Text,
750-
KnowledgePayloadName.DataSource
746+
KnowledgePayloadName.Text
751747
]}
752748
toggleModal={() => isOpenEditKnowledge = !isOpenEditKnowledge}
753749
confirm={(e) => confirmEdit(e)}

src/routes/page/knowledge-base/question-answer/+page.svelte

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -485,24 +485,21 @@
485485
function confirmEdit(e) {
486486
isLoading = true;
487487
isOpenEditKnowledge = false;
488-
const dataSource = e.data?.dataSource || VectorDataSource.User;
489-
e.data.dataSource = dataSource;
488+
e.payload = {
489+
...e.payload || {},
490+
dataSource: e.payload?.dataSource || VectorDataSource.User
491+
};
490492
491493
if (!!editItem) {
492-
const {
493-
text,
494-
...payload
495-
} = e.data;
496494
updateVectorKnowledgeData(
497495
e.id,
498496
editCollection,
499497
e.data?.text,
500-
e.data.dataSource,
498+
e.payload?.dataSource,
501499
{ answer: e.data?.answer, ...e.payload }
502500
).then(res => {
503501
if (res) {
504502
isComplete = true;
505-
e.data.dataSource = dataSource;
506503
refreshItems(e);
507504
resetEditData();
508505
successText = "Knowledge has been updated!";
@@ -526,7 +523,7 @@
526523
createVectorKnowledgeData(
527524
editCollection,
528525
e.data?.text,
529-
e.data.dataSource,
526+
e.payload?.dataSource,
530527
{ answer: e.data?.answer, ...e.payload }
531528
).then(res => {
532529
if (res) {
@@ -561,7 +558,6 @@
561558
const newData = {
562559
text: newItem.data?.text || '',
563560
answer: newItem.data?.answer || '',
564-
dataSource: newItem.data?.dataSource,
565561
...newItem.payload
566562
};
567563
@@ -698,8 +694,7 @@
698694
excludedPayloads={[
699695
KnowledgePayloadName.Text,
700696
KnowledgePayloadName.Question,
701-
KnowledgePayloadName.Answer,
702-
KnowledgePayloadName.DataSource
697+
KnowledgePayloadName.Answer
703698
]}
704699
toggleModal={() => isOpenEditKnowledge = !isOpenEditKnowledge}
705700
confirm={(e) => confirmEdit(e)}

0 commit comments

Comments
 (0)