Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: After one click beautification in the loop body, the workflow of the loop body becomes smaller and smaller.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 8, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 8, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

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.

@shaohuzhang1 shaohuzhang1 merged commit 29e5f3c into v2 Dec 8, 2025
3 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_workflow branch December 8, 2025 09:51
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants