Skip to content

Commit 9b2688f

Browse files
fix review comments
Co-authored-by: Saikrishna321 <[email protected]>
1 parent 5f3e163 commit 9b2688f

File tree

11 files changed

+82
-774
lines changed

11 files changed

+82
-774
lines changed

app/common/renderer/actions/Inspector.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import _ from 'lodash';
22

3-
import {SAVED_FRAMEWORK, SET_SAVED_GESTURES} from '../../shared/setting-defs';
3+
import {SAVED_FRAMEWORK, SET_SAVED_GESTURES, ENVIRONMENT_VARIABLES} from '../../shared/setting-defs';
44
import {POINTER_TYPES} from '../constants/gestures';
55
import {APP_MODE, NATIVE_APP} from '../constants/session-inspector';
66
import i18n from '../i18next';
@@ -360,6 +360,9 @@ export function quitSession(reason, killedByUser = true) {
360360
const applyAction = applyClientMethod({methodName: 'quit'});
361361
await applyAction(dispatch, getState);
362362
dispatch({type: QUIT_SESSION_DONE});
363+
// Reload environment variables from persistent settings after session ends
364+
const loadEnvAction = loadEnvironmentVariables();
365+
await loadEnvAction(dispatch);
363366
if (!killedByUser) {
364367
showError(new Error(reason || i18n.t('Session has been terminated')), {secs: 0});
365368
}
@@ -923,23 +926,37 @@ export function setGestureUploadErrors(errors) {
923926
}
924927

925928
export function setEnvironmentVariables(envVars) {
926-
return (dispatch) => {
929+
return async (dispatch) => {
930+
await setSetting(ENVIRONMENT_VARIABLES, envVars);
927931
dispatch({type: SET_ENVIRONMENT_VARIABLES, envVars});
928932
};
929933
}
930934

931935
export function addEnvironmentVariable(key, value) {
932-
return (dispatch) => {
936+
return async (dispatch, getState) => {
937+
const currentEnvVars = getState().inspector.environmentVariables || [];
938+
const newEnvVars = [...currentEnvVars, {key, value}];
939+
await setSetting(ENVIRONMENT_VARIABLES, newEnvVars);
933940
dispatch({type: ADD_ENVIRONMENT_VARIABLE, key, value});
934941
};
935942
}
936943

937944
export function deleteEnvironmentVariable(key) {
938-
return (dispatch) => {
945+
return async (dispatch, getState) => {
946+
const currentEnvVars = getState().inspector.environmentVariables || [];
947+
const newEnvVars = currentEnvVars.filter(v => v.key !== key);
948+
await setSetting(ENVIRONMENT_VARIABLES, newEnvVars);
939949
dispatch({type: DELETE_ENVIRONMENT_VARIABLE, key});
940950
};
941951
}
942952

953+
export function loadEnvironmentVariables() {
954+
return async (dispatch) => {
955+
const envVars = await getSetting(ENVIRONMENT_VARIABLES) || [];
956+
dispatch({type: SET_ENVIRONMENT_VARIABLES, envVars});
957+
};
958+
}
959+
943960
export function uploadGesturesFromFile(fileList) {
944961
return async (dispatch) => {
945962
const gestures = await readTextFromUploadedFiles(fileList);

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

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import {PlusOutlined, DeleteOutlined} from '@ant-design/icons';
2-
import {Button, Input, Space, Table, Tooltip} from 'antd';
2+
import {Button, Input, Space, Table, Tooltip, Popconfirm} from 'antd';
33
import {useState} from 'react';
4-
import {useDispatch, useSelector} from 'react-redux';
4+
import {connect} from 'react-redux';
55
import {setEnvironmentVariables, addEnvironmentVariable, deleteEnvironmentVariable} from '../../actions/Inspector';
6-
import styles from './EnvironmentVariables.module.css';
6+
import styles from './Inspector.module.css';
77

8-
const EnvironmentVariables = ({t}) => {
9-
const dispatch = useDispatch();
10-
const envVars = useSelector(state => state.inspector.environmentVariables || []);
8+
const EnvironmentVariables = ({t, envVars, addVariable, deleteVariable}) => {
119
const [newVar, setNewVar] = useState({key: '', value: ''});
1210

1311
const columns = [
@@ -29,15 +27,21 @@ const EnvironmentVariables = ({t}) => {
2927
key: 'action',
3028
width: '20%',
3129
render: (_, record) => (
32-
<Tooltip title={t('Delete Variable')}>
33-
<Button
34-
type="text"
35-
danger
36-
icon={<DeleteOutlined />}
37-
onClick={() => {
38-
dispatch(deleteEnvironmentVariable(record.key));
39-
}}
40-
/>
30+
<Tooltip zIndex={3} title={t('Delete Variable')}>
31+
<Popconfirm
32+
zIndex={4}
33+
title={t('Are you sure you want to delete this variable?')}
34+
placement="topRight"
35+
okText={t('OK')}
36+
cancelText={t('Cancel')}
37+
onConfirm={() => deleteVariable(record.key)}
38+
>
39+
<Button
40+
type="text"
41+
danger
42+
icon={<DeleteOutlined />}
43+
/>
44+
</Popconfirm>
4145
</Tooltip>
4246
),
4347
},
@@ -51,7 +55,7 @@ const EnvironmentVariables = ({t}) => {
5155
return;
5256
}
5357

54-
dispatch(addEnvironmentVariable(newVar.key, newVar.value));
58+
addVariable(newVar.key, newVar.value);
5559
setNewVar({key: '', value: ''});
5660
};
5761

@@ -90,4 +94,13 @@ const EnvironmentVariables = ({t}) => {
9094
);
9195
};
9296

93-
export default EnvironmentVariables;
97+
const mapStateToProps = (state) => ({
98+
envVars: state.inspector.environmentVariables || []
99+
});
100+
101+
const mapDispatchToProps = (dispatch) => ({
102+
addVariable: (key, value) => dispatch(addEnvironmentVariable(key, value)),
103+
deleteVariable: (key) => dispatch(deleteEnvironmentVariable(key))
104+
});
105+
106+
export default connect(mapStateToProps, mapDispatchToProps)(EnvironmentVariables);

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

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

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,3 +732,13 @@
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+
}

0 commit comments

Comments
 (0)