mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-26 20:08:38 +02:00
Ensure metadata overrides file contents (#3512)
* ensure metadata overrides file contents * update more blocks
This commit is contained in:
@@ -7,7 +7,7 @@ import { DocumentUpdatedAtBadge } from "@/components/search/DocumentUpdatedAtBad
|
|||||||
import { MetadataBadge } from "@/components/MetadataBadge";
|
import { MetadataBadge } from "@/components/MetadataBadge";
|
||||||
import { WebResultIcon } from "@/components/WebResultIcon";
|
import { WebResultIcon } from "@/components/WebResultIcon";
|
||||||
import { Dispatch, SetStateAction } from "react";
|
import { Dispatch, SetStateAction } from "react";
|
||||||
import { ValidSources } from "@/lib/types";
|
import { openDocument } from "@/lib/search/utils";
|
||||||
|
|
||||||
interface DocumentDisplayProps {
|
interface DocumentDisplayProps {
|
||||||
closeSidebar: () => void;
|
closeSidebar: () => void;
|
||||||
@@ -73,14 +73,6 @@ export function ChatDocumentDisplay({
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleViewFile = async () => {
|
|
||||||
if (document.source_type == ValidSources.File && setPresentingDocument) {
|
|
||||||
setPresentingDocument(document);
|
|
||||||
} else if (document.link) {
|
|
||||||
window.open(document.link, "_blank");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const hasMetadata =
|
const hasMetadata =
|
||||||
document.updated_at || Object.keys(document.metadata).length > 0;
|
document.updated_at || Object.keys(document.metadata).length > 0;
|
||||||
return (
|
return (
|
||||||
@@ -91,7 +83,7 @@ export function ChatDocumentDisplay({
|
|||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
onClick={handleViewFile}
|
onClick={() => openDocument(document, setPresentingDocument)}
|
||||||
className="cursor-pointer text-left flex flex-col px-2 py-1.5"
|
className="cursor-pointer text-left flex flex-col px-2 py-1.5"
|
||||||
>
|
>
|
||||||
<div className="line-clamp-1 mb-1 flex h-6 items-center gap-2 text-xs">
|
<div className="line-clamp-1 mb-1 flex h-6 items-center gap-2 text-xs">
|
||||||
|
@@ -2,9 +2,7 @@ import { WebResultIcon } from "@/components/WebResultIcon";
|
|||||||
import { SourceIcon } from "@/components/SourceIcon";
|
import { SourceIcon } from "@/components/SourceIcon";
|
||||||
import { OnyxDocument } from "@/lib/search/interfaces";
|
import { OnyxDocument } from "@/lib/search/interfaces";
|
||||||
import { truncateString } from "@/lib/utils";
|
import { truncateString } from "@/lib/utils";
|
||||||
import { SetStateAction } from "react";
|
import { openDocument } from "@/lib/search/utils";
|
||||||
import { Dispatch } from "react";
|
|
||||||
import { ValidSources } from "@/lib/types";
|
|
||||||
|
|
||||||
export default function SourceCard({
|
export default function SourceCard({
|
||||||
doc,
|
doc,
|
||||||
@@ -16,13 +14,7 @@ export default function SourceCard({
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={doc.document_id}
|
key={doc.document_id}
|
||||||
onClick={() => {
|
onClick={() => openDocument(doc, setPresentingDocument)}
|
||||||
if (doc.source_type == ValidSources.File && setPresentingDocument) {
|
|
||||||
setPresentingDocument(doc);
|
|
||||||
} else if (doc.link) {
|
|
||||||
window.open(doc.link, "_blank");
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
className="cursor-pointer text-left overflow-hidden flex flex-col gap-0.5 rounded-sm px-3 py-2.5 hover:bg-background-125 bg-background-100 w-[200px]"
|
className="cursor-pointer text-left overflow-hidden flex flex-col gap-0.5 rounded-sm px-3 py-2.5 hover:bg-background-125 bg-background-100 w-[200px]"
|
||||||
>
|
>
|
||||||
<div className="line-clamp-1 font-semibold text-ellipsis text-text-900 flex h-6 items-center gap-2 text-sm">
|
<div className="line-clamp-1 font-semibold text-ellipsis text-text-900 flex h-6 items-center gap-2 text-sm">
|
||||||
|
@@ -22,6 +22,7 @@ import { WarningCircle } from "@phosphor-icons/react";
|
|||||||
import TextView from "../chat_search/TextView";
|
import TextView from "../chat_search/TextView";
|
||||||
import { SearchResultIcon } from "../SearchResultIcon";
|
import { SearchResultIcon } from "../SearchResultIcon";
|
||||||
import { ValidSources } from "@/lib/types";
|
import { ValidSources } from "@/lib/types";
|
||||||
|
import { openDocument } from "@/lib/search/utils";
|
||||||
|
|
||||||
export const buildDocumentSummaryDisplay = (
|
export const buildDocumentSummaryDisplay = (
|
||||||
matchHighlights: string[],
|
matchHighlights: string[],
|
||||||
@@ -428,19 +429,15 @@ export function CompactDocumentCard({
|
|||||||
url,
|
url,
|
||||||
updatePresentingDocument,
|
updatePresentingDocument,
|
||||||
}: {
|
}: {
|
||||||
document: LoadedOnyxDocument;
|
document: OnyxDocument;
|
||||||
icon?: React.ReactNode;
|
icon?: React.ReactNode;
|
||||||
url?: string;
|
url?: string;
|
||||||
updatePresentingDocument: (documentIndex: LoadedOnyxDocument) => void;
|
updatePresentingDocument: (document: OnyxDocument) => void;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (document.source_type === ValidSources.File) {
|
openDocument(document, updatePresentingDocument);
|
||||||
updatePresentingDocument(document);
|
|
||||||
} else if (document.link) {
|
|
||||||
window.open(document.link, "_blank");
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
className="max-w-[250px] cursor-pointer pb-0 pt-0 mt-0 flex gap-y-0 flex-col content-start items-start gap-0 "
|
className="max-w-[250px] cursor-pointer pb-0 pt-0 mt-0 flex gap-y-0 flex-col content-start items-start gap-0 "
|
||||||
>
|
>
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { ReactNode } from "react";
|
import { ReactNode } from "react";
|
||||||
import { CompactDocumentCard } from "../DocumentDisplay";
|
import { CompactDocumentCard } from "../DocumentDisplay";
|
||||||
import { LoadedOnyxDocument } from "@/lib/search/interfaces";
|
import { LoadedOnyxDocument, OnyxDocument } from "@/lib/search/interfaces";
|
||||||
import {
|
import {
|
||||||
Tooltip,
|
Tooltip,
|
||||||
TooltipContent,
|
TooltipContent,
|
||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
TooltipTrigger,
|
TooltipTrigger,
|
||||||
} from "@/components/ui/tooltip";
|
} from "@/components/ui/tooltip";
|
||||||
import { ValidSources } from "@/lib/types";
|
import { ValidSources } from "@/lib/types";
|
||||||
|
import { openDocument } from "@/lib/search/utils";
|
||||||
|
|
||||||
export function Citation({
|
export function Citation({
|
||||||
children,
|
children,
|
||||||
@@ -21,7 +22,7 @@ export function Citation({
|
|||||||
link?: string;
|
link?: string;
|
||||||
children?: JSX.Element | string | null | ReactNode;
|
children?: JSX.Element | string | null | ReactNode;
|
||||||
index?: number;
|
index?: number;
|
||||||
updatePresentingDocument: (documentIndex: LoadedOnyxDocument) => void;
|
updatePresentingDocument: (document: OnyxDocument) => void;
|
||||||
document: LoadedOnyxDocument;
|
document: LoadedOnyxDocument;
|
||||||
icon?: React.ReactNode;
|
icon?: React.ReactNode;
|
||||||
url?: string;
|
url?: string;
|
||||||
@@ -30,20 +31,12 @@ export function Citation({
|
|||||||
? children?.toString().split("[")[1].split("]")[0]
|
? children?.toString().split("[")[1].split("]")[0]
|
||||||
: index;
|
: index;
|
||||||
|
|
||||||
const onClick = () => {
|
|
||||||
if (document.source_type == ValidSources.File) {
|
|
||||||
updatePresentingDocument(document);
|
|
||||||
} else {
|
|
||||||
window.open(link || document.link, "_blank");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TooltipProvider delayDuration={0}>
|
<TooltipProvider delayDuration={0}>
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<div
|
<div
|
||||||
onMouseDown={onClick}
|
onClick={() => openDocument(document, updatePresentingDocument)}
|
||||||
className="inline-flex items-center cursor-pointer transition-all duration-200 ease-in-out"
|
className="inline-flex items-center cursor-pointer transition-all duration-200 ease-in-out"
|
||||||
>
|
>
|
||||||
<span className="flex items-center justify-center w-6 h-6 text-[11px] font-medium text-gray-700 bg-gray-100 rounded-full border border-gray-300 hover:bg-gray-200 hover:text-gray-900 shadow-sm">
|
<span className="flex items-center justify-center w-6 h-6 text-[11px] font-medium text-gray-700 bg-gray-100 rounded-full border border-gray-300 hover:bg-gray-200 hover:text-gray-900 shadow-sm">
|
||||||
|
@@ -1,5 +1,10 @@
|
|||||||
import { Tag } from "../types";
|
import { Tag, ValidSources } from "../types";
|
||||||
import { Filters, SourceMetadata } from "./interfaces";
|
import {
|
||||||
|
Filters,
|
||||||
|
LoadedOnyxDocument,
|
||||||
|
OnyxDocument,
|
||||||
|
SourceMetadata,
|
||||||
|
} from "./interfaces";
|
||||||
import { DateRangePickerValue } from "@/app/ee/admin/performance/DateRangeSelector";
|
import { DateRangePickerValue } from "@/app/ee/admin/performance/DateRangeSelector";
|
||||||
|
|
||||||
export const buildFilters = (
|
export const buildFilters = (
|
||||||
@@ -22,3 +27,16 @@ export const buildFilters = (
|
|||||||
export function endsWithLetterOrNumber(str: string) {
|
export function endsWithLetterOrNumber(str: string) {
|
||||||
return /[a-zA-Z0-9]$/.test(str);
|
return /[a-zA-Z0-9]$/.test(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we have a link, open it in a new tab (including if it's a file)
|
||||||
|
// If above fails and we have a file, update the presenting document
|
||||||
|
export const openDocument = (
|
||||||
|
document: OnyxDocument,
|
||||||
|
updatePresentingDocument?: (document: OnyxDocument) => void
|
||||||
|
) => {
|
||||||
|
if (document.link) {
|
||||||
|
window.open(document.link, "_blank");
|
||||||
|
} else if (document.source_type === ValidSources.File) {
|
||||||
|
updatePresentingDocument?.(document);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user