@@ -48,9 +48,7 @@ import {
48
48
AddDataSourceReloadError ,
49
49
setFileView ,
50
50
setColumns ,
51
- COLLAPSE_ALL_FILE_FOLDERS ,
52
51
EXPAND_ALL_FILE_FOLDERS ,
53
- setIsLoadingFullTree ,
54
52
} from "./actions" ;
55
53
import { interaction , metadata , ReduxLogicDeps , selection } from "../" ;
56
54
import * as selectionSelectors from "./selectors" ;
@@ -349,19 +347,23 @@ const toggleFileFolderCollapse = createLogic({
349
347
* actions into SET_OPEN_FILE_FOLDERS actions by either setting to none or recursively
350
348
* unpacking the directory structure
351
349
*/
352
- const toggleAllFileFolders = createLogic ( {
350
+ const expandAllFileFolders = createLogic ( {
353
351
async process ( deps : ReduxLogicDeps , dispatch , done ) {
354
- const { action , getState } = deps ;
352
+ const { getState } = deps ;
355
353
const hierarchy = selection . selectors . getAnnotationHierarchy ( getState ( ) ) ;
356
354
const annotationService = interaction . selectors . getAnnotationService ( getState ( ) ) ;
357
355
const selectedFileFilters = selection . selectors . getFileFilters ( getState ( ) ) ;
358
- const fileFoldersToOpen : FileFolder [ ] = [ ] ;
359
- dispatch ( setIsLoadingFullTree ( true ) as AnyAction ) ;
356
+ // Track internally rather than relying on selector (may be out of sync)
357
+ const openedSoFar : FileFolder [ ] = [ ] ;
360
358
// Recursive helper
361
359
async function unpackAllFileFolders ( values : string [ ] , pathSoFar : string [ ] ) {
360
+ const fileFoldersToOpen : FileFolder [ ] = values . map (
361
+ ( value ) => new FileFolder ( [ ...pathSoFar , value ] as AnnotationValue [ ] )
362
+ ) ;
363
+ // Needs to be set wholesale so must include already opened folderes
364
+ openedSoFar . push ( ...fileFoldersToOpen ) ;
365
+ dispatch ( setOpenFileFolders ( openedSoFar ) ) ;
362
366
for ( const value of values ) {
363
- fileFoldersToOpen . push ( new FileFolder ( [ ...pathSoFar , value ] as AnnotationValue [ ] ) ) ;
364
-
365
367
// At end of folder hierarchy
366
368
if ( ! ! hierarchy . length && pathSoFar . length === hierarchy . length - 1 ) continue ;
367
369
@@ -377,18 +379,15 @@ const toggleAllFileFolders = createLogic({
377
379
}
378
380
}
379
381
380
- if ( action . type === EXPAND_ALL_FILE_FOLDERS ) {
381
- const rootHierarchyValues = await annotationService . fetchRootHierarchyValues (
382
- hierarchy ,
383
- selectedFileFilters
384
- ) ;
385
- await unpackAllFileFolders ( rootHierarchyValues , [ ] ) ;
386
- }
387
- dispatch ( setOpenFileFolders ( fileFoldersToOpen ) ) ;
388
- dispatch ( setIsLoadingFullTree ( false ) as AnyAction ) ;
382
+ const rootHierarchyValues = await annotationService . fetchRootHierarchyValues (
383
+ hierarchy ,
384
+ selectedFileFilters
385
+ ) ;
386
+ await unpackAllFileFolders ( rootHierarchyValues , [ ] ) ;
387
+ dispatch ( interaction . actions . refresh ( ) as AnyAction ) ; // synchronize UI with state
389
388
done ( ) ;
390
389
} ,
391
- type : [ COLLAPSE_ALL_FILE_FOLDERS , EXPAND_ALL_FILE_FOLDERS ] ,
390
+ type : [ EXPAND_ALL_FILE_FOLDERS ] ,
392
391
} ) ;
393
392
394
393
/**
@@ -805,7 +804,7 @@ export default [
805
804
modifyAnnotationHierarchy ,
806
805
modifyFileFilters ,
807
806
toggleFileFolderCollapse ,
808
- toggleAllFileFolders ,
807
+ expandAllFileFolders ,
809
808
decodeFileExplorerURLLogics ,
810
809
selectNearbyFile ,
811
810
setAvailableAnnotationsLogic ,
0 commit comments