chore: lint

This commit is contained in:
amhsirak
2025-01-25 15:50:27 +05:30
parent 5f0427232d
commit a06c6a59ec

View File

@@ -79,22 +79,22 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
const [robot, setRobot] = useState<RobotSettings | null>(null); const [robot, setRobot] = useState<RobotSettings | null>(null);
const [credentials, setCredentials] = useState<Credentials>({}); const [credentials, setCredentials] = useState<Credentials>({});
const { recordingId, notify } = useGlobalInfoStore(); const { recordingId, notify } = useGlobalInfoStore();
const [credentialGroups, setCredentialGroups] = useState<GroupedCredentials>({ const [credentialGroups, setCredentialGroups] = useState<GroupedCredentials>({
passwords: [], passwords: [],
emails: [], emails: [],
usernames: [], usernames: [],
others: [] others: []
}); });
const [showPasswords, setShowPasswords] = useState<CredentialVisibility>({}); const [showPasswords, setShowPasswords] = useState<CredentialVisibility>({});
const isEmailPattern = (value: string): boolean => { const isEmailPattern = (value: string): boolean => {
return value.includes('@'); return value.includes('@');
}; };
const isUsernameSelector = (selector: string): boolean => { const isUsernameSelector = (selector: string): boolean => {
return selector.toLowerCase().includes('username') || return selector.toLowerCase().includes('username') ||
selector.toLowerCase().includes('user') || selector.toLowerCase().includes('user') ||
selector.toLowerCase().includes('email'); selector.toLowerCase().includes('email');
}; };
const determineCredentialType = (selector: string, info: CredentialInfo): 'password' | 'email' | 'username' | 'other' => { const determineCredentialType = (selector: string, info: CredentialInfo): 'password' | 'email' | 'username' | 'other' => {
@@ -102,20 +102,20 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
if (info.type === 'password') { if (info.type === 'password') {
return 'password'; return 'password';
} }
// Check for email patterns in the value or selector // Check for email patterns in the value or selector
if (isEmailPattern(info.value) || selector.toLowerCase().includes('email')) { if (isEmailPattern(info.value) || selector.toLowerCase().includes('email')) {
return 'email'; return 'email';
} }
// Check for username patterns in the selector // Check for username patterns in the selector
if (isUsernameSelector(selector)) { if (isUsernameSelector(selector)) {
return 'username'; return 'username';
} }
return 'other'; return 'other';
}; };
useEffect(() => { useEffect(() => {
if (isOpen) { if (isOpen) {
getRobot(); getRobot();
@@ -132,32 +132,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 // Helper function to check if a character is printable
const isPrintableCharacter = (char: string): boolean => { const isPrintableCharacter = (char: string): boolean => {
return char.length === 1 && !!char.match(/^[\x20-\x7E]$/); 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 // Keep track of the current input field being processed
let currentSelector = ''; let currentSelector = '';
let currentValue = ''; let currentValue = '';
let currentType = ''; 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.action === 'press') &&
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 character: string = action.args[1];
const inputType: string = action.args[2] || ''; const inputType: string = action.args[2] || '';
// If we're dealing with a new selector, store the previous one // If we're dealing with a new selector, store the previous one
if (currentSelector && selector !== currentSelector) { if (currentSelector && selector !== currentSelector) {
if (!credentials[currentSelector]) { if (!credentials[currentSelector]) {
@@ -169,14 +169,14 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
credentials[currentSelector].value = currentValue; credentials[currentSelector].value = currentValue;
} }
} }
// Update current tracking variables // Update current tracking variables
if (selector !== currentSelector) { if (selector !== currentSelector) {
currentSelector = selector; currentSelector = selector;
currentValue = credentials[selector]?.value || ''; currentValue = credentials[selector]?.value || '';
currentType = inputType || credentials[selector]?.type || ''; currentType = inputType || credentials[selector]?.type || '';
} }
// Handle different types of key actions // Handle different types of key actions
if (character === 'Backspace') { if (character === 'Backspace') {
// Remove the last character when backspace is pressed // Remove the last character when backspace is pressed
@@ -188,7 +188,7 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
// Note: We ignore other special keys like 'Shift', 'Enter', etc. // Note: We ignore other special keys like 'Shift', 'Enter', etc.
} }
}); });
// Store the final state of the last processed selector // Store the final state of the last processed selector
if (currentSelector) { if (currentSelector) {
credentials[currentSelector] = { credentials[currentSelector] = {
@@ -197,14 +197,14 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
}; };
} }
}); });
return credentials; return credentials;
}; };
const groupCredentialsByType = (credentials: Credentials): GroupedCredentials => { const groupCredentialsByType = (credentials: Credentials): GroupedCredentials => {
return Object.entries(credentials).reduce((acc: GroupedCredentials, [selector, info]) => { return Object.entries(credentials).reduce((acc: GroupedCredentials, [selector, info]) => {
const credentialType = determineCredentialType(selector, info); const credentialType = determineCredentialType(selector, info);
switch (credentialType) { switch (credentialType) {
case 'password': case 'password':
acc.passwords.push(selector); acc.passwords.push(selector);
@@ -218,7 +218,7 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
default: default:
acc.others.push(selector); acc.others.push(selector);
} }
return acc; return acc;
}, { passwords: [], emails: [], usernames: [], others: [] }); }, { passwords: [], emails: [], usernames: [], others: [] });
}; };
@@ -279,25 +279,25 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
return ( return (
<> <>
{renderCredentialFields( {renderCredentialFields(
credentialGroups.usernames, credentialGroups.usernames,
t('Username'), t('Username'),
'text' 'text'
)} )}
{renderCredentialFields( {renderCredentialFields(
credentialGroups.emails, credentialGroups.emails,
t('Email'), t('Email'),
'text' 'text'
)} )}
{renderCredentialFields( {renderCredentialFields(
credentialGroups.passwords, credentialGroups.passwords,
t('Password'), t('Password'),
'password' 'password'
)} )}
{renderCredentialFields( {renderCredentialFields(
credentialGroups.others, credentialGroups.others,
t('Other'), t('Other'),
'text' 'text'
)} )}
@@ -307,15 +307,15 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
const renderCredentialFields = (selectors: string[], headerText: string, defaultType: 'text' | 'password' = 'text') => { const renderCredentialFields = (selectors: string[], headerText: string, defaultType: 'text' | 'password' = 'text') => {
if (selectors.length === 0) return null; if (selectors.length === 0) return null;
return ( return (
<> <>
<Typography variant="h6" style={{ marginBottom: '20px'}}> <Typography variant="h6" style={{ marginBottom: '20px' }}>
{headerText} {headerText}
</Typography> </Typography>
{selectors.map((selector, index) => { {selectors.map((selector, index) => {
const isVisible = showPasswords[selector]; const isVisible = showPasswords[selector];
return ( return (
<TextField <TextField
key={selector} key={selector}
@@ -408,7 +408,7 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
onChange={(e) => handleRobotNameChange(e.target.value)} onChange={(e) => handleRobotNameChange(e.target.value)}
style={{ marginBottom: '20px' }} style={{ marginBottom: '20px' }}
/> />
{robot.recording.workflow?.[0]?.what?.[0]?.args?.[0]?.limit !== undefined && ( {robot.recording.workflow?.[0]?.what?.[0]?.args?.[0]?.limit !== undefined && (
<TextField <TextField
label={t('robot_edit.robot_limit')} label={t('robot_edit.robot_limit')}