Skip to content

Commit

Permalink
feat: save remote connection
Browse files Browse the repository at this point in the history
  • Loading branch information
emaan-c authored and jlipps committed May 18, 2022
1 parent 929e6fb commit c92cedf
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 18 deletions.
21 changes: 13 additions & 8 deletions app/renderer/actions/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const SET_CAPABILITY_PARAM = 'SET_CAPABILITY_PARAM';
export const ADD_CAPABILITY = 'ADD_CAPABILITY';
export const REMOVE_CAPABILITY = 'REMOVE_CAPABILITY';
export const SWITCHED_TABS = 'SWITCHED_TABS';
export const SET_CAPS = 'SET_CAPS';
export const SET_CAPS_AND_SERVER = 'SET_CAPS_AND_SERVER';
export const SAVE_AS_MODAL_REQUESTED = 'SAVE_AS_MODAL_REQUESTED';
export const HIDE_SAVE_AS_MODAL_REQUESTED = 'HIDE_SAVE_AS_MODAL_REQUESTED';
export const SET_SAVE_AS_TEXT = 'SET_SAVE_AS_TEXT';
Expand Down Expand Up @@ -157,11 +157,11 @@ export function showError (e, methodName, secs = 5) {
}

/**
* Change the caps object and then go back to the new session tab
* Change the caps object, along with the server details and then go back to the new session tab
*/
export function setCaps (caps, uuid) {
export function setCapsAndServer (server, serverType, caps, uuid) {
return (dispatch) => {
dispatch({type: SET_CAPS, caps, uuid});
dispatch({type: SET_CAPS_AND_SERVER, server, serverType, caps, uuid});
};
}

Expand Down Expand Up @@ -202,8 +202,9 @@ export function removeCapability (index) {
}

function _addVendorPrefixes (caps, dispatch, getState) {
const {server, serverType, capsUUID} = getState().session;
const prefixedCaps = addVendorPrefixes(caps);
setCaps(prefixedCaps, getState().session.capsUUID)(dispatch);
setCapsAndServer(server, serverType, prefixedCaps, capsUUID)(dispatch);
return prefixedCaps;
}

Expand Down Expand Up @@ -569,9 +570,9 @@ export function newSession (caps, attachSessId = null) {


/**
* Saves the caps
* Saves the caps and server details
*/
export function saveSession (caps, params) {
export function saveSession (server, serverType, caps, params) {
return async (dispatch) => {
let {name, uuid} = params;
dispatch({type: SAVE_SESSION_REQUESTED});
Expand All @@ -585,6 +586,8 @@ export function saveSession (caps, params) {
name,
uuid,
caps,
server,
serverType,
};
savedSessions.push(newSavedSession);
} else {
Expand All @@ -593,13 +596,15 @@ export function saveSession (caps, params) {
for (let session of savedSessions) {
if (session.uuid === uuid) {
session.caps = caps;
session.server = server;
session.serverType = serverType;
}
}
}
await setSetting(SAVED_SESSIONS, savedSessions);
const action = getSavedSessions();
await action(dispatch);
dispatch({type: SET_CAPS, caps, uuid});
dispatch({type: SET_CAPS_AND_SERVER, server, serverType, caps, uuid});
dispatch({type: SAVE_SESSION_DONE});
};
}
Expand Down
4 changes: 2 additions & 2 deletions app/renderer/components/Session/CapabilityEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ export default class CapabilityEditor extends Component {
render () {
const {setCapabilityParam, caps, addCapability, removeCapability, saveSession, hideSaveAsModal,
saveAsText, showSaveAsModal, setSaveAsText, isEditingDesiredCaps, t,
setAddVendorPrefixes, addVendorPrefixes} = this.props;
setAddVendorPrefixes, addVendorPrefixes, server, serverType} = this.props;
const numCaps = caps.length;
const onSaveAsOk = () => saveSession(caps, {name: saveAsText});
const onSaveAsOk = () => saveSession(server, serverType, caps, {name: saveAsText});

return <>
<Row type={ROW.FLEX} align="top" justify="start" className={SessionStyles.capsFormRow}>
Expand Down
15 changes: 11 additions & 4 deletions app/renderer/components/Session/SavedSessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ export default class SavedSessions extends Component {
onRow (record) {
return {
onClick: () => {
const {setCaps} = this.props;
let session = this.sessionFromUUID(record.key);
setCaps(session.caps, session.uuid);
this.handleCapsAndServer(session);
}
};
}
Expand All @@ -31,6 +30,14 @@ export default class SavedSessions extends Component {
return capsUUID === record.key ? SessionCSS.selected : '';
}

handleCapsAndServer (session) {
const {setCapsAndServer, server, serverType } = this.props;

// Incase user has CAPS saved from older version of Inspector which
// doesn't contain server and serverType within the session object
setCapsAndServer(session.server || server, session.serverType || serverType, session.caps, session.uuid);
}

handleDelete (uuid) {
return () => {
if (window.confirm('Are you sure?')) {
Expand All @@ -50,7 +57,7 @@ export default class SavedSessions extends Component {
}

render () {
const {savedSessions, setCaps, capsUUID, switchTabs} = this.props;
const {savedSessions, capsUUID, switchTabs} = this.props;

const columns = [{
title: 'Capability Set',
Expand All @@ -69,7 +76,7 @@ export default class SavedSessions extends Component {
<div>
<Button
icon={<EditOutlined/>}
onClick={() => {setCaps(session.caps, session.uuid); switchTabs('new');}}
onClick={() => {this.handleCapsAndServer(session); switchTabs('new');}}
className={SessionCSS['edit-session']}
/>
<Button
Expand Down
4 changes: 2 additions & 2 deletions app/renderer/components/Session/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class Session extends Component {

render () {
const {newSessionBegan, savedSessions, tabKey, switchTabs,
serverType,
serverType, server,
requestSaveAsModal, newSession, caps, capsUUID, saveSession,
visibleProviders = [],
isCapsDirty, sessionLoading, attachSessId, t} = this.props;
Expand Down Expand Up @@ -116,7 +116,7 @@ export default class Session extends Component {
{t('desiredCapabilitiesDocumentation')}
</a>
</div>
{ (!isAttaching && capsUUID) && <Button onClick={() => saveSession(caps, {uuid: capsUUID})} disabled={!isCapsDirty}>{t('Save')}</Button> }
{ (!isAttaching && capsUUID) && <Button onClick={() => saveSession(server, serverType, caps, {uuid: capsUUID})} disabled={!isCapsDirty}>{t('Save')}</Button> }
{!isAttaching && <Button onClick={requestSaveAsModal}>{t('saveAs')}</Button>}
{!isAttaching && <Button type={BUTTON.PRIMARY} id='btnStartSession'
onClick={() => newSession(caps)} className={SessionStyles['start-session-button']}>{t('startSession')}</Button>
Expand Down
6 changes: 4 additions & 2 deletions app/renderer/reducers/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import formatJSON from 'format-json';
import { NEW_SESSION_REQUESTED, NEW_SESSION_BEGAN, NEW_SESSION_DONE,
SAVE_SESSION_REQUESTED, SAVE_SESSION_DONE, GET_SAVED_SESSIONS_REQUESTED,
GET_SAVED_SESSIONS_DONE, SESSION_LOADING, SESSION_LOADING_DONE,
SET_CAPABILITY_PARAM, ADD_CAPABILITY, REMOVE_CAPABILITY, SET_CAPS,
SET_CAPABILITY_PARAM, ADD_CAPABILITY, REMOVE_CAPABILITY, SET_CAPS_AND_SERVER,
SWITCHED_TABS, SAVE_AS_MODAL_REQUESTED, HIDE_SAVE_AS_MODAL_REQUESTED, SET_SAVE_AS_TEXT,
DELETE_SAVED_SESSION_REQUESTED, DELETE_SAVED_SESSION_DONE,
CHANGE_SERVER_TYPE, SET_SERVER_PARAM, SET_SERVER, SET_ATTACH_SESS_ID,
Expand Down Expand Up @@ -125,9 +125,11 @@ export default function session (state = INITIAL_STATE, action) {
}),
};

case SET_CAPS:
case SET_CAPS_AND_SERVER:
nextState = {
...state,
server: action.server,
serverType: action.serverType,
caps: action.caps,
capsUUID: action.uuid,
};
Expand Down

0 comments on commit c92cedf

Please sign in to comment.