Merge branch 'develop' of https://github.com/getmaxun/maxun into develop

This commit is contained in:
amhsirak
2025-01-25 16:29:48 +05:30
2 changed files with 75 additions and 63 deletions

View File

@@ -76,7 +76,14 @@ interface RecordingsTableProps {
handleDuplicateRobot: (id: string, name: string, params: string[]) => void; handleDuplicateRobot: (id: string, name: string, params: string[]) => void;
} }
export const RecordingsTable = ({ handleEditRecording, handleRunRecording, handleScheduleRecording, handleIntegrateRecording, handleSettingsRecording, handleEditRobot, handleDuplicateRobot }: RecordingsTableProps) => { export const RecordingsTable = ({
handleEditRecording,
handleRunRecording,
handleScheduleRecording,
handleIntegrateRecording,
handleSettingsRecording,
handleEditRobot,
handleDuplicateRobot }: RecordingsTableProps) => {
const { t } = useTranslation(); const { t } = useTranslation();
const [page, setPage] = React.useState(0); const [page, setPage] = React.useState(0);
const [rowsPerPage, setRowsPerPage] = React.useState(10); const [rowsPerPage, setRowsPerPage] = React.useState(10);
@@ -109,7 +116,20 @@ export const RecordingsTable = ({ handleEditRecording, handleRunRecording, handl
}, },
]; ];
const { notify, setRecordings, browserId, setBrowserId, setInitialUrl, recordingUrl, setRecordingUrl, isLogin, setIsLogin, recordingName, setRecordingName, recordingId, setRecordingId } = useGlobalInfoStore(); const {
notify,
setRecordings,
browserId,
setBrowserId,
setInitialUrl,
recordingUrl,
setRecordingUrl,
isLogin,
setIsLogin,
recordingName,
setRecordingName,
recordingId,
setRecordingId } = useGlobalInfoStore();
const navigate = useNavigate(); const navigate = useNavigate();
const handleChangePage = (event: unknown, newPage: number) => { const handleChangePage = (event: unknown, newPage: number) => {

View File

@@ -8,7 +8,6 @@ import { useGlobalInfoStore } from '../../context/globalInfo';
import { getStoredRecording, updateRecording } from '../../api/storage'; import { getStoredRecording, updateRecording } from '../../api/storage';
import { WhereWhatPair } from 'maxun-core'; import { WhereWhatPair } from 'maxun-core';
// Base interfaces for robot data structure
interface RobotMeta { interface RobotMeta {
name: string; name: string;
id: string; id: string;
@@ -55,7 +54,6 @@ interface RobotSettingsProps {
initialSettings?: RobotSettings | null; initialSettings?: RobotSettings | null;
} }
// Enhanced interfaces for credential handling
interface CredentialInfo { interface CredentialInfo {
value: string; value: string;
type: string; type: string;
@@ -81,44 +79,37 @@ 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' => {
// Check for password type first if (info.type === 'password' || selector.toLowerCase().includes('password')) {
if (info.type === 'password') {
return 'password'; return 'password';
} }
// 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
if (isUsernameSelector(selector)) { if (isUsernameSelector(selector)) {
return 'username'; return 'username';
} }
// If no specific pattern is matched, classify as other
return 'other'; return 'other';
}; };
useEffect(() => { useEffect(() => {
if (isOpen) { if (isOpen) {
getRobot(); getRobot();
@@ -135,32 +126,37 @@ 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] || '';
// Detect `input[type="password"]`
if (!currentType && inputType.toLowerCase() === 'password') {
currentType = 'password';
}
// 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]) {
@@ -172,14 +168,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
@@ -191,7 +187,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] = {
@@ -200,14 +196,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);
@@ -221,7 +217,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: [] });
}; };
@@ -281,32 +277,28 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
const renderAllCredentialFields = () => { const renderAllCredentialFields = () => {
return ( return (
<> <>
{/* Render username credentials */}
{renderCredentialFields( {renderCredentialFields(
credentialGroups.usernames, credentialGroups.usernames,
t('Username Credentials'), t('Username'),
'text' // Always show usernames as text 'text'
)} )}
{/* Render email credentials */}
{renderCredentialFields( {renderCredentialFields(
credentialGroups.emails, credentialGroups.emails,
t('Email Credentials'), t('Email'),
'text' // Always show emails as text 'text'
)} )}
{/* Render password credentials */}
{renderCredentialFields( {renderCredentialFields(
credentialGroups.passwords, credentialGroups.passwords,
t('Password Credentials'), t('Password'),
'password' // Use password masking 'password'
)} )}
{/* Render other credentials */}
{renderCredentialFields( {renderCredentialFields(
credentialGroups.others, credentialGroups.others,
t('Other Credentials'), t('Other'),
'text' // Show other credentials as text 'text'
)} )}
</> </>
); );
@@ -314,33 +306,30 @@ 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) => { {selectors.map((selector, index) => {
const isVisible = showPasswords[selector]; const isVisible = showPasswords[selector];
return ( return (
<TextField <TextField
key={selector} key={selector}
// The type changes based on visibility state
type={isVisible ? 'text' : 'password'} type={isVisible ? 'text' : 'password'}
label={`Credential for ${selector}`} label={headerText === 'Other' ? `${`Input`} ${index + 1}` : headerText}
value={credentials[selector]?.value || ''} value={credentials[selector]?.value || ''}
onChange={(e) => handleCredentialChange(selector, e.target.value)} onChange={(e) => handleCredentialChange(selector, e.target.value)}
style={{ marginBottom: '20px' }} style={{ marginBottom: '20px' }}
InputProps={{ InputProps={{
// Now showing visibility toggle for all fields
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
<IconButton <IconButton
aria-label="toggle credential visibility" aria-label="Show input"
onClick={() => handleClickShowPassword(selector)} onClick={() => handleClickShowPassword(selector)}
edge="end" edge="end"
// Optional: disable if field is empty
disabled={!credentials[selector]?.value} disabled={!credentials[selector]?.value}
> >
{isVisible ? <Visibility /> : <VisibilityOff />} {isVisible ? <Visibility /> : <VisibilityOff />}
@@ -415,7 +404,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')}
@@ -434,6 +423,9 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
{(robot.isLogin || Object.keys(credentials).length > 0) && ( {(robot.isLogin || Object.keys(credentials).length > 0) && (
<> <>
<Typography variant="body1" style={{ marginBottom: '20px' }}>
{t('Input Texts')}
</Typography>
{renderAllCredentialFields()} {renderAllCredentialFields()}
</> </>
)} )}