-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: The form failed to parse when there are labels in the internal data #3980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+62
−9
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ export default { | |
| RadioRow: 'Radio Row', | ||
| UploadInput: 'File upload', | ||
| TextareaInput: 'Multiline Input', | ||
| MultiRow: 'Multi Row', | ||
| }, | ||
| default: { | ||
| label: 'Default', | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
Here's an updated version of the default: {
label: "Default",This modification makes it clear that these are string properties, which is good practice when working with JavaScript objects. |
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
Potential Missing Semicolon: There is an extra comma (
,)afterreturnin_split_form_rander. It should be fixed to use semicolons (;`) properly.Incorrect Function Signature and Usage:
<script setup>should have a consistent structure where it either includes props or event handlers directly.Optimization Suggestions:
extractFormRanderContentcan 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:
_split_form_randerfunction.extractFormRanderContentfunction to parse HTML once efficiently without unnecessary looping constructs.