feat: extract type action creds
This commit is contained in:
@@ -118,6 +118,7 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (robot?.recording?.workflow) {
|
if (robot?.recording?.workflow) {
|
||||||
const extractedCredentials = extractInitialCredentials(robot.recording.workflow);
|
const extractedCredentials = extractInitialCredentials(robot.recording.workflow);
|
||||||
|
console.log(extractedCredentials);
|
||||||
setCredentials(extractedCredentials);
|
setCredentials(extractedCredentials);
|
||||||
setCredentialGroups(groupCredentialsByType(extractedCredentials));
|
setCredentialGroups(groupCredentialsByType(extractedCredentials));
|
||||||
}
|
}
|
||||||
@@ -126,74 +127,32 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
|
|||||||
const extractInitialCredentials = (workflow: any[]): Credentials => {
|
const extractInitialCredentials = (workflow: any[]): Credentials => {
|
||||||
const credentials: Credentials = {};
|
const credentials: Credentials = {};
|
||||||
|
|
||||||
// Helper function to check if a character is printable
|
|
||||||
const isPrintableCharacter = (char: string): boolean => {
|
|
||||||
return char.length === 1 && !!char.match(/^[\x20-\x7E]$/);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Process each step in the workflow
|
// Process each step in the workflow
|
||||||
workflow.forEach(step => {
|
workflow.forEach(step => {
|
||||||
if (!step.what) return;
|
if (!step.what) return;
|
||||||
|
|
||||||
// Keep track of the current input field being processed
|
|
||||||
let currentSelector = '';
|
|
||||||
let currentValue = '';
|
|
||||||
let currentType = '';
|
|
||||||
|
|
||||||
// Process actions in sequence to maintain correct text state
|
// Process actions in sequence to maintain correct text state
|
||||||
step.what.forEach((action: any) => {
|
step.what.forEach((action: any) => {
|
||||||
if (
|
if (
|
||||||
(action.action === 'type' || action.action === 'press') &&
|
action.action === 'type' &&
|
||||||
action.args?.length >= 2 &&
|
action.args?.length >= 2 &&
|
||||||
typeof action.args[1] === 'string'
|
typeof action.args[1] === 'string'
|
||||||
) {
|
) {
|
||||||
const selector: string = action.args[0];
|
const selector: string = action.args[0];
|
||||||
const character: string = action.args[1];
|
const value: string = action.args[1];
|
||||||
const inputType: string = action.args[2] || '';
|
const type: string = action.args[2];
|
||||||
|
|
||||||
// Detect `input[type="password"]`
|
if (!credentials[selector]) {
|
||||||
if (!currentType && inputType.toLowerCase() === 'password') {
|
credentials[selector] = {
|
||||||
currentType = 'password';
|
value: '',
|
||||||
|
type: ''
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're dealing with a new selector, store the previous one
|
credentials[selector].value = value;
|
||||||
if (currentSelector && selector !== currentSelector) {
|
credentials[selector].type = type;
|
||||||
if (!credentials[currentSelector]) {
|
|
||||||
credentials[currentSelector] = {
|
|
||||||
value: currentValue,
|
|
||||||
type: currentType
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
credentials[currentSelector].value = currentValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update current tracking variables
|
|
||||||
if (selector !== currentSelector) {
|
|
||||||
currentSelector = selector;
|
|
||||||
currentValue = credentials[selector]?.value || '';
|
|
||||||
currentType = inputType || credentials[selector]?.type || '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle different types of key actions
|
|
||||||
if (character === 'Backspace') {
|
|
||||||
// Remove the last character when backspace is pressed
|
|
||||||
currentValue = currentValue.slice(0, -1);
|
|
||||||
} else if (isPrintableCharacter(character)) {
|
|
||||||
// Add the character to the current value
|
|
||||||
currentValue += character;
|
|
||||||
}
|
|
||||||
// Note: We ignore other special keys like 'Shift', 'Enter', etc.
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Store the final state of the last processed selector
|
|
||||||
if (currentSelector) {
|
|
||||||
credentials[currentSelector] = {
|
|
||||||
value: currentValue,
|
|
||||||
type: currentType
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return credentials;
|
return credentials;
|
||||||
@@ -224,6 +183,7 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
|
|||||||
const getRobot = async () => {
|
const getRobot = async () => {
|
||||||
if (recordingId) {
|
if (recordingId) {
|
||||||
const robot = await getStoredRecording(recordingId);
|
const robot = await getStoredRecording(recordingId);
|
||||||
|
console.log("ROBOT:", robot);
|
||||||
setRobot(robot);
|
setRobot(robot);
|
||||||
} else {
|
} else {
|
||||||
notify('error', t('robot_edit.notifications.update_failed'));
|
notify('error', t('robot_edit.notifications.update_failed'));
|
||||||
|
|||||||
Reference in New Issue
Block a user