Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
fix: stale session ids being displayed in the attach to session dropd…
Browse files Browse the repository at this point in the history
…own (#1727)

* fix: attachSessId placeholder not getting displayed

* fix: stale session ids being displayed in the attach session dropdown
  • Loading branch information
huzaifaiftikhar committed Mar 15, 2021
1 parent e407bd7 commit 03601e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/renderer/components/Session/AttachToSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class AttachToSession extends Component {

render () {
let {attachSessId, setAttachSessId, runningAppiumSessions, getRunningSessions, t} = this.props;
attachSessId = attachSessId || '';
attachSessId = attachSessId || undefined;
return (<Form>
<FormItem>
<Card>
Expand Down
19 changes: 17 additions & 2 deletions app/renderer/reducers/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ const INITIAL_STATE = {

let nextState;

// returns false if the attachSessId is not present in the runningSessions list
const isAttachSessIdValid = (runningSessions, attachSessId) => {
if (!attachSessId || !runningSessions) {
return false;
}
for (const session of runningSessions) {
if (session.id === attachSessId) {
return true;
}
}
return false;
};

export default function session (state = INITIAL_STATE, action) {
switch (action.type) {
case NEW_SESSION_REQUESTED:
Expand Down Expand Up @@ -237,13 +250,15 @@ export default function session (state = INITIAL_STATE, action) {
gettingSessions: true,
};

case GET_SESSIONS_DONE:
case GET_SESSIONS_DONE: {
const attachSessId = isAttachSessIdValid(action.sessions, state.attachSessId) ? state.attachSessId : null;
return {
...state,
gettingSessions: false,
attachSessId: (action.sessions && action.sessions.length > 0 && !state.attachSessId) ? action.sessions[0].id : state.attachSessId,
attachSessId: (action.sessions && action.sessions.length > 0 && !attachSessId) ? action.sessions[0].id : attachSessId,
runningAppiumSessions: action.sessions || [],
};
}

case ENABLE_DESIRED_CAPS_EDITOR:
return {
Expand Down

0 comments on commit 03601e7

Please sign in to comment.