ishaq101 commited on
Commit
d808371
Β·
1 Parent(s): 9f6e84b

[KM-476] [DED][FE] Knowledge (Document and DB) Flow Page

Browse files
src/app/components/KnowledgeManagement.tsx CHANGED
@@ -16,6 +16,7 @@ import {
16
  uploadDocument,
17
  processDocument,
18
  deleteDocument,
 
19
  getDatabaseClientTypes,
20
  connectDatabase,
21
  getDatabaseClients,
@@ -23,6 +24,7 @@ import {
23
  ingestDatabaseClient,
24
  type ApiDocument,
25
  type DocumentStatus,
 
26
  type DbType,
27
  type DbTypeInfo,
28
  type DatabaseClient,
@@ -55,6 +57,7 @@ export default function KnowledgeManagement({
55
  onClose,
56
  }: KnowledgeManagementProps) {
57
  // ── Document state ──────────────────────────────────────────────────────────
 
58
  const [documents, setDocuments] = useState<ApiDocument[]>([]);
59
  const [loadingDocs, setLoadingDocs] = useState(false);
60
  const [docsError, setDocsError] = useState<string | null>(null);
@@ -85,8 +88,20 @@ export default function KnowledgeManagement({
85
  if (!userId) return;
86
  loadDocuments(userId);
87
  loadDbData(userId);
 
 
 
 
 
 
 
 
 
88
  }, [open]);
89
 
 
 
 
90
  const loadDbData = async (userId: string) => {
91
  setLoadingDbTypes(true);
92
  try {
@@ -387,12 +402,12 @@ export default function KnowledgeManagement({
387
  <>Drop files, or <span className="text-[#FF8F00]">browse</span></>
388
  )}
389
  </p>
390
- <p className="text-xs text-slate-400 mt-0.5">PDF, CSV, XLSX</p>
391
  </div>
392
  <input
393
  id="file-upload"
394
  type="file"
395
- accept=".pdf,.csv,.xlsx"
396
  multiple
397
  onChange={handleFileUpload}
398
  className="hidden"
@@ -721,7 +736,7 @@ export default function KnowledgeManagement({
721
  <div className="px-5 py-3 border-t border-slate-100">
722
  <p className="text-[10px] text-slate-300 text-center">
723
  {view === "main"
724
- ? "Supported formats: PDF, CSV, XLSX"
725
  : view === "db-select"
726
  ? "More integrations coming soon"
727
  : "Credentials are encrypted at rest"}
 
16
  uploadDocument,
17
  processDocument,
18
  deleteDocument,
19
+ getDocumentTypes,
20
  getDatabaseClientTypes,
21
  connectDatabase,
22
  getDatabaseClients,
 
24
  ingestDatabaseClient,
25
  type ApiDocument,
26
  type DocumentStatus,
27
+ type DocTypeInfo,
28
  type DbType,
29
  type DbTypeInfo,
30
  type DatabaseClient,
 
57
  onClose,
58
  }: KnowledgeManagementProps) {
59
  // ── Document state ──────────────────────────────────────────────────────────
60
+ const [docTypes, setDocTypes] = useState<DocTypeInfo[]>([]);
61
  const [documents, setDocuments] = useState<ApiDocument[]>([]);
62
  const [loadingDocs, setLoadingDocs] = useState(false);
63
  const [docsError, setDocsError] = useState<string | null>(null);
 
88
  if (!userId) return;
89
  loadDocuments(userId);
90
  loadDbData(userId);
91
+ getDocumentTypes()
92
+ .then((types) => setDocTypes(types.filter((t) => t.status === "active")))
93
+ .catch(() =>
94
+ setDocTypes([
95
+ { doc_type: "pdf", max_size: 10, status: "active", message: null },
96
+ { doc_type: "csv", max_size: 10, status: "active", message: null },
97
+ { doc_type: "xlsx", max_size: 10, status: "active", message: null },
98
+ ])
99
+ );
100
  }, [open]);
101
 
102
+ const acceptedExtensions = docTypes.map((t) => `.${t.doc_type}`).join(",");
103
+ const supportedFormatsText = docTypes.map((t) => t.doc_type.toUpperCase()).join(", ");
104
+
105
  const loadDbData = async (userId: string) => {
106
  setLoadingDbTypes(true);
107
  try {
 
402
  <>Drop files, or <span className="text-[#FF8F00]">browse</span></>
403
  )}
404
  </p>
405
+ <p className="text-xs text-slate-400 mt-0.5">{supportedFormatsText}</p>
406
  </div>
407
  <input
408
  id="file-upload"
409
  type="file"
410
+ accept={acceptedExtensions}
411
  multiple
412
  onChange={handleFileUpload}
413
  className="hidden"
 
736
  <div className="px-5 py-3 border-t border-slate-100">
737
  <p className="text-[10px] text-slate-300 text-center">
738
  {view === "main"
739
+ ? `Supported formats: ${supportedFormatsText}`
740
  : view === "db-select"
741
  ? "More integrations coming soon"
742
  : "Credentials are encrypted at rest"}
src/services/api.ts CHANGED
@@ -65,6 +65,13 @@ export interface UploadDocumentResponse {
65
  data: { id: string; filename: string; status: DocumentStatus };
66
  }
67
 
 
 
 
 
 
 
 
68
  // ─── Base Client ──────────────────────────────────────────────────────────────
69
 
70
  const BASE_URL = ((import.meta as unknown as { env: Record<string, string> }).env.VITE_API_BASE_URL) ?? "";
@@ -151,6 +158,11 @@ export const deleteDocument = (userId: string, documentId: string) =>
151
  { method: "DELETE" }
152
  );
153
 
 
 
 
 
 
154
  // ─── Database Clients ─────────────────────────────────────────────────────────
155
 
156
  export type DbType = "postgres" | "mysql" | "sqlserver" | "supabase" | "bigquery" | "snowflake";
 
65
  data: { id: string; filename: string; status: DocumentStatus };
66
  }
67
 
68
+ export interface DocTypeInfo {
69
+ doc_type: string;
70
+ max_size: number;
71
+ status: "active" | "inactive";
72
+ message: string | null;
73
+ }
74
+
75
  // ─── Base Client ──────────────────────────────────────────────────────────────
76
 
77
  const BASE_URL = ((import.meta as unknown as { env: Record<string, string> }).env.VITE_API_BASE_URL) ?? "";
 
158
  { method: "DELETE" }
159
  );
160
 
161
+ export const getDocumentTypes = (): Promise<DocTypeInfo[]> =>
162
+ request<{ status: string; data: DocTypeInfo[] }>("/api/v1/documents/doctypes").then(
163
+ (res) => res.data
164
+ );
165
+
166
  // ─── Database Clients ─────────────────────────────────────────────────────────
167
 
168
  export type DbType = "postgres" | "mysql" | "sqlserver" | "supabase" | "bigquery" | "snowflake";