refactor(documents): remove unused document editing functionality and streamline components

- Eliminated references to document editing in DocumentNode, FolderTreeView, and DocumentsSidebar for a cleaner interface.
- Updated DocumentNode to enhance accessibility with keyboard interactions and improved click handling.
- Adjusted layout in AllChatsSidebar and MobileSidebar for better user experience and consistency across components.
This commit is contained in:
Anish Sarkar 2026-07-06 16:02:22 +05:30
parent 556f02c5be
commit 4088289f95
7 changed files with 66 additions and 83 deletions

View file

@ -4,11 +4,9 @@ import {
AlertCircle,
Clock,
Download,
Eye,
History,
MoreHorizontal,
Move,
Pencil,
RotateCcw,
Trash2,
} from "lucide-react";
@ -44,8 +42,6 @@ import { SidebarListItem } from "../layout/ui/sidebar/SidebarListItem";
import { DND_TYPES } from "./FolderNode";
import { isVersionableType } from "./version-history";
const EDITABLE_DOCUMENT_TYPES = new Set(["FILE", "NOTE"]);
export interface DocumentNodeDoc {
id: number;
title: string;
@ -60,7 +56,6 @@ interface DocumentNodeProps {
isMentioned: boolean;
onToggleChatMention: (doc: DocumentNodeDoc, isMentioned: boolean) => void;
onPreview: (doc: DocumentNodeDoc) => void;
onEdit: (doc: DocumentNodeDoc) => void;
onDelete: (doc: DocumentNodeDoc) => void;
onMove: (doc: DocumentNodeDoc) => void;
onReset?: (doc: DocumentNodeDoc) => void;
@ -69,7 +64,6 @@ interface DocumentNodeProps {
canDelete?: boolean;
canMove?: boolean;
canMention?: boolean;
canEdit?: boolean;
contextMenuOpen?: boolean;
onContextMenuOpenChange?: (open: boolean) => void;
}
@ -80,7 +74,6 @@ export const DocumentNode = React.memo(function DocumentNode({
isMentioned,
onToggleChatMention,
onPreview,
onEdit,
onDelete,
onMove,
onReset,
@ -89,7 +82,6 @@ export const DocumentNode = React.memo(function DocumentNode({
canDelete = true,
canMove = true,
canMention = true,
canEdit = true,
contextMenuOpen,
onContextMenuOpenChange,
}: DocumentNodeProps) {
@ -100,10 +92,6 @@ export const DocumentNode = React.memo(function DocumentNode({
const isMemoryDocument =
doc.document_type === "USER_MEMORY" || doc.document_type === "TEAM_MEMORY";
const isSelectable = canMention && !isUnavailable;
const isEditable =
canEdit &&
(isMemoryDocument || EDITABLE_DOCUMENT_TYPES.has(doc.document_type)) &&
!isUnavailable;
const handleCheckChange = useCallback(() => {
if (isSelectable) {
@ -112,12 +100,20 @@ export const DocumentNode = React.memo(function DocumentNode({
}, [doc, isMentioned, isSelectable, onToggleChatMention]);
const handlePrimaryClick = useCallback(() => {
if (canMention) {
handleCheckChange();
return;
}
if (isUnavailable) return;
onPreview(doc);
}, [canMention, doc, handleCheckChange, onPreview]);
}, [doc, isUnavailable, onPreview]);
const handlePrimaryKeyDown = useCallback(
(event: React.KeyboardEvent<HTMLDivElement>) => {
if (event.currentTarget !== event.target) return;
if (event.key !== "Enter" && event.key !== " ") return;
event.preventDefault();
handlePrimaryClick();
},
[handlePrimaryClick]
);
const [{ isDragging }, drag] = useDrag(
() => ({
@ -172,6 +168,11 @@ export const DocumentNode = React.memo(function DocumentNode({
dragging={isDragging}
className="gap-2.5 px-1"
style={{ paddingLeft: `${depth * 16 + 4}px` }}
role="button"
tabIndex={isUnavailable ? -1 : 0}
aria-disabled={isUnavailable}
onClick={handlePrimaryClick}
onKeyDown={handlePrimaryKeyDown}
>
{(() => {
if (statusState === "pending") {
@ -248,17 +249,11 @@ export const DocumentNode = React.memo(function DocumentNode({
onOpenChange={handleTitleTooltipOpenChange}
>
<TooltipTrigger asChild>
<Button
type="button"
variant="ghost"
aria-disabled={canMention ? !isSelectable : false}
onClick={handlePrimaryClick}
className="h-full min-w-0 flex-1 justify-start bg-transparent px-0 py-0 text-left font-normal text-inherit hover:bg-transparent hover:text-inherit"
>
<span className="flex h-full min-w-0 flex-1 items-center text-left font-normal text-inherit">
<span ref={titleRef} className="min-w-0 flex-1 truncate">
{doc.title}
</span>
</Button>
</span>
</TooltipTrigger>
<TooltipContent side="bottom" className="max-w-xs break-words">
{doc.title}
@ -304,16 +299,6 @@ export const DocumentNode = React.memo(function DocumentNode({
className="w-40"
onClick={(e) => e.stopPropagation()}
>
<DropdownMenuItem onClick={() => onPreview(doc)} disabled={isUnavailable}>
<Eye className="mr-2 h-4 w-4" />
Open
</DropdownMenuItem>
{isEditable && (
<DropdownMenuItem onClick={() => onEdit(doc)}>
<Pencil className="mr-2 h-4 w-4" />
Edit
</DropdownMenuItem>
)}
{canMove && (
<DropdownMenuItem onClick={() => onMove(doc)}>
<Move className="mr-2 h-4 w-4" />
@ -362,16 +347,6 @@ export const DocumentNode = React.memo(function DocumentNode({
{contextMenuOpen && (
<ContextMenuContent className="w-40" onClick={(e) => e.stopPropagation()}>
<ContextMenuItem onClick={() => onPreview(doc)} disabled={isUnavailable}>
<Eye className="mr-2 h-4 w-4" />
Open
</ContextMenuItem>
{isEditable && (
<ContextMenuItem onClick={() => onEdit(doc)}>
<Pencil className="mr-2 h-4 w-4" />
Edit
</ContextMenuItem>
)}
{canMove && (
<ContextMenuItem onClick={() => onMove(doc)}>
<Move className="mr-2 h-4 w-4" />

View file

@ -29,7 +29,6 @@ interface FolderTreeViewProps {
onMoveFolder: (folder: FolderDisplay) => void;
onCreateFolder: (parentId: number | null) => void;
onPreviewDocument: (doc: DocumentNodeDoc) => void;
onEditDocument: (doc: DocumentNodeDoc) => void;
onDeleteDocument: (doc: DocumentNodeDoc) => void;
onMoveDocument: (doc: DocumentNodeDoc) => void;
onResetDocument?: (doc: DocumentNodeDoc) => void;
@ -72,7 +71,6 @@ export function FolderTreeView({
onMoveFolder,
onCreateFolder,
onPreviewDocument,
onEditDocument,
onDeleteDocument,
onMoveDocument,
onResetDocument,
@ -215,7 +213,6 @@ export function FolderTreeView({
isMentioned={!isMemoryDocument && mentionedDocKeys.has(getMentionDocKey(d))}
onToggleChatMention={onToggleChatMention}
onPreview={onPreviewDocument}
onEdit={onEditDocument}
onDelete={onDeleteDocument}
onMove={onMoveDocument}
onReset={onResetDocument}
@ -224,7 +221,6 @@ export function FolderTreeView({
canDelete={!isMemoryDocument}
canMove={!isMemoryDocument}
canMention={!isMemoryDocument}
canEdit
contextMenuOpen={openContextMenuId === `doc-${d.id}`}
onContextMenuOpenChange={(open) => setOpenContextMenuId(open ? `doc-${d.id}` : null)}
/>
@ -233,7 +229,6 @@ export function FolderTreeView({
[
mentionedDocKeys,
onDeleteDocument,
onEditDocument,
onExportDocument,
onMoveDocument,
onPreviewDocument,