File tree Expand file tree Collapse file tree 2 files changed +56
-10
lines changed
superset-frontend/src/SqlLab/reducers Expand file tree Collapse file tree 2 files changed +56
-10
lines changed Original file line number Diff line number Diff line change @@ -667,16 +667,27 @@ export default function sqlLabReducer(state = {}, action) {
667667 [ actions . CLEAR_INACTIVE_QUERIES ] ( ) {
668668 const { queries } = state ;
669669 const cleanedQueries = Object . fromEntries (
670- Object . entries ( queries ) . filter ( ( [ , query ] ) => {
671- if (
672- [ 'running' , 'pending' ] . includes ( query . state ) &&
673- Date . now ( ) - query . startDttm > action . interval &&
674- query . progress === 0
675- ) {
676- return false ;
677- }
678- return true ;
679- } ) ,
670+ Object . entries ( queries )
671+ . filter ( ( [ , query ] ) => {
672+ if (
673+ [ 'running' , 'pending' ] . includes ( query . state ) &&
674+ Date . now ( ) - query . startDttm > action . interval &&
675+ query . progress === 0
676+ ) {
677+ return false ;
678+ }
679+ return true ;
680+ } )
681+ . map ( ( [ id , query ] ) => [
682+ id ,
683+ {
684+ ...query ,
685+ state :
686+ query . resultsKey && query . results ?. status
687+ ? query . results . status
688+ : query . state ,
689+ } ,
690+ ] ) ,
680691 ) ;
681692 return { ...state , queries : cleanedQueries } ;
682693 } ,
Original file line number Diff line number Diff line change 1616 * specific language governing permissions and limitations
1717 * under the License.
1818 */
19+ import { QueryState } from '@superset-ui/core' ;
1920import sqlLabReducer from 'src/SqlLab/reducers/sqlLab' ;
2021import * as actions from 'src/SqlLab/actions/sqlLab' ;
2122import { table , initialState as mockState } from '../fixtures' ;
@@ -388,4 +389,38 @@ describe('sqlLabReducer', () => {
388389 newState = sqlLabReducer ( newState , actions . refreshQueries ( { } ) ) ;
389390 } ) ;
390391 } ) ;
392+ describe ( 'CLEAR_INACTIVE_QUERIES' , ( ) => {
393+ let newState ;
394+ let query ;
395+ beforeEach ( ( ) => {
396+ query = {
397+ id : 'abcd' ,
398+ changed_on : Date . now ( ) ,
399+ startDttm : Date . now ( ) ,
400+ state : QueryState . FETCHING ,
401+ progress : 100 ,
402+ resultsKey : 'fa3dccc4-c549-4fbf-93c8-b4fb5a6fb8b7' ,
403+ cached : false ,
404+ } ;
405+ } ) ;
406+ it ( 'updates queries that have already been completed' , ( ) => {
407+ newState = sqlLabReducer (
408+ {
409+ ...newState ,
410+ queries : {
411+ abcd : {
412+ ...query ,
413+ results : {
414+ query_id : 1234 ,
415+ status : QueryState . SUCCESS ,
416+ data : [ ] ,
417+ } ,
418+ } ,
419+ } ,
420+ } ,
421+ actions . clearInactiveQueries ( Date . now ( ) ) ,
422+ ) ;
423+ expect ( newState . queries . abcd . state ) . toBe ( QueryState . SUCCESS ) ;
424+ } ) ;
425+ } ) ;
391426} ) ;
You can’t perform that action at this time.
0 commit comments