Skip to content

Commit 0b6a4f4

Browse files
committed
feat: update document editing
1 parent 05f9c14 commit 0b6a4f4

4 files changed

Lines changed: 670 additions & 85 deletions

File tree

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
# Document Edit Component
2+
3+
The `DocumentEdit` component provides a comprehensive editing interface for knowledge documents with enhanced metadata management and intelligent suggestions.
4+
5+
## Key Features
6+
7+
### 🏷️ Smart Metadata Management
8+
- **Editable Key-Value Pairs**: Add, edit, and remove metadata fields dynamically
9+
- **Context-based Suggestions**: Field names suggested from knowledge contexts and existing documents
10+
- **Value Autocomplete**: Common values suggested for known metadata fields
11+
- **Visual Guidance**: Shows which fields are commonly used for organization
12+
13+
### 🔗 Knowledge Context Integration
14+
- **Context-aware Fields**: Suggests metadata keys based on knowledge context grouping rules
15+
- **Organizational Alignment**: Helps maintain consistency with existing document organization
16+
- **Cross-document Learning**: Learns from existing documents to suggest appropriate values
17+
18+
### 📝 Enhanced Editing Experience
19+
- **Streamlined Interface**: Clean, intuitive design focused on content creation
20+
- **Rich Metadata**: Support for flexible metadata schemas
21+
- **Format Support**: Works with markdown, MDX, rich text, and plain text formats
22+
- **Real-time Validation**: Immediate feedback on changes
23+
24+
## Usage
25+
26+
### Basic Usage
27+
28+
```tsx
29+
import { DocumentEdit } from './document-edit'
30+
31+
const document = {
32+
id: '1',
33+
title: 'My Document',
34+
description: 'Document description',
35+
format: 'markdown',
36+
metadata: { category: 'Development' },
37+
content: '# Hello World',
38+
createdAt: new Date()
39+
}
40+
41+
<DocumentEdit
42+
document={document}
43+
onSave={(updatedDocument) => console.log('Saved:', updatedDocument)}
44+
onCancel={() => console.log('Cancelled')}
45+
/>
46+
```
47+
48+
### With Knowledge Context Support
49+
50+
```tsx
51+
import { DocumentEdit } from './document-edit'
52+
53+
const knowledgeContexts = [
54+
{
55+
id: 'development',
56+
label: 'Development Docs',
57+
menuConfig: {
58+
groupBy: ['category', 'team', 'difficulty'],
59+
sortBy: 'updatedAt'
60+
}
61+
}
62+
]
63+
64+
const availableDocuments = [
65+
// ... existing documents for learning metadata patterns
66+
]
67+
68+
<DocumentEdit
69+
document={document}
70+
onSave={handleSave}
71+
onCancel={handleCancel}
72+
availableDocuments={availableDocuments}
73+
knowledgeContexts={knowledgeContexts}
74+
/>
75+
```
76+
77+
## Props
78+
79+
### DocumentEditProps
80+
81+
| Prop | Type | Default | Description |
82+
|------|------|---------|-------------|
83+
| `document` | `KnowledgeDocument` | - | The document to edit |
84+
| `onSave` | `(document: KnowledgeDocument) => void` | - | Callback when document is saved |
85+
| `onCancel` | `() => void` | - | Callback when editing is cancelled |
86+
| `availableDocuments` | `KnowledgeDocument[]` | `[]` | Existing documents for metadata suggestions |
87+
| `knowledgeContexts` | `KnowledgeContext[]` | `[]` | Knowledge contexts for field suggestions |
88+
89+
## Metadata Features
90+
91+
### Suggested Fields
92+
93+
The component automatically suggests metadata field names based on:
94+
95+
1. **Knowledge Context Grouping**: Fields used in `menuConfig.groupBy` arrays
96+
2. **Existing Documents**: Fields found in `metadata` of available documents
97+
3. **Common Patterns**: Frequently used organizational fields
98+
99+
Common suggested fields include:
100+
- `category` - Document category (Development, Design, Management, etc.)
101+
- `type` - Document type (Guide, Reference, Tutorial, etc.)
102+
- `team` - Responsible team (Frontend, Backend, DevOps, etc.)
103+
- `difficulty` - Complexity level (Beginner, Intermediate, Advanced)
104+
- `project` - Associated project name
105+
- `priority` - Priority level (High, Medium, Low)
106+
107+
### Value Suggestions
108+
109+
When editing metadata values:
110+
- **Dropdown Selection**: Shows common values for known fields
111+
- **Custom Input**: Option to enter custom values
112+
- **Learning System**: Builds suggestions from existing document metadata
113+
114+
### Visual Feedback
115+
116+
- **Context Hints**: Shows which fields come from knowledge contexts
117+
- **Value Previews**: Displays common values for each field
118+
- **Empty State**: Helpful guidance when no metadata exists yet
119+
120+
## Integration Examples
121+
122+
### With Document Browser
123+
124+
```tsx
125+
function KnowledgeManager() {
126+
const [selectedDocument, setSelectedDocument] = useState(null)
127+
const [isEditing, setIsEditing] = useState(false)
128+
129+
return (
130+
<div className="flex h-screen">
131+
<KnowledgeBrowser
132+
documents={documents}
133+
contexts={knowledgeContexts}
134+
onDocumentClick={setSelectedDocument}
135+
/>
136+
137+
{isEditing ? (
138+
<DocumentEdit
139+
document={selectedDocument}
140+
availableDocuments={documents}
141+
knowledgeContexts={knowledgeContexts}
142+
onSave={(doc) => {
143+
updateDocument(doc)
144+
setIsEditing(false)
145+
}}
146+
onCancel={() => setIsEditing(false)}
147+
/>
148+
) : (
149+
<DocumentPreview
150+
document={selectedDocument}
151+
onEdit={() => setIsEditing(true)}
152+
/>
153+
)}
154+
</div>
155+
)
156+
}
157+
```
158+
159+
### Custom Metadata Schema
160+
161+
```tsx
162+
// Define your organization's metadata schema
163+
const metadataSchema = {
164+
category: ['Development', 'Design', 'Management', 'Operations'],
165+
priority: ['Critical', 'High', 'Medium', 'Low'],
166+
team: ['Frontend', 'Backend', 'DevOps', 'Design', 'Product'],
167+
status: ['Draft', 'Review', 'Approved', 'Published', 'Archived']
168+
}
169+
170+
// Use with pre-populated documents that follow your schema
171+
const documentsWithSchema = documents.map(doc => ({
172+
...doc,
173+
metadata: {
174+
...doc.metadata,
175+
category: doc.metadata?.category || 'Development',
176+
priority: doc.metadata?.priority || 'Medium'
177+
}
178+
}))
179+
```
180+
181+
## Best Practices
182+
183+
### Metadata Consistency
184+
1. **Define Schema Early**: Establish common metadata fields for your organization
185+
2. **Use Knowledge Contexts**: Align metadata with how documents are organized
186+
3. **Provide Examples**: Include sample documents with good metadata
187+
4. **Regular Review**: Periodically review and standardize metadata usage
188+
189+
### User Experience
190+
1. **Progressive Enhancement**: Start with basic fields, add more as needed
191+
2. **Clear Labels**: Use descriptive field names that users understand
192+
3. **Helpful Defaults**: Pre-populate common fields when possible
193+
4. **Validation**: Provide feedback for required or invalid fields
194+
195+
### Performance
196+
1. **Lazy Loading**: Load available documents only when needed
197+
2. **Debounced Suggestions**: Avoid excessive API calls for suggestions
198+
3. **Efficient Filtering**: Optimize metadata value lookups
199+
4. **Caching**: Cache frequently used metadata patterns
200+
201+
## Migration from Tags
202+
203+
If migrating from a tag-based system:
204+
205+
```tsx
206+
// Convert tags to metadata
207+
function convertTagsToMetadata(document) {
208+
const metadata = { ...document.metadata }
209+
210+
if (document.tags) {
211+
// Convert common tag patterns to structured metadata
212+
document.tags.forEach(tag => {
213+
if (['beginner', 'intermediate', 'advanced'].includes(tag)) {
214+
metadata.difficulty = tag
215+
} else if (['frontend', 'backend', 'devops'].includes(tag)) {
216+
metadata.team = tag
217+
} else if (['guide', 'reference', 'tutorial'].includes(tag)) {
218+
metadata.type = tag
219+
}
220+
// Add remaining tags as topics or keywords array
221+
else {
222+
metadata.topics = metadata.topics || []
223+
metadata.topics.push(tag)
224+
}
225+
})
226+
}
227+
228+
return { ...document, metadata }
229+
}
230+
```
231+
232+
## Related Components
233+
234+
- **DocumentPreview**: For viewing documents with metadata display
235+
- **KnowledgeBrowser**: For browsing documents organized by metadata
236+
- **KnowledgeSearch**: For searching documents by metadata fields
237+
- **KnowledgeView**: For complete knowledge management interfaces

0 commit comments

Comments
 (0)