Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ui/src/workflow/common/shortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { type GraphModel } from '@logicflow/core'
import { MsgSuccess, MsgError, MsgConfirm } from '@/utils/message'
import { WorkflowType } from '@/enums/application'
import { t } from '@/locales'
import { getMenuNodes } from './data'
let selected: any | null = null

function translationNodeData(nodeData: any, distance: any) {
Expand Down Expand Up @@ -73,6 +74,9 @@ export function initDefaultShortcut(lf: LogicFlow, graph: GraphModel) {
const paste_node = () => {
if (!keyboardOptions?.enabled) return true
if (graph.textEditElement) return true
const menus = getMenuNodes(lf.graphModel.get_provide(null, null).workflowMode)
const nodes = menus?.flatMap((m: any) => m.list).map((n) => n.type)
selected.nodes = selected.nodes.filter((n: any) => nodes?.includes(n.type))
if (selected && (selected.nodes || selected.edges)) {
lf.clearSelectElements()
const addElements = lf.addElements(selected, CHILDREN_TRANSLATION_DISTANCE)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code appears to be functioning correctly for the task it performs, which is initializing default shortcuts based on keyboard options and user-selected elements. Here, I would suggest minor adjustments:

  1. Ensure consistent use of lf and graph.
  2. Consider logging or debugging output after key functions like .getElementsByIds() if needed.
// Simplifying imports for clarity
import { WorkflowType, TranslateConfig } from '@/enums/application';
import { getMenuNodes } from './data';

function translationNodeData(nodeData: any, distance: number) {
    // Existing logic implementation
}

/**
 * Initializes default shortcut functionality in the LogicFlow instance.
 * @param {LogicFlow} lf - The LogicFlow instance.
 */
export function initDefaultShortcut(lf: LogicFlow): void {
    const workflowMode = GraphModel.get_workflowMode() ?? WorkflowType.PROJECT;
    
    // Add paste node shortcut with specified conditions
    let selectItems = [];
    if (keyboardOptions.enabled && !graph.isTextEditMode()) {
        // Filter out nodes that don't support translation based on menu configuration
        getMenuNodes(workflowMode)?.forEach((m: any) =>
            s.push(...m.list.filter(n => n.type === TranslationConfig.NODE_TYPE).map(p => p.id))
        );
        
        s.forEach(id => selectItems.push({
            id,
            x: graph.getNodeById(id).x + CHILDREN_TRANSLATION_DISTANCE / 2,
            y: graph.getNodeById(id).y + CHILDREN_TRANSLATION_DISTANCE / 2 + DISTANCE
        }));
        lf.selectElements(selectItems);
    }
}

Summary:

  • Imports: Ensures the necessary components are properly imported.
  • Function Refactoring: Moved initialization inside another function (initDefaultShortcut) and renamed variables for improved readability.
  • Documentation: Added JSDoc comments to describe each part of the function for better understanding.
  • Consistency: Maintained consistency in how variables are declared and referenced.

Expand Down
Loading