Skip to content

Commit d1ae883

Browse files
authored
Merge pull request #74 from cortex-reply/fix/knowledge-view
fix: applies fixes on knowledge
2 parents e1eb458 + 3e55ed9 commit d1ae883

3 files changed

Lines changed: 125 additions & 117 deletions

File tree

src/components/Foundary/RichText/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,20 @@ const RichTextContent: React.FC<RichTextProps> = ({ setValue, value, name, edita
3535
})
3636
}
3737

38+
useEffect(() => {
39+
editor.setEditable(editable)
40+
}, [editable])
41+
3842
useEffect(() => {
3943
if (value) {
4044
editor.update(() => {
4145
editor.setEditorState(editor.parseEditorState(value as any))
4246
})
4347
}
44-
// editor?.setEditorState(value)
4548
}, [])
4649

4750
return (
48-
<div className="w-full px-10">
51+
<div className="w-full">
4952
<div className=" ">
5053
{editable && <ToolbarPlugin />}
5154
<div className="px-4 my-4 border-l border-[#222222]">
Lines changed: 80 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client'
2+
13
import { useEffect, useState } from 'react'
24
import { DashboardHero } from '../../Heros/DashboardHero/DashboardHero'
35
import type { KnowledgeDocument, KnowledgeContext, Knowledge, TeamKnowledgeContext } from '../types'
@@ -32,6 +34,10 @@ export default function KnowledgeView({
3234
const [isAddKnowledgeModalOpen, setIsAddKnowledgeModalOpen] = useState(false)
3335
const [isAddTeamContextModalOpen, setIsAddTeamContextModalOpen] = useState(false)
3436

37+
useEffect(() => {
38+
if (!activeContext && contexts && contexts.length > 0) setActiveContext(contexts[0])
39+
}, [contexts])
40+
3541
const handleAddKnowledge = (knowledge: Omit<Knowledge, 'id'>) => {
3642
if (onAddKnowledge) {
3743
onAddKnowledge(knowledge)
@@ -46,32 +52,81 @@ export default function KnowledgeView({
4652
setIsAddTeamContextModalOpen(false)
4753
}
4854

49-
const Hero = () => (
50-
<DashboardHero
51-
title="Knowledge"
52-
description="Access, manage, and share all your team knowledge in one place."
53-
gradient="bg-gradient-to-r from-teal-600 via-cyan-600 to-blue-600"
54-
primaryAction={
55-
onAddKnowledge
56-
? {
57-
label: 'Create',
58-
onClick: () => setIsAddKnowledgeModalOpen(true),
59-
}
60-
: undefined
61-
}
62-
secondaryAction={
63-
onAddTeamContext
64-
? {
65-
label: 'Add Context',
66-
onClick: () => setIsAddTeamContextModalOpen(true),
67-
}
68-
: undefined
69-
}
70-
/>
71-
)
55+
return (
56+
<div className="flex flex-col h-full max-h-[calc(100vh-8rem)]">
57+
<div className="px-2 md:px-4 py-4 flex-shrink-0">
58+
<DashboardHero
59+
title="Knowledge"
60+
description="Access, manage, and share all your team knowledge in one place."
61+
gradient="bg-gradient-to-r from-teal-600 via-cyan-600 to-blue-600"
62+
primaryAction={
63+
onAddKnowledge
64+
? {
65+
label: 'Create',
66+
onClick: () => setIsAddKnowledgeModalOpen(true),
67+
}
68+
: undefined
69+
}
70+
secondaryAction={
71+
onAddTeamContext
72+
? {
73+
label: 'Add Context',
74+
onClick: () => setIsAddTeamContextModalOpen(true),
75+
}
76+
: undefined
77+
}
78+
/>
79+
80+
{/* Context Tabs */}
81+
{contexts && contexts.length > 0 && (
82+
<div className="mt-6">
83+
<div className="border-b border-border">
84+
<nav className="-mb-px flex space-x-8 overflow-x-auto">
85+
{contexts.map((context) => (
86+
<button
87+
key={context.id}
88+
onClick={() => setActiveContext(context)}
89+
className={`group inline-flex items-center gap-2 py-3 px-1 border-b-2 font-medium text-sm whitespace-nowrap transition-colors ${
90+
activeContext?.id === context.id
91+
? 'border-primary text-primary'
92+
: 'border-transparent text-muted-foreground hover:text-foreground hover:border-muted-foreground'
93+
}`}
94+
>
95+
{context.icon}
96+
{context.label}
97+
</button>
98+
))}
99+
</nav>
100+
</div>
72101

73-
const Modals = () => {
74-
return (
102+
{/* Active Context Description */}
103+
{activeContext?.description && (
104+
<div className="mt-3 px-1">
105+
<p className="text-sm text-muted-foreground">{activeContext?.description}</p>
106+
</div>
107+
)}
108+
</div>
109+
)}
110+
</div>
111+
112+
{activeContext ? (
113+
<div className="flex-1 min-h-0 px-2 md:px-4 pb-4">
114+
<div className="h-full rounded-3xl border overflow-hidden">
115+
<KnowledgeBrowser
116+
documents={documents}
117+
menuConfig={activeContext?.menuConfig}
118+
onDocumentClick={onDocumentClick}
119+
onDocumentShare={onDocumentShare}
120+
selectedDocumentId={selectedDocumentId}
121+
onDocumentUpdate={onDocumentUpdate}
122+
/>
123+
</div>
124+
</div>
125+
) : (
126+
<div className="flex-1 min-h-0 px-2 md:px-4 pb-4 flex items-center justify-center">
127+
<p className="text-muted-foreground">No contexts available</p>
128+
</div>
129+
)}
75130
<>
76131
<AddTeamContext
77132
isOpen={isAddTeamContextModalOpen}
@@ -86,72 +141,6 @@ export default function KnowledgeView({
86141
knowledgeContexts={contexts}
87142
/>
88143
</>
89-
)
90-
}
91-
92-
// Return early if no contexts are provided
93-
if (!contexts || contexts.length === 0) {
94-
return (
95-
<div className="flex flex-col h-full max-h-[calc(100vh-8rem)]">
96-
<div className="px-2 md:px-4 py-4 flex-shrink-0">
97-
<Hero />
98-
</div>
99-
<div className="flex-1 min-h-0 px-2 md:px-4 pb-4 flex items-center justify-center">
100-
<p className="text-muted-foreground">No contexts available</p>
101-
</div>
102-
<Modals />
103-
</div>
104-
)
105-
}
106-
107-
return (
108-
<div className="flex flex-col h-full max-h-[calc(100vh-8rem)]">
109-
<div className="px-2 md:px-4 py-4 flex-shrink-0">
110-
<Hero />
111-
112-
{/* Context Tabs */}
113-
<div className="mt-6">
114-
<div className="border-b border-border">
115-
<nav className="-mb-px flex space-x-8 overflow-x-auto">
116-
{contexts.map((context) => (
117-
<button
118-
key={context.id}
119-
onClick={() => setActiveContext(context)}
120-
className={`group inline-flex items-center gap-2 py-3 px-1 border-b-2 font-medium text-sm whitespace-nowrap transition-colors ${
121-
activeContext.id === context.id
122-
? 'border-primary text-primary'
123-
: 'border-transparent text-muted-foreground hover:text-foreground hover:border-muted-foreground'
124-
}`}
125-
>
126-
{context.icon}
127-
{context.label}
128-
</button>
129-
))}
130-
</nav>
131-
</div>
132-
133-
{/* Active Context Description */}
134-
{activeContext.description && (
135-
<div className="mt-3 px-1">
136-
<p className="text-sm text-muted-foreground">{activeContext.description}</p>
137-
</div>
138-
)}
139-
</div>
140-
</div>
141-
142-
<div className="flex-1 min-h-0 px-2 md:px-4 pb-4">
143-
<div className="h-full rounded-3xl border overflow-hidden">
144-
<KnowledgeBrowser
145-
documents={documents}
146-
menuConfig={activeContext.menuConfig}
147-
onDocumentClick={onDocumentClick}
148-
onDocumentShare={onDocumentShare}
149-
selectedDocumentId={selectedDocumentId}
150-
onDocumentUpdate={onDocumentUpdate}
151-
/>
152-
</div>
153-
</div>
154-
<Modals />
155144
</div>
156145
)
157146
}

src/components/Foundary/knowledge-browser.tsx

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -282,31 +282,47 @@ export function KnowledgeBrowser({
282282
{/* Menu Content */}
283283
<ScrollArea className="h-[calc(100%-100px)]">
284284
<div className="p-4 space-y-3">
285-
{Object.entries(hierarchy).map(([label, data]) => (
286-
<MenuItem
287-
key={label}
288-
label={label}
289-
documents={data.documents}
290-
children={data.children}
291-
level={0}
292-
onDocumentClick={handleDocumentClick}
293-
selectedDocumentId={selectedDocumentId}
294-
showDocumentCount={menuConfig.showDocumentCount}
295-
/>
296-
))}
285+
{menuConfig.groupBy.length === 0 ? (
286+
<>
287+
<MenuItem
288+
key={'Document'}
289+
label={'Document'}
290+
documents={filteredDocuments}
291+
level={0}
292+
onDocumentClick={handleDocumentClick}
293+
selectedDocumentId={selectedDocumentId}
294+
showDocumentCount={menuConfig.showDocumentCount}
295+
/>
296+
</>
297+
) : (
298+
<>
299+
{Object.entries(hierarchy).map(([label, data]) => (
300+
<MenuItem
301+
key={label}
302+
label={label}
303+
documents={data.documents}
304+
children={data.children}
305+
level={0}
306+
onDocumentClick={handleDocumentClick}
307+
selectedDocumentId={selectedDocumentId}
308+
showDocumentCount={menuConfig.showDocumentCount}
309+
/>
310+
))}
297311

298-
{Object.keys(hierarchy).length === 0 && (
299-
<motion.div
300-
initial={{ opacity: 0 }}
301-
animate={{ opacity: 1 }}
302-
className="text-center text-muted-foreground py-12"
303-
>
304-
<div className="w-16 h-16 mx-auto mb-4 rounded-full bg-muted flex items-center justify-center">
305-
<FileText className="h-8 w-8 text-muted-foreground" />
306-
</div>
307-
<p className="text-sm font-medium">No documents found</p>
308-
<p className="text-xs mt-1">Try adjusting your search terms</p>
309-
</motion.div>
312+
{Object.keys(hierarchy).length === 0 && (
313+
<motion.div
314+
initial={{ opacity: 0 }}
315+
animate={{ opacity: 1 }}
316+
className="text-center text-muted-foreground py-12"
317+
>
318+
<div className="w-16 h-16 mx-auto mb-4 rounded-full bg-muted flex items-center justify-center">
319+
<FileText className="h-8 w-8 text-muted-foreground" />
320+
</div>
321+
<p className="text-sm font-medium">No documents found</p>
322+
<p className="text-xs mt-1">Try adjusting your search terms</p>
323+
</motion.div>
324+
)}
325+
</>
310326
)}
311327
</div>
312328
</ScrollArea>

0 commit comments

Comments
 (0)