# Pull Request Template ## Description FE code for document sync Adds: - UI to show counts (stats) of available web pages, stale and synced documents and last synced at - Bulk action and manual ways to sync web documents - index to stats related columns ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration. https://linear.app/chatwoot/issue/AI-153/fe-document-auto-sync Documents dashboard: <img width="2160" height="986" alt="CleanShot 2026-05-11 at 17 57 09@2x" src="https://github.com/user-attachments/assets/6d934764-964c-4656-b005-1b4f0329e553" /> Filters: <img width="1138" height="564" alt="CleanShot 2026-05-11 at 17 58 13@2x" src="https://github.com/user-attachments/assets/cee780e6-eb8f-4aed-8cc5-b674244a821b" /> Needs update: <img width="2222" height="966" alt="CleanShot 2026-05-11 at 17 57 53@2x" src="https://github.com/user-attachments/assets/70c85ddd-7eb1-4328-ba14-7929e67e7b36" /> pdfs: <img width="2180" height="558" alt="CleanShot 2026-05-11 at 17 58 30@2x" src="https://github.com/user-attachments/assets/975b5c9f-bd1c-4979-9870-8f926d7f6e11" /> bulk actions: <img width="2244" height="992" alt="CleanShot 2026-05-11 at 17 58 57@2x" src="https://github.com/user-attachments/assets/bdb3c63f-d2de-41dc-a6d5-8821d3303be0" /> single url sync: <img width="2264" height="722" alt="CleanShot 2026-05-11 at 17 59 19@2x" src="https://github.com/user-attachments/assets/7d7323a5-0fcb-4be9-8635-55e56964999b" /> ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: iamsivin <iamsivin@gmail.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Sony Mathew <sony@chatwoot.com> Co-authored-by: Vishnu Narayanan <iamwishnu@gmail.com>
248 lines
6.6 KiB
Vue
248 lines
6.6 KiB
Vue
<script setup>
|
|
import { computed } from 'vue';
|
|
import { useToggle } from '@vueuse/core';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { dynamicTime } from 'shared/helpers/timeHelper';
|
|
import { usePolicy } from 'dashboard/composables/usePolicy';
|
|
import {
|
|
isSafeHttpLink,
|
|
formatDocumentLink,
|
|
getDocumentDisplayPath,
|
|
} from 'shared/helpers/documentHelper';
|
|
|
|
import Icon from 'dashboard/components-next/icon/Icon.vue';
|
|
import CardLayout from 'dashboard/components-next/CardLayout.vue';
|
|
import DropdownMenu from 'dashboard/components-next/dropdown-menu/DropdownMenu.vue';
|
|
import Button from 'dashboard/components-next/button/Button.vue';
|
|
import Checkbox from 'dashboard/components-next/checkbox/Checkbox.vue';
|
|
import DocumentSyncStatus from 'dashboard/components-next/captain/assistant/DocumentSyncStatus.vue';
|
|
|
|
const props = defineProps({
|
|
id: {
|
|
type: Number,
|
|
required: true,
|
|
},
|
|
name: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
assistant: {
|
|
type: Object,
|
|
default: () => ({}),
|
|
},
|
|
externalLink: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
pdfDocument: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
createdAt: {
|
|
type: Number,
|
|
required: true,
|
|
},
|
|
status: {
|
|
type: String,
|
|
default: null,
|
|
},
|
|
syncStatus: {
|
|
type: String,
|
|
default: null,
|
|
},
|
|
lastSyncedAt: {
|
|
type: Number,
|
|
default: null,
|
|
},
|
|
lastSyncErrorCode: {
|
|
type: String,
|
|
default: null,
|
|
},
|
|
syncInProgress: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
syncStaleAfterHours: {
|
|
type: Number,
|
|
default: null,
|
|
},
|
|
isSelected: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
selectable: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
showSelectionControl: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
showMenu: {
|
|
type: Boolean,
|
|
default: true,
|
|
},
|
|
});
|
|
|
|
const emit = defineEmits(['action', 'select', 'hover']);
|
|
const { checkPermissions } = usePolicy();
|
|
|
|
const { t } = useI18n();
|
|
|
|
const [showActionsDropdown, toggleDropdown] = useToggle();
|
|
const modelValue = computed({
|
|
get: () => props.isSelected,
|
|
set: () => emit('select', props.id),
|
|
});
|
|
|
|
const isPdf = computed(() => props.pdfDocument);
|
|
const hasSafeLink = computed(() => isSafeHttpLink(props.externalLink));
|
|
const canManage = computed(() => checkPermissions(['administrator']));
|
|
const isAvailable = computed(() => props.status === 'available');
|
|
const canSync = computed(
|
|
() => canManage.value && !isPdf.value && isAvailable.value
|
|
);
|
|
const isSyncing = computed(() => props.syncStatus === 'syncing');
|
|
const isFailed = computed(() => props.syncStatus === 'failed');
|
|
const isRetryableSync = computed(
|
|
() => isFailed.value || (isSyncing.value && !props.syncInProgress)
|
|
);
|
|
const showSyncStatus = computed(() => !isPdf.value);
|
|
|
|
const menuItems = computed(() => {
|
|
const allOptions = [
|
|
{
|
|
label: t('CAPTAIN.DOCUMENTS.OPTIONS.VIEW_RELATED_RESPONSES'),
|
|
value: 'viewRelatedQuestions',
|
|
action: 'viewRelatedQuestions',
|
|
icon: 'i-ph-tree-view-duotone',
|
|
},
|
|
];
|
|
|
|
if (canSync.value) {
|
|
allOptions.push({
|
|
label: isRetryableSync.value
|
|
? t('CAPTAIN.DOCUMENTS.OPTIONS.RETRY_SYNC')
|
|
: t('CAPTAIN.DOCUMENTS.OPTIONS.SYNC_NOW'),
|
|
value: 'sync',
|
|
action: 'sync',
|
|
icon: 'i-lucide-refresh-cw',
|
|
disabled: props.syncInProgress,
|
|
});
|
|
}
|
|
|
|
if (canManage.value) {
|
|
allOptions.push({
|
|
label: t('CAPTAIN.DOCUMENTS.OPTIONS.DELETE_DOCUMENT'),
|
|
value: 'delete',
|
|
action: 'delete',
|
|
icon: 'i-lucide-trash',
|
|
});
|
|
}
|
|
|
|
return allOptions;
|
|
});
|
|
|
|
const createdAtLabel = computed(() => dynamicTime(props.createdAt));
|
|
|
|
const displayLink = computed(() =>
|
|
isPdf.value
|
|
? formatDocumentLink(props.externalLink)
|
|
: getDocumentDisplayPath(props.externalLink)
|
|
);
|
|
const linkIcon = computed(() =>
|
|
isPdf.value ? 'i-ph-file-pdf' : 'i-ph-link-simple'
|
|
);
|
|
|
|
const handleAction = ({ action, value }) => {
|
|
toggleDropdown(false);
|
|
emit('action', { action, value, id: props.id });
|
|
};
|
|
|
|
const handleRetry = () => {
|
|
emit('action', { action: 'sync', id: props.id });
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<CardLayout
|
|
:selectable="selectable"
|
|
class="relative"
|
|
@mouseenter="emit('hover', true)"
|
|
@mouseleave="emit('hover', false)"
|
|
>
|
|
<div
|
|
v-show="showSelectionControl"
|
|
class="absolute top-7 ltr:left-3 rtl:right-3"
|
|
>
|
|
<Checkbox v-model="modelValue" />
|
|
</div>
|
|
<div class="flex gap-1 justify-between w-full">
|
|
<span class="text-base text-n-slate-12 line-clamp-1">
|
|
{{ name }}
|
|
</span>
|
|
<div v-if="showMenu" class="flex gap-2 items-center">
|
|
<div
|
|
v-on-clickaway="() => toggleDropdown(false)"
|
|
class="flex relative items-center group"
|
|
>
|
|
<Button
|
|
icon="i-lucide-ellipsis-vertical"
|
|
color="slate"
|
|
size="xs"
|
|
class="rounded-md group-hover:bg-n-alpha-2"
|
|
@click="toggleDropdown()"
|
|
/>
|
|
<DropdownMenu
|
|
v-if="showActionsDropdown"
|
|
:menu-items="menuItems"
|
|
class="top-full mt-1 ltr:right-0 rtl:left-0 xl:ltr:right-0 xl:rtl:left-0"
|
|
@action="handleAction($event)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="flex gap-4 justify-between items-center w-full">
|
|
<span
|
|
class="flex gap-1 items-center text-sm truncate shrink-0 text-n-slate-11"
|
|
>
|
|
<Icon icon="i-woot-captain" />
|
|
{{ assistant?.name || '' }}
|
|
</span>
|
|
<a
|
|
v-if="!isPdf && hasSafeLink"
|
|
:href="externalLink"
|
|
:title="externalLink"
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
class="flex flex-1 gap-1 justify-start items-center text-sm truncate text-n-slate-11 hover:text-n-slate-12 hover:underline"
|
|
@click.stop
|
|
>
|
|
<Icon :icon="linkIcon" class="shrink-0" />
|
|
<span class="truncate">{{ displayLink }}</span>
|
|
<Icon icon="i-lucide-external-link size-3 shrink-0 opacity-70" />
|
|
</a>
|
|
<span
|
|
v-else
|
|
class="flex flex-1 gap-1 justify-start items-center text-sm truncate text-n-slate-11"
|
|
>
|
|
<Icon :icon="linkIcon" class="shrink-0" />
|
|
<span class="truncate">{{ displayLink }}</span>
|
|
</span>
|
|
<DocumentSyncStatus
|
|
v-if="showSyncStatus"
|
|
:status="syncStatus"
|
|
:last-synced-at="lastSyncedAt"
|
|
:error-code="lastSyncErrorCode"
|
|
:sync-in-progress="syncInProgress"
|
|
:stale-after-hours="syncStaleAfterHours"
|
|
:show-retry="canSync && isRetryableSync"
|
|
@retry="handleRetry"
|
|
/>
|
|
<div v-else class="text-sm shrink-0 text-n-slate-11 line-clamp-1">
|
|
{{ createdAtLabel }}
|
|
</div>
|
|
</div>
|
|
</CardLayout>
|
|
</template>
|