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

fix: stale session ids being displayed in the attach to session dropdown #1727

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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