Skip to content

Commit c223843

Browse files
committed
refine conv tags
1 parent 3a08132 commit c223843

File tree

3 files changed

+81
-50
lines changed

3 files changed

+81
-50
lines changed

src/lib/common/shared/Label.svelte

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
export let text = "";
55
export let className = "";
66
export let style = "";
7+
export let color = "primary";
8+
export let ellipsis = false;
79
/** @type {string | number} */
810
export let index;
911
/** @type {(args0: number | string) => void} */
@@ -20,9 +22,9 @@
2022
</script>
2123

2224
<div class={`label-container ${className}`} style={`${style}`}>
23-
<button class="btn btn-primary btn-sm label-btn">
25+
<button class={`btn btn-${color} btn-sm label-btn`}>
2426
<div style="display: flex;">
25-
<span class="d-none d-sm-inline-block me-2 label-text">
27+
<span class={`me-2 label-text ${ellipsis ? 'label-ellipsis' : 'd-none d-sm-inline-block'}`}>
2628
{text}
2729
</span>
2830
<i
@@ -55,6 +57,13 @@
5557
text-align: left;
5658
}
5759
60+
.label-ellipsis {
61+
overflow: hidden;
62+
text-overflow: ellipsis;
63+
white-space: nowrap;
64+
max-width: 120px;
65+
}
66+
5867
.label-close {
5968
cursor: pointer;
6069
display: flex;

src/lib/scss/custom/pages/_chat.scss

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -829,16 +829,14 @@
829829
display: flex;
830830
flex-wrap: wrap;
831831
overflow-y: auto;
832-
scrollbar-width: none;
832+
scrollbar-width: thin;
833833
min-height: 80px;
834834
max-height: 180px;
835+
}
835836

836-
.conv-tag-unit {
837-
flex: 0 0 50%;
838-
839-
label {
840-
font-size: 14px;
841-
font-weight: 400;
842-
}
843-
}
837+
.conv-tag-add {
838+
display: flex;
839+
align-items: center;
840+
gap: 8px;
841+
margin-top: 10px;
844842
}

