clean
This commit is contained in:
@@ -7,6 +7,7 @@ import { isTagTransferEvent } from '../tagTransfer';
|
||||
import PreviewZoomOverlay from '../../detail/PreviewZoomOverlay';
|
||||
import { useAssetNavigator } from '../../hooks/useAssetNavigator';
|
||||
import { isPointerModifierEvent, isPrimaryPointerEvent } from '../useEntryPointer';
|
||||
import { useWorkspaceSelectionContext } from '../../app/WorkspaceSelectionContext';
|
||||
|
||||
const DEFAULT_GRID_ICON_SIZE = 144;
|
||||
|
||||
@@ -37,19 +38,14 @@ const DocumentsPanel: React.FC<DocumentsPanelProps> = ({
|
||||
onFolderDragEnd,
|
||||
draggedFolderId,
|
||||
onFolderRename,
|
||||
selectedFolderIds = [],
|
||||
selectedDocumentIds = [],
|
||||
focusedRowKey,
|
||||
draggingDocumentIds = [],
|
||||
onDocumentDragStart,
|
||||
onDocumentDragEnd,
|
||||
onDocumentRename,
|
||||
onEntryPointer = null,
|
||||
onEntrySelection = null,
|
||||
onInspectDocument = null,
|
||||
tagLookupById,
|
||||
activeCorrespondentIds = [],
|
||||
onFocusedRowChange,
|
||||
ensureAssetUrl = null,
|
||||
getDocumentAsset = defaultGetDocumentAsset,
|
||||
onTagClick,
|
||||
@@ -58,10 +54,15 @@ const DocumentsPanel: React.FC<DocumentsPanelProps> = ({
|
||||
onDocumentTagDrop,
|
||||
viewMode = 'list',
|
||||
onViewModeChange,
|
||||
onClearSelection,
|
||||
selectedEntries = [],
|
||||
showHeader = true,
|
||||
}) => {
|
||||
const {
|
||||
selectedEntries,
|
||||
focusedRowKey,
|
||||
setFocusedRowKey,
|
||||
handleEntrySelection,
|
||||
clearSelection,
|
||||
} = useWorkspaceSelectionContext();
|
||||
const showingSearchResults = searchResults !== null;
|
||||
const rows = showingSearchResults ? searchResults : documents;
|
||||
|
||||
@@ -89,9 +90,9 @@ const DocumentsPanel: React.FC<DocumentsPanelProps> = ({
|
||||
const changed = previous.type !== nextContext.type
|
||||
|| previous.marker !== nextContext.marker;
|
||||
if (changed) {
|
||||
onClearSelection?.();
|
||||
clearSelection();
|
||||
}
|
||||
}, [showingSearchResults, currentFolderId, searchResults, onClearSelection]);
|
||||
}, [showingSearchResults, currentFolderId, searchResults, clearSelection]);
|
||||
|
||||
const entries = useMemo(() => {
|
||||
const list = [];
|
||||
@@ -112,14 +113,6 @@ const DocumentsPanel: React.FC<DocumentsPanelProps> = ({
|
||||
return list;
|
||||
}, [showingSearchResults, subfolders, rows]);
|
||||
|
||||
const selectedSet = useMemo(
|
||||
() => new Set(selectedDocumentIds),
|
||||
[selectedDocumentIds],
|
||||
);
|
||||
const selectedFolderSet = useMemo(
|
||||
() => new Set(selectedFolderIds || []),
|
||||
[selectedFolderIds],
|
||||
);
|
||||
const draggingSet = useMemo(
|
||||
() => new Set(draggingDocumentIds || []),
|
||||
[draggingDocumentIds],
|
||||
@@ -271,12 +264,12 @@ const DocumentsPanel: React.FC<DocumentsPanelProps> = ({
|
||||
return;
|
||||
}
|
||||
|
||||
onFocusedRowChange?.(resolvedKey);
|
||||
setFocusedRowKey(resolvedKey);
|
||||
}, [
|
||||
focusedRowKey,
|
||||
navigableRowKeys,
|
||||
navigableRows,
|
||||
onFocusedRowChange,
|
||||
setFocusedRowKey,
|
||||
selectedEntries,
|
||||
]);
|
||||
|
||||
@@ -320,7 +313,7 @@ const DocumentsPanel: React.FC<DocumentsPanelProps> = ({
|
||||
|
||||
if (key === 'Enter' || key === ' ' || key === 'Space' || key === 'Spacebar') {
|
||||
if (activeRow) {
|
||||
onEntrySelection?.(activeRow.key, event);
|
||||
handleEntrySelection(activeRow.key, event);
|
||||
if (activeRow.type === EntryType.folder) {
|
||||
onFolderSelect?.(activeRow.id);
|
||||
} else {
|
||||
@@ -353,8 +346,8 @@ const DocumentsPanel: React.FC<DocumentsPanelProps> = ({
|
||||
return;
|
||||
}
|
||||
|
||||
onFocusedRowChange?.(targetRow.key);
|
||||
onEntrySelection?.(targetRow.key, {
|
||||
setFocusedRowKey(targetRow.key);
|
||||
handleEntrySelection(targetRow.key, {
|
||||
shiftKey,
|
||||
preventDefault: () => {},
|
||||
});
|
||||
@@ -364,11 +357,11 @@ const DocumentsPanel: React.FC<DocumentsPanelProps> = ({
|
||||
getEntryByKey,
|
||||
navigableRowKeys,
|
||||
navigableRows,
|
||||
onEntrySelection,
|
||||
onFocusedRowChange,
|
||||
onFolderSelect,
|
||||
selectedEntries,
|
||||
handleDocumentPreviewZoom,
|
||||
handleEntrySelection,
|
||||
setFocusedRowKey,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -529,10 +522,10 @@ const DocumentsPanel: React.FC<DocumentsPanelProps> = ({
|
||||
&& scrollRef.current
|
||||
) {
|
||||
scrollRef.current.focus({ preventScroll: true });
|
||||
onFocusedRowChange?.(`folder:${folder.id}`);
|
||||
setFocusedRowKey(`folder:${folder.id}`);
|
||||
}
|
||||
},
|
||||
[onEntryPointer, onFocusedRowChange],
|
||||
[onEntryPointer, setFocusedRowKey],
|
||||
);
|
||||
|
||||
const handleDocumentDragStartLocal = useCallback(
|
||||
@@ -666,7 +659,7 @@ const DocumentsPanel: React.FC<DocumentsPanelProps> = ({
|
||||
}}
|
||||
onClick={(event) => {
|
||||
if (event.target === event.currentTarget) {
|
||||
onClearSelection?.();
|
||||
clearSelection();
|
||||
}
|
||||
}}
|
||||
aria-activedescendant={isGridView ? undefined : activeDescendantId}
|
||||
@@ -674,8 +667,6 @@ const DocumentsPanel: React.FC<DocumentsPanelProps> = ({
|
||||
{isGridView ? (
|
||||
<DocumentsGrid
|
||||
entries={entries}
|
||||
selectedDocumentIdsSet={selectedSet}
|
||||
selectedFolderIdsSet={selectedFolderSet}
|
||||
draggingDocumentIdsSet={draggingSet}
|
||||
draggedFolderId={draggedFolderId}
|
||||
onFolderClick={handleFolderClick}
|
||||
@@ -700,7 +691,6 @@ const DocumentsPanel: React.FC<DocumentsPanelProps> = ({
|
||||
scrollRef={scrollRef}
|
||||
onCorrespondentClick={onCorrespondentClick}
|
||||
activeCorrespondentIdSet={activeCorrespondentIdSet}
|
||||
onClearSelection={onClearSelection}
|
||||
onDocumentRename={onDocumentRename}
|
||||
onFolderRename={onFolderRename}
|
||||
/>
|
||||
@@ -708,8 +698,6 @@ const DocumentsPanel: React.FC<DocumentsPanelProps> = ({
|
||||
<DocumentsList
|
||||
entries={entries}
|
||||
focusedRowKey={focusedRowKey}
|
||||
selectedDocumentIdsSet={selectedSet}
|
||||
selectedFolderIdsSet={selectedFolderSet}
|
||||
draggingDocumentIdsSet={draggingSet}
|
||||
draggedFolderId={draggedFolderId}
|
||||
ensureAssetUrl={ensureAssetUrl}
|
||||
@@ -735,7 +723,6 @@ const DocumentsPanel: React.FC<DocumentsPanelProps> = ({
|
||||
onCorrespondentClick={onCorrespondentClick}
|
||||
activeCorrespondentIdSet={activeCorrespondentIdSet}
|
||||
scrollRef={scrollRef}
|
||||
onClearSelection={onClearSelection}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -4,6 +4,27 @@ import SelectionFloatingActions from '../SelectionFloatingActions';
|
||||
import createWorkspaceSurfaceConfig from '../workspaceHeader';
|
||||
import DocumentsPanel from './DocumentsPanel';
|
||||
import { createDocumentsTableHeaderActions } from './DocumentsToolbar';
|
||||
import { useWorkspaceSelectionContext } from '../../app/WorkspaceSelectionContext';
|
||||
|
||||
type SelectionFloatingActionsBaseProps = Omit<React.ComponentProps<typeof SelectionFloatingActions>, 'selectionCount' | 'selectedDocumentIds' | 'selectedFolderIds'>;
|
||||
|
||||
const SelectionFloatingActionsWithSelection: React.FC<SelectionFloatingActionsBaseProps> = (props) => {
|
||||
const { selectedDocumentIds, selectedFolderIds } = useWorkspaceSelectionContext();
|
||||
const documentIds = Array.isArray(selectedDocumentIds) ? selectedDocumentIds : [];
|
||||
const folderIds = Array.isArray(selectedFolderIds) ? selectedFolderIds : [];
|
||||
const selectionCount = documentIds.length + folderIds.length;
|
||||
if (selectionCount === 0) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<SelectionFloatingActions
|
||||
selectionCount={selectionCount}
|
||||
selectedDocumentIds={documentIds}
|
||||
selectedFolderIds={folderIds}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
interface CreateDocumentsSurfaceArgs {
|
||||
tableProps: Record<string, any>;
|
||||
@@ -30,8 +51,6 @@ const createDocumentsSurface = ({
|
||||
sortDirection,
|
||||
onSortFieldChange,
|
||||
onSortDirectionToggle,
|
||||
selectedDocumentIds,
|
||||
selectedFolderIds,
|
||||
onDeleteSelection,
|
||||
onClearSelection,
|
||||
tags,
|
||||
@@ -55,10 +74,6 @@ const createDocumentsSurface = ({
|
||||
? `${searchResults.length} matching document${searchResults.length === 1 ? '' : 's'}`
|
||||
: null;
|
||||
|
||||
const documentSelectionCount = Array.isArray(selectedDocumentIds) ? selectedDocumentIds.length : 0;
|
||||
const folderSelectionCount = Array.isArray(selectedFolderIds) ? selectedFolderIds.length : 0;
|
||||
const selectionCount = documentSelectionCount + folderSelectionCount;
|
||||
|
||||
const actions = createDocumentsTableHeaderActions({
|
||||
viewMode,
|
||||
onViewModeChange,
|
||||
@@ -72,28 +87,23 @@ const createDocumentsSurface = ({
|
||||
onToggleIncludeDescendants: onToggleSearchIncludeDescendants,
|
||||
});
|
||||
|
||||
const floatingActions = selectionCount > 0
|
||||
? (
|
||||
<SelectionFloatingActions
|
||||
selectionCount={selectionCount}
|
||||
selectedDocumentIds={selectedDocumentIds}
|
||||
selectedFolderIds={selectedFolderIds}
|
||||
documentLookup={documentLookup}
|
||||
tags={tags}
|
||||
tagLookupById={tagLookupById}
|
||||
correspondents={correspondents}
|
||||
onBulkTagAdd={onBulkTagAdd}
|
||||
onBulkTagRemove={onBulkTagRemove}
|
||||
onBulkCorrespondentAdd={onBulkCorrespondentAdd}
|
||||
onBulkCorrespondentRemove={onBulkCorrespondentRemove}
|
||||
onBulkReanalyze={onBulkReanalyze}
|
||||
onDeleteSelection={onDeleteSelection}
|
||||
onClearSelection={onClearSelection}
|
||||
folderOptions={folderOptions}
|
||||
onMoveDocumentsToFolder={onMoveDocumentsToFolder}
|
||||
/>
|
||||
)
|
||||
: null;
|
||||
const floatingActions = (
|
||||
<SelectionFloatingActionsWithSelection
|
||||
documentLookup={documentLookup}
|
||||
tags={tags}
|
||||
tagLookupById={tagLookupById}
|
||||
correspondents={correspondents}
|
||||
onBulkTagAdd={onBulkTagAdd}
|
||||
onBulkTagRemove={onBulkTagRemove}
|
||||
onBulkCorrespondentAdd={onBulkCorrespondentAdd}
|
||||
onBulkCorrespondentRemove={onBulkCorrespondentRemove}
|
||||
onBulkReanalyze={onBulkReanalyze}
|
||||
onDeleteSelection={onDeleteSelection}
|
||||
onClearSelection={onClearSelection}
|
||||
folderOptions={folderOptions}
|
||||
onMoveDocumentsToFolder={onMoveDocumentsToFolder}
|
||||
/>
|
||||
);
|
||||
|
||||
const sidebarToggle = renderSidebarToggle ? renderSidebarToggle() : null;
|
||||
const detail = detailOpen && detailProps
|
||||
|
||||
Reference in New Issue
Block a user