Skip to content

Commit

Permalink
fix response state transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed May 24, 2018
1 parent eee112c commit 53f8658
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ export const {
sessionId,
response,
}),
SET_RESPONSE: simpleAction('response'),
SET_RESPONSE: (workspaceId, sessionId, response) => ({
workspaceId,
sessionId,
response,
}),
CLEAR_RESPONSES: simpleAction(),

FETCH_SCHEMA: simpleAction(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
setCurrentQueryStartTime,
setCurrentQueryEndTime,
setEndpointUnreachable,
clearResponses,
setResponse,
} from './actions'
import {
getSelectedSession,
Expand Down Expand Up @@ -138,6 +140,7 @@ function* runQuerySaga(action) {
})
yield put(setCurrentQueryStartTime(new Date()))

let firstResponse = false
const channel = eventChannel(emitter => {
let closed = false
if (subscriptionClient && operationIsSubscription) {
Expand Down Expand Up @@ -197,7 +200,15 @@ function* runQuerySaga(action) {
if (errorMessage === 'Failed to fetch') {
yield put(setEndpointUnreachable(session.endpoint))
}
yield put(addResponse(selectedWorkspaceId, session.id, response))
if (operationIsSubscription) {
if (firstResponse) {
yield put(clearResponses())
firstResponse = false
}
yield put(addResponse(selectedWorkspaceId, session.id, response))
} else {
yield put(setResponse(selectedWorkspaceId, session.id, response))
}
yield put(addHistoryItem(session))
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ const reducer = handleActions(
)
},
SET_RESPONSE: (state, { payload: { response, sessionId } }) => {
return state.setIn(['sessions', sessionId, 'responses'], List(response))
return state.setIn(['sessions', sessionId, 'responses'], List([response]))
},
CLEAR_RESPONSES: state => {
return state.setIn(
Expand Down

0 comments on commit 53f8658

Please sign in to comment.