chore(async-task-manager): cancelable options

This commit is contained in:
Chareice 2025-01-16 23:09:48 +08:00
parent 27f760b8a1
commit f6ac57f34d
No known key found for this signature in database
3 changed files with 6 additions and 2 deletions

View File

@ -148,13 +148,14 @@ export const AsyncTasks = () => {
}; };
const actionText = actionTypeMap[title.actionType] || title.actionType; const actionText = actionTypeMap[title.actionType] || title.actionType;
const taskTypeMap = { const taskTypeMap = {
'export-attachments': t('Export {collection} attachments'), 'export-attachments': t('Export {collection} attachments'),
export: t('Export {collection} data'), export: t('Export {collection} data'),
import: t('Import {collection} data'), import: t('Import {collection} data'),
}; };
const taskTemplate = taskTypeMap[title.actionType] || `${actionText} ${title.collection} ${t('Data')}`; const taskTemplate = taskTypeMap[title.actionType] || `${actionText}`;
return taskTemplate.replace('{collection}', title.collection); return taskTemplate.replace('{collection}', title.collection);
}, },
}, },
@ -275,7 +276,7 @@ export const AsyncTasks = () => {
const actions = []; const actions = [];
const isTaskCancelling = cancellingTasks.has(record.taskId); const isTaskCancelling = cancellingTasks.has(record.taskId);
if (record.status.type === 'running' || record.status.type === 'pending') { if ((record.status.type === 'running' || record.status.type === 'pending') && record.cancelable) {
actions.push( actions.push(
<Popconfirm <Popconfirm
key="cancel" key="cancel"

View File

@ -1,4 +1,5 @@
export * from './interfaces/async-task-manager'; export * from './interfaces/async-task-manager';
export * from './task-type';
export * from './static-import'; export * from './static-import';
export { default } from './plugin'; export { default } from './plugin';

View File

@ -8,6 +8,7 @@ import PluginErrorHandler, { ErrorHandler } from '@nocobase/plugin-error-handler
export abstract class TaskType extends EventEmitter implements ITask { export abstract class TaskType extends EventEmitter implements ITask {
static type: string; static type: string;
static cancelable = true;
public status: TaskStatus; public status: TaskStatus;
protected logger: Logger; protected logger: Logger;
@ -168,6 +169,7 @@ export abstract class TaskType extends EventEmitter implements ITask {
toJSON(options?: { raw?: boolean }) { toJSON(options?: { raw?: boolean }) {
const json = { const json = {
cancelable: (this.constructor as typeof TaskType).cancelable,
taskId: this.taskId, taskId: this.taskId,
status: { ...this.status }, status: { ...this.status },
progress: this.progress, progress: this.progress,