src/routes/chat/[agentId]/[conversationId]/chat-box.svelte

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
Dropdown,
1414
DropdownToggle,
1515
DropdownMenu,
16-
DropdownItem,
17-
Input
16+
DropdownItem
1817
} from '@sveltestrap/sveltestrap';
1918
import {
2019
conversationStore,
@@ -56,6 +55,7 @@
5655
import LoadingToComplete from '$lib/common/spinners/LoadingToComplete.svelte';
5756
import AudioSpeaker from '$lib/common/audio-player/AudioSpeaker.svelte';
5857
import CodeScript from '$lib/common/shared/CodeScript.svelte';
58+
import Label from '$lib/common/shared/Label.svelte';
5959
import { realtimeChat } from '$lib/services/realtime-chat-service';
6060
import { webSpeech } from '$lib/services/web-speech';
6161
import LocalStorageManager from '$lib/helpers/utils/storage-manager';
@@ -64,7 +64,7 @@
6464
import { utcToLocal } from '$lib/helpers/datetime';
6565
import { replaceNewLine } from '$lib/helpers/http';
6666
import { isAudio, isExcel, isPdf } from '$lib/helpers/utils/file';
67-
import { ChatAction, ConversationTag, EditorType, FileSourceType, RichType, SenderAction, UserRole } from '$lib/helpers/enums';
67+
import { ChatAction, EditorType, FileSourceType, RichType, SenderAction, UserRole } from '$lib/helpers/enums';
6868
import ChatTextArea from './chat-util/chat-text-area.svelte';
6969
import RichContent from './rich-content/rich-content.svelte';
7070
import RcMessage from "./rich-content/rc-message.svelte";
@@ -131,12 +131,9 @@
131131
/** @type {string[]} */
132132
let chatUtilOptions = [];
133133
/** @type {string[]} */
134-
let selectedTags = [];
134+
let convTags = [];
135+
let newTagText = '';
135136
136-
/** @type {import('$commonTypes').KeyValuePair[]} */
137-
let tagOptions = Object.entries(ConversationTag).map(([k, v]) => (
138-
{ key: k, value: v }
139-
));
140137
141138
/** @type {any[]} */
142139
let scrollbars = [];
@@ -239,7 +236,8 @@
239236
conversation = await getConversation(params.conversationId, true);
240237
dialogs = await getDialogs(params.conversationId, dialogCount);
241238
conversationUser = conversation?.user;
242-
selectedTags = conversation?.tags || [];
239+
convTags = conversation?.tags || [];
240+
243241
latestStateLog = conversation?.states;
244242
initUserSentMessages(dialogs);
245243
initChatView();
@@ -1409,44 +1407,55 @@
14091407
function toggleTagModal() {
14101408
isOpenTagModal = !isOpenTagModal;
14111409
if (!isOpenTagModal) {
1412-
selectedTags = conversation?.tags || [];
1410+
newTagText = '';
1411+
convTags = conversation?.tags || [];
14131412
}
14141413
}
14151414
1416-
/**
1417-
* @param {any} e
1418-
* @param {string} value
1419-
*/
1420-
function changeTagSelection(e, value) {
1421-
const checked = e.target.checked;
1422-
if (checked) {
1423-
selectedTags = [...new Set([...selectedTags, value])];
1424-
} else {
1425-
selectedTags = selectedTags.filter(x => x !== value);
1415+
/** @param {number | string} idx */
1416+
function removeTag(idx) {
1417+
const tag = convTags?.[/** @type {number} */ (idx)];
1418+
if (!tag) return;
1419+
convTags = convTags.filter(t => t !== tag);
1420+
}
1421+
1422+
function addTag() {
1423+
const tag = _.trim(newTagText);
1424+
if (!tag || convTags.includes(tag)) {
1425+
return;
14261426
}
1427+
convTags = [...convTags, tag];
1428+
newTagText = '';
14271429
}
14281430
14291431
function updateChatTags() {
1432+
const originalTags = conversation?.tags || [];
1433+
const toAddTags = convTags.filter(t => !originalTags.includes(t));
1434+
const toDeleteTags = originalTags.filter((/** @type {string} */ t) => !convTags.includes(t));
1435+
1436+
if (toAddTags.length === 0 && toDeleteTags.length === 0) {
1437+
isOpenTagModal = false;
1438+
return;
1439+
}
1440+
14301441
isLoading = true;
14311442
updateConversationTags(
14321443
params.conversationId,
1433-
{
1434-
toAddTags: selectedTags,
1435-
toDeleteTags: tagOptions.filter(x => !selectedTags.includes(x.value)).map(x => x.value)
1436-
})
1444+
{ toAddTags, toDeleteTags })
14371445
.then(res => {
14381446
if (res) {
1447+
conversation.tags = [...convTags];
14391448
isComplete = true;
1440-
successText = "Tags has been updated!";
1449+
successText = "Tags have been updated!";
14411450
setTimeout(() => {
14421451
isComplete = false;
14431452
successText = "";
14441453
}, duration);
14451454
} else {
1446-
throw "Failed to update chat tags.";
1455+
throw "Failed to update tags.";
14471456
}
14481457
}).catch(() => {
1449-
selectedTags = conversation?.tags || [];
1458+
convTags = conversation?.tags || [];
14501459
isError = true;
14511460
errorText = "Failed to update tags!";
14521461
setTimeout(() => {
@@ -1567,23 +1576,38 @@
15671576
closeable
15681577
toggleModal={() => toggleTagModal()}
15691578
confirmBtnText={'Confirm'}
1570-
cancelBtnText={'Cancel'}
1579+
cancelBtnText={''}
15711580
confirm={() => updateChatTags()}
1572-
cancel={() => toggleTagModal()}
15731581
close={() => toggleTagModal()}
15741582
>
15751583
<div class="conv-tags-container">
1576-
{#each tagOptions as op}
1577-
<div class="conv-tag-unit">
1578-
<Input
1579-
type="checkbox"
1580-
label={op.value}
1581-
checked={selectedTags.includes(op.value)}
1582-
on:change={e => changeTagSelection(e, op.value)}
1583-
/>
1584-
</div>
1584+
{#each convTags as tag, idx}
1585+
<Label
1586+
text={tag}
1587+
index={idx}
1588+
color="info"
1589+
ellipsis
1590+
onClose={removeTag}
1591+
/>
15851592
{/each}
15861593
</div>
1594+
<div class="conv-tag-add">
1595+
<input
1596+
class="form-control form-control-sm"
1597+
type="text"
1598+
placeholder="Enter new tag..."
1599+
maxlength={50}
1600+
bind:value={newTagText}
1601+
on:keydown={e => { if (e.key === 'Enter') addTag(); }}
1602+
/>
1603+
<button
1604+
class="btn btn-primary btn-sm"
1605+
disabled={!_.trim(newTagText)}
1606+
on:click={() => addTag()}
1607+
>
1608+
<i class="bx bx-plus" />
1609+
</button>
1610+
</div>
15871611
</DialogModal>
15881612
15891613
<DialogModal
@@ -1763,7 +1787,7 @@
17631787
disabled={disableAction}
17641788
on:click={() => toggleTagModal()}
17651789
>
1766-
Add Tags
1790+
Tags
17671791
</DropdownItem>
17681792
{/if}
17691793
{#if agent?.id === LEARNER_AGENT_ID && mode === TRAINING_MODE}

0 commit comments

Comments
 (0)