fix: Ensure Edit Crawler Configuration loads initial data properly

Fixed bug where edit configuration dialog wasn't showing the existing crawl config:

1. **Enhanced data loading in EditCrawlConfigDialog**:
   - Check for data at both top-level and metadata level
   - Properly handle max_depth, tags, and crawl_config fields
   - Ensure crawl_config has the right shape with all arrays initialized
   - Reset form state when dialog opens without data

2. **Improved type definitions**:
   - Added crawl_config and max_depth to KnowledgeItemMetadata interface
   - Added optional fields to KnowledgeItem for top-level storage
   - Added index signature to allow additional untyped fields from backend

3. **Better state management**:
   - Reset form when dialog opens to prevent stale data
   - Only load data when both item exists and dialog is open
   - Initialize empty arrays for all crawl_config fields

This ensures that when editing an existing knowledge item:
- All original crawl settings are properly loaded
- Advanced configuration shows the domain filters and patterns
- Form is pre-filled with the exact configuration used for initial crawl
This commit is contained in:
leex279
2025-09-22 13:58:13 +02:00
parent dbe5855d84
commit 2dbf6c32b9
2 changed files with 40 additions and 10 deletions

View File

@@ -39,22 +39,45 @@ export const EditCrawlConfigDialog: React.FC<EditCrawlConfigDialogProps> = ({
const [tags, setTags] = useState<string[]>([]);
const [crawlConfig, setCrawlConfig] = useState<CrawlConfig>({});
// Reset form when dialog opens
useEffect(() => {
if (open && !item) {
// Reset to defaults while loading
setUrl("");
setKnowledgeType("technical");
setMaxDepth("2");
setTags([]);
setCrawlConfig({});
}
}, [open, item]);
// Load existing configuration when item loads
useEffect(() => {
if (item) {
if (item && open) {
setUrl(item.url || "");
setKnowledgeType(item.knowledge_type || "technical");
// Access max_depth from metadata as any since it's not typed
const metadata = item.metadata as any;
setMaxDepth(metadata?.max_depth?.toString() || "2");
setTags(metadata?.tags || []);
setKnowledgeType(item.knowledge_type || item.metadata?.knowledge_type || "technical");
// Max depth might be at top level or in metadata
const depthValue = item.max_depth || item.metadata?.max_depth || 2;
setMaxDepth(depthValue.toString());
// Tags could be at top level or in metadata
const tagsValue = item.tags || item.metadata?.tags || [];
setTags(Array.isArray(tagsValue) ? tagsValue : []);
// Load existing crawl config if available
if (metadata?.crawl_config) {
setCrawlConfig(metadata.crawl_config);
}
// It could be at top level or nested in metadata
const configValue = item.crawl_config || item.metadata?.crawl_config || {};
// Ensure the config has the right shape
setCrawlConfig({
allowed_domains: configValue.allowed_domains || [],
excluded_domains: configValue.excluded_domains || [],
include_patterns: configValue.include_patterns || [],
exclude_patterns: configValue.exclude_patterns || []
});
}
}, [item]);
}, [item, open]);
const handleSave = async () => {
if (!url) {

View File

@@ -21,6 +21,9 @@ export interface KnowledgeItemMetadata {
original_url?: string;
document_count?: number; // Number of documents in this knowledge item
code_examples_count?: number; // Number of code examples found
max_depth?: number; // Crawl depth configuration
crawl_config?: CrawlConfig; // Advanced crawl configuration
[key: string]: any; // Allow additional untyped fields from backend
}
export interface KnowledgeItem {
@@ -36,6 +39,10 @@ export interface KnowledgeItem {
metadata: KnowledgeItemMetadata;
created_at: string;
updated_at: string;
// Additional fields that might be at top level
max_depth?: number;
tags?: string[];
crawl_config?: CrawlConfig;
}
export interface CodeExampleMetadata {