cleanup
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
|
||||
const useDeskWorkspaceProps = ({
|
||||
documents,
|
||||
@@ -9,16 +9,10 @@ const useDeskWorkspaceProps = ({
|
||||
handleDocumentsViewModeChange,
|
||||
handleDeskExit,
|
||||
refreshCurrentFolder,
|
||||
handleDeskDocumentOpen,
|
||||
inspectDocument,
|
||||
handleEntryPointerCore,
|
||||
handleDeskDocumentStackSelect,
|
||||
promoteSelectionOrder,
|
||||
handleDeskHelpOpen,
|
||||
deskHelpOpen,
|
||||
handleDeskHelpClose,
|
||||
currentTenantId,
|
||||
deskViewId,
|
||||
selectedDocumentIds,
|
||||
selectedFolderIds,
|
||||
clearDocumentSelection,
|
||||
@@ -44,8 +38,102 @@ const useDeskWorkspaceProps = ({
|
||||
moveDocumentsToFolder,
|
||||
searchIncludeDescendants,
|
||||
toggleSearchIncludeDescendants,
|
||||
}) =>
|
||||
useMemo(
|
||||
selectedEntries,
|
||||
selectionAnchorRef,
|
||||
applySelection,
|
||||
resolveDocumentRowKey,
|
||||
showingSearchResults,
|
||||
searchQuery,
|
||||
activeCorrespondentFilters,
|
||||
selectedFolder,
|
||||
setDeskHelpOpen,
|
||||
deskHelpOpen,
|
||||
openDetailPanel,
|
||||
}) => {
|
||||
const handleDeskDocumentStackSelect = useCallback(
|
||||
(docIds) => {
|
||||
if (!Array.isArray(docIds) || docIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const rowKeys = docIds
|
||||
.map((id) => resolveDocumentRowKey(id))
|
||||
.filter(Boolean);
|
||||
|
||||
if (!rowKeys.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const nextKeys = [...selectedEntries];
|
||||
rowKeys.forEach((key) => {
|
||||
if (!nextKeys.includes(key)) {
|
||||
nextKeys.push(key);
|
||||
}
|
||||
});
|
||||
|
||||
const anchor = rowKeys[0]
|
||||
|| selectionAnchorRef.current
|
||||
|| nextKeys[nextKeys.length - 1];
|
||||
|
||||
applySelection(nextKeys, {
|
||||
anchor,
|
||||
interactedKeys: rowKeys,
|
||||
});
|
||||
},
|
||||
[applySelection, resolveDocumentRowKey, selectedEntries, selectionAnchorRef],
|
||||
);
|
||||
|
||||
const handleDeskDocumentOpen = useCallback(
|
||||
(docId, { useSelection = false } = {}) => {
|
||||
const selectionDocIds = Array.isArray(selectedDocumentIds)
|
||||
? selectedDocumentIds
|
||||
: [];
|
||||
let targetIds = [];
|
||||
|
||||
if ((useSelection || selectionDocIds.includes(docId)) && selectionDocIds.length) {
|
||||
targetIds = selectionDocIds;
|
||||
} else if (selectionDocIds.length) {
|
||||
targetIds = selectionDocIds;
|
||||
} else if (docId) {
|
||||
targetIds = [docId];
|
||||
}
|
||||
|
||||
if (!targetIds.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
openDetailPanel({ documentIds: targetIds });
|
||||
},
|
||||
[openDetailPanel, selectedDocumentIds],
|
||||
);
|
||||
|
||||
const handleDeskHelpOpen = useCallback(() => {
|
||||
setDeskHelpOpen(true);
|
||||
}, [setDeskHelpOpen]);
|
||||
|
||||
const handleDeskHelpClose = useCallback(() => {
|
||||
setDeskHelpOpen(false);
|
||||
}, [setDeskHelpOpen]);
|
||||
|
||||
const deskViewId = useMemo(() => {
|
||||
if (showingSearchResults) {
|
||||
const trimmedQuery = searchQuery.trim();
|
||||
const tagsKey = [...activeTagFilters].sort().join(',');
|
||||
const correspondentsKey = [...activeCorrespondentFilters].sort().join(',');
|
||||
return `search:${trimmedQuery}|tags:${tagsKey}|corr:${correspondentsKey}`;
|
||||
}
|
||||
|
||||
const folderKey = selectedFolder && selectedFolder !== '' ? selectedFolder : 'root';
|
||||
return `folder:${folderKey}`;
|
||||
}, [
|
||||
showingSearchResults,
|
||||
searchQuery,
|
||||
activeTagFilters,
|
||||
activeCorrespondentFilters,
|
||||
selectedFolder,
|
||||
]);
|
||||
|
||||
return useMemo(
|
||||
() => ({
|
||||
documents,
|
||||
searchResults,
|
||||
@@ -137,5 +225,6 @@ const useDeskWorkspaceProps = ({
|
||||
toggleSearchIncludeDescendants,
|
||||
],
|
||||
);
|
||||
};
|
||||
|
||||
export default useDeskWorkspaceProps;
|
||||
|
||||
Reference in New Issue
Block a user