-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: handle displayed input texts #435
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
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3c0f790
fix: register type actions correctly
RohitR311 80356b5
feat: add cursor position on click action
RohitR311 9ff7813
feat: modify logic to gen cursor index
RohitR311 f63ff72
feat: add selection start property to get cursor index
RohitR311 2199149
feat: rm previous cursor logic
RohitR311 206d760
feat: accurately get cursor index value for input field
RohitR311 945f120
feat: optimize press actions to type actions
RohitR311 afe7c2f
feat: maintain input type for fields
RohitR311 6a989ad
feat: extract type action creds
RohitR311 4c21e27
feat: console log cleanup
RohitR311 b7ce40c
feat: update workflow type actions, update robot
RohitR311 81b917b
feat: console log cleanup
RohitR311 8369714
feat: comments cleanup
RohitR311 5207d7d
feat: default to text if type not specified
RohitR311 cd57419
feat: console log cleanup
RohitR311 c6f5479
feat: add support for full and partial word type actions
RohitR311 ff21f53
feat: fallback to update type actions
RohitR311 99696aa
feat: comment cleanup
RohitR311 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,54 +163,82 @@ interface Credentials { | |
| [key: string]: CredentialInfo; | ||
| } | ||
|
|
||
| function updateTypeActionsInWorkflow(workflow: any[], credentials: Credentials) { | ||
| function handleWorkflowActions(workflow: any[], credentials: Credentials) { | ||
| return workflow.map(step => { | ||
| if (!step.what) return step; | ||
|
|
||
| const indicesToRemove = new Set<number>(); | ||
| step.what.forEach((action: any, index: number) => { | ||
| if (!action.action || !action.args?.[0]) return; | ||
| const newWhat: any[] = []; | ||
| const processedSelectors = new Set<string>(); | ||
|
|
||
| for (let i = 0; i < step.what.length; i++) { | ||
| const action = step.what[i]; | ||
|
|
||
| if ((action.action === 'type' || action.action === 'press') && credentials[action.args[0]]) { | ||
| indicesToRemove.add(index); | ||
|
|
||
| if (step.what[index + 1]?.action === 'waitForLoadState') { | ||
| indicesToRemove.add(index + 1); | ||
| } | ||
| if (!action?.action || !action?.args?.[0]) { | ||
| newWhat.push(action); | ||
| continue; | ||
| } | ||
| }); | ||
|
|
||
| const filteredWhat = step.what.filter((_: any, index: number) => !indicesToRemove.has(index)); | ||
| const selector = action.args[0]; | ||
| const credential = credentials[selector]; | ||
|
|
||
| Object.entries(credentials).forEach(([selector, credentialInfo]) => { | ||
| const clickIndex = filteredWhat.findIndex((action: any) => | ||
| action.action === 'click' && action.args?.[0] === selector | ||
| ); | ||
| if (!credential) { | ||
| newWhat.push(action); | ||
| continue; | ||
| } | ||
|
|
||
| if (clickIndex !== -1) { | ||
| const chars = credentialInfo.value.split(''); | ||
| if (action.action === 'click') { | ||
| newWhat.push(action); | ||
|
|
||
| chars.forEach((char, i) => { | ||
| filteredWhat.splice(clickIndex + 1 + (i * 2), 0, { | ||
| if (!processedSelectors.has(selector) && | ||
| i + 1 < step.what.length && | ||
| (step.what[i + 1].action === 'type' || step.what[i + 1].action === 'press')) { | ||
|
|
||
| newWhat.push({ | ||
| action: 'type', | ||
| args: [ | ||
| selector, | ||
| encrypt(char), | ||
| credentialInfo.type | ||
| ] | ||
| args: [selector, encrypt(credential.value), credential.type] | ||
| }); | ||
|
|
||
| filteredWhat.splice(clickIndex + 2 + (i * 2), 0, { | ||
| newWhat.push({ | ||
| action: 'waitForLoadState', | ||
| args: ['networkidle'] | ||
| }); | ||
|
|
||
| processedSelectors.add(selector); | ||
|
|
||
| while (i + 1 < step.what.length && | ||
| (step.what[i + 1].action === 'type' || | ||
| step.what[i + 1].action === 'press' || | ||
| step.what[i + 1].action === 'waitForLoadState')) { | ||
| i++; | ||
| } | ||
| } | ||
| } else if ((action.action === 'type' || action.action === 'press') && | ||
| !processedSelectors.has(selector)) { | ||
| newWhat.push({ | ||
| action: 'type', | ||
| args: [selector, encrypt(credential.value), credential.type] | ||
| }); | ||
|
|
||
| newWhat.push({ | ||
| action: 'waitForLoadState', | ||
| args: ['networkidle'] | ||
| }); | ||
|
|
||
| processedSelectors.add(selector); | ||
|
|
||
| // Skip subsequent type/press/waitForLoadState actions for this selector | ||
| while (i + 1 < step.what.length && | ||
| (step.what[i + 1].action === 'type' || | ||
| step.what[i + 1].action === 'press' || | ||
| step.what[i + 1].action === 'waitForLoadState')) { | ||
| i++; | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| return { | ||
| ...step, | ||
| what: filteredWhat | ||
| what: newWhat | ||
| }; | ||
| }); | ||
| } | ||
|
|
@@ -243,7 +271,7 @@ router.put('/recordings/:id', requireSignIn, async (req: AuthenticatedRequest, r | |
| let workflow = [...robot.recording.workflow]; // Create a copy of the workflow | ||
|
|
||
| if (credentials) { | ||
| workflow = updateTypeActionsInWorkflow(workflow, credentials); | ||
| workflow = handleWorkflowActions(workflow, credentials); | ||
| } | ||
|
|
||
| // Update the limit | ||
|
|
@@ -281,9 +309,23 @@ router.put('/recordings/:id', requireSignIn, async (req: AuthenticatedRequest, r | |
| } | ||
| } | ||
|
|
||
| robot.set('recording', { ...robot.recording, workflow }); | ||
| const updates: any = { | ||
| recording: { | ||
| ...robot.recording, | ||
| workflow | ||
| } | ||
| }; | ||
|
|
||
| await robot.save(); | ||
| if (name) { | ||
| updates.recording_meta = { | ||
| ...robot.recording_meta, | ||
| name | ||
| }; | ||
| } | ||
|
|
||
| await Robot.update(updates, { | ||
| where: { 'recording_meta.id': id } | ||
| }); | ||
|
Comment on lines
+312
to
+328
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. 🛠️ Refactor suggestion Add type safety and validation for the update operation. The update operation could fail if any of the spread properties are undefined. Consider adding type checking and validation. - const updates: any = {
+ const updates: {
+ recording?: {
+ workflow: any[];
+ [key: string]: any;
+ };
+ recording_meta?: {
+ name: string;
+ [key: string]: any;
+ };
+ } = {};
+
+ // Validate recording object before spread
+ if (robot.recording) {
recording: {
- ...robot.recording,
+ ...robot.recording,
workflow
}
+ }
if (name) {
+ // Validate recording_meta object before spread
+ if (robot.recording_meta) {
updates.recording_meta = {
...robot.recording_meta,
name
};
+ }
}
|
||
|
|
||
| const updatedRobot = await Robot.findOne({ where: { 'recording_meta.id': id } }); | ||
|
|
||
|
|
||
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.
Add safeguards against potential infinite loops.
The while loops for skipping subsequent actions could potentially become infinite if the array structure is malformed.
Also applies to: 240-245