mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-26 21:39:43 +02:00
refactor: update editable document types to include 'FILE' and enhance related logic across components for improved functionality
This commit is contained in:
parent
69b8eef5ce
commit
38b77dfb6b
4 changed files with 24 additions and 5 deletions
|
|
@ -24,7 +24,7 @@ import {
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import type { Document } from "./types";
|
import type { Document } from "./types";
|
||||||
|
|
||||||
const EDITABLE_DOCUMENT_TYPES = ["NOTE"] as const;
|
const EDITABLE_DOCUMENT_TYPES = ["FILE", "NOTE"] as const;
|
||||||
|
|
||||||
// SURFSENSE_DOCS are system-managed and cannot be deleted
|
// SURFSENSE_DOCS are system-managed and cannot be deleted
|
||||||
const NON_DELETABLE_DOCUMENT_TYPES = ["SURFSENSE_DOCS"] as const;
|
const NON_DELETABLE_DOCUMENT_TYPES = ["SURFSENSE_DOCS"] as const;
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,8 @@ import type { DocumentTypeEnum } from "@/contracts/types/document.types";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { DND_TYPES } from "./FolderNode";
|
import { DND_TYPES } from "./FolderNode";
|
||||||
|
|
||||||
|
const EDITABLE_DOCUMENT_TYPES = new Set(["FILE", "NOTE"]);
|
||||||
|
|
||||||
export interface DocumentNodeDoc {
|
export interface DocumentNodeDoc {
|
||||||
id: number;
|
id: number;
|
||||||
title: string;
|
title: string;
|
||||||
|
|
@ -78,7 +80,9 @@ export const DocumentNode = React.memo(function DocumentNode({
|
||||||
const statusState = doc.status?.state ?? "ready";
|
const statusState = doc.status?.state ?? "ready";
|
||||||
const isSelectable = statusState !== "pending" && statusState !== "processing";
|
const isSelectable = statusState !== "pending" && statusState !== "processing";
|
||||||
const isEditable =
|
const isEditable =
|
||||||
doc.document_type === "NOTE" && statusState !== "pending" && statusState !== "processing";
|
EDITABLE_DOCUMENT_TYPES.has(doc.document_type) &&
|
||||||
|
statusState !== "pending" &&
|
||||||
|
statusState !== "processing";
|
||||||
|
|
||||||
const handleCheckChange = useCallback(() => {
|
const handleCheckChange = useCallback(() => {
|
||||||
if (isSelectable) {
|
if (isSelectable) {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { AlertCircle, XIcon } from "lucide-react";
|
||||||
import { useCallback, useEffect, useRef, useState } from "react";
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { closeEditorPanelAtom, editorPanelAtom } from "@/atoms/editor/editor-panel.atom";
|
import { closeEditorPanelAtom, editorPanelAtom } from "@/atoms/editor/editor-panel.atom";
|
||||||
|
import { MarkdownViewer } from "@/components/markdown-viewer";
|
||||||
import { PlateEditor } from "@/components/editor/plate-editor";
|
import { PlateEditor } from "@/components/editor/plate-editor";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Drawer, DrawerContent, DrawerHandle, DrawerTitle } from "@/components/ui/drawer";
|
import { Drawer, DrawerContent, DrawerHandle, DrawerTitle } from "@/components/ui/drawer";
|
||||||
|
|
@ -18,6 +19,8 @@ interface EditorContent {
|
||||||
source_markdown: string;
|
source_markdown: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EDITABLE_DOCUMENT_TYPES = new Set(["FILE", "NOTE"]);
|
||||||
|
|
||||||
function EditorPanelSkeleton() {
|
function EditorPanelSkeleton() {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6 p-6">
|
<div className="space-y-6 p-6">
|
||||||
|
|
@ -165,12 +168,16 @@ export function EditorPanelContent({
|
||||||
}
|
}
|
||||||
}, [documentId, searchSpaceId]);
|
}, [documentId, searchSpaceId]);
|
||||||
|
|
||||||
|
const isEditableType = editorDoc
|
||||||
|
? EDITABLE_DOCUMENT_TYPES.has(editorDoc.document_type ?? "")
|
||||||
|
: false;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="flex items-center justify-between px-4 py-2 shrink-0 border-b">
|
<div className="flex items-center justify-between px-4 py-2 shrink-0 border-b">
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
<h2 className="text-sm font-semibold truncate">{displayTitle}</h2>
|
<h2 className="text-sm font-semibold truncate">{displayTitle}</h2>
|
||||||
{editedMarkdown !== null && (
|
{isEditableType && editedMarkdown !== null && (
|
||||||
<p className="text-[10px] text-muted-foreground">Unsaved changes</p>
|
<p className="text-[10px] text-muted-foreground">Unsaved changes</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -193,7 +200,7 @@ export function EditorPanelContent({
|
||||||
<p className="text-sm text-red-500 mt-1">{error || "An unknown error occurred"}</p>
|
<p className="text-sm text-red-500 mt-1">{error || "An unknown error occurred"}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : isEditableType ? (
|
||||||
<PlateEditor
|
<PlateEditor
|
||||||
key={documentId}
|
key={documentId}
|
||||||
preset="full"
|
preset="full"
|
||||||
|
|
@ -208,6 +215,10 @@ export function EditorPanelContent({
|
||||||
defaultEditing={true}
|
defaultEditing={true}
|
||||||
className="[&_[role=toolbar]]:!bg-sidebar"
|
className="[&_[role=toolbar]]:!bg-sidebar"
|
||||||
/>
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="h-full overflow-y-auto px-5 py-4">
|
||||||
|
<MarkdownViewer content={editorDoc.source_markdown} />
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,8 @@ interface DocumentTabContentProps {
|
||||||
title?: string;
|
title?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EDITABLE_DOCUMENT_TYPES = new Set(["FILE", "NOTE"]);
|
||||||
|
|
||||||
export function DocumentTabContent({ documentId, searchSpaceId, title }: DocumentTabContentProps) {
|
export function DocumentTabContent({ documentId, searchSpaceId, title }: DocumentTabContentProps) {
|
||||||
const [doc, setDoc] = useState<DocumentContent | null>(null);
|
const [doc, setDoc] = useState<DocumentContent | null>(null);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
@ -171,6 +173,8 @@ export function DocumentTabContent({ documentId, searchSpaceId, title }: Documen
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isEditable = EDITABLE_DOCUMENT_TYPES.has(doc.document_type ?? "");
|
||||||
|
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col h-full overflow-hidden">
|
<div className="flex flex-col h-full overflow-hidden">
|
||||||
|
|
@ -218,7 +222,7 @@ export function DocumentTabContent({ documentId, searchSpaceId, title }: Documen
|
||||||
<h1 className="text-base font-semibold truncate flex-1 min-w-0">
|
<h1 className="text-base font-semibold truncate flex-1 min-w-0">
|
||||||
{doc.title || title || "Untitled"}
|
{doc.title || title || "Untitled"}
|
||||||
</h1>
|
</h1>
|
||||||
{doc.document_type === "NOTE" && (
|
{isEditable && (
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue