Skip to content

Commit 9e8f5a4

Browse files
Fixed review comments
Co-authored-by: Saikrishna321 <[email protected]>
1 parent fc17cb3 commit 9e8f5a4

File tree

10 files changed

+246
-207
lines changed

10 files changed

+246
-207
lines changed

app/common/renderer/actions/Inspector.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ export const TOGGLE_REFRESHING_STATE = 'TOGGLE_REFRESHING_STATE';
121121

122122
export const SET_GESTURE_UPLOAD_ERROR = 'SET_GESTURE_UPLOAD_ERROR';
123123
export const SET_ENVIRONMENT_VARIABLES = 'SET_ENVIRONMENT_VARIABLES';
124-
export const ADD_ENVIRONMENT_VARIABLE = 'ADD_ENVIRONMENT_VARIABLE';
125-
export const DELETE_ENVIRONMENT_VARIABLE = 'DELETE_ENVIRONMENT_VARIABLE';
126124

127125
const KEEP_ALIVE_PING_INTERVAL = 20 * 1000;
128126
const NO_NEW_COMMAND_LIMIT = 24 * 60 * 60 * 1000; // Set timeout to 24 hours
@@ -929,31 +927,6 @@ export function setGestureUploadErrors(errors) {
929927
};
930928
}
931929

