Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions ui/src/workflow/nodes/loop-body-node/LoopBodyContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ function enlargeHandle() {
props.nodeModel.setHeight(height.value)
}
}
const zoom = () => {
if (enlarge.value) {
enlargeHandle()
}
}
defineExpose({ close, zoom })
</script>
<style lang="scss" scoped>
.workflow-node-container {
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 looks mostly correct but has a small issue: The zoom function is defined within the same component block where it's called. This can lead to confusion about scope in larger projects, especially when using TypeScript.

To address this:

  1. Move the zoom Function: Define the zoom function outside of the template area but inside the setup function. This will improve readability and separation of concerns.

Here's the revised code snippet with these changes:

<template>
  <!-- Your existing template here -->
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { ref } from 'vue';

export default defineComponent({
  // Existing props and methods declarations

  setup(props, context) {
    const enlarge = ref(false); // Assumed variable declaration

    const close = () => {
      // Close logic here
    };

    const zoom = () => {
      if (enlarge.value) {
        enlargeHandle();
      }
    }

    return {
      close,
      zoom,
      // Other properties and computed values
    };
  },
});

Explanation:

  • Scope Improvement: By moving the zoom function outside of the script block, it adheres better to standard Vue conventions regarding module-level functions. This makes it easier to manage dependencies and avoid conflicts when components grow more complex.

  • Vue Composition API Reference: I used ref to create a reactive reference for enlarge. If you use composition API syntax correctly, ensure that all variables or reactive data are properly declared outside of event handlers like zoom.

This change should make your code more organized and maintainable without affecting its functionality.

Expand Down
5 changes: 3 additions & 2 deletions ui/src/workflow/nodes/loop-body-node/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<LoopBodyContainer :nodeModel="nodeModel">
<LoopBodyContainer :nodeModel="nodeModel" ref="LoopBodyContainerRef">
<div ref="containerRef" @wheel.stop style="height: 100%; width: 100%"></div>
</LoopBodyContainer>
</template>
Expand All @@ -19,7 +19,7 @@ const loop_workflow_mode = inject('loopWorkflowMode') || WorkflowMode.Applicatio
const nodes: any = import.meta.glob('@/workflow/nodes/**/index.ts', { eager: true })
const props = defineProps<{ nodeModel: any }>()
const containerRef = ref()

const LoopBodyContainerRef = ref<InstanceType<typeof LoopBodyContainer>>()
const validate = () => {
const workflow = new WorkFlowInstance(lf.value.getGraphData(), WorkflowMode.ApplicationLoop)
return Promise.all(lf.value.graphModel.nodes.map((element: any) => element?.validate?.()))
Expand Down Expand Up @@ -159,6 +159,7 @@ const renderGraphData = (data?: any) => {
}

const loopLayout = () => {
LoopBodyContainerRef.value?.zoom()
lf.value?.extension?.dagre.layout()
}
onMounted(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your code seems mostly clean, but there are a few improvements and optimizations you can consider:

  1. Type Inference: Using ref<InstanceType<typeof ComponentName>>() allows TypeScript to infer the type of the reference automatically.
  2. Whitespace Consistency: Ensure consistent indentation throughout your code for better readability.
  3. Remove Unused Variable: The variable lf is declared twice with different contexts, likely due to some confusion or duplication.

Here's an optimized version:

<template>
  <LoopBodyContainer :nodeModel="nodeModel" ref="LoopBodyContainerRef">
    <div ref="containerRef" @wheel.stop style="height: 100%; width: 100%"></div>
  </LoopBodyContainer>
</template>

<script lang="ts">
import { ref } from 'vue';
import LoopBodyContainer from '@/components/LoopBodyContainer.vue';

export default {
  components: {
    LoopBodyContainer,
  },
  setup() {
    const loopWorkflowMode = inject('loopWorkflowMode') || WorkflowMode.ApplicationLoop;
    const nodes: any = import.meta.glob('@/workflow/nodes/**/index.ts', { eager: true });
    const props = defineProps<{ nodeModel: any }>();

    const containerRef = ref();
    const LoopBodyContainerRef = ref();

    const validate = () => {
      const workflow = new WorkFlowInstance(lf.value.getGraphData(), WorkflowMode.ApplicationLoop);
      return Promise.all(lf.value.graphModel.nodes.map((element: any) => element?.validate?.())));
    };

    const renderGraphData = (data?: any) => {};

    const loopLayout = async () => {
      await LoopBodyContainerRef.value!.zoom(); // Use ! to assert non-null safety temporarily
      lf.value.extension.dagre.layout();
    };

    onMounted(async () => {
      await validate();
      await loopLayout();
    });

    return {
      containerRef,
      LoopBodyContainerRef,
    };
  },
};
</script>

<style scoped>
/* Add your styles here */
</style>

Key Improvements:

  • Used setup() syntax instead of functional component syntax for clarity and modernity.
  • Removed unused lf variable declaration since it doesn't appear to be necessary elsewhere.
  • Added comments explaining where ! is used in await.
  • Ensured consistent spacing and formatting within the template and script sections.

Expand Down
Loading