feat: extract and set initial credentials
This commit is contained in:
@@ -93,11 +93,7 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
|
|||||||
const selectors = findCredentialSelectors(robot.recording.workflow);
|
const selectors = findCredentialSelectors(robot.recording.workflow);
|
||||||
setCredentialSelectors(selectors);
|
setCredentialSelectors(selectors);
|
||||||
|
|
||||||
// Initialize credentials state
|
const initialCredentials = extractInitialCredentials(robot.recording.workflow);
|
||||||
const initialCredentials: Record<string, string> = {};
|
|
||||||
selectors.forEach(selector => {
|
|
||||||
initialCredentials[selector] = '';
|
|
||||||
});
|
|
||||||
setCredentials(initialCredentials);
|
setCredentials(initialCredentials);
|
||||||
}
|
}
|
||||||
}, [robot]);
|
}, [robot]);
|
||||||
@@ -108,7 +104,7 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
|
|||||||
workflow?.forEach(step => {
|
workflow?.forEach(step => {
|
||||||
step.what?.forEach(action => {
|
step.what?.forEach(action => {
|
||||||
if (
|
if (
|
||||||
(action.action === 'type' || action.action === 'press') &&
|
(action.action === 'type') &&
|
||||||
action.args &&
|
action.args &&
|
||||||
action.args[0] &&
|
action.args[0] &&
|
||||||
typeof action.args[0] === 'string'
|
typeof action.args[0] === 'string'
|
||||||
@@ -121,9 +117,43 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
|
|||||||
return Array.from(selectors);
|
return Array.from(selectors);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const extractInitialCredentials = (workflow: any[]): Record<string, string> => {
|
||||||
|
const credentials: Record<string, string> = {};
|
||||||
|
|
||||||
|
const isPrintableCharacter = (char: string): boolean => {
|
||||||
|
return char.length === 1 && !!char.match(/^[\x20-\x7E]$/);
|
||||||
|
};
|
||||||
|
|
||||||
|
workflow.forEach(step => {
|
||||||
|
if (!step.what) return;
|
||||||
|
|
||||||
|
step.what.forEach((action: any) => {
|
||||||
|
if (
|
||||||
|
(action.action === 'type' || action.action === 'press') &&
|
||||||
|
action.args?.length >= 2 &&
|
||||||
|
typeof action.args[1] === 'string'
|
||||||
|
) {
|
||||||
|
let currentSelector: string = action.args[0];
|
||||||
|
let character: string = action.args[1];
|
||||||
|
|
||||||
|
if (!credentials.hasOwnProperty(currentSelector)) {
|
||||||
|
credentials[currentSelector] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPrintableCharacter(character)) {
|
||||||
|
credentials[currentSelector] += character;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return credentials;
|
||||||
|
};
|
||||||
|
|
||||||
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