932-
export function setEnvironmentVariables(envVars) {
933-
return async (dispatch) => {
934-
await setSetting(ENVIRONMENT_VARIABLES, envVars);
935-
dispatch({type: SET_ENVIRONMENT_VARIABLES, envVars});
936-
};
937-
}
938-
939-
export function addEnvironmentVariable(key, value) {
940-
return async (dispatch, getState) => {
941-
const currentEnvVars = getState().inspector.environmentVariables || [];
942-
const newEnvVars = [...currentEnvVars, {key, value}];
943-
await setSetting(ENVIRONMENT_VARIABLES, newEnvVars);
944-
dispatch({type: ADD_ENVIRONMENT_VARIABLE, key, value});
945-
};
946-
}
947-
948-
export function deleteEnvironmentVariable(key) {
949-
return async (dispatch, getState) => {
950-
const currentEnvVars = getState().inspector.environmentVariables || [];
951-
const newEnvVars = currentEnvVars.filter((v) => v.key !== key);
952-
await setSetting(ENVIRONMENT_VARIABLES, newEnvVars);
953-
dispatch({type: DELETE_ENVIRONMENT_VARIABLE, key});
954-
};
955-
}
956-
957930
export function loadEnvironmentVariables() {
958931
return async (dispatch) => {
959932
const envVars = (await getSetting(ENVIRONMENT_VARIABLES)) || [];

app/common/renderer/actions/Session.js

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {log} from '../utils/logger';
2121
import {addVendorPrefixes} from '../utils/other';
2222
import {quitSession, setSessionDetails} from './Inspector';
2323

24+
export const ENVIRONMENT_VARIABLES = 'ENVIRONMENT_VARIABLES';
25+
2426
export const NEW_SESSION_REQUESTED = 'NEW_SESSION_REQUESTED';
2527
export const NEW_SESSION_LOADING = 'NEW_SESSION_LOADING';
2628
export const NEW_SESSION_DONE = 'NEW_SESSION_DONE';
@@ -69,6 +71,10 @@ export const SET_CAPABILITY_NAME_ERROR = 'SET_CAPABILITY_NAME_ERROR';
6971
export const SET_STATE_FROM_URL = 'SET_STATE_FROM_URL';
7072
export const SET_STATE_FROM_FILE = 'SET_STATE_FROM_FILE';
7173

74+
export const SET_ENVIRONMENT_VARIABLES = 'SET_ENVIRONMENT_VARIABLES';
75+
export const ADD_ENVIRONMENT_VARIABLE = 'ADD_ENVIRONMENT_VARIABLE';
76+
export const DELETE_ENVIRONMENT_VARIABLE = 'DELETE_ENVIRONMENT_VARIABLE';
77+
7278
const APPIUM_SESSION_FILE_VERSION = '1.0';
7379

7480
const CAPS_NEW_COMMAND = 'appium:newCommandTimeout';
@@ -231,14 +237,24 @@ export function newSession(caps, attachSessId = null) {
231237
dispatch({type: NEW_SESSION_REQUESTED, caps});
232238

233239
// Get environment variables from state
234-
const environmentVariables = getState().inspector.environmentVariables || [];
240+
const environmentVariables = session.environmentVariables || [];
235241

236242
// Get capabilities and interpolate environment variables
237243
let desiredCapabilities = caps ? getCapsObject(caps) : {};
238-
desiredCapabilities = interpolateEnvironmentVariables(
239-
desiredCapabilities,
240-
environmentVariables,
241-
);
244+
245+
// Modify this section to handle W3C capabilities format
246+
if (desiredCapabilities.alwaysMatch) {
247+
desiredCapabilities.alwaysMatch = interpolateEnvironmentVariables(
248+
desiredCapabilities.alwaysMatch,
249+
environmentVariables
250+
);
251+
} else {
252+
desiredCapabilities = interpolateEnvironmentVariables(
253+
desiredCapabilities,
254+
environmentVariables
255+
);
256+
}
257+
242258
let host, port, username, accessKey, https, path, token;
243259
desiredCapabilities = addCustomCaps(desiredCapabilities);
244260

@@ -1195,3 +1211,35 @@ export function initFromQueryString(loadNewSession) {
11951211
}
11961212
};
11971213
}
1214+
1215+
export function setEnvironmentVariables(envVars) {
1216+
return async (dispatch) => {
1217+
await setSetting(ENVIRONMENT_VARIABLES, envVars);
1218+
dispatch({type: SET_ENVIRONMENT_VARIABLES, envVars});
1219+
};
1220+
}
1221+
1222+
export function loadEnvironmentVariables() {
1223+
return async (dispatch) => {
1224+
const envVars = await getSetting(ENVIRONMENT_VARIABLES) || [];
1225+
dispatch({type: SET_ENVIRONMENT_VARIABLES, envVars});
1226+
};
1227+
}
1228+
1229+
export function addEnvironmentVariable(key, value) {
1230+
return async (dispatch, getState) => {
1231+
const currentEnvVars = getState().inspector.environmentVariables || [];
1232+
const newEnvVars = [...currentEnvVars, {key, value}];
1233+
await setSetting(ENVIRONMENT_VARIABLES, newEnvVars);
1234+
dispatch({type: ADD_ENVIRONMENT_VARIABLE, key, value});
1235+
};
1236+
}
1237+
1238+
export function deleteEnvironmentVariable(key) {
1239+
return async (dispatch, getState) => {
1240+
const currentEnvVars = getState().inspector.environmentVariables || [];
1241+
const newEnvVars = currentEnvVars.filter((v) => v.key !== key);
1242+
await setSetting(ENVIRONMENT_VARIABLES, newEnvVars);
1243+
dispatch({type: DELETE_ENVIRONMENT_VARIABLE, key});
1244+
};
1245+
}

app/common/renderer/components/Inspector/EnvironmentVariables.jsx

Lines changed: 0 additions & 103 deletions
This file was deleted.

app/common/renderer/components/Inspector/Inspector.module.css

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,3 @@
732732
color: red;
733733
margin: 5px;
734734
}
735-
736-
.container {
737-
display: flex;
738-
flex-direction: column;
739-
gap: 16px;
740-
}
741-
742-
.addForm {
743-
padding: 8px 0;
744-
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import {DeleteOutlined, PlusOutlined, SettingOutlined} from '@ant-design/icons';
2+
import {Button, Card, Input, Popconfirm, Space, Table, Tooltip} from 'antd';
3+
import {useState} from 'react';
4+
import SessionStyles from '../Session/Session.module.css';
5+
import styles from './Session.module.css';
6+
7+
const EnvironmentVariables = ({t, envVars, addVariable, deleteVariable}) => {
8+
const [newVar, setNewVar] = useState({key: '', value: ''});
9+
10+
const tableData = Array.from(envVars, ([key, value]) => ({key, value}));
11+
12+
const columns = [
13+
{
14+
title: t('Variable Name'),
15+
dataIndex: 'key',
16+
key: 'key',
17+
width: '40%',
18+
},
19+
{
20+
title: t('Value'),
21+
dataIndex: 'value',
22+
key: 'value',
23+
width: '40%',
24+
render: (text) => <Input.Password value={text} readOnly />,
25+
},
26+
{
27+
title: t('Actions'),
28+
key: 'action',
29+
width: '20%',
30+
render: (_, record) => (
31+
<Tooltip zIndex={3} title={t('Delete')}>
32+
<Popconfirm
33+
zIndex={4}
34+
title={t('confirmDeletion')}
35+
placement="topRight"
36+
okText={t('OK')}
37+
cancelText={t('Cancel')}
38+
onConfirm={() => deleteVariable(record.key)}
39+
>
40+
<Button icon={<DeleteOutlined />} />
41+
</Popconfirm>
42+
</Tooltip>
43+
),
44+
},
45+
];
46+
47+
const handleAddVariable = () => {
48+
if (!newVar.key || !newVar.value) {
49+
return;
50+
}
51+
52+
// Check for duplicate keys is no longer needed since Map handles this automatically
53+
addVariable(newVar.key, newVar.value);
54+
setNewVar({key: '', value: ''});
55+
};
56+
57+
return (
58+
<Card
59+
title={
60+
<span>
61+
<SettingOutlined /> {t('Environment Variables')}
62+
</span>
63+
}
64+
className={SessionStyles['interaction-tab-card']}
65+
>
66+
<div className={styles.container}>
67+
<div className={styles.addForm}>
68+
<Space.Compact style={{width: '100%'}}>
69+
<Input
70+
placeholder={t('Variable Name')}
71+
value={newVar.key}
72+
onChange={(e) => setNewVar({...newVar, key: e.target.value})}
73+
/>
74+
<Input.Password
75+
placeholder={t('Value')}
76+
value={newVar.value}
77+
onChange={(e) => setNewVar({...newVar, value: e.target.value})}
78+
/>
79+
<Button
80+
type="primary"
81+
icon={<PlusOutlined />}
82+
onClick={handleAddVariable}
83+
disabled={!newVar.key || !newVar.value}
84+
>
85+
{t('Add')}
86+
</Button>
87+
</Space.Compact>
88+
</div>
89+
<Table columns={columns} dataSource={tableData} pagination={false} rowKey="key" size="small" />
90+
</div>
91+
</Card>
92+
);
93+
};
94+
95+
export default EnvironmentVariables;

app/common/renderer/components/Session/Session.jsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from '../../constants/session-builder';
1414
import {ipcRenderer, openLink} from '../../polyfills';
1515
import {log} from '../../utils/logger';
16-
import EnvironmentVariables from '../Inspector/EnvironmentVariables.jsx';
16+
import EnvironmentVariables from './EnvironmentVariables.jsx';
1717
import AdvancedServerParams from './AdvancedServerParams.jsx';
1818
import AttachToSession from './AttachToSession.jsx';
1919
import CapabilityEditor from './CapabilityEditor.jsx';
@@ -41,8 +41,10 @@ const Session = (props) => {
4141
savedSessions,
4242
newSessionLoading,
4343
attachSessId,
44-
loadEnvironmentVariables,
4544
t,
45+
environmentVariables,
46+
addEnvironmentVariable,
47+
deleteEnvironmentVariable,
4648
} = props;
4749

4850
const navigate = useNavigate();
@@ -164,17 +166,14 @@ const Session = (props) => {
164166
{
165167
label: t('Environment Variables'),
166168
key: SESSION_BUILDER_TABS.ENV_VARS,
169+
className: SessionStyles.scrollingTab,
167170
children: (
168-
<Card
169-
title={
170-
<span>
171-
<SettingOutlined /> {t('Environment Variables')}
172-
</span>
173-
}
174-
className={SessionStyles['interaction-tab-card']}
175-
>
176-
<EnvironmentVariables {...props} />
177-
</Card>
171+
<EnvironmentVariables
172+
t={t}
173+
envVars={environmentVariables}
174+
addVariable={addEnvironmentVariable}
175+
deleteVariable={deleteEnvironmentVariable}
176+
/>
178177
),
179178
},
180179
]}

0 commit comments

Comments
 (0)