mirror of
https://github.com/taskgenius/taskgenius-plugin.git
synced 2026-07-22 06:40:25 +00:00
- Remove debug console.log statements from workflow handlers - Add proper TypeScript type definitions (WorkflowInfo, ResolvedWorkflowInfo) - Extract regex patterns and magic strings as constants - Create helper functions for cleaner code (getIndentation, getEditorFromView) - Improve error handling with bounds checking - Enhance time parsing service with better fallback logic - Add fallback property names for date fields in file task manager - Fix test import paths for relocated modules - Consolidate duplicate code in workflow stage transitions - Improve indentation handling in parent task updater Breaking changes: None
123 lines
3.4 KiB
TypeScript
123 lines
3.4 KiB
TypeScript
import {
|
|
OnCompletionConfig,
|
|
OnCompletionExecutionContext,
|
|
OnCompletionExecutionResult,
|
|
} from "../../types/onCompletion";
|
|
import { Task, CanvasTaskMetadata } from "../../types/task";
|
|
import { CanvasTaskUpdater } from "../../parsers/canvas-task-updater";
|
|
import TaskProgressBarPlugin from "@/index";
|
|
|
|
/**
|
|
* Abstract base class for all onCompletion action executors
|
|
*/
|
|
export abstract class BaseActionExecutor {
|
|
/**
|
|
* Execute the onCompletion action
|
|
* @param context Execution context containing task, plugin, and app references
|
|
* @param config Configuration for the specific action
|
|
* @returns Promise resolving to execution result
|
|
*/
|
|
public async execute(
|
|
context: OnCompletionExecutionContext,
|
|
config: OnCompletionConfig,
|
|
): Promise<OnCompletionExecutionResult> {
|
|
if (!this.validateConfig(config)) {
|
|
return this.createErrorResult("Invalid configuration");
|
|
}
|
|
|
|
// Route to appropriate execution method based on task type
|
|
if (this.isCanvasTask(context.task)) {
|
|
return this.executeForCanvas(context, config);
|
|
} else {
|
|
return this.executeForMarkdown(context, config);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Execute the action for Canvas tasks
|
|
* @param context Execution context
|
|
* @param config Configuration for the action
|
|
* @returns Promise resolving to execution result
|
|
*/
|
|
protected abstract executeForCanvas(
|
|
context: OnCompletionExecutionContext,
|
|
config: OnCompletionConfig,
|
|
): Promise<OnCompletionExecutionResult>;
|
|
|
|
/**
|
|
* Execute the action for Markdown tasks
|
|
* @param context Execution context
|
|
* @param config Configuration for the action
|
|
* @returns Promise resolving to execution result
|
|
*/
|
|
protected abstract executeForMarkdown(
|
|
context: OnCompletionExecutionContext,
|
|
config: OnCompletionConfig,
|
|
): Promise<OnCompletionExecutionResult>;
|
|
|
|
/**
|
|
* Validate the configuration for this executor type
|
|
* @param config Configuration to validate
|
|
* @returns true if configuration is valid, false otherwise
|
|
*/
|
|
protected abstract validateConfig(config: OnCompletionConfig): boolean;
|
|
|
|
/**
|
|
* Get a human-readable description of the action
|
|
* @param config Configuration for the action
|
|
* @returns Description string
|
|
*/
|
|
public abstract getDescription(config: OnCompletionConfig): string;
|
|
|
|
/**
|
|
* Helper method to create a success result
|
|
* @param message Optional success message
|
|
* @returns Success result
|
|
*/
|
|
protected createSuccessResult(
|
|
message?: string,
|
|
): OnCompletionExecutionResult {
|
|
return {
|
|
success: true,
|
|
message,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Helper method to create an error result
|
|
* @param error Error message
|
|
* @returns Error result
|
|
*/
|
|
protected createErrorResult(error: string): OnCompletionExecutionResult {
|
|
return {
|
|
success: false,
|
|
error,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Check if a task is a Canvas task
|
|
* @param task Task to check
|
|
* @returns true if task is a Canvas task
|
|
*/
|
|
protected isCanvasTask(task: Task): task is Task<CanvasTaskMetadata> {
|
|
return CanvasTaskUpdater.isCanvasTask(task);
|
|
}
|
|
|
|
/**
|
|
* Get Canvas task updater instance from context
|
|
* @param context Execution context
|
|
* @returns CanvasTaskUpdater instance
|
|
*/
|
|
protected getCanvasTaskUpdater(
|
|
context: OnCompletionExecutionContext,
|
|
): CanvasTaskUpdater {
|
|
// Prefer using the plugin's task manager if available (allows mocking in tests)
|
|
const plugin = context.plugin as TaskProgressBarPlugin;
|
|
if (plugin?.writeAPI) {
|
|
return plugin.writeAPI.canvasTaskUpdater;
|
|
}
|
|
|
|
return new CanvasTaskUpdater(context.app.vault, context.plugin);
|
|
}
|
|
}
|