# 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>
114 lines
3.3 KiB
Vue
114 lines
3.3 KiB
Vue
<script setup>
|
|
import { computed, ref } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { useStore } from 'dashboard/composables/store';
|
|
import { useAlert } from 'dashboard/composables';
|
|
|
|
import BulkSelectBar from 'dashboard/components-next/captain/assistant/BulkSelectBar.vue';
|
|
import BulkDeleteDialog from 'dashboard/components-next/captain/pageComponents/BulkDeleteDialog.vue';
|
|
import Button from 'dashboard/components-next/button/Button.vue';
|
|
|
|
const props = defineProps({
|
|
selectedIds: { type: Set, default: () => new Set() },
|
|
documents: { type: Array, default: () => [] },
|
|
});
|
|
|
|
const emit = defineEmits([
|
|
'update:selectedIds',
|
|
'bulkSyncQueued',
|
|
'bulkDeleteSucceeded',
|
|
]);
|
|
|
|
const { t } = useI18n();
|
|
const store = useStore();
|
|
|
|
const bulkDeleteDialog = ref(null);
|
|
|
|
const isSyncableDocument = doc =>
|
|
!doc.pdf_document && doc.status === 'available' && !doc.sync_in_progress;
|
|
|
|
const syncableSelectedIds = computed(() => {
|
|
if (!props.selectedIds.size) return [];
|
|
return props.documents
|
|
.filter(doc => props.selectedIds.has(doc.id) && isSyncableDocument(doc))
|
|
.map(doc => doc.id);
|
|
});
|
|
|
|
const hasSyncableSelection = computed(
|
|
() => syncableSelectedIds.value.length > 0
|
|
);
|
|
|
|
const selectAllLabel = computed(() => {
|
|
const count = props.documents.length;
|
|
const isAllSelected = props.selectedIds.size === count && count > 0;
|
|
return isAllSelected
|
|
? t('CAPTAIN.DOCUMENTS.UNSELECT_ALL', { count })
|
|
: t('CAPTAIN.DOCUMENTS.SELECT_ALL', { count });
|
|
});
|
|
|
|
const selectedCountLabel = computed(() =>
|
|
t('CAPTAIN.DOCUMENTS.SELECTED', { count: props.selectedIds.size })
|
|
);
|
|
|
|
const handleBulkSync = async () => {
|
|
const ids = syncableSelectedIds.value;
|
|
if (!ids.length) return;
|
|
|
|
try {
|
|
const response = await store.dispatch('captainBulkActions/handleBulkSync', {
|
|
ids,
|
|
});
|
|
const queuedCount = response?.count ?? response?.ids?.length ?? 0;
|
|
let message = t('CAPTAIN.DOCUMENTS.BULK_SYNC.ZERO_MESSAGE');
|
|
|
|
if (queuedCount === 1) {
|
|
message = t('CAPTAIN.DOCUMENTS.BULK_SYNC.SUCCESS_MESSAGE_ONE');
|
|
} else if (queuedCount > 1) {
|
|
message = t('CAPTAIN.DOCUMENTS.BULK_SYNC.SUCCESS_MESSAGE', {
|
|
count: queuedCount,
|
|
});
|
|
}
|
|
|
|
useAlert(message);
|
|
emit('update:selectedIds', new Set());
|
|
if (queuedCount > 0) emit('bulkSyncQueued');
|
|
} catch (error) {
|
|
useAlert(t('CAPTAIN.DOCUMENTS.BULK_SYNC.ERROR_MESSAGE'));
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<BulkSelectBar
|
|
:model-value="selectedIds"
|
|
:all-items="documents"
|
|
:select-all-label="selectAllLabel"
|
|
:selected-count-label="selectedCountLabel"
|
|
:delete-label="$t('CAPTAIN.DOCUMENTS.BULK_DELETE_BUTTON')"
|
|
class="w-fit"
|
|
:class="{ 'mb-2': selectedIds.size > 0 }"
|
|
@update:model-value="emit('update:selectedIds', $event)"
|
|
@bulk-delete="bulkDeleteDialog.dialogRef.open()"
|
|
>
|
|
<template v-if="hasSyncableSelection" #secondaryActions>
|
|
<Button
|
|
:label="$t('CAPTAIN.DOCUMENTS.BULK_SYNC_BUTTON')"
|
|
sm
|
|
slate
|
|
ghost
|
|
icon="i-lucide-refresh-cw"
|
|
class="!px-1.5"
|
|
@click="handleBulkSync"
|
|
/>
|
|
</template>
|
|
</BulkSelectBar>
|
|
<BulkDeleteDialog
|
|
ref="bulkDeleteDialog"
|
|
:bulk-ids="selectedIds"
|
|
type="AssistantDocument"
|
|
@delete-success="emit('bulkDeleteSucceeded')"
|
|
/>
|
|
</div>
|
|
</template>
|