folder-selection
This commit is contained in:
@@ -346,8 +346,8 @@ const AppLayout = () => {
|
|||||||
const tagManager = tagManagerRef.current;
|
const tagManager = tagManagerRef.current;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
selectedRowKeys,
|
selectedEntries,
|
||||||
setSelectedRowKeys,
|
setSelectedEntries,
|
||||||
selectionOrder,
|
selectionOrder,
|
||||||
setSelectionOrder,
|
setSelectionOrder,
|
||||||
selectionOrderRef,
|
selectionOrderRef,
|
||||||
@@ -368,7 +368,7 @@ const AppLayout = () => {
|
|||||||
isDocumentRowKey,
|
isDocumentRowKey,
|
||||||
isFolderRowKey,
|
isFolderRowKey,
|
||||||
getRowId,
|
getRowId,
|
||||||
initialSelection: initialRowSelection,
|
initialEntries: initialRowSelection,
|
||||||
});
|
});
|
||||||
|
|
||||||
const getDocumentAsset = useCallback((doc, type) => {
|
const getDocumentAsset = useCallback((doc, type) => {
|
||||||
@@ -382,22 +382,22 @@ const AppLayout = () => {
|
|||||||
|
|
||||||
const selectedDocumentIds = useMemo(
|
const selectedDocumentIds = useMemo(
|
||||||
() =>
|
() =>
|
||||||
selectedRowKeys
|
selectedEntries
|
||||||
.filter(isDocumentRowKey)
|
.filter(isDocumentRowKey)
|
||||||
.map((key) => getRowId(key))
|
.map((key) => getRowId(key))
|
||||||
.filter(Boolean),
|
.filter(Boolean),
|
||||||
[selectedRowKeys],
|
[selectedEntries],
|
||||||
);
|
);
|
||||||
|
|
||||||
const selectionCount = selectedDocumentIds.length;
|
const selectionCount = selectedDocumentIds.length;
|
||||||
|
|
||||||
const selectedFolderIds = useMemo(
|
const selectedFolderIds = useMemo(
|
||||||
() =>
|
() =>
|
||||||
selectedRowKeys
|
selectedEntries
|
||||||
.filter(isFolderRowKey)
|
.filter(isFolderRowKey)
|
||||||
.map((key) => getRowId(key))
|
.map((key) => getRowId(key))
|
||||||
.filter(Boolean),
|
.filter(Boolean),
|
||||||
[selectedRowKeys],
|
[selectedEntries],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@@ -409,7 +409,7 @@ const AppLayout = () => {
|
|||||||
setCurrentFolder(null);
|
setCurrentFolder(null);
|
||||||
setCurrentSubfolders([]);
|
setCurrentSubfolders([]);
|
||||||
setDocuments([]);
|
setDocuments([]);
|
||||||
setSelectedRowKeys([]);
|
setSelectedEntries([]);
|
||||||
setSelectionOrder([]);
|
setSelectionOrder([]);
|
||||||
selectionOrderRef.current = [];
|
selectionOrderRef.current = [];
|
||||||
setFocusedDocumentId(null);
|
setFocusedDocumentId(null);
|
||||||
@@ -440,7 +440,7 @@ const AppLayout = () => {
|
|||||||
selectionInitializedRef,
|
selectionInitializedRef,
|
||||||
selectionOrderRef,
|
selectionOrderRef,
|
||||||
setFocusedDocumentId,
|
setFocusedDocumentId,
|
||||||
setSelectedRowKeys,
|
setSelectedEntries,
|
||||||
setSelectionOrder,
|
setSelectionOrder,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -594,7 +594,7 @@ const AppLayout = () => {
|
|||||||
let nextDocKeys = [];
|
let nextDocKeys = [];
|
||||||
let mergedSelection = [];
|
let mergedSelection = [];
|
||||||
|
|
||||||
setSelectedRowKeys((previous) => {
|
setSelectedEntries((previous) => {
|
||||||
const previousFolderKeys = previous
|
const previousFolderKeys = previous
|
||||||
.filter(isFolderRowKey)
|
.filter(isFolderRowKey)
|
||||||
.filter((key) => availableFolderKeys.has(key));
|
.filter((key) => availableFolderKeys.has(key));
|
||||||
@@ -638,7 +638,7 @@ const AppLayout = () => {
|
|||||||
selectionInitializedRef,
|
selectionInitializedRef,
|
||||||
selectionOrderRef,
|
selectionOrderRef,
|
||||||
setFocusedDocumentId,
|
setFocusedDocumentId,
|
||||||
setSelectedRowKeys,
|
setSelectedEntries,
|
||||||
setSelectionOrder,
|
setSelectionOrder,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -952,7 +952,7 @@ const AppLayout = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedKey = selectedRowKeys.find((key) => navigableRowKeys.includes(key));
|
const selectedKey = selectedEntries.find((key) => navigableRowKeys.includes(key));
|
||||||
if (selectedKey) {
|
if (selectedKey) {
|
||||||
setFocusedRowKey(selectedKey);
|
setFocusedRowKey(selectedKey);
|
||||||
return;
|
return;
|
||||||
@@ -965,7 +965,7 @@ const AppLayout = () => {
|
|||||||
focusedRowKey,
|
focusedRowKey,
|
||||||
focusedDocumentId,
|
focusedDocumentId,
|
||||||
navigableRowKeys,
|
navigableRowKeys,
|
||||||
selectedRowKeys,
|
selectedEntries,
|
||||||
setFocusedRowKey,
|
setFocusedRowKey,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -2446,7 +2446,7 @@ const AppLayout = () => {
|
|||||||
}
|
}
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const folderKey = resolveFolderRowKey(folderId);
|
const folderKey = resolveFolderRowKey(folderId);
|
||||||
const isAlreadySelected = folderKey ? selectedRowKeys.includes(folderKey) : false;
|
const isAlreadySelected = folderKey ? selectedEntries.includes(folderKey) : false;
|
||||||
|
|
||||||
let effectiveFolderSelection = selectedFolderIds;
|
let effectiveFolderSelection = selectedFolderIds;
|
||||||
let effectiveDocumentSelection = selectedDocumentIds;
|
let effectiveDocumentSelection = selectedDocumentIds;
|
||||||
@@ -2500,7 +2500,7 @@ const AppLayout = () => {
|
|||||||
event.currentTarget?.classList.add('dragging');
|
event.currentTarget?.classList.add('dragging');
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
selectedRowKeys,
|
selectedEntries,
|
||||||
selectedFolderIds,
|
selectedFolderIds,
|
||||||
selectedDocumentIds,
|
selectedDocumentIds,
|
||||||
setDraggedFolderId,
|
setDraggedFolderId,
|
||||||
@@ -2898,7 +2898,7 @@ const AppLayout = () => {
|
|||||||
return changed ? next : prev;
|
return changed ? next : prev;
|
||||||
});
|
});
|
||||||
|
|
||||||
setSelectedRowKeys((prev) => pruneRowCollection(prev));
|
setSelectedEntries((prev) => pruneRowCollection(prev));
|
||||||
setSelectionOrder((prev) => pruneRowCollection(prev));
|
setSelectionOrder((prev) => pruneRowCollection(prev));
|
||||||
selectionOrderRef.current = pruneRowCollection(selectionOrderRef.current);
|
selectionOrderRef.current = pruneRowCollection(selectionOrderRef.current);
|
||||||
if (
|
if (
|
||||||
@@ -2944,7 +2944,7 @@ const AppLayout = () => {
|
|||||||
focusedRowKey,
|
focusedRowKey,
|
||||||
setFocusedRowKey,
|
setFocusedRowKey,
|
||||||
setSelectionOrder,
|
setSelectionOrder,
|
||||||
setSelectedRowKeys,
|
setSelectedEntries,
|
||||||
setStatusMessage,
|
setStatusMessage,
|
||||||
selectionAnchorRef,
|
selectionAnchorRef,
|
||||||
selectionOrderRef,
|
selectionOrderRef,
|
||||||
@@ -3056,8 +3056,8 @@ const AppLayout = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let resolvedKey = null;
|
let resolvedKey = null;
|
||||||
for (let index = selectedRowKeys.length - 1; index >= 0; index -= 1) {
|
for (let index = selectedEntries.length - 1; index >= 0; index -= 1) {
|
||||||
const candidate = selectedRowKeys[index];
|
const candidate = selectedEntries[index];
|
||||||
if (navigableRowKeys.includes(candidate)) {
|
if (navigableRowKeys.includes(candidate)) {
|
||||||
resolvedKey = candidate;
|
resolvedKey = candidate;
|
||||||
break;
|
break;
|
||||||
@@ -3072,19 +3072,19 @@ const AppLayout = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedRowKeys.length === 0) {
|
if (selectedEntries.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setFocusedRowKey(resolvedKey);
|
setFocusedRowKey(resolvedKey);
|
||||||
|
|
||||||
if (!selectedRowKeys.includes(resolvedKey) && selectedRowKeys.length > 0) {
|
if (!selectedEntries.includes(resolvedKey) && selectedEntries.length > 0) {
|
||||||
applySelection([resolvedKey], { anchor: resolvedKey, interactedKeys: [resolvedKey] });
|
applySelection([resolvedKey], { anchor: resolvedKey, interactedKeys: [resolvedKey] });
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
focusedRowKey,
|
focusedRowKey,
|
||||||
navigableRowKeys,
|
navigableRowKeys,
|
||||||
selectedRowKeys,
|
selectedEntries,
|
||||||
navigableRows,
|
navigableRows,
|
||||||
applySelection,
|
applySelection,
|
||||||
setFocusedRowKey,
|
setFocusedRowKey,
|
||||||
@@ -3110,8 +3110,8 @@ const AppLayout = () => {
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
if (!activeKey) {
|
if (!activeKey) {
|
||||||
for (let index = selectedRowKeys.length - 1; index >= 0; index -= 1) {
|
for (let index = selectedEntries.length - 1; index >= 0; index -= 1) {
|
||||||
const candidate = selectedRowKeys[index];
|
const candidate = selectedEntries[index];
|
||||||
if (navigableRowKeys.includes(candidate)) {
|
if (navigableRowKeys.includes(candidate)) {
|
||||||
activeKey = candidate;
|
activeKey = candidate;
|
||||||
break;
|
break;
|
||||||
@@ -3183,7 +3183,7 @@ const AppLayout = () => {
|
|||||||
navigableRows,
|
navigableRows,
|
||||||
navigableRowKeys,
|
navigableRowKeys,
|
||||||
focusedRowKey,
|
focusedRowKey,
|
||||||
selectedRowKeys,
|
selectedEntries,
|
||||||
handleRowSelection,
|
handleRowSelection,
|
||||||
selectFolder,
|
selectFolder,
|
||||||
openDocumentPreview,
|
openDocumentPreview,
|
||||||
@@ -3716,7 +3716,7 @@ const AppLayout = () => {
|
|||||||
|
|
||||||
if (!results.length) {
|
if (!results.length) {
|
||||||
setSearchLoading(false);
|
setSearchLoading(false);
|
||||||
setSelectedRowKeys([]);
|
setSelectedEntries([]);
|
||||||
setFocusedDocumentId(null);
|
setFocusedDocumentId(null);
|
||||||
selectionOrderRef.current = [];
|
selectionOrderRef.current = [];
|
||||||
setSelectionOrder([]);
|
setSelectionOrder([]);
|
||||||
@@ -3731,7 +3731,7 @@ const AppLayout = () => {
|
|||||||
let targetKey = null;
|
let targetKey = null;
|
||||||
let nextSelectionKeys = [];
|
let nextSelectionKeys = [];
|
||||||
|
|
||||||
setSelectedRowKeys((previous) => {
|
setSelectedEntries((previous) => {
|
||||||
const previousDocKeys = previous.filter(isDocumentRowKey);
|
const previousDocKeys = previous.filter(isDocumentRowKey);
|
||||||
const filtered = previousDocKeys.filter((key) => resultKeys.includes(key));
|
const filtered = previousDocKeys.filter((key) => resultKeys.includes(key));
|
||||||
if (filtered.length) {
|
if (filtered.length) {
|
||||||
@@ -3788,7 +3788,7 @@ const AppLayout = () => {
|
|||||||
assetManager,
|
assetManager,
|
||||||
selectionOrderRef,
|
selectionOrderRef,
|
||||||
selectionAnchorRef,
|
selectionAnchorRef,
|
||||||
setSelectedRowKeys,
|
setSelectedEntries,
|
||||||
setSelectionOrder,
|
setSelectionOrder,
|
||||||
setFocusedDocumentId,
|
setFocusedDocumentId,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useCallback, useRef, useState } from 'react';
|
import { useCallback, useRef, useState } from 'react';
|
||||||
|
|
||||||
const DEFAULT_INITIAL_SELECTION = [];
|
const DEFAULT_INITIAL_ENTRIES = [];
|
||||||
|
|
||||||
export const useDocumentSelection = ({
|
export const useDocumentSelection = ({
|
||||||
resolveDocumentRowKey,
|
resolveDocumentRowKey,
|
||||||
@@ -8,11 +8,11 @@ export const useDocumentSelection = ({
|
|||||||
isDocumentRowKey,
|
isDocumentRowKey,
|
||||||
isFolderRowKey,
|
isFolderRowKey,
|
||||||
getRowId,
|
getRowId,
|
||||||
initialSelection = DEFAULT_INITIAL_SELECTION,
|
initialEntries = DEFAULT_INITIAL_ENTRIES,
|
||||||
}) => {
|
}) => {
|
||||||
const [selectedRowKeys, setSelectedRowKeys] = useState(initialSelection);
|
const [selectedEntries, setSelectedEntries] = useState(initialEntries);
|
||||||
const [selectionOrder, setSelectionOrder] = useState(initialSelection);
|
const [selectionOrder, setSelectionOrder] = useState(initialEntries);
|
||||||
const selectionOrderRef = useRef(initialSelection);
|
const selectionOrderRef = useRef(initialEntries);
|
||||||
const selectionAnchorRef = useRef(null);
|
const selectionAnchorRef = useRef(null);
|
||||||
const selectionInitializedRef = useRef(false);
|
const selectionInitializedRef = useRef(false);
|
||||||
const [focusedDocumentId, setFocusedDocumentId] = useState(null);
|
const [focusedDocumentId, setFocusedDocumentId] = useState(null);
|
||||||
@@ -96,7 +96,7 @@ export const useDocumentSelection = ({
|
|||||||
resolvedAnchor = null;
|
resolvedAnchor = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
setSelectedRowKeys(unique);
|
setSelectedEntries(unique);
|
||||||
updateSelectionOrder(unique, interactedKeys);
|
updateSelectionOrder(unique, interactedKeys);
|
||||||
|
|
||||||
const nextFocusedDocumentId = (() => {
|
const nextFocusedDocumentId = (() => {
|
||||||
@@ -163,8 +163,8 @@ export const useDocumentSelection = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
let anchorKey = selectionAnchorRef.current;
|
let anchorKey = selectionAnchorRef.current;
|
||||||
if (!anchorKey && shiftKey && selectedRowKeys.length) {
|
if (!anchorKey && shiftKey && selectedEntries.length) {
|
||||||
anchorKey = selectedRowKeys[selectedRowKeys.length - 1];
|
anchorKey = selectedEntries[selectedEntries.length - 1];
|
||||||
}
|
}
|
||||||
if (!anchorKey) {
|
if (!anchorKey) {
|
||||||
anchorKey = rowKey;
|
anchorKey = rowKey;
|
||||||
@@ -183,7 +183,7 @@ export const useDocumentSelection = ({
|
|||||||
const range = navigableRowKeys.slice(start, end + 1);
|
const range = navigableRowKeys.slice(start, end + 1);
|
||||||
nextKeys = range;
|
nextKeys = range;
|
||||||
|
|
||||||
const previousSet = new Set(selectedRowKeys);
|
const previousSet = new Set(selectedEntries);
|
||||||
interactedKeys = range.filter((key) => key === rowKey || !previousSet.has(key));
|
interactedKeys = range.filter((key) => key === rowKey || !previousSet.has(key));
|
||||||
if (!interactedKeys.includes(rowKey)) {
|
if (!interactedKeys.includes(rowKey)) {
|
||||||
interactedKeys.push(rowKey);
|
interactedKeys.push(rowKey);
|
||||||
@@ -193,11 +193,11 @@ export const useDocumentSelection = ({
|
|||||||
interactedKeys = [rowKey];
|
interactedKeys = [rowKey];
|
||||||
}
|
}
|
||||||
} else if (additive) {
|
} else if (additive) {
|
||||||
if (selectedRowKeys.includes(rowKey)) {
|
if (selectedEntries.includes(rowKey)) {
|
||||||
nextKeys = selectedRowKeys.filter((key) => key !== rowKey);
|
nextKeys = selectedEntries.filter((key) => key !== rowKey);
|
||||||
interactedKeys = [];
|
interactedKeys = [];
|
||||||
} else {
|
} else {
|
||||||
nextKeys = [...selectedRowKeys, rowKey];
|
nextKeys = [...selectedEntries, rowKey];
|
||||||
interactedKeys = [rowKey];
|
interactedKeys = [rowKey];
|
||||||
}
|
}
|
||||||
anchorKey = rowKey;
|
anchorKey = rowKey;
|
||||||
@@ -209,7 +209,7 @@ export const useDocumentSelection = ({
|
|||||||
|
|
||||||
applySelection(nextKeys, { anchor: anchorKey, interactedKeys });
|
applySelection(nextKeys, { anchor: anchorKey, interactedKeys });
|
||||||
},
|
},
|
||||||
[applySelection, selectedRowKeys],
|
[applySelection, selectedEntries],
|
||||||
);
|
);
|
||||||
|
|
||||||
const promoteSelectionOrder = useCallback(
|
const promoteSelectionOrder = useCallback(
|
||||||
@@ -218,18 +218,18 @@ export const useDocumentSelection = ({
|
|||||||
const rowKey = resolveDocumentRowKey(docId);
|
const rowKey = resolveDocumentRowKey(docId);
|
||||||
if (!rowKey) return;
|
if (!rowKey) return;
|
||||||
|
|
||||||
if (!selectedRowKeys.includes(rowKey)) {
|
if (!selectedEntries.includes(rowKey)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSelectionOrder(selectedRowKeys, [rowKey]);
|
updateSelectionOrder(selectedEntries, [rowKey]);
|
||||||
},
|
},
|
||||||
[resolveDocumentRowKey, selectedRowKeys, updateSelectionOrder],
|
[resolveDocumentRowKey, selectedEntries, updateSelectionOrder],
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
selectedRowKeys,
|
selectedEntries,
|
||||||
setSelectedRowKeys,
|
setSelectedEntries,
|
||||||
selectionOrder,
|
selectionOrder,
|
||||||
setSelectionOrder,
|
setSelectionOrder,
|
||||||
selectionOrderRef,
|
selectionOrderRef,
|
||||||
|
|||||||
@@ -2078,7 +2078,8 @@ button.danger:hover:not([disabled]) {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.documents-panel tbody tr.document.selected {
|
.documents-panel tbody tr.document.selected,
|
||||||
|
.documents-panel tbody tr.folder.selected {
|
||||||
background: var(--selection-soft);
|
background: var(--selection-soft);
|
||||||
box-shadow: inset 2px 0 0 var(--accent-outline-strong);
|
box-shadow: inset 2px 0 0 var(--accent-outline-strong);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user