Skip to content

Commit

Permalink
fix(de): cancel button cancels all running queries (#299)
Browse files Browse the repository at this point in the history
* fix(de): update logic for cancel button to cancel all running queries

* chore(de): remove unused thunk to get query status

Co-authored-by: Palak Bhojani <palak@palaks-mbp-2.lan>
  • Loading branch information
Palakp41 and Palak Bhojani authored Nov 11, 2020
1 parent b9fb345 commit 72d97c5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/flows/components/header/Submit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {notify} from 'src/shared/actions/notifications'

// Utils
import {event} from 'src/cloud/utils/reporting'
import {cancelAllRunningQueries} from 'src/timeMachine/actions/queries'

// Types
import {RemoteDataState} from 'src/types'
Expand Down Expand Up @@ -122,6 +123,7 @@ export const Submit: FC = () => {
onSubmit={submit}
onNotify={fakeNotify}
queryID=""
cancelAllRunningQueries={cancelAllRunningQueries}
/>
<SquareButton
active={active}
Expand Down
15 changes: 2 additions & 13 deletions src/timeMachine/actions/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ const cancelQuerysByHashIDs = (queryIDs?: string[]): void => {
})
}

export const cancelAllRunningQueries = (): void => {
export const cancelAllRunningQueries = () => dispatch => {
cancelQuerysByHashIDs(Object.keys(queryReference))
dispatch(setQueryResults(RemoteDataState.Done, null, null))
}

export const setQueryByHashID = (queryID: string, result: any): void => {
Expand All @@ -244,18 +245,6 @@ export const setQueryByHashID = (queryID: string, result: any): void => {
})
}

export const getQueryStatusByID = (queryID: string): any => {
if (queryID in queryReference) {
return queryReference[queryID]
}
return {
cancel: new AbortController(),
issuedAt: Date.now(),
promise: Promise.resolve(),
status: RemoteDataState.NotStarted,
}
}

export const executeQueries = (abortController?: AbortController) => async (
dispatch,
getState: GetState
Expand Down
10 changes: 3 additions & 7 deletions src/timeMachine/components/SubmitQueryButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {getActiveTimeMachine, getActiveQuery} from 'src/timeMachine/selectors'
import {event} from 'src/cloud/utils/reporting'
import {queryCancelRequest} from 'src/shared/copy/notifications'
import {
cancelQueryByHashID,
cancelAllRunningQueries,
generateHashedQueryID,
} from 'src/timeMachine/actions/queries'
Expand Down Expand Up @@ -78,7 +77,7 @@ class SubmitQueryButton extends PureComponent<Props> {
}

componentWillUnmount() {
cancelAllRunningQueries()
this.props.cancelAllRunningQueries()
}

public render() {
Expand Down Expand Up @@ -136,11 +135,7 @@ class SubmitQueryButton extends PureComponent<Props> {
if (this.props.onNotify) {
this.props.onNotify(queryCancelRequest())
}
if (this.props.queryID) {
cancelQueryByHashID(this.props.queryID)
} else {
cancelAllRunningQueries()
}
this.props.cancelAllRunningQueries()
}
}

Expand All @@ -162,6 +157,7 @@ const mstp = (state: AppState) => {
const mdtp = {
onSubmit: saveAndExecuteQueries,
onNotify: notify,
cancelAllRunningQueries: cancelAllRunningQueries,
}

const connector = connect(mstp, mdtp)
Expand Down

0 comments on commit 72d97c5

Please sign in to comment.