Skip to content

fix: The form failed to parse when there are labels in the internal data#3980

Merged
shaohuzhang1 merged 1 commit intov2from
pr@v2@fix_form_node
Sep 2, 2025
Merged

fix: The form failed to parse when there are labels in the internal data#3980
shaohuzhang1 merged 1 commit intov2from
pr@v2@fix_form_node

Conversation

@shaohuzhang1
Copy link
Contributor

fix: The form failed to parse when there are labels in the internal data

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Sep 2, 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 Sep 2, 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


return result
}
</script>
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 code checks for some common issues and provides a few performance optimization suggestions:

  1. Potential Missing Semicolon: There is an extra comma (,)afterreturnin_split_form_rander. It should be fixed to use semicolons (;`) properly.

  2. Incorrect Function Signature and Usage:

    • The function <script setup> should have a consistent structure where it either includes props or event handlers directly.
    • In this context, it seems like there might be inconsistencies with how the functions are declared and used within this specific setup block.
  3. Optimization Suggestions:

    • The extractFormRanderContent can improve efficiency by using more direct search methods that avoid recursive loops through substrings.

Here's the revised version of the file with these corrections and optimizations noted:

@@ -879,9 +879,9 @@ const handleUpdateMarkdown = () => {
       console.error('Cannot generate markdown')
     }
   })
-  // Add any other necessary updates here
 }

// New function to extract all form_rander contents efficiently
function extractFormRanderContent(html: string): string[] {
  const results: string[] = []
  const regex = /<form_rander>([\s\S]*?)<\/form_rander>/g

  const matches = html.match(regex)

  if (matches) {
    for (const match of matches) {
      results.push(match.slice(13, match.length - 13).trim()) // Remove tags first then trim whitespaces
    }
  }

  return results
}

// Updated _split_form_rander using the optimized extraction method
const _split_form_rander = (source: string, form_rander_list: string[]): string[] => {
  const uuid = nanoid()
  if (form_rander_list.length > 0) {
    form_rander_list.forEach((item) => {
      source = source.replace(`<form_rander>${item}</form_rander>`, uuid)
    })
  }

  const splitQuickQuestionValue = _extractFormRanderContent(source);

  return (
    [
      ...source.split(uuid),
      ...splitQuickQuestionValue,
    ]
    .filter(Boolean) // Filter out falsy values
    .filter((item) => !form_rander_list.includes(item)) // Ensure unique items remain
  )
}

const split_form_rander_ = (source: string, type: string): Record<string, unknown>[] => {
  const tempMd_quick_question_list = extractFormRanderContent(source);
  
  if (!(tempMd_quick_question_list instanceof Array)) {
    throw new Error("Invalid data returned from extractFormRanderContent");
  }

  const md_quick_question_list = tempMd_quick_question_list.filter((i) => i);
  const split_quick_question_value = _split_form_rander(source, md_quick_question_list);

  const result = [];

  for (let index = 0; index < md_quick_question_list.length + split_quick_question_value.length; index++) {
    if (index % 2 === 0) {
      result.push({
        type: 'markdown',
        content: md_quick_question_list[Math.floor(index / 2)].trim(),
      });
    } else {
      const element = split_quick_question_value[index - Math.floor(md_quick_question_list.length / 2)];
      result.push({ type: 'form_render', content: element.trim() });
    }
  }

  return result;
}

Summary Changes Made:

  1. Fixed misplaced commas in the _split_form_rander function.
  2. Added missing semicolons within the same statement at the end.
  3. Optimized the extractFormRanderContent function to parse HTML once efficiently without unnecessary looping constructs.

@shaohuzhang1 shaohuzhang1 merged commit 2f12c61 into v2 Sep 2, 2025
3 of 5 checks passed
MultiRow: 'Multi Row',
},
default: {
label: 'Default',
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 clean and functional. However, there is one minor suggestion:

  • Code Formatting: Enclosing property keys with quotes can be useful, especially to avoid any issues if the key contains special characters or spaces.

Here's an updated version of the default object:

default: {
  label: "Default",

This modification makes it clear that these are string properties, which is good practice when working with JavaScript objects.

@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_form_node branch September 2, 2025 06:12
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.

1 participant