fix: code review cleanup - schema sync, type safety, null handling
- Sync KnowledgeLink schema with migration (add displayText, positionStart, positionEnd, resolved) - Make targetId optional to support unresolved links - Fix null handling in graph.service.ts (skip unresolved links) - Add explicit types to frontend components (remove implicit any) - Remove unused WikiLink import - Add null-safe statusInfo check in EntryCard
This commit is contained in:
@@ -750,18 +750,22 @@ model KnowledgeLink {
|
|||||||
sourceId String @map("source_id") @db.Uuid
|
sourceId String @map("source_id") @db.Uuid
|
||||||
source KnowledgeEntry @relation("SourceEntry", fields: [sourceId], references: [id], onDelete: Cascade)
|
source KnowledgeEntry @relation("SourceEntry", fields: [sourceId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
targetId String @map("target_id") @db.Uuid
|
targetId String? @map("target_id") @db.Uuid
|
||||||
target KnowledgeEntry @relation("TargetEntry", fields: [targetId], references: [id], onDelete: Cascade)
|
target KnowledgeEntry? @relation("TargetEntry", fields: [targetId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
// Link metadata
|
// Link metadata
|
||||||
linkText String @map("link_text")
|
linkText String @map("link_text")
|
||||||
context String?
|
displayText String @map("display_text")
|
||||||
|
positionStart Int @map("position_start")
|
||||||
|
positionEnd Int @map("position_end")
|
||||||
|
resolved Boolean @default(false)
|
||||||
|
context String?
|
||||||
|
|
||||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
|
||||||
|
|
||||||
@@unique([sourceId, targetId])
|
|
||||||
@@index([sourceId])
|
@@index([sourceId])
|
||||||
@@index([targetId])
|
@@index([targetId])
|
||||||
|
@@index([sourceId, resolved])
|
||||||
@@map("knowledge_links")
|
@@map("knowledge_links")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -104,8 +104,11 @@ export class GraphService {
|
|||||||
|
|
||||||
// Continue BFS if not at max depth
|
// Continue BFS if not at max depth
|
||||||
if (depth < maxDepth) {
|
if (depth < maxDepth) {
|
||||||
// Process outgoing links
|
// Process outgoing links (only resolved ones)
|
||||||
for (const link of currentEntry.outgoingLinks) {
|
for (const link of currentEntry.outgoingLinks) {
|
||||||
|
// Skip unresolved links
|
||||||
|
if (!link.targetId || !link.resolved) continue;
|
||||||
|
|
||||||
// Add edge
|
// Add edge
|
||||||
edges.push({
|
edges.push({
|
||||||
id: link.id,
|
id: link.id,
|
||||||
@@ -122,8 +125,11 @@ export class GraphService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process incoming links
|
// Process incoming links (only resolved ones)
|
||||||
for (const link of currentEntry.incomingLinks) {
|
for (const link of currentEntry.incomingLinks) {
|
||||||
|
// Skip unresolved links
|
||||||
|
if (!link.targetId || !link.resolved) continue;
|
||||||
|
|
||||||
// Add edge
|
// Add edge
|
||||||
const edgeExists = edges.some(
|
const edgeExists = edges.some(
|
||||||
(e) => e.sourceId === link.sourceId && e.targetId === link.targetId
|
(e) => e.sourceId === link.sourceId && e.targetId === link.targetId
|
||||||
|
|||||||
@@ -131,7 +131,9 @@ export class LinkResolutionService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fuzzyMatches[0].id;
|
// Return the single match
|
||||||
|
const match = fuzzyMatches[0];
|
||||||
|
return match ? match.id : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { PrismaService } from "../../prisma/prisma.service";
|
import { PrismaService } from "../../prisma/prisma.service";
|
||||||
import { LinkResolutionService } from "./link-resolution.service";
|
import { LinkResolutionService } from "./link-resolution.service";
|
||||||
import { parseWikiLinks, WikiLink } from "../utils/wiki-link-parser";
|
import { parseWikiLinks } from "../utils/wiki-link-parser";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a backlink to a knowledge entry
|
* Represents a backlink to a knowledge entry
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export default function EntryPage() {
|
|||||||
setEditContent(data.content);
|
setEditContent(data.content);
|
||||||
setEditStatus(data.status);
|
setEditStatus(data.status);
|
||||||
setEditVisibility(data.visibility);
|
setEditVisibility(data.visibility);
|
||||||
setEditTags(data.tags.map((tag) => tag.id));
|
setEditTags(data.tags.map((tag: { id: string }) => tag.id));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : "Failed to load entry");
|
setError(err instanceof Error ? err.message : "Failed to load entry");
|
||||||
} finally {
|
} finally {
|
||||||
@@ -82,7 +82,7 @@ export default function EntryPage() {
|
|||||||
editStatus !== entry.status ||
|
editStatus !== entry.status ||
|
||||||
editVisibility !== entry.visibility ||
|
editVisibility !== entry.visibility ||
|
||||||
JSON.stringify(editTags.sort()) !==
|
JSON.stringify(editTags.sort()) !==
|
||||||
JSON.stringify(entry.tags.map((t) => t.id).sort());
|
JSON.stringify(entry.tags.map((t: { id: string }) => t.id).sort());
|
||||||
|
|
||||||
setHasUnsavedChanges(changed);
|
setHasUnsavedChanges(changed);
|
||||||
}, [entry, isEditing, editTitle, editContent, editStatus, editVisibility, editTags]);
|
}, [entry, isEditing, editTitle, editContent, editStatus, editVisibility, editTags]);
|
||||||
@@ -158,7 +158,7 @@ export default function EntryPage() {
|
|||||||
setEditContent(entry.content);
|
setEditContent(entry.content);
|
||||||
setEditStatus(entry.status);
|
setEditStatus(entry.status);
|
||||||
setEditVisibility(entry.visibility);
|
setEditVisibility(entry.visibility);
|
||||||
setEditTags(entry.tags.map((tag) => tag.id));
|
setEditTags(entry.tags.map((tag: { id: string }) => tag.id));
|
||||||
setIsEditing(false);
|
setIsEditing(false);
|
||||||
setHasUnsavedChanges(false);
|
setHasUnsavedChanges(false);
|
||||||
}
|
}
|
||||||
@@ -250,7 +250,7 @@ export default function EntryPage() {
|
|||||||
</span>
|
</span>
|
||||||
|
|
||||||
{/* Tags */}
|
{/* Tags */}
|
||||||
{entry.tags.map((tag) => (
|
{entry.tags.map((tag: { id: string; name: string; color: string | null }) => (
|
||||||
<span
|
<span
|
||||||
key={tag.id}
|
key={tag.id}
|
||||||
className="px-3 py-1 rounded-full text-xs font-medium bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-300"
|
className="px-3 py-1 rounded-full text-xs font-medium bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-300"
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export default function KnowledgePage() {
|
|||||||
// Filter by tag
|
// Filter by tag
|
||||||
if (selectedTag !== "all") {
|
if (selectedTag !== "all") {
|
||||||
filtered = filtered.filter((entry) =>
|
filtered = filtered.filter((entry) =>
|
||||||
entry.tags.some((tag) => tag.slug === selectedTag)
|
entry.tags.some((tag: { slug: string }) => tag.slug === selectedTag)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ export default function KnowledgePage() {
|
|||||||
(entry) =>
|
(entry) =>
|
||||||
entry.title.toLowerCase().includes(query) ||
|
entry.title.toLowerCase().includes(query) ||
|
||||||
entry.summary?.toLowerCase().includes(query) ||
|
entry.summary?.toLowerCase().includes(query) ||
|
||||||
entry.tags.some((tag) => tag.name.toLowerCase().includes(query))
|
entry.tags.some((tag: { name: string }) => tag.name.toLowerCase().includes(query))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export function EntryCard({ entry }: EntryCardProps) {
|
|||||||
{/* Tags */}
|
{/* Tags */}
|
||||||
{entry.tags && entry.tags.length > 0 && (
|
{entry.tags && entry.tags.length > 0 && (
|
||||||
<div className="flex flex-wrap gap-1.5 mb-3">
|
<div className="flex flex-wrap gap-1.5 mb-3">
|
||||||
{entry.tags.map((tag) => (
|
{entry.tags.map((tag: { id: string; name: string; color: string | null }) => (
|
||||||
<span
|
<span
|
||||||
key={tag.id}
|
key={tag.id}
|
||||||
className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium"
|
className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium"
|
||||||
@@ -79,10 +79,12 @@ export function EntryCard({ entry }: EntryCardProps) {
|
|||||||
{/* Metadata row */}
|
{/* Metadata row */}
|
||||||
<div className="flex flex-wrap items-center gap-3 text-xs text-gray-500">
|
<div className="flex flex-wrap items-center gap-3 text-xs text-gray-500">
|
||||||
{/* Status */}
|
{/* Status */}
|
||||||
<span className={`inline-flex items-center gap-1 px-2 py-1 rounded-full ${statusInfo.className}`}>
|
{statusInfo && (
|
||||||
<span>{statusInfo.icon}</span>
|
<span className={`inline-flex items-center gap-1 px-2 py-1 rounded-full ${statusInfo.className}`}>
|
||||||
<span>{statusInfo.label}</span>
|
<span>{statusInfo.icon}</span>
|
||||||
</span>
|
<span>{statusInfo.label}</span>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Visibility */}
|
{/* Visibility */}
|
||||||
<span className="inline-flex items-center gap-1">
|
<span className="inline-flex items-center gap-1">
|
||||||
|
|||||||
1339
pnpm-lock.yaml
generated
1339
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user