Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

feat(dataset-overview): show datasource sync logs on dataset logs page (#20738)

chanx82d1c2603f94
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index 84a4f2ac8e..d4a5252855 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -510,6 +510,7 @@ Example: A 1 KB message with 1024-dim embedding uses ~9 KB. The 5 MB default lim
source: 'Source',
fileName: 'File name',
datasetLogs: 'Dataset',
+ datasourceLogs: 'Data source',
fileLogs: 'File',
overview: 'Logs',
success: 'Success',
diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts
index 6b8218e2fc..79cf236498 100644
--- a/web/src/locales/zh.ts
+++ b/web/src/locales/zh.ts
@@ -454,6 +454,7 @@ export default {
source: '来源',
fileName: '文件名',
datasetLogs: '知识库',
+ datasourceLogs: '数据源',
fileLogs: '文件',
overview: '日志',
success: '成功',
diff --git a/web/src/pages/dataset/dataset-overview/data-source-logs-table.tsx b/web/src/pages/dataset/dataset-overview/data-source-logs-table.tsx
new file mode 100644
index 0000000000..0074dfdd70
--- /dev/null
+++ b/web/src/pages/dataset/dataset-overview/data-source-logs-table.tsx
@@ -0,0 +1,174 @@
+import { EmptyType } from '@/components/empty/constant';
+import Empty from '@/components/empty/empty';
+import { RAGFlowPagination } from '@/components/ui/ragflow-pagination';
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from '@/components/ui/table';
+import { RunningStatus, RunningStatusOld } from '@/constants/knowledge';
+import { useGetPaginationWithRouter } from '@/hooks/logic-hooks';
+import { IDataSourceLog } from '@/pages/user-setting/data-source/interface';
+import { getDataSourceLogsTableColumns } from '@/pages/user-setting/data-source/log-columns';
+import { listDataPipelineLogDocument } from '@/services/knowledge-service';
+import {
+ flexRender,
+ getCoreRowModel,
+ getFilteredRowModel,
+ getPaginationRowModel,
+ getSortedRowModel,
+ useReactTable,
+} from '@tanstack/react-table';
+import { useQuery } from '@tanstack/react-query';
+import { useMemo } from 'react';
+import { useTranslation } from 'react-i18next';
+import { LogTabs } from './dataset-common';
+import { DatasetOverviewKeys } from './utils';
+
+const PollIntervalMs = 5000;
+
+// Backend variants differ: Python emits "SCHEDULE", Go emits "5".
+const isScheduledRow = (log: IDataSourceLog) => {
+ const status = log.status as string;
+ return (
+ status === RunningStatus.SCHEDULE || status === RunningStatusOld.SCHEDULE
+ );
+};
+
+const DataSourceLogsTable = ({ datasetId }: { datasetId: string }) => {
+ const { t: tDatasetOverview } = useTranslation('datasetOverview');
+ const { pagination, setPagination } = useGetPaginationWithRouter();
+
+ const { data } = useQuery<{ logs: IDataSourceLog[]; total: number }>({
+ queryKey: DatasetOverviewKeys.logs(
+ datasetId,
+ pagination.current,
+ pagination.pageSize,
+ '',
+ LogTabs.DATASOURCE_LOGS,
+ {},
+ ),
+ placeholderData: (previousData) => previousData ?? { logs: [], total: 0 },
+ enabled: !!datasetId,
+ // Refetch immediately whenever the tab is shown so the user always
+ // sees the latest sync state on entry.
+ refetchOnMount: 'always',
+ // Poll at a fixed cadence while the tab is open.
+ refetchInterval: PollIntervalMs,
+ queryFn: async () => {
+ const { data: res = {} } = await listDataPipelineLogDocument(datasetId, {
+ page: pagination.current,
+ page_size: pagination.pageSize,
+ log_type: 'datasource',
+ });
+ return res.data || { logs: [], total: 0 };
+ },
+ });
+
+ // Scheduled rows (the ones rendering the "Task starts in" countdown)
+ // are hidden here: the dataset view is a completed-history log, the
+ // live schedule belongs on the personal data source detail page.
+ const visibleLogs = useMemo(
+ () => (data?.logs || []).filter((log) => !isScheduledRow(log)),
+ [data?.logs],
+ );
+
+ // Static `now`: with scheduled rows filtered out no cell renders a
+ // live countdown, so the table doesn't need a 1s re-render tick.
+ const columns = useMemo(
+ () =>
+ getDataSourceLogsTableColumns({
+ now: Date.now(),
+ showDatasetColumn: false,
+ }),
+ [],
+ );
+
+ const currentPagination = useMemo(
+ () => ({
+ pageIndex: (pagination.current || 1) - 1,
+ pageSize: pagination.pageSize || 10,
+ }),
+ [pagination],
+ );
+
+ const table = useReactTable<IDataSourceLog>({
+ data: visibleLogs,
+ columns,
+ manualPagination: true,
+ getCoreRowModel: getCoreRowModel(),
+ getPaginationRowModel: getPaginationRowModel(),
+ getSortedRowModel: getSortedRowModel(),
+ getFilteredRowModel: getFilteredRowModel(),
+ state: {
+ pagination: currentPagination,
+ },
+ rowCount: data?.total ?? 0,
+ });
+
+ return (
+ <div className="flex-1 min-h-0 flex flex-col">
+ <Table
+ rootClassName="max-h-[calc(100vh-380px)] mb-4"
+ className="table-fixed"
+ >
+ <TableHeader>
+ {table.getHeaderGroups().map((headerGroup) => (
+ <TableRow key={headerGroup.id}>
+ {headerGroup.headers.map((header) => (
+ <TableHead
+ key={header.id}
+ className={header.column.columnDef.meta?.headerClassName}
+ >
+ {flexRender(
+ header.column.columnDef.header,
+ header.getContext(),
+ )}
+ </TableHead>
+ ))}
+ </TableRow>
+ ))}
+ </TableHeader>
+ <TableBody className="min-w-[1280px]">
+ {table.getRowModel().rows?.length ? (
+ table.getRowModel().rows.map((row) => (
+ <TableRow key={row.id}>
+ {row.getVisibleCells().map((cell) => (
+ <TableCell
+ key={cell.id}
+ className={cell.column.columnDef.meta?.cellClassName}
+ >
+ {flexRender(cell.column.columnDef.cell, cell.getContext())}
+ </TableCell>
+ ))}
+ </TableRow>
+ ))
+ ) : (
+ <TableRow>
+ <TableCell colSpan={columns.length} className="h-24 text-center">
+ <Empty
+ type={EmptyType.Data}
+ text={tDatasetOverview('noData')}
+ />
+ </TableCell>
+ </TableRow>
+ )}
+ </TableBody>
+ </Table>
+
+ <div className="mt-auto flex items-center justify-end">
+ <RAGFlowPagination
+ current={pagination.current}
+ pageSize={pagination.pageSize}
+ total={data?.total}
+ onChange={(page, pageSize) => setPagination({ page, pageSize })}
+ />
+ </div>
+ </div>
+ );
+};
+
+export default DataSourceLogsTable;
diff --git a/web/src/pages/dataset/dataset-overview/dataset-common.ts b/web/src/pages/dataset/dataset-overview/dataset-common.ts
index 18b25a14b1..9f53b48c1d 100644
--- a/web/src/pages/dataset/dataset-overview/dataset-common.ts
+++ b/web/src/pages/dataset/dataset-overview/dataset-common.ts
@@ -1,4 +1,5 @@
export enum LogTabs {
FILE_LOGS = 'fileLogs',
DATASET_LOGS = 'datasetLogs',
+ DATASOURCE_LOGS = 'datasourceLogs',
}
diff --git a/web/src/pages/dataset/dataset-overview/dataset-filter.tsx b/web/src/pages/dataset/dataset-overview/dataset-filter.tsx
index ab7bb4f25f..1cefb12e58 100644
--- a/web/src/pages/dataset/dataset-overview/dataset-filter.tsx
+++ b/web/src/pages/dataset/dataset-overview/dataset-filter.tsx
@@ -48,6 +48,10 @@ const DatasetFilter = (
value: LogTabs.DATASET_LOGS,
label: t('knowledgeDetails.datasetLogs'),
},
+ {
+ value: LogTabs.DATASOURCE_LOGS,
+ label: t('knowledgeDetails.datasourceLogs'),
+ },
]}
onChange={(value) =>
setActive?.(value as (typeof LogTabs)[keyof typeof LogTabs])
diff --git a/web/src/pages/dataset/dataset-overview/hook.ts b/web/src/pages/dataset/dataset-overview/hook.ts
index 0270f1c6c5..95f3bb41c5 100644
--- a/web/src/pages/dataset/dataset-overview/hook.ts
+++ b/web/src/pages/dataset/dataset-overview/hook.ts
@@ -58,6 +58,7 @@ const useFetchFileLogList = () => {
);
const knowledgeBaseId = searchParams.get('id') || id;
const logType = active === LogTabs.DATASET_LOGS ? 'dataset' : 'file';
+ const isDataSourceLogs = active === LogTabs.DATASOURCE_LOGS;
const { data } = useQuery<IFileLogList>({
queryKey: DatasetOverviewKeys.logs(
knowledgeBaseId,
@@ -73,7 +74,7 @@ const useFetchFileLogList = () => {
}
return previousData;
},
- enabled: !!knowledgeBaseId,
+ enabled: !!knowledgeBaseId && !isDataSourceLogs,
refetchInterval: (query) =>
hasActiveIngestionLogs(query.state.data) ? PollIntervalMs : false,
queryFn: async () => {
diff --git a/web/src/pages/dataset/dataset-overview/index.tsx b/web/src/pages/dataset/dataset-overview/index.tsx
index 7b8ccd2c53..6f84d38b4b 100644
--- a/web/src/pages/dataset/dataset-overview/index.tsx
+++ b/web/src/pages/dataset/dataset-overview/index.tsx
@@ -13,8 +13,10 @@ import WhatIsThis from '@/components/what-is-this';
import { RunningStatusMap, RunningStatusOld } from '@/constants/knowledge';
import { FC, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
+import { useParams, useSearchParams } from 'react-router';
import { RunningStatus } from '../dataset/constant';
import { LogTabs } from './dataset-common';
+import DataSourceLogsTable from './data-source-logs-table';
import { DatasetFilter } from './dataset-filter';
import { useFetchFileLogList, useFetchOverviewTotal } from './hook';
import { DocumentLog, IFileLogItem } from './interface';
@@ -116,6 +118,9 @@ const CardFooterProcess: FC<CardFooterProcessProps> = ({
const FileLogsPage: FC = () => {
const { t } = useTranslation();
+ const [searchParams] = useSearchParams();
+ const { id } = useParams();
+ const datasetId = searchParams.get('id') || id || '';
const { data: topData } = useFetchOverviewTotal();
const overviewStats = buildDatasetOverviewStats(topData);
@@ -282,13 +287,17 @@ const FileLogsPage: FC = () => {
/>
{/* Table */}
- <FileLogsTable
- data={tableList}
- pagination={pagination}
- setPagination={handlePaginationChange}
- pageCount={10}
- active={active}
- />
+ {active === LogTabs.DATASOURCE_LOGS ? (
+ <DataSourceLogsTable datasetId={datasetId} />
+ ) : (
+ <FileLogsTable
+ data={tableList}
+ pagination={pagination}
+ setPagination={handlePaginationChange}
+ pageCount={10}
+ active={active}
+ />
+ )}
</Card>
);
};
diff --git a/web/src/pages/user-setting/data-source/data-source-detail-page/log-table.tsx b/web/src/pages/user-setting/data-source/data-source-detail-page/log-table.tsx
index 3eaafb53ef..4e3078d239 100644
--- a/web/src/pages/user-setting/data-source/data-source-detail-page/log-table.tsx
+++ b/web/src/pages/user-setting/data-source/data-source-detail-page/log-table.tsx
@@ -14,8 +14,6 @@
* limitations under the License.
*/
-import FileStatusBadge from '@/components/file-status-badge';
-import { RAGFlowAvatar } from '@/components/ragflow-avatar';
import { RAGFlowPagination } from '@/components/ui/ragflow-pagination';
import {
Table,
@@ -25,12 +23,8 @@ import {
TableHeader,
TableRow,
} from '@/components/ui/table';
-import { RunningStatusMap } from '@/constants/knowledge';
-import { RunningStatus } from '@/pages/dataset/dataset/constant';
import { Routes } from '@/routes';
-import { formatDate } from '@/utils/date';
import {
- ColumnDef,
flexRender,
getCoreRowModel,
getFilteredRowModel,
@@ -43,158 +37,8 @@ import { pick } from 'lodash';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useNavigate } from 'react-router';
import { useLogListDataSource } from '../hooks';
-import { IDataSourceLog } from '../interface';
+import { getDataSourceLogsTableColumns } from '../log-columns';
-const formatDuration = (seconds: number) => {
- const safeSeconds = Math.max(0, seconds);
- const hours = Math.floor(safeSeconds / 3600);
- const minutes = Math.floor((safeSeconds % 3600) / 60);
- const remainingSeconds = safeSeconds % 60;
-
- if (hours > 0) {
- return `${hours}h ${minutes}m ${remainingSeconds}s`;
- }
- if (minutes > 0) {
- return `${minutes}m ${remainingSeconds}s`;
- }
- return `${remainingSeconds}s`;
-};
-
-const getTaskCountdownSeconds = (row: IDataSourceLog, now: number) => {
- const freqMinutes =
- row.task_type === 'prune'
- ? Number(row.prune_freq || 0)
- : Number(row.refresh_freq || 0);
- const scheduledAt = row.time_started
- ? new Date(row.time_started).getTime()
- : 0;
-
- if (!freqMinutes || !scheduledAt) {
- return null;
- }
-
- const nextRunAt = scheduledAt + freqMinutes * 60 * 1000;
- return Math.ceil((nextRunAt - now) / 1000);
-};
-
-const TaskCountdown = ({ row, now }: { row: IDataSourceLog; now: number }) => {
- const remainingSeconds = getTaskCountdownSeconds(row, now);
-
- if (remainingSeconds === null) {
- return '';
- }
-
- return (
- <span className="tabular-nums">
- Task starts in {formatDuration(remainingSeconds)}
- </span>
- );
-};
-
-const getSummary = (row: IDataSourceLog, now: number) => {
- if (row.status === RunningStatus.SCHEDULE || row.status === '5') {
- return <TaskCountdown row={row} now={now} />;
- }
-
- if (row.status === RunningStatus.RUNNING || row.status === '1') {
- return row.task_type === 'prune' ? 'Prune in progress' : 'Sync in progress';
- }
-
- if (row.status === RunningStatus.FAIL || row.status === '4') {
- return row.error_msg || 'Task failed';
- }
-
- if (row.status === RunningStatus.CANCEL || row.status === '2') {
- return '';
- }
-
- if (row.task_type === 'prune') {
- return `deleted=${row.docs_removed_from_index || 0}, error=${row.error_count || 0}`;
- }
-
- return `total=${row.total_docs_indexed || 0}, added=${row.new_docs_indexed || 0}, updated=${Math.max(
- 0,
- (row.total_docs_indexed || 0) - (row.new_docs_indexed || 0),
- )}, error=${row.error_count || 0}`;
-};
-
-const columns = ({
- handleToDataSetDetail,
- now,
-}: {
- handleToDataSetDetail: (id: string) => void;
- now: number;
-}) => {
- return [
- {
- accessorKey: 'update_date',
- header: t('setting.timeStarted'),
- meta: { headerClassName: 'w-44' },
- cell: ({ row }) => (
- <div className="flex items-center gap-2 text-text-primary">
- {row.original.update_date
- ? formatDate(row.original.update_date)
- : '-'}
- </div>
- ),
- },
- {
- accessorKey: 'status',
- header: t('knowledgeDetails.status'),
- meta: { headerClassName: 'w-28' },
- cell: ({ row }) => (
- <FileStatusBadge
- status={row.original.status as RunningStatus}
- name={RunningStatusMap[row.original.status as RunningStatus]}
- className="!w-20"
- />
- ),
- },
- {
- accessorKey: 'kb_name',
- header: t('knowledgeDetails.dataset'),
- meta: { headerClassName: 'w-1/4' },
- cell: ({ row }) => {
- return (
- <div
- className="flex items-center gap-2 text-text-primary cursor-pointer"
- onClick={() => {
- handleToDataSetDetail(row.original.kb_id);
- }}
- >
- <RAGFlowAvatar
- avatar={row.original.avatar}
- name={row.original.kb_name}
- className="size-4"
- />
- <span className="truncate">{row.original.kb_name}</span>
- </div>
- );
- },
- },
- {
- accessorKey: 'task_type',
- header: 'Task Type',
- meta: { headerClassName: 'w-28' },
- cell: ({ row }) => row.original.task_type || 'sync',
- },
- {
- id: 'summary',
- header: 'Summary',
- cell: ({ row }) => (
- <div className="max-w-[32rem] whitespace-normal break-words text-text-primary">
- {getSummary(row.original as IDataSourceLog, now)}
- </div>
- ),
- },
- ] as ColumnDef<any>[];
-};
-
-// const paginationInit = {
-// current: 1,
-// pageSize: 10,
-// total: 0,
-// };
export const DataSourceLogsTable = ({
autoRefresh,
}: {
@@ -227,32 +71,30 @@ export const DataSourceLogsTable = ({
[navigate],
);
- const table = useReactTable<any>({
+ const columns = useMemo(
+ () =>
+ getDataSourceLogsTableColumns({
+ now,
+ handleToDataSetDetail,
+ }),
+ [now, handleToDataSetDetail],
+ );
+
+ const table = useReactTable({
data: data || [],
- columns: columns({ handleToDataSetDetail, now }),
+ columns,
manualPagination: true,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
getSortedRowModel: getSortedRowModel(),
getFilteredRowModel: getFilteredRowModel(),
- // onSortingChange: setSorting,
- // onColumnFiltersChange: setColumnFilters,
- // onRowSelectionChange: setRowSelection,
state: {
- // sorting,
- // columnFilters,
- // rowSelection,
pagination: currentPagination,
},
- // pageCount: pagination.total
- // ? Math.ceil(pagination.total / pagination.pageSize)
- // : 0,
rowCount: pagination.total ?? 0,
});
return (
- // <div className="w-full h-[calc(100vh-360px)]">
- // <Table rootClassName="max-h-[calc(100vh-380px)]">
<div className="w-full">
<Table className="table-fixed">
<TableHeader>
@@ -292,7 +134,7 @@ export const DataSourceLogsTable = ({
))
) : (
<TableRow>
- <TableCell colSpan={5} className="h-24 text-center">
+ <TableCell colSpan={columns.length} className="h-24 text-center">
{t('common.noData')}
</TableCell>
</TableRow>
@@ -301,11 +143,6 @@ export const DataSourceLogsTable = ({
</Table>
<div className="flex items-center justify-end mt-4">
<div className="space-x-2">
- {/* <RAGFlowPagination
- {...{ current: pagination.current, pageSize: pagination.pageSize }}
- total={pagination.total}
- onChange={(page, pageSize) => setPagination({ page, pageSize })}
- /> */}
<RAGFlowPagination
{...pick(pagination, 'current', 'pageSize')}
total={pagination.total}
diff --git a/web/src/pages/user-setting/data-source/interface.ts b/web/src/pages/user-setting/data-source/interface.ts
index 25305d3300..db3cfb44a9 100644
--- a/web/src/pages/user-setting/data-source/interface.ts
+++ b/web/src/pages/user-setting/data-source/interface.ts
@@ -43,6 +43,7 @@ export interface IDataSourceBase {
}
export interface IDataSourceLog {
+ avatar?: string;
connector_id: string;
docs_removed_from_index?: number;
error_count: number;
diff --git a/web/src/pages/user-setting/data-source/log-columns.tsx b/web/src/pages/user-setting/data-source/log-columns.tsx
new file mode 100644
index 0000000000..baf670292e
--- /dev/null
+++ b/web/src/pages/user-setting/data-source/log-columns.tsx
@@ -0,0 +1,92 @@
+import FileStatusBadge from '@/components/file-status-badge';
+import { RAGFlowAvatar } from '@/components/ragflow-avatar';
+import { RunningStatusMap } from '@/constants/knowledge';
+import { RunningStatus } from '@/pages/dataset/dataset/constant';
+import { formatDate } from '@/utils/date';
+import { ColumnDef } from '@tanstack/react-table';
+import { t } from 'i18next';
+import { IDataSourceLog } from './interface';
+import { getSummary } from './log-summary';
+
+// The data source sync log table is shared by the data source detail page and
+// the dataset logs page. The dataset page already scopes every row to one
+// knowledge base, so it renders the table without the dataset column.
+export const getDataSourceLogsTableColumns = ({
+ now,
+ showDatasetColumn = true,
+ handleToDataSetDetail,
+}: {
+ now: number;
+ showDatasetColumn?: boolean;
+ handleToDataSetDetail?: (id: string) => void;
+}): ColumnDef<IDataSourceLog>[] => {
+ const columns: ColumnDef<IDataSourceLog>[] = [
+ {
+ accessorKey: 'update_date',
+ header: t('setting.timeStarted'),
+ meta: { headerClassName: 'w-44' },
+ cell: ({ row }) => (
+ <div className="flex items-center gap-2 text-text-primary">
+ {row.original.update_date
+ ? formatDate(row.original.update_date)
+ : '-'}
+ </div>
+ ),
+ },
+ {
+ accessorKey: 'status',
+ header: t('knowledgeDetails.status'),
+ meta: { headerClassName: 'w-28' },
+ cell: ({ row }) => (
+ <FileStatusBadge
+ status={row.original.status as RunningStatus}
+ name={RunningStatusMap[row.original.status as RunningStatus]}
+ className="!w-20"
+ />
+ ),
+ },
+ ];
+
+ if (showDatasetColumn) {
+ columns.push({
+ accessorKey: 'kb_name',
+ header: t('knowledgeDetails.dataset'),
+ meta: { headerClassName: 'w-1/4' },
+ cell: ({ row }) => (
+ <div
+ className="flex items-center gap-2 text-text-primary cursor-pointer"
+ onClick={() => {
+ handleToDataSetDetail?.(row.original.kb_id);
+ }}
+ >
+ <RAGFlowAvatar
+ avatar={row.original.avatar}
+ name={row.original.kb_name}
+ className="size-4"
+ />
+ <span className="truncate">{row.original.kb_name}</span>
+ </div>
+ ),
+ });
+ }
+
+ columns.push(
+ {
+ accessorKey: 'task_type',
+ header: 'Task Type',
+ meta: { headerClassName: 'w-28' },
+ cell: ({ row }) => row.original.task_type || 'sync',
+ },
+ {
+ id: 'summary',
+ header: 'Summary',
+ cell: ({ row }) => (
+ <div className="max-w-[32rem] whitespace-normal break-words text-text-primary">
+ {getSummary(row.original, now)}
+ </div>
+ ),
+ },
+ );
+
+ return columns;
+};
diff --git a/web/src/pages/user-setting/data-source/log-summary.tsx b/web/src/pages/user-setting/data-source/log-summary.tsx
new file mode 100644
index 0000000000..f134f78bbb
--- /dev/null
+++ b/web/src/pages/user-setting/data-source/log-summary.tsx
@@ -0,0 +1,81 @@
+import { RunningStatus } from '@/pages/dataset/dataset/constant';
+import { IDataSourceLog } from './interface';
+
+export const formatDuration = (seconds: number) => {
+ const safeSeconds = Math.max(0, seconds);
+ const hours = Math.floor(safeSeconds / 3600);
+ const minutes = Math.floor((safeSeconds % 3600) / 60);
+ const remainingSeconds = safeSeconds % 60;
+
+ if (hours > 0) {
+ return `${hours}h ${minutes}m ${remainingSeconds}s`;
+ }
+ if (minutes > 0) {
+ return `${minutes}m ${remainingSeconds}s`;
+ }
+ return `${remainingSeconds}s`;
+};
+
+export const getTaskCountdownSeconds = (row: IDataSourceLog, now: number) => {
+ const freqMinutes =
+ row.task_type === 'prune'
+ ? Number(row.prune_freq || 0)
+ : Number(row.refresh_freq || 0);
+ const scheduledAt = row.time_started
+ ? new Date(row.time_started).getTime()
+ : 0;
+
+ if (!freqMinutes || !scheduledAt) {
+ return null;
+ }
+
+ const nextRunAt = scheduledAt + freqMinutes * 60 * 1000;
+ return Math.ceil((nextRunAt - now) / 1000);
+};
+
+export const TaskCountdown = ({
+ row,
+ now,
+}: {
+ row: IDataSourceLog;
+ now: number;
+}) => {
+ const remainingSeconds = getTaskCountdownSeconds(row, now);
+
+ if (remainingSeconds === null) {
+ return '';
+ }
+
+ return (
+ <span className="tabular-nums">
+ Task starts in {formatDuration(remainingSeconds)}
+ </span>
+ );
+};
+
+export const getSummary = (row: IDataSourceLog, now: number) => {
+ if (row.status === RunningStatus.SCHEDULE || row.status === '5') {
+ return <TaskCountdown row={row} now={now} />;
+ }
+
+ if (row.status === RunningStatus.RUNNING || row.status === '1') {
+ return row.task_type === 'prune' ? 'Prune in progress' : 'Sync in progress';
+ }
+
+ if (row.status === RunningStatus.FAIL || row.status === '4') {
+ return row.error_msg || 'Task failed';
+ }
+
+ if (row.status === RunningStatus.CANCEL || row.status === '2') {
+ return '';
+ }
+
+ if (row.task_type === 'prune') {
+ return `deleted=${row.docs_removed_from_index || 0}, error=${row.error_count || 0}`;
+ }
+
+ return `total=${row.total_docs_indexed || 0}, added=${row.new_docs_indexed || 0}, updated=${Math.max(
+ 0,
+ (row.total_docs_indexed || 0) - (row.new_docs_indexed || 0),
+ )}, error=${row.error_count || 0}`;
+};