fix(registratura): NAS links copy to clipboard instead of broken file:///
Browsers block file:/// URLs from web pages for security. Changed: - Detail sheet: click on NAS attachment copies path to clipboard with 'Copiat!' green badge feedback. Full UNC path shown below. - Entry form: NAS link click = copy path (removed window.open fallback) - Removed unused toFileUrl/toFileUrlByIp imports from form - User pastes in Explorer address bar to open the file
This commit is contained in:
@@ -34,14 +34,9 @@ import {
|
||||
import type { RegistryEntry } from "../types";
|
||||
import { DEFAULT_DOC_TYPE_LABELS } from "../types";
|
||||
import { getOverdueDays } from "../services/registry-service";
|
||||
import {
|
||||
toFileUrl,
|
||||
toFileUrlByIp,
|
||||
shortDisplayPath,
|
||||
shareLabelFor,
|
||||
} from "@/config/nas-paths";
|
||||
import { shortDisplayPath, shareLabelFor } from "@/config/nas-paths";
|
||||
import { cn } from "@/shared/lib/utils";
|
||||
import { useState } from "react";
|
||||
import { useState, useCallback } from "react";
|
||||
|
||||
interface RegistryEntryDetailProps {
|
||||
entry: RegistryEntry | null;
|
||||
@@ -139,6 +134,13 @@ export function RegistryEntryDetail({
|
||||
const [previewAttachment, setPreviewAttachment] = useState<string | null>(
|
||||
null,
|
||||
);
|
||||
const [copiedPath, setCopiedPath] = useState<string | null>(null);
|
||||
|
||||
const copyPath = useCallback(async (path: string) => {
|
||||
await navigator.clipboard.writeText(path);
|
||||
setCopiedPath(path);
|
||||
setTimeout(() => setCopiedPath(null), 2000);
|
||||
}, []);
|
||||
|
||||
if (!entry) return null;
|
||||
|
||||
@@ -396,64 +398,35 @@ export function RegistryEntryDetail({
|
||||
att.networkPath ? (
|
||||
<div
|
||||
key={att.id}
|
||||
className="flex items-center gap-2 rounded-md border border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/20 px-3 py-2 group"
|
||||
className="rounded-md border border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/20 px-3 py-2 group cursor-pointer hover:bg-blue-100/50 dark:hover:bg-blue-900/30 transition-colors"
|
||||
onClick={() => copyPath(att.networkPath!)}
|
||||
title="Click pentru a copia calea — lipește în Explorer"
|
||||
>
|
||||
<HardDrive className="h-4 w-4 text-blue-600 dark:text-blue-400 shrink-0" />
|
||||
<div className="flex-1 min-w-0">
|
||||
<a
|
||||
href={toFileUrl(att.networkPath)}
|
||||
className="text-sm text-blue-700 dark:text-blue-300 hover:underline font-mono"
|
||||
title={att.networkPath}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
window.open(
|
||||
toFileUrl(att.networkPath!),
|
||||
"_blank",
|
||||
);
|
||||
}}
|
||||
>
|
||||
<FolderOpen className="mr-1 inline h-3 w-3" />
|
||||
{shortDisplayPath(att.networkPath)}
|
||||
</a>
|
||||
<p className="text-[10px] text-muted-foreground mt-0.5">
|
||||
{att.networkPath}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-1 shrink-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<HardDrive className="h-4 w-4 text-blue-600 dark:text-blue-400 shrink-0" />
|
||||
<div className="flex-1 min-w-0">
|
||||
<span className="text-sm text-blue-700 dark:text-blue-300 font-mono">
|
||||
<FolderOpen className="mr-1 inline h-3 w-3" />
|
||||
{shortDisplayPath(att.networkPath)}
|
||||
</span>
|
||||
</div>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="text-[10px] border-blue-300 dark:border-blue-700 text-blue-600 dark:text-blue-400"
|
||||
className="text-[10px] border-blue-300 dark:border-blue-700 text-blue-600 dark:text-blue-400 shrink-0"
|
||||
>
|
||||
{shareLabelFor(att.networkPath) ?? "NAS"}
|
||||
</Badge>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity"
|
||||
onClick={() =>
|
||||
navigator.clipboard.writeText(att.networkPath!)
|
||||
}
|
||||
title="Copiază calea"
|
||||
>
|
||||
<Copy className="h-3 w-3" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity text-blue-500"
|
||||
onClick={() =>
|
||||
window.open(
|
||||
toFileUrlByIp(att.networkPath!),
|
||||
"_blank",
|
||||
)
|
||||
}
|
||||
title="Deschide prin IP (fallback)"
|
||||
>
|
||||
<ExternalLink className="h-3 w-3" />
|
||||
</Button>
|
||||
{copiedPath === att.networkPath ? (
|
||||
<Badge className="text-[10px] bg-green-600 text-white shrink-0 animate-in fade-in">
|
||||
Copiat!
|
||||
</Badge>
|
||||
) : (
|
||||
<Copy className="h-3.5 w-3.5 text-blue-400 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity" />
|
||||
)}
|
||||
</div>
|
||||
<p className="text-[10px] text-muted-foreground mt-1 pl-6 font-mono truncate">
|
||||
{att.networkPath}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
|
||||
@@ -33,8 +33,6 @@ import { DEFAULT_DOC_TYPE_LABELS } from "../types";
|
||||
import {
|
||||
isNetworkPath,
|
||||
toUncPath,
|
||||
toFileUrl,
|
||||
toFileUrlByIp,
|
||||
pathFileName,
|
||||
shortDisplayPath,
|
||||
shareLabelFor,
|
||||
@@ -1273,48 +1271,25 @@ export function RegistryEntryForm({
|
||||
className="flex items-center gap-2 rounded border border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/20 px-2 py-1.5 text-sm group"
|
||||
>
|
||||
<HardDrive className="h-3.5 w-3.5 text-blue-600 dark:text-blue-400 shrink-0" />
|
||||
<a
|
||||
href={toFileUrl(att.networkPath)}
|
||||
className="flex-1 min-w-0 flex items-center gap-1 text-blue-700 dark:text-blue-300 hover:underline cursor-pointer"
|
||||
title={`Deschide în Explorer: ${att.networkPath}`}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
window.open(toFileUrl(att.networkPath!), "_blank");
|
||||
<button
|
||||
type="button"
|
||||
className="flex-1 min-w-0 flex items-center gap-1 text-blue-700 dark:text-blue-300 hover:underline cursor-pointer text-left"
|
||||
title="Click copiază calea — lipește în Explorer"
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(att.networkPath!);
|
||||
}}
|
||||
>
|
||||
<FolderOpen className="h-3 w-3 shrink-0" />
|
||||
<span className="truncate font-mono text-xs">
|
||||
{shortDisplayPath(att.networkPath)}
|
||||
</span>
|
||||
</a>
|
||||
{/* IP fallback link — visible on hover when DNS fails */}
|
||||
<a
|
||||
href={toFileUrlByIp(att.networkPath)}
|
||||
className="opacity-0 group-hover:opacity-100 transition-opacity text-[10px] text-blue-400 hover:text-blue-600 dark:hover:text-blue-200 shrink-0"
|
||||
title={`Fallback IP: ${toFileUrlByIp(att.networkPath!)}`}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
window.open(toFileUrlByIp(att.networkPath!), "_blank");
|
||||
}}
|
||||
>
|
||||
IP
|
||||
</a>
|
||||
</button>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="text-[10px] border-blue-300 dark:border-blue-700 text-blue-600 dark:text-blue-400 shrink-0"
|
||||
>
|
||||
{shareLabelFor(att.networkPath) ?? "NAS"}
|
||||
</Badge>
|
||||
<button
|
||||
type="button"
|
||||
className="text-blue-400 hover:text-destructive opacity-0 group-hover:opacity-100 transition-opacity"
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(att.networkPath!);
|
||||
}}
|
||||
title="Copiază calea"
|
||||
>
|
||||
<Link2 className="h-3 w-3" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removeAttachment(att.id)}
|
||||
|
||||
Reference in New Issue
Block a user