Skip to content

Commit c16c1ae

Browse files
committed
expand folders during recursion
1 parent 825544d commit c16c1ae

File tree

6 files changed

+22
-75
lines changed

6 files changed

+22
-75
lines changed

packages/core/components/DirectoryTree/index.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ export default function DirectoryTree(props: FileListProps) {
4040
const fileService = useSelector(interaction.selectors.getFileService);
4141
const globalFilters = useSelector(selection.selectors.getFileFilters);
4242
const sortColumn = useSelector(selection.selectors.getSortColumn);
43-
// Check loading in full app state instead of individual node state
44-
const isLoadingFullTree = useSelector(selection.selectors.getIsLoadingFullTree);
4543
const fileSet = React.useMemo(() => {
4644
return new FileSet({
4745
fileService: fileService,
@@ -76,7 +74,7 @@ export default function DirectoryTree(props: FileListProps) {
7674

7775
return (
7876
<div className={classNames(props.className, styles.container)}>
79-
<RootLoadingIndicator visible={isLoading || isLoadingFullTree} />
77+
<RootLoadingIndicator visible={isLoading} />
8078
<ul
8179
className={styles.scrollContainer}
8280
role="tree"

packages/core/state/selection/actions.ts

-19
Original file line numberDiff line numberDiff line change
@@ -550,25 +550,6 @@ export function expandAllFileFolders(): ExpandAllFileFoldersAction {
550550
};
551551
}
552552

553-
/**
554-
* SET_IS_LOADING_FULL_TREE
555-
* Intention to set the loading state for all directories in the tree.
556-
* Differentiated from isLoading in directory hierarchy node sub-states
557-
*/
558-
export const SET_IS_LOADING_FULL_TREE = makeConstant(STATE_BRANCH_NAME, "set-is-loading-full-tree");
559-
560-
export interface SetIsLoadingFullTreeAction {
561-
payload: boolean;
562-
type: string;
563-
}
564-
565-
export function setIsLoadingFullTree(isLoadingFullTree: boolean): SetIsLoadingFullTreeAction {
566-
return {
567-
payload: isLoadingFullTree,
568-
type: SET_IS_LOADING_FULL_TREE,
569-
};
570-
}
571-
572553
/**
573554
* SET_OPEN_FILE_FOLDERS
574555
* Intention to set which file folders are open as opposed to collapsed

packages/core/state/selection/logics.ts

+18-19
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ import {
4848
AddDataSourceReloadError,
4949
setFileView,
5050
setColumns,
51-
COLLAPSE_ALL_FILE_FOLDERS,
5251
EXPAND_ALL_FILE_FOLDERS,
53-
setIsLoadingFullTree,
5452
} from "./actions";
5553
import { interaction, metadata, ReduxLogicDeps, selection } from "../";
5654
import * as selectionSelectors from "./selectors";
@@ -349,19 +347,23 @@ const toggleFileFolderCollapse = createLogic({
349347
* actions into SET_OPEN_FILE_FOLDERS actions by either setting to none or recursively
350348
* unpacking the directory structure
351349
*/
352-
const toggleAllFileFolders = createLogic({
350+
const expandAllFileFolders = createLogic({
353351
async process(deps: ReduxLogicDeps, dispatch, done) {
354-
const { action, getState } = deps;
352+
const { getState } = deps;
355353
const hierarchy = selection.selectors.getAnnotationHierarchy(getState());
356354
const annotationService = interaction.selectors.getAnnotationService(getState());
357355
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[] = [];
360358
// Recursive helper
361359
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));
362366
for (const value of values) {
363-
fileFoldersToOpen.push(new FileFolder([...pathSoFar, value] as AnnotationValue[]));
364-
365367
// At end of folder hierarchy
366368
if (!!hierarchy.length && pathSoFar.length === hierarchy.length - 1) continue;
367369

@@ -377,18 +379,15 @@ const toggleAllFileFolders = createLogic({
377379
}
378380
}
379381

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
389388
done();
390389
},
391-
type: [COLLAPSE_ALL_FILE_FOLDERS, EXPAND_ALL_FILE_FOLDERS],
390+
type: [EXPAND_ALL_FILE_FOLDERS],
392391
});
393392

394393
/**
@@ -805,7 +804,7 @@ export default [
805804
modifyAnnotationHierarchy,
806805
modifyFileFilters,
807806
toggleFileFolderCollapse,
808-
toggleAllFileFolders,
807+
expandAllFileFolders,
809808
decodeFileExplorerURLLogics,
810809
selectNearbyFile,
811810
setAvailableAnnotationsLogic,

packages/core/state/selection/reducer.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
Column,
3434
SetColumns,
3535
SET_COLUMNS,
36-
SET_IS_LOADING_FULL_TREE,
36+
COLLAPSE_ALL_FILE_FOLDERS,
3737
} from "./actions";
3838
import interaction from "../interaction";
3939
import { FileView, Source } from "../../entity/FileExplorerURL";
@@ -52,7 +52,6 @@ export interface SelectionStateBranch {
5252
fileSelection: FileSelection;
5353
fileView: FileView;
5454
filters: FileFilter[];
55-
isLoadingFullTree: boolean;
5655
openFileFolders: FileFolder[];
5756
recentAnnotations: string[];
5857
requiresDataSourceReload?: boolean;
@@ -73,7 +72,6 @@ export const initialState = {
7372
fileSelection: new FileSelection(),
7473
fileView: FileView.LIST,
7574
filters: [],
76-
isLoadingFullTree: false,
7775
openFileFolders: [],
7876
queries: [],
7977
recentAnnotations: [],
@@ -197,9 +195,9 @@ export default makeReducer<SelectionStateBranch>(
197195
availableAnnotationsForHierarchy: action.payload,
198196
availableAnnotationsForHierarchyLoading: false,
199197
}),
200-
[SET_IS_LOADING_FULL_TREE]: (state, action) => ({
198+
[COLLAPSE_ALL_FILE_FOLDERS]: (state) => ({
201199
...state,
202-
isLoadingFullTree: action.payload,
200+
openFileFolders: [],
203201
}),
204202
[SET_OPEN_FILE_FOLDERS]: (state, action) => ({
205203
...state,

packages/core/state/selection/selectors.ts

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export const getColumns = (state: State) => state.selection.columns;
1818
export const getFileFilters = (state: State) => state.selection.filters;
1919
export const getFileSelection = (state: State) => state.selection.fileSelection;
2020
export const getFileView = (state: State) => state.selection.fileView;
21-
export const getIsLoadingFullTree = (state: State) => state.selection.isLoadingFullTree;
2221
export const getOpenFileFolders = (state: State) => state.selection.openFileFolders;
2322
export const getRecentAnnotations = (state: State) => state.selection.recentAnnotations;
2423
export const getRequiresDataSourceReload = (state: State) =>

packages/core/state/selection/test/logics.test.ts

-28
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
SET_SORT_COLUMN,
2626
changeDataSources,
2727
changeSourceMetadata,
28-
collapseAllFileFolders,
2928
expandAllFileFolders,
3029
} from "../actions";
3130
import { initialState, interaction } from "../../";
@@ -944,33 +943,6 @@ describe("Selection logics", () => {
944943
sinon.restore();
945944
});
946945

947-
it("dispatches empty array for collapse all folders actions", async () => {
948-
// Arrange
949-
const { store, logicMiddleware, actions } = configureMockStore({
950-
logics: selectionLogics,
951-
state: initialState,
952-
});
953-
// not evergreen
954-
expect(
955-
actions.includesMatch({
956-
type: SET_OPEN_FILE_FOLDERS,
957-
payload: [],
958-
})
959-
).to.be.false;
960-
961-
// Act
962-
store.dispatch(collapseAllFileFolders());
963-
await logicMiddleware.whenComplete();
964-
965-
// Assert
966-
expect(
967-
actions.includesMatch({
968-
type: SET_OPEN_FILE_FOLDERS,
969-
payload: [],
970-
})
971-
).to.be.true;
972-
});
973-
974946
it("dispatches all array combinations for expand all folders actions", async () => {
975947
// Arrange
976948
const state = mergeState(initialState, {

0 commit comments

Comments
 (0)