+
{text}
(
- { key: k, value: v }
- ));
/** @type {any[]} */
let scrollbars = [];
@@ -239,7 +236,8 @@
conversation = await getConversation(params.conversationId, true);
dialogs = await getDialogs(params.conversationId, dialogCount);
conversationUser = conversation?.user;
- selectedTags = conversation?.tags || [];
+ convTags = conversation?.tags || [];
+
latestStateLog = conversation?.states;
initUserSentMessages(dialogs);
initChatView();
@@ -1409,44 +1407,55 @@
function toggleTagModal() {
isOpenTagModal = !isOpenTagModal;
if (!isOpenTagModal) {
- selectedTags = conversation?.tags || [];
+ newTagText = '';
+ convTags = conversation?.tags || [];
}
}
- /**
- * @param {any} e
- * @param {string} value
- */
- function changeTagSelection(e, value) {
- const checked = e.target.checked;
- if (checked) {
- selectedTags = [...new Set([...selectedTags, value])];
- } else {
- selectedTags = selectedTags.filter(x => x !== value);
+ /** @param {number | string} idx */
+ function removeTag(idx) {
+ const tag = convTags?.[/** @type {number} */ (idx)];
+ if (!tag) return;
+ convTags = convTags.filter(t => t !== tag);
+ }
+
+ function addTag() {
+ const tag = _.trim(newTagText);
+ if (!tag || convTags.includes(tag)) {
+ return;
}
+ convTags = [...convTags, tag];
+ newTagText = '';
}
function updateChatTags() {
+ const originalTags = conversation?.tags || [];
+ const toAddTags = convTags.filter(t => !originalTags.includes(t));
+ const toDeleteTags = originalTags.filter((/** @type {string} */ t) => !convTags.includes(t));
+
+ if (toAddTags.length === 0 && toDeleteTags.length === 0) {
+ isOpenTagModal = false;
+ return;
+ }
+
isLoading = true;
updateConversationTags(
params.conversationId,
- {
- toAddTags: selectedTags,
- toDeleteTags: tagOptions.filter(x => !selectedTags.includes(x.value)).map(x => x.value)
- })
+ { toAddTags, toDeleteTags })
.then(res => {
if (res) {
+ conversation.tags = [...convTags];
isComplete = true;
- successText = "Tags has been updated!";
+ successText = "Tags have been updated!";
setTimeout(() => {
isComplete = false;
successText = "";
}, duration);
} else {
- throw "Failed to update chat tags.";
+ throw "Failed to update tags.";
}
}).catch(() => {
- selectedTags = conversation?.tags || [];
+ convTags = conversation?.tags || [];
isError = true;
errorText = "Failed to update tags!";
setTimeout(() => {
@@ -1567,23 +1576,38 @@
closeable
toggleModal={() => toggleTagModal()}
confirmBtnText={'Confirm'}
- cancelBtnText={'Cancel'}
+ cancelBtnText={''}
confirm={() => updateChatTags()}
- cancel={() => toggleTagModal()}
close={() => toggleTagModal()}
>
+
+ { if (e.key === 'Enter') addTag(); }}
+ />
+
+
toggleTagModal()}
>
- Add Tags
+ Tags
{/if}
{#if agent?.id === LEARNER_AGENT_ID && mode === TRAINING_MODE}