Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

feat(ui): wire TanStack query, update UI types, and configure Vite proxy

ZohaibHassan161b277dcdd787
diff --git a/semantica-explorer/src/workspaces/VocabularyWorkspace/ImportDropzone.tsx b/semantica-explorer/src/workspaces/VocabularyWorkspace/ImportDropzone.tsx
index 62746ed6..c7ca25bc 100644
--- a/semantica-explorer/src/workspaces/VocabularyWorkspace/ImportDropzone.tsx
+++ b/semantica-explorer/src/workspaces/VocabularyWorkspace/ImportDropzone.tsx
@@ -2,25 +2,26 @@ import React, { useCallback, useState } from 'react';
import { useDropzone } from 'react-dropzone';
import { UploadCloud, CheckCircle2, Loader2 } from 'lucide-react';
import { useImportVocabulary } from './queries';
+import type { ImportResponse } from './types';
export const ImportDropzone: React.FC = () => {
const [file, setFile] = useState<File | null>(null);
- const [isSuccess, setIsSuccess] = useState(false);
+ const [importResult, setImportResult] = useState<ImportResponse | null>(null);
const importMutation = useImportVocabulary();
const onDrop = useCallback((acceptedFiles: File[]) => {
if (acceptedFiles.length > 0) {
const selectedFile = acceptedFiles[0];
setFile(selectedFile);
- setIsSuccess(false);
+ setImportResult(null);
importMutation.mutate(selectedFile, {
- onSuccess: () => {
- setIsSuccess(true);
+ onSuccess: (data) => {
+ setImportResult(data);
setTimeout(() => {
setFile(null);
- setIsSuccess(false);
- }, 3000);
+ setImportResult(null);
+ }, 4000);
},
onError: (err) => {
console.error("Upload failed:", err);
@@ -60,10 +61,13 @@ export const ImportDropzone: React.FC = () => {
<Loader2 className="animate-spin" size={24} style={{ marginBottom: '8px' }} />
<span style={{ fontSize: '14px' }}>Uploading {file?.name}...</span>
</div>
- ) : isSuccess ? (
+ ) : importResult ? (
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', color: '#10b981' }}>
<CheckCircle2 size={24} style={{ marginBottom: '8px' }} />
- <span style={{ fontSize: '14px' }}>Import Successful!</span>
+ <span style={{ fontSize: '14px', fontWeight: 500 }}>Import Successful!</span>
+ <span style={{ fontSize: '12px', marginTop: '4px', color: '#059669' }}>
+ Added {importResult.nodes_added} concepts & {importResult.edges_added} links.
+ </span>
</div>
) : (
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', color: '#6b7280' }}>
diff --git a/semantica-explorer/src/workspaces/VocabularyWorkspace/VocabularyWorkspace.tsx b/semantica-explorer/src/workspaces/VocabularyWorkspace/VocabularyWorkspace.tsx
index 5e367d3a..18d9d21d 100644
--- a/semantica-explorer/src/workspaces/VocabularyWorkspace/VocabularyWorkspace.tsx
+++ b/semantica-explorer/src/workspaces/VocabularyWorkspace/VocabularyWorkspace.tsx
@@ -42,10 +42,16 @@ export const VocabularyWorkspace: React.FC = () => {
</div>
<div style={{ flex: 1, borderRight: '1px solid #e5e7eb', padding: '16px', backgroundColor: 'white', display: 'flex', flexDirection: 'column' }}>
- <h2 style={{ fontSize: '1.2rem', fontWeight: 'bold', marginBottom: '16px' }}>
+ <h2 style={{ fontSize: '1.2rem', fontWeight: 'bold', marginBottom: selectedScheme?.description ? '4px' : '16px' }}>
{selectedScheme ? selectedScheme.label : "Select a Vocabulary"}
</h2>
+ {selectedScheme?.description && (
+ <p style={{ fontSize: '13px', color: '#6b7280', marginBottom: '16px' }}>
+ {selectedScheme.description}
+ </p>
+ )}
+
{selectedScheme ? (
isLoadingTree ? (
<p style={{ color: '#6b7280', marginTop: '20px' }}>Loading tree...</p>
diff --git a/semantica-explorer/src/workspaces/VocabularyWorkspace/queries.ts b/semantica-explorer/src/workspaces/VocabularyWorkspace/queries.ts
index 5f269abb..1848c0a6 100644
--- a/semantica-explorer/src/workspaces/VocabularyWorkspace/queries.ts
+++ b/semantica-explorer/src/workspaces/VocabularyWorkspace/queries.ts
@@ -1,8 +1,6 @@
// queries.ts
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
-import type { VocabularyScheme, ConceptNode } from './types';
-
-
+import type { VocabularyScheme, ConceptNode, ImportResponse } from './types';
const fetchSchemes = async (): Promise<VocabularyScheme[]> => {
const res = await fetch('/api/vocabulary/schemes');
@@ -16,7 +14,8 @@ const fetchHierarchy = async (schemeUri: string): Promise<ConceptNode[]> => {
return res.json();
};
-const importVocabulary = async (file: File): Promise<void> => {
+// Updated to return the ImportResponse
+const importVocabulary = async (file: File): Promise<ImportResponse> => {
const formData = new FormData();
formData.append('file', file);
const res = await fetch('/api/vocabulary/import', {
@@ -24,10 +23,9 @@ const importVocabulary = async (file: File): Promise<void> => {
body: formData,
});
if (!res.ok) throw new Error('Failed to import vocabulary');
+ return res.json();
};
-
-
export const useVocabularies = () => {
return useQuery({
queryKey: ['vocabularies'],
diff --git a/semantica-explorer/src/workspaces/VocabularyWorkspace/types.ts b/semantica-explorer/src/workspaces/VocabularyWorkspace/types.ts
index 77647f7a..8465795d 100644
--- a/semantica-explorer/src/workspaces/VocabularyWorkspace/types.ts
+++ b/semantica-explorer/src/workspaces/VocabularyWorkspace/types.ts
@@ -3,40 +3,20 @@
export interface VocabularyScheme {
uri: string;
label: string;
+ description?: string;
}
export interface ConceptNode {
uri: string;
pref_label: string;
alt_labels: string[];
- children?: ConceptNode[];
+ children?: ConceptNode[] | null;
}
-// Mock data, will del once backend apis are finished
-export const MOCK_SCHEMES: VocabularyScheme[] = [
- { uri: "http://example.org/medical", label: "Medical Taxonomy" },
- { uri: "http://example.org/finance", label: "Financial Glossary" }
-];
-
-export const MOCK_HIERARCHY: ConceptNode[] = [
- {
- uri: "http://example.org/medical/diseases",
- pref_label: "Diseases",
- alt_labels: ["Illnesses", "Conditions"],
- children: [
- {
- uri: "http://example.org/medical/infectious",
- pref_label: "Infectious Diseases",
- alt_labels: ["Communicable Diseases"],
- children: []
- },
- {
- uri: "http://example.org/medical/genetic",
- pref_label: "Genetic Disorders",
- alt_labels: ["Hereditary Diseases"],
- children: []
- }
- ]
- }
-];
\ No newline at end of file
+export interface ImportResponse {
+ status: string;
+ filename: string;
+ nodes_added: number;
+ edges_added: number;
+}
\ No newline at end of file
diff --git a/semantica-explorer/vite.config.ts b/semantica-explorer/vite.config.ts
index d1203cd0..08d68e69 100644
--- a/semantica-explorer/vite.config.ts
+++ b/semantica-explorer/vite.config.ts
@@ -8,4 +8,12 @@ export default defineConfig({
react(),
babel({ presets: [reactCompilerPreset()] })
],
-})
+ server: {
+ proxy: {
+ '/api': {
+ target: 'http://127.0.0.1:8000',
+ changeOrigin: true,
+ },
+ },
+ },
+})
\ No newline at end of file