selection fix
This commit is contained in:
@@ -59,6 +59,34 @@ const DocumentsPanel = ({
|
|||||||
const showingSearchResults = searchResults !== null;
|
const showingSearchResults = searchResults !== null;
|
||||||
const rows = showingSearchResults ? searchResults : documents;
|
const rows = showingSearchResults ? searchResults : documents;
|
||||||
|
|
||||||
|
const currentFolderId = useMemo(() => {
|
||||||
|
if (showingSearchResults) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const trail = Array.isArray(breadcrumbs) ? breadcrumbs : [];
|
||||||
|
if (trail.length === 0) {
|
||||||
|
return 'root';
|
||||||
|
}
|
||||||
|
return trail[trail.length - 1]?.id || 'root';
|
||||||
|
}, [breadcrumbs, showingSearchResults]);
|
||||||
|
|
||||||
|
const selectionContextRef = useRef(null);
|
||||||
|
useEffect(() => {
|
||||||
|
const nextContext = showingSearchResults
|
||||||
|
? { type: 'search', marker: searchResults }
|
||||||
|
: { type: 'folder', marker: currentFolderId || 'root' };
|
||||||
|
const previous = selectionContextRef.current;
|
||||||
|
selectionContextRef.current = nextContext;
|
||||||
|
if (!previous) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const changed = previous.type !== nextContext.type
|
||||||
|
|| previous.marker !== nextContext.marker;
|
||||||
|
if (changed) {
|
||||||
|
onClearSelection?.();
|
||||||
|
}
|
||||||
|
}, [showingSearchResults, currentFolderId, searchResults, onClearSelection]);
|
||||||
|
|
||||||
const entries = useMemo(() => {
|
const entries = useMemo(() => {
|
||||||
const list = [];
|
const list = [];
|
||||||
if (!showingSearchResults) {
|
if (!showingSearchResults) {
|
||||||
|
|||||||
@@ -796,7 +796,6 @@ const useDocumentsWorkspace = ({
|
|||||||
setDraggedFolderId,
|
setDraggedFolderId,
|
||||||
isInvalidFolderDrop,
|
isInvalidFolderDrop,
|
||||||
setCreatingFolder,
|
setCreatingFolder,
|
||||||
clearSelection,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useMemo, useRef, useState } from 'react';
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
DEFAULT_FOLDER_NAME,
|
DEFAULT_FOLDER_NAME,
|
||||||
createRootNode,
|
createRootNode,
|
||||||
@@ -30,8 +30,6 @@ const useFolderTree = ({
|
|||||||
const [currentFolder, setCurrentFolder] = useState(null);
|
const [currentFolder, setCurrentFolder] = useState(null);
|
||||||
const [currentSubfolders, setCurrentSubfolders] = useState([]);
|
const [currentSubfolders, setCurrentSubfolders] = useState([]);
|
||||||
|
|
||||||
const lastAppliedFolderIdRef = useRef(null);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
focusedDocumentId,
|
focusedDocumentId,
|
||||||
setFocusedDocumentId,
|
setFocusedDocumentId,
|
||||||
@@ -43,9 +41,6 @@ const useFolderTree = ({
|
|||||||
|
|
||||||
const applySelectedFolder = useCallback(
|
const applySelectedFolder = useCallback(
|
||||||
(folderId, contents) => {
|
(folderId, contents) => {
|
||||||
const folderChanged = lastAppliedFolderIdRef.current !== folderId;
|
|
||||||
lastAppliedFolderIdRef.current = folderId;
|
|
||||||
|
|
||||||
const subfolders = contents?.subfolders ?? [];
|
const subfolders = contents?.subfolders ?? [];
|
||||||
const docs = assetManager.hydrateDocuments(contents?.documents ?? []);
|
const docs = assetManager.hydrateDocuments(contents?.documents ?? []);
|
||||||
const folderInfo = contents?.folder ?? null;
|
const folderInfo = contents?.folder ?? null;
|
||||||
@@ -68,11 +63,6 @@ const useFolderTree = ({
|
|||||||
let mergedSelection = [];
|
let mergedSelection = [];
|
||||||
|
|
||||||
setSelectedEntries((previous) => {
|
setSelectedEntries((previous) => {
|
||||||
if (folderChanged) {
|
|
||||||
nextDocKeys = [];
|
|
||||||
mergedSelection = [];
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
const previousFolderKeys = previous
|
const previousFolderKeys = previous
|
||||||
.filter(isFolderRowKey)
|
.filter(isFolderRowKey)
|
||||||
.filter((key) => availableFolderKeys.has(key));
|
.filter((key) => availableFolderKeys.has(key));
|
||||||
@@ -82,14 +72,6 @@ const useFolderTree = ({
|
|||||||
return mergedSelection;
|
return mergedSelection;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (folderChanged) {
|
|
||||||
setFocusedDocumentId(null);
|
|
||||||
selectionAnchorRef.current = null;
|
|
||||||
selectionOrderRef.current = [];
|
|
||||||
setSelectionOrder([]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const nextFocus = (() => {
|
const nextFocus = (() => {
|
||||||
const currentFocusedKey = resolveDocumentRowKey(focusedDocumentId);
|
const currentFocusedKey = resolveDocumentRowKey(focusedDocumentId);
|
||||||
if (currentFocusedKey && availableDocKeySet.has(currentFocusedKey)) {
|
if (currentFocusedKey && availableDocKeySet.has(currentFocusedKey)) {
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ const useFolderTreeActions = ({
|
|||||||
setDraggedFolderId,
|
setDraggedFolderId,
|
||||||
isInvalidFolderDrop,
|
isInvalidFolderDrop,
|
||||||
setCreatingFolder,
|
setCreatingFolder,
|
||||||
clearSelection,
|
|
||||||
}) => {
|
}) => {
|
||||||
const moveFolder = useCallback(
|
const moveFolder = useCallback(
|
||||||
async (folderId, targetFolderId) => {
|
async (folderId, targetFolderId) => {
|
||||||
@@ -174,10 +173,6 @@ const useFolderTreeActions = ({
|
|||||||
async (folderId, { replace = false, immediate = false } = {}) => {
|
async (folderId, { replace = false, immediate = false } = {}) => {
|
||||||
const targetId = folderId && folderId !== 'root' ? folderId : 'root';
|
const targetId = folderId && folderId !== 'root' ? folderId : 'root';
|
||||||
|
|
||||||
if (typeof clearSelection === 'function') {
|
|
||||||
clearSelection();
|
|
||||||
}
|
|
||||||
|
|
||||||
await ensureFolderAncestorsLoaded(targetId);
|
await ensureFolderAncestorsLoaded(targetId);
|
||||||
expandFolderAncestors(targetId);
|
expandFolderAncestors(targetId);
|
||||||
|
|
||||||
@@ -191,7 +186,6 @@ const useFolderTreeActions = ({
|
|||||||
navigate(path, { replace });
|
navigate(path, { replace });
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
clearSelection,
|
|
||||||
ensureFolderAncestorsLoaded,
|
ensureFolderAncestorsLoaded,
|
||||||
expandFolderAncestors,
|
expandFolderAncestors,
|
||||||
isFilterActive,
|
isFilterActive,
|
||||||
|
|||||||
Reference in New Issue
Block a user