Skip to content

Commit

Permalink
chore: store session settings in Redux (#1592)
Browse files Browse the repository at this point in the history
* chore: store session settings in redux

* chore: do not reassign function argument

* chore: fix review comment
  • Loading branch information
eglitise authored Aug 9, 2024
1 parent 4dd8e91 commit 3717494
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
16 changes: 16 additions & 0 deletions app/common/renderer/actions/Inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {showError} from './Session';

export const SET_SESSION_DETAILS = 'SET_SESSION_DETAILS';
export const SET_SOURCE_AND_SCREENSHOT = 'SET_SOURCE_AND_SCREENSHOT';
export const STORE_SESSION_SETTINGS = 'STORE_SESSION_SETTINGS';
export const SESSION_DONE = 'SESSION_DONE';
export const SELECT_ELEMENT = 'SELECT_ELEMENT';
export const UNSELECT_ELEMENT = 'UNSELECT_ELEMENT';
Expand Down Expand Up @@ -368,6 +369,21 @@ export function setSessionDetails({driver, sessionDetails, mode, mjpegScreenshot
};
}

export function storeSessionSettings(updatedSessionSettings = null) {
return async (dispatch, getState) => {
let sessionSettings = updatedSessionSettings;
if (sessionSettings === null) {
const action = applyClientMethod({
methodName: 'getSettings',
skipRefresh: true,
ignoreResult: true,
});
sessionSettings = await action(dispatch, getState);
}
dispatch({type: STORE_SESSION_SETTINGS, sessionSettings});
};
}

export function showLocatorTestModal() {
return (dispatch) => {
dispatch({type: SHOW_LOCATOR_TEST_MODAL});
Expand Down
5 changes: 5 additions & 0 deletions app/common/renderer/components/Inspector/Commands.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Commands = (props) => {
setCommandArg,
applyClientMethod,
automationName,
storeSessionSettings,
t,
} = props;

Expand Down Expand Up @@ -115,6 +116,10 @@ const Commands = (props) => {
skipRefresh: !refresh,
ignoreResult: false,
});
// if updating settings, store the updated values
if (commandName === 'updateSettings') {
storeSessionSettings(...copiedArgs);
}
}

cancelPendingCommand();
Expand Down
9 changes: 8 additions & 1 deletion app/common/renderer/components/Inspector/Inspector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@ const Inspector = (props) => {
};

useEffect(() => {
const {applyClientMethod, getSavedActionFramework, runKeepAliveLoop, setSessionTime} = props;
const {
applyClientMethod,
getSavedActionFramework,
runKeepAliveLoop,
setSessionTime,
storeSessionSettings,
} = props;
const curHeight = window.innerHeight;
const curWidth = window.innerWidth;
const needsResize =
Expand All @@ -190,6 +196,7 @@ const Inspector = (props) => {
}
didInitialResize.current = true;
applyClientMethod({methodName: 'getPageSource', ignoreResult: true});
storeSessionSettings();
getSavedActionFramework();
runKeepAliveLoop();
setSessionTime(Date.now());
Expand Down
8 changes: 8 additions & 0 deletions app/common/renderer/reducers/Inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import {
SHOW_LOCATOR_TEST_MODAL,
SHOW_SIRI_COMMAND_MODAL,
START_RECORDING,
STORE_SESSION_SETTINGS,
TOGGLE_REFRESHING_STATE,
TOGGLE_SHOW_ATTRIBUTES,
UNSELECT_CENTROID,
Expand Down Expand Up @@ -103,6 +104,7 @@ const INITIAL_STATE = {
recordedActions: [],
actionFramework: DEFAULT_FRAMEWORK,
sessionDetails: {},
sessionSettings: {},
isGestureEditorVisible: false,
isLocatorTestModalVisible: false,
isSiriCommandModalVisible: false,
Expand Down Expand Up @@ -317,6 +319,12 @@ export default function inspector(state = INITIAL_STATE, action) {
};
}

case STORE_SESSION_SETTINGS:
return {
...state,
sessionSettings: {...state.sessionSettings, ...action.sessionSettings},
};

case SHOW_LOCATOR_TEST_MODAL:
return {
...state,
Expand Down

0 comments on commit 3717494

Please sign in to comment.