-
Notifications
You must be signed in to change notification settings - Fork 6
:fix: Handle error when no public field is present in the regex #239
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
Open
wryonik
wants to merge
15
commits into
main
Choose a base branch
from
shubham/reg-563-fe-ux-fix-error-message-when-there-is-no-public-output-for-a
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
58cfb8d
Merge pull request #154 from zkemail/staging
DimiDumo fa4244c
hotfix: add domain selector pair automatically
rutefig b19462f
:fix: Disable automatic update for the regex length field
wryonik 4f3803b
fix: cannot edit max length
DimiDumo de6cb3c
feat: sort blueprints by total proofs
rutefig 6c287e6
Merge pull request #163 from zkemail/rutefig/feat-sort-blueprints-by-…
DimiDumo 8ce20a1
hotfix: bump sdk version
DimiDumo 28b356a
:hotfix: Remove restriction of uploading blueprint while making basic…
wryonik 057448a
hotfix: prompt user consent for gmail login
rutefig f6ff9f7
:fix: Fix auto updation of email headers length while creating blueprint
wryonik 542c70c
:fix: Copy change
wryonik 0e66ab9
:chore: Skip body hash check by default while creating blueprint
wryonik 2be2403
:fix: Update the order of useEffects being called during github auth
wryonik 302e782
:fix: Handle error when no public field is present in the regex
wryonik 85e9cb2
:chore: Improve regex output logic readability
wryonik 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
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
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
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
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
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
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 |
|---|---|---|
|
|
@@ -114,6 +114,9 @@ const ExtractFields = ({ | |
| const [regexGeneratedOutputs, setRegexGeneratedOutputs] = useState<string[]>( | ||
| Array(store.decomposedRegexes?.length ?? 0).fill('') | ||
| ); | ||
| const [regexGeneratedOutputErrors, setRegexGeneratedOutputErrors] = useState<string[]>( | ||
| Array(store.decomposedRegexes?.length ?? 0).fill('') | ||
| ); | ||
|
|
||
| const [isExtractSubjectChecked, setIsExtractSubjectChecked] = useState(false); | ||
| const [isExtractReceiverChecked, setIsExtractReceiverChecked] = useState(false); | ||
|
|
@@ -149,32 +152,37 @@ const ExtractFields = ({ | |
| revealPrivateFields | ||
| ); | ||
|
|
||
| const outputUpdated = | ||
| JSON.stringify(regexOutputs) !== JSON.stringify(regexGeneratedOutputs[index]); | ||
|
|
||
| setRegexGeneratedOutputs((prev) => { | ||
| const updated = [...prev]; | ||
| // @ts-ignore | ||
| updated[index] = regexOutputs; | ||
| return updated; | ||
| }); | ||
|
|
||
| // // update the max length of the regex at that particular index | ||
| const decomposedRegexes = [...store.decomposedRegexes]; | ||
| decomposedRegexes[index].maxLength = regexOutputs[0].length ?? 64; | ||
| setField('decomposedRegexes', decomposedRegexes); | ||
| setRegexGeneratedOutputErrors((prev) => { | ||
| const updated = [...prev]; | ||
| // @ts-ignore | ||
| updated[index] = ''; | ||
| return updated; | ||
| }); | ||
|
|
||
| // update the max length of the regex at that particular index | ||
| // Only update when the output changes, so we can still set maxLength | ||
| if (outputUpdated) { | ||
| const totalLength = regexOutputs.reduce((acc, cur) => (acc += cur.length), 0); | ||
| const decomposedRegexes = [...store.decomposedRegexes]; | ||
| decomposedRegexes[index].maxLength = totalLength ?? 64; | ||
| setField('decomposedRegexes', decomposedRegexes); | ||
| } | ||
| } catch (error) { | ||
| console.error('Error testing decomposed regex:', error); | ||
| setRegexGeneratedOutputs((prev) => { | ||
| setRegexGeneratedOutputErrors((prev) => { | ||
| const updated = [...prev]; | ||
|
|
||
| if (regex.parts.filter((part) => part.isPublic).length === 0) { | ||
| // @ts-ignore | ||
| updated[index] = [ | ||
| 'Error: Empty regex — you must define at least one public part for each pattern.', | ||
| ]; | ||
| } else { | ||
| // @ts-ignore | ||
| updated[index] = ['Error: ' + error]; | ||
| } | ||
|
|
||
| // @ts-ignore | ||
| updated[index] = 'Error: ' + error; | ||
| return updated; | ||
| }); | ||
| } | ||
|
|
@@ -615,6 +623,9 @@ const ExtractFields = ({ | |
| setField('decomposedRegexes', updatedRegexes); | ||
|
|
||
| setRegexGeneratedOutputs(regexGeneratedOutputs.filter((_, i) => i !== index)); | ||
| setRegexGeneratedOutputErrors( | ||
| regexGeneratedOutputErrors.filter((_, i) => i !== index) | ||
| ); | ||
| }} | ||
| > | ||
| Delete | ||
|
|
@@ -826,27 +837,36 @@ const ExtractFields = ({ | |
| </Button> | ||
| </div> | ||
| {/* Only show output if there are regex parts and valid outputs */} | ||
| {parseRegexParts(regex.parts).length > 0 && | ||
| regexGeneratedOutputs[index] !== undefined && | ||
| regexGeneratedOutputs[index] !== null && | ||
| regexGeneratedOutputs[index].length > 0 ? ( | ||
| {regex.parts.some((p: any) => p.isPublic) ? ( | ||
| parseRegexParts(regex.parts).length > 0 && | ||
| regexGeneratedOutputs[index] !== undefined && | ||
| regexGeneratedOutputs[index] !== null && | ||
| regexGeneratedOutputs[index].length > 0 ? ( | ||
|
Member
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. can you make the goal of these conditions more clear? maybe store them in a variable with a descriptive name so that in the future if we need to modify this it's easier to understand what is this doing |
||
| <> | ||
| <Label>Output</Label> | ||
| <div | ||
| className={`rounded-lg border p-2 text-sm ${ | ||
| regexGeneratedOutputErrors[index] | ||
| ? 'border-red-500 bg-red-100' | ||
| : 'border-grey-500 bg-neutral-100' | ||
| }`} | ||
| > | ||
| {regexGeneratedOutputErrors[index] | ||
| ? JSON.stringify(regexGeneratedOutputErrors[index]) | ||
| : regexGeneratedOutputs | ||
| ? `${regex.name}: ${JSON.stringify(regexGeneratedOutputs[index])}` | ||
| : ''} | ||
| </div> | ||
| </> | ||
| ) : null | ||
| ) : ( | ||
| <> | ||
| <Label>Output</Label> | ||
| <div | ||
| className={`rounded-lg border p-2 text-sm ${ | ||
| JSON.stringify(regexGeneratedOutputs[index]).includes('Error:') | ||
| ? 'border-red-500 bg-red-100' | ||
| : 'border-grey-500 bg-neutral-100' | ||
| }`} | ||
| > | ||
| {JSON.stringify(regexGeneratedOutputs[index]).includes('Error: ') | ||
| ? JSON.stringify(regexGeneratedOutputs[index]) | ||
| : regexGeneratedOutputs | ||
| ? `${regex.name}: ${JSON.stringify(regexGeneratedOutputs[index])}` | ||
| : ''} | ||
| <div className={`rounded-lg border border-red-500 bg-red-100 p-2 text-sm`}> | ||
| Please add at least one public regex | ||
| </div> | ||
| </> | ||
| ) : null} | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
|
|
||
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
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
Oops, something went wrong.
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.
Bug: Regex Parts Parsing Error
The condition checking for public regex parts directly calls
.some()onregex.parts. This can lead to a runtime error whenregex.partsis a string (JSON) instead of an array, as strings lack a.some()method. TheparseRegexParts()helper is designed to handle both formats.