-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PKG visualization - frontend #98
base: main
Are you sure you want to change the base?
Changes from all commits
b7f8b7e
eb04780
899debc
9548c33
9fb18f6
fdab204
1742a73
aab37c6
a91614f
a7eeeaa
f0a9bf5
37aa02c
ff155dc
ff2fa8b
f09f232
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import React, { useContext } from "react"; | |
import "./App.css"; | ||
import APIHandler from "./components/APIHandler"; | ||
import LoginForm from "./components/LoginForm"; | ||
import Container from 'react-bootstrap/Container' | ||
import Container from 'react-bootstrap/Container'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: use double quotes as other imports. |
||
import { UserContext } from "./contexts/UserContext"; | ||
|
||
function App() { | ||
|
@@ -13,9 +13,7 @@ function App() { | |
return ( | ||
<Container className="p-3"> | ||
<Container className="p-3 mb-4 bg-light rounded-3"> | ||
<div className="App"> | ||
{content} | ||
</div> | ||
<div className="App">{content}</div> | ||
</Container> | ||
</Container> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,38 @@ | ||
import React, { useContext, useEffect, useState } from "react"; | ||
import axios from "axios"; | ||
import React, { useContext } from "react"; | ||
import { UserContext } from "../contexts/UserContext"; | ||
import Container from "react-bootstrap/Container"; | ||
import { BrowserRouter, Routes, Route } from "react-router-dom"; | ||
import Layout from "./Layout"; | ||
import PKGVisualization from "./PKGVisualization"; | ||
|
||
const APIHandler: React.FC = () => { | ||
const { user } = useContext(UserContext); | ||
// State tracker for service management data. | ||
const [serviceData, setServiceData] = useState(null); | ||
// State tracker for personal facts data. | ||
const [factsData, setFactsData] = useState(null); | ||
// State tracker for PKG exploration data. Data presentation, graphs, etc. | ||
const [exploreData, setExploreData] = useState(null); | ||
|
||
useEffect(() => { | ||
const baseURL = | ||
(window as any)["PKG_API_BASE_URL"] || "http://localhost:5000"; | ||
|
||
axios | ||
.get(`${baseURL}/service`) | ||
.then((response) => setServiceData(response.data)); | ||
axios | ||
.get(`${baseURL}/facts`) | ||
.then((response) => setFactsData(response.data)); | ||
axios | ||
.get(`${baseURL}/explore`) | ||
.then((response) => setExploreData(response.data)); | ||
}, []); | ||
|
||
return ( | ||
<Container> | ||
<h1>Personal Knowledge Graph API</h1> | ||
<div> | ||
<p>Welcome {JSON.stringify(user, null, 2)}</p> | ||
</div> | ||
<div> | ||
<h2>Service Management Data</h2> | ||
<pre>{JSON.stringify(serviceData, null, 2)}</pre> | ||
</div> | ||
<div> | ||
<h2>Personal Facts Data</h2> | ||
<pre>{JSON.stringify(factsData, null, 2)}</pre> | ||
</div> | ||
<div> | ||
<h2>PKG Exploration Data</h2> | ||
<pre>{JSON.stringify(exploreData, null, 2)}</pre> | ||
</div> | ||
<h1>Personal Knowledge Graph</h1> | ||
|
||
<BrowserRouter> | ||
<Routes> | ||
<Route path="/" element={<Layout />}> | ||
<Route | ||
index | ||
element={ | ||
<div> | ||
<div>Welcome {user?.username}.</div> | ||
</div> | ||
} | ||
/> | ||
<Route path="service" element={<div>Service Management</div>} /> | ||
<Route path="population" element={<div>Population form</div>} /> | ||
<Route | ||
path="preferences" | ||
element={<div>Personal Preferences</div>} | ||
/> | ||
<Route path="explore" element={<PKGVisualization />} /> | ||
Comment on lines
+26
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to remove these, they can be added in a PR related to the implementatio of their view. |
||
</Route> | ||
</Routes> | ||
</BrowserRouter> | ||
</Container> | ||
); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Layout component for the application includes a navigation bar and content | ||
// of the current tab. | ||
import { Outlet, Link } from "react-router-dom"; | ||
import Nav from "react-bootstrap/Nav"; | ||
import { useState } from "react"; | ||
|
||
const Layout = () => { | ||
const [activeKey, setActiveKey] = useState("/"); | ||
|
||
const handleSelect = (eventKey: string | null) => { | ||
if (eventKey !== null) { | ||
setActiveKey(eventKey); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Nav variant="underline" activeKey={activeKey} onSelect={handleSelect}> | ||
<Nav.Item> | ||
<Nav.Link eventKey="/" as={Link} to="/"> | ||
Home | ||
</Nav.Link> | ||
</Nav.Item> | ||
<Nav.Item> | ||
<Nav.Link eventKey="/service" as={Link} to="/service"> | ||
Service Management | ||
</Nav.Link> | ||
</Nav.Item> | ||
<Nav.Item> | ||
<Nav.Link eventKey="/population" as={Link} to="/population"> | ||
Populate PKG | ||
</Nav.Link> | ||
</Nav.Item> | ||
Comment on lines
+24
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as before, we may want to include these routes in related PRs. |
||
<Nav.Item> | ||
<Nav.Link eventKey="/explore" as={Link} to="/explore"> | ||
Explore PKG | ||
</Nav.Link> | ||
</Nav.Item> | ||
</Nav> | ||
|
||
<br /> | ||
<Outlet /> | ||
</> | ||
); | ||
}; | ||
|
||
export default Layout; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Natural language to PKG component | ||
|
||
import { Container } from "react-bootstrap"; | ||
import { UserContext } from "../contexts/UserContext"; | ||
import { useContext, useEffect, useState } from "react"; | ||
import axios from "axios"; | ||
import QueryForm from "./QueryForm"; | ||
import Button from "react-bootstrap/Button"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: remove unused import. |
||
|
||
const PKGVisualization = () => { | ||
const { user } = useContext(UserContext); | ||
const [error, setError] = useState(""); | ||
const [image_path, setImagePath] = useState(""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: usually in javascript, the variable name uses a capital letter instead of |
||
const [query_info, setQueryInfo] = useState(""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: same comment as for |
||
const [result, setResult] = useState(""); | ||
const baseURL = | ||
(window as any)["PKG_API_BASE_URL"] || "http://127.0.0.1:5000"; | ||
|
||
useEffect(() => { | ||
getImage(); | ||
}, []); | ||
|
||
const getImage = () => { | ||
axios | ||
.get(`${baseURL}/explore`, { | ||
params: { | ||
owner_username: user?.username, | ||
owner_uri: user?.uri, | ||
}, | ||
responseType: "blob", | ||
}) | ||
.then((response) => { | ||
setError(""); | ||
const imageURL = URL.createObjectURL( | ||
new Blob([response.data], { | ||
type: "image/png", | ||
}) | ||
); | ||
setImagePath(imageURL); | ||
}) | ||
.catch((error) => { | ||
setError(error.message); | ||
throw error; | ||
}); | ||
}; | ||
|
||
const executeQuery = (query: string) => { | ||
return axios | ||
.post(`${baseURL}/explore`, { | ||
sparql_query: query, | ||
owner_username: user?.username, | ||
owner_uri: user?.uri, | ||
}) | ||
.then((response) => { | ||
setError(""); | ||
console.log(response.data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this can be removed. |
||
setQueryInfo(response.data.message); | ||
setResult(response.data.result); | ||
}) | ||
.catch((error) => { | ||
setError(error.message); | ||
throw error; | ||
}); | ||
}; | ||
|
||
return ( | ||
<Container> | ||
<div> | ||
<b>Here you can execute your own SPARQL queries to manage your PKG.</b> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be queries to select statements within the PKG? From my understanding only SELECT queries are accepted. |
||
</div> | ||
<QueryForm handleSubmit={executeQuery} error={error} /> | ||
<div>Query execution status: {query_info}</div> | ||
<div>Query execution result: {result}</div> | ||
<div> | ||
<b>This is your current PKG:</b> | ||
</div> | ||
{/* <div>[Only for testing] Local path to the image: {image_path}</div> */} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this can be removed. |
||
<img src={image_path} alt="PKG" style={{ width: "100%" }} /> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default PKGVisualization; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: missing dot at the end.
Can you create a follow-up issue and link it here?