Skip to content
Snippets Groups Projects
Commit eae4e6d3 authored by Leonardo Christino's avatar Leonardo Christino
Browse files

feat(query): wip adding new query logic

parent 022500ec
No related branches found
No related tags found
1 merge request!35feat(querybuilder): full rework of querybuilder
Showing
with 176 additions and 239 deletions
...@@ -7,6 +7,8 @@ indent_style = space ...@@ -7,6 +7,8 @@ indent_style = space
indent_size = 2 indent_size = 2
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true trim_trailing_whitespace = true
max_line_length = 140
end_of_line = lf
[*.md] [*.md]
max_line_length = off max_line_length = off
......
...@@ -74,4 +74,5 @@ debug.log ...@@ -74,4 +74,5 @@ debug.log
Thumbs.db Thumbs.db
# Certs # Certs
certs/*.pem certs/*.pem
\ No newline at end of file node_modules
\ No newline at end of file
module.exports = { module.exports = {
root: true, root: true,
extends: ["custom"], extends: ['custom'],
}; };
module.exports = { module.exports = {
reactStrictMode: true, reactStrictMode: true,
transpilePackages: ["ui"], transpilePackages: ['ui'],
}; };
import { Button } from "ui"; import { Button } from 'ui';
export default function Docs() { export default function Docs() {
return ( return (
......
interface ImportMeta { interface ImportMeta {
env: { env: {
VITE_BACKEND_URL: string; VITE_BACKEND_URL: string;
VITE_STAGING: string; VITE_STAGING: string;
VITE_KEYCLOAK_URL: string; VITE_KEYCLOAK_URL: string;
VITE_KEYCLOAK_REALM: string; VITE_KEYCLOAK_REALM: string;
VITE_KEYCLOAK_CLIENT: string; VITE_KEYCLOAK_CLIENT: string;
} };
} }
\ No newline at end of file
/* Your styles goes here. */ /* Your styles goes here. */
.mainContainer { .mainContainer {
padding: 2.5rem; padding: 0.8rem;
gap: 1rem; gap: 0.7rem;
height: 100%; height: 100%;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
...@@ -11,10 +11,13 @@ ...@@ -11,10 +11,13 @@
max-width: 33%; max-width: 33%;
height: 100%; height: 100%;
max-height: 100%; max-height: 100%;
h1 {
margin-left: 0.8em;
}
} }
.panel { .panel {
display: flex; display: flex;
gap: 1rem; gap: 0.7rem;
width: 100%; width: 100%;
max-width: 67%; max-width: 67%;
flex-direction: column; flex-direction: column;
...@@ -24,14 +27,18 @@ ...@@ -24,14 +27,18 @@
height: 100%; height: 100%;
max-height: 70%; max-height: 70%;
overflow-y: clip; overflow-y: clip;
border-radius: 8px;
h1 { h1 {
margin-left: 2em; margin-left: 0.8em;
} }
} }
.queryBuilder { .queryBuilder {
height: 100%; height: 100%;
max-height: 30%; max-height: 30%;
overflow-y: clip;
h1 {
margin-top: 0.25em;
margin-left: 0.8em;
}
} }
} }
} }
...@@ -7,19 +7,13 @@ import { ...@@ -7,19 +7,13 @@ import {
useQuerybuilderGraph, useQuerybuilderGraph,
useQuerybuilderHash, useQuerybuilderHash,
useSchemaAPI, useSchemaAPI,
useSessionCache useSessionCache,
} from '@graphpolaris/shared/lib/data-access'; } from '@graphpolaris/shared/lib/data-access';
import { WebSocketHandler } from '@graphpolaris/shared/lib/data-access/socket'; import { WebSocketHandler } from '@graphpolaris/shared/lib/data-access/socket';
import Broker from '@graphpolaris/shared/lib/data-access/socket/broker'; import Broker from '@graphpolaris/shared/lib/data-access/socket/broker';
import { import { assignNewGraphQueryResult, useAppDispatch } from '@graphpolaris/shared/lib/data-access/store';
assignNewGraphQueryResult,
useAppDispatch,
} from '@graphpolaris/shared/lib/data-access/store';
import { GraphQueryResultFromBackend, resetGraphQueryResults } from '@graphpolaris/shared/lib/data-access/store/graphQueryResultSlice'; import { GraphQueryResultFromBackend, resetGraphQueryResults } from '@graphpolaris/shared/lib/data-access/store/graphQueryResultSlice';
import { import { Query2BackendQuery, QueryBuilder } from '@graphpolaris/shared/lib/querybuilder';
Query2BackendQuery,
QueryBuilder,
} from '@graphpolaris/shared/lib/querybuilder';
import { Schema } from '@graphpolaris/shared/lib/schema/panel'; import { Schema } from '@graphpolaris/shared/lib/schema/panel';
import { useEffect, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
import { Navbar } from '../components/navbar/navbar'; import { Navbar } from '../components/navbar/navbar';
...@@ -36,7 +30,7 @@ export interface App { ...@@ -36,7 +30,7 @@ export interface App {
export function App(props: App) { export function App(props: App) {
const isLogin = useAuth(); const isLogin = useAuth();
const auth = useAuthorizationCache() const auth = useAuthorizationCache();
const api = useDatabaseAPI(domain); const api = useDatabaseAPI(domain);
const api_schema = useSchemaAPI(domain); const api_schema = useSchemaAPI(domain);
const api_query = useQueryAPI(domain); const api_query = useQueryAPI(domain);
...@@ -54,16 +48,9 @@ export function App(props: App) { ...@@ -54,16 +48,9 @@ export function App(props: App) {
useEffect(() => { useEffect(() => {
// Default // Default
Broker.instance().subscribe( Broker.instance().subscribe((data: SchemaFromBackend) => dispatch(readInSchemaFromBackend(data)), 'schema_result');
(data: SchemaFromBackend) => dispatch(readInSchemaFromBackend(data)),
'schema_result'
);
Broker.instance().subscribe( Broker.instance().subscribe((data: GraphQueryResultFromBackend) => dispatch(assignNewGraphQueryResult(data)), 'query_result');
(data: GraphQueryResultFromBackend) =>
dispatch(assignNewGraphQueryResult(data)),
'query_result'
);
return () => { return () => {
Broker.instance().unSubscribeAll('schema_result'); Broker.instance().unSubscribeAll('schema_result');
...@@ -83,32 +70,28 @@ export function App(props: App) { ...@@ -83,32 +70,28 @@ export function App(props: App) {
useEffect(() => { useEffect(() => {
// Newly (un)authorized // Newly (un)authorized
if (auth.authorized) { if (auth.authorized) {
console.info("App is authorized; Getting Datatabases", isLogin); console.info('App is authorized; Getting Databases', isLogin);
api.GetAllDatabases({ updateSessionCache: true }); api.GetAllDatabases({ updateSessionCache: true });
setAuthCheck(true); setAuthCheck(true);
} else { } else {
dispatch(logout()) dispatch(logout());
} }
}, [isLogin]); }, [isLogin]);
useEffect(() => { useEffect(() => {
// New query // New query
if (session?.currentDatabase && query) { if (session?.currentDatabase && query) {
console.log('New query', query);
if (query.edges.length === 0) { if (query.edges.length === 0) {
dispatch(resetGraphQueryResults()); dispatch(resetGraphQueryResults());
} else } else api_query.execute(Query2BackendQuery(session.currentDatabase, query));
api_query.execute(Query2BackendQuery(session.currentDatabase, query));
} }
}, [queryHash]); }, [queryHash]);
return ( return (
<div className="h-screen w-screen"> <div className="h-screen w-screen">
<div <div className={'flex h-screen w-screen overflow-hidden ' + (!auth.authorized ? 'blur-sm pointer-events-none ' : '')}>
className={
'flex h-screen w-screen overflow-hidden ' +
(!auth.authorized ? 'blur-sm pointer-events-none ' : '')
}
>
<div className="h-full relative flex flex-col flex-1 overflow-y-auto overflow-x-hidden"> <div className="h-full relative flex flex-col flex-1 overflow-y-auto overflow-x-hidden">
<div className="h-fit flex-grow-0"> <div className="h-fit flex-grow-0">
<Navbar /> <Navbar />
...@@ -121,7 +104,9 @@ export function App(props: App) { ...@@ -121,7 +104,9 @@ export function App(props: App) {
</div> </div>
<div className={styles.panel}> <div className={styles.panel}>
<div className={styles.visualization}> <div className={styles.visualization}>
<VisualizationPanel /> <Panel content="Visualization Panel">
<VisualizationPanel />
</Panel>
</div> </div>
<div className={styles.queryBuilder}> <div className={styles.queryBuilder}>
<Panel content="Query Panel"> <Panel content="Query Panel">
......
import { RawJSONVis, NodeLinkVis } from '@graphpolaris/shared/lib/vis'; import { RawJSONVis, NodeLinkVis, PaohVis, SemanticSubstrates } from '@graphpolaris/shared/lib/vis';
import Panel from '../../components/panels/panel'; import Panel from '../../components/panels/panel';
import { import { assignNewGraphQueryResult, useAppDispatch } from '@graphpolaris/shared/lib/data-access';
assignNewGraphQueryResult,
useAppDispatch,
} from '@graphpolaris/shared/lib/data-access';
export const VisualizationPanel = () => { export const VisualizationPanel = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
return ( return (
<Panel content="Visualization Panel"> <div>
{/* <div> {/* <div>
<button <button
onClick={() => onClick={() =>
...@@ -36,12 +33,24 @@ export const VisualizationPanel = () => { ...@@ -36,12 +33,24 @@ export const VisualizationPanel = () => {
Remove mock result Remove mock result
</button> </button>
</div> */} </div> */}
<div className="h-[48rem] overflow-y-auto">
{/* width: '83%',
height: '95vh', */}
<div className="h-[60vh] overflow-y-auto">
{/* <div className="h-full overflow-y-auto"> */}
{/* <RawJSONVis /> */}
{/* <PaohVis
rowHeight={30}
hyperedgeColumnWidth={30}
gapBetweenRanges={3}
/> */}
{/* <RawJSONVis /> */}
{/* <RawJSONVis /> */} {/* <RawJSONVis /> */}
<NodeLinkVis /> <NodeLinkVis />
{/* <SemanticSubstrates /> */}
</div> </div>
{/* <SemanticSubstrates /> */}
{/* <div /> */} {/* <div /> */}
</Panel> </div>
); );
}; };
...@@ -11,11 +11,7 @@ ...@@ -11,11 +11,7 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { TextField, Button, NativeSelect } from '@mui/material'; import { TextField, Button, NativeSelect } from '@mui/material';
import styles from './add-database-form.module.scss'; import styles from './add-database-form.module.scss';
import { import { AddDatabaseRequest, DatabaseType, databaseNameMapping } from '@graphpolaris/shared/lib/data-access';
AddDatabaseRequest,
DatabaseType,
databaseNameMapping,
} from '@graphpolaris/shared/lib/data-access';
/** AddDatabaseFormProps is an interface containing the AuthViewModel. */ /** AddDatabaseFormProps is an interface containing the AuthViewModel. */
export interface AddDatabaseFormProps { export interface AddDatabaseFormProps {
...@@ -164,9 +160,7 @@ export default function AddDatabaseForm(props: AddDatabaseFormProps) { ...@@ -164,9 +160,7 @@ export default function AddDatabaseForm(props: AddDatabaseFormProps) {
label="Port error" label="Port error"
type="port" type="port"
value={state.port} value={state.port}
onChange={(event) => onChange={(event) => handlePortChanged(event.currentTarget.value)}
handlePortChanged(event.currentTarget.value)
}
required required
/> />
) : ( ) : (
...@@ -175,9 +169,7 @@ export default function AddDatabaseForm(props: AddDatabaseFormProps) { ...@@ -175,9 +169,7 @@ export default function AddDatabaseForm(props: AddDatabaseFormProps) {
label="Port" label="Port"
type="port" type="port"
value={state.port} value={state.port}
onChange={(event) => onChange={(event) => handlePortChanged(event.currentTarget.value)}
handlePortChanged(event.currentTarget.value)
}
required required
/> />
)} )}
...@@ -229,12 +221,7 @@ export default function AddDatabaseForm(props: AddDatabaseFormProps) { ...@@ -229,12 +221,7 @@ export default function AddDatabaseForm(props: AddDatabaseFormProps) {
</div> </div>
<div className={styles.loginContainerButton}> <div className={styles.loginContainerButton}>
{portValidation && portValidation == 'error' ? ( {portValidation && portValidation == 'error' ? (
<Button <Button disabled variant="contained" type="submit" color="success">
disabled
variant="contained"
type="submit"
color="success"
>
Submit Submit
</Button> </Button>
) : ( ) : (
......
import { import { AddDatabaseRequest, GraphPolarisThemeProvider, store } from '@graphpolaris/shared/lib/data-access';
AddDatabaseRequest,
GraphPolarisThemeProvider,
store,
} from '@graphpolaris/shared/lib/data-access';
import AddDatabaseForm, { AddDatabaseFormProps } from '../index'; import AddDatabaseForm, { AddDatabaseFormProps } from '../index';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { Meta } from '@storybook/react'; import { Meta } from '@storybook/react';
......
...@@ -9,17 +9,7 @@ ...@@ -9,17 +9,7 @@
* We do not test components/renderfunctions/styling files. * We do not test components/renderfunctions/styling files.
* See testing plan for more details.*/ * See testing plan for more details.*/
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { import { AppBar, Toolbar, CssBaseline, Typography, MenuItem, ListItemText, Menu, IconButton, Button } from '@mui/material';
AppBar,
Toolbar,
CssBaseline,
Typography,
MenuItem,
ListItemText,
Menu,
IconButton,
Button,
} from '@mui/material';
import { AccountCircle } from '@mui/icons-material'; import { AccountCircle } from '@mui/icons-material';
import logo from './logogp.png'; import logo from './logogp.png';
import logo_white from './logogpwhite.png'; import logo_white from './logogpwhite.png';
...@@ -27,10 +17,7 @@ import AddDatabaseForm from './AddDatabaseForm'; ...@@ -27,10 +17,7 @@ import AddDatabaseForm from './AddDatabaseForm';
import { useTheme } from '@mui/material/styles'; import { useTheme } from '@mui/material/styles';
import styles from './navbar.module.scss'; import styles from './navbar.module.scss';
import { import { updateCurrentDatabase, updateDatabaseList } from '@graphpolaris/shared/lib/data-access/store/sessionSlice';
updateCurrentDatabase,
updateDatabaseList,
} from '@graphpolaris/shared/lib/data-access/store/sessionSlice';
import { import {
AddDatabaseRequest, AddDatabaseRequest,
useAppDispatch, useAppDispatch,
...@@ -129,14 +116,10 @@ export const Navbar = (props: NavbarComponentProps) => { ...@@ -129,14 +116,10 @@ export const Navbar = (props: NavbarComponentProps) => {
/** /**
* Called when the user clicks on the 'submit' button of the add database form. * Called when the user clicks on the 'submit' button of the add database form.
*/ */
function onAddDatabaseFormSubmit( function onAddDatabaseFormSubmit(request: AddDatabaseRequest): Promise<void | Response> {
request: AddDatabaseRequest return api.AddDatabase(request, { updateDatabaseCache: true, setAsCurrent: true }).then(() => {
): Promise<void | Response> { schemaApi.RequestSchema(request.name);
return api });
.AddDatabase(request, { updateDatabaseCache: true, setAsCurrent: true })
.then(() => {
schemaApi.RequestSchema(request.name);
});
} }
const currentLogo = theme.palette.custom.logo == 'white' ? logo_white : logo; const currentLogo = theme.palette.custom.logo == 'white' ? logo_white : logo;
...@@ -167,11 +150,7 @@ export const Navbar = (props: NavbarComponentProps) => { ...@@ -167,11 +150,7 @@ export const Navbar = (props: NavbarComponentProps) => {
> >
Change Palette Change Palette
</Button> */} </Button> */}
<Button <Button href="https://graphpolaris.com/" className={styles.menuText} style={{ color: theme.palette.custom.menuText }}>
href="https://graphpolaris.com/"
className={styles.menuText}
style={{ color: theme.palette.custom.menuText }}
>
Home Home
</Button> </Button>
<Button <Button
...@@ -181,11 +160,7 @@ export const Navbar = (props: NavbarComponentProps) => { ...@@ -181,11 +160,7 @@ export const Navbar = (props: NavbarComponentProps) => {
> >
Products Products
</Button> </Button>
<Button <Button href="https://graphpolaris.com#usecases" className={styles.menuText} style={{ color: theme.palette.custom.menuText }}>
href="https://graphpolaris.com#usecases"
className={styles.menuText}
style={{ color: theme.palette.custom.menuText }}
>
Use Cases Use Cases
</Button> </Button>
<Button <Button
...@@ -252,10 +227,7 @@ export const Navbar = (props: NavbarComponentProps) => { ...@@ -252,10 +227,7 @@ export const Navbar = (props: NavbarComponentProps) => {
}) })
} }
> >
<ListItemText <ListItemText onClick={() => openChangeSubMenu()} primary={'Change database'} />
onClick={() => openChangeSubMenu()}
primary={'Change database'}
/>
</MenuItem> </MenuItem>
<Menu <Menu
id="databases-menus" id="databases-menus"
...@@ -298,10 +270,7 @@ export const Navbar = (props: NavbarComponentProps) => { ...@@ -298,10 +270,7 @@ export const Navbar = (props: NavbarComponentProps) => {
}) })
} }
> >
<ListItemText <ListItemText onClick={() => openDeleteSubMenu()} primary={'Delete database'} />
onClick={() => openDeleteSubMenu()}
primary={'Delete database'}
/>
</MenuItem> </MenuItem>
<Menu <Menu
id="delete-databases-menus" id="delete-databases-menus"
......
...@@ -12,7 +12,8 @@ const Wrapper = styled.div<{ color: string }>` ...@@ -12,7 +12,8 @@ const Wrapper = styled.div<{ color: string }>`
font-family: 'Arial'; font-family: 'Arial';
// Light shadow // Light shadow
box-shadow: 0 3px 10px rgb(0 0 0 / 0.2); // box-shadow: 0 3px 10px rgb(0 0 0 / 0.2);
border: 1px solid #dddddd;
height: 100%; height: 100%;
width: 100%; width: 100%;
...@@ -20,14 +21,13 @@ const Wrapper = styled.div<{ color: string }>` ...@@ -20,14 +21,13 @@ const Wrapper = styled.div<{ color: string }>`
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
border-radius: 8px;
`; `;
const Content = styled.div` const Content = styled.div`
margin: 2em; margin: 0.8em;
border-radius: 8px; border-radius: 8px;
width: 100%; width: 100%;
height: 95%; height: 98%;
overflow: hidden; overflow: hidden;
`; `;
......
export const domain = import.meta.env.VITE_BACKEND_URL; export const domain = import.meta.env.VITE_BACKEND_URL;
\ No newline at end of file
...@@ -16,10 +16,7 @@ export default defineConfig({ ...@@ -16,10 +16,7 @@ export default defineConfig({
], ],
resolve: { resolve: {
alias: { alias: {
'@graphpolaris/shared/lib': path.resolve( '@graphpolaris/shared/lib': path.resolve(__dirname, '../../libs/shared/lib'),
__dirname,
'../../libs/shared/lib'
),
}, },
}, },
}); });
// All database related API calls // All database related API calls
import { useAppDispatch, useAuthorizationCache, useSessionCache } from "../store"; import { useAppDispatch, useAuthorizationCache, useSessionCache } from '../store';
import { updateCurrentDatabase, updateDatabaseList } from "../store/sessionSlice"; import { updateCurrentDatabase, updateDatabaseList } from '../store/sessionSlice';
export enum DatabaseType { export enum DatabaseType {
ArangoDB = 0, ArangoDB = 0,
...@@ -21,34 +21,31 @@ export type AddDatabaseRequest = { ...@@ -21,34 +21,31 @@ export type AddDatabaseRequest = {
}; };
export type AddDatabaseOptions = { export type AddDatabaseOptions = {
setAsCurrent?: boolean, updateDatabaseCache?: boolean setAsCurrent?: boolean;
} updateDatabaseCache?: boolean;
};
export type GetDatabasesOptions = { export type GetDatabasesOptions = {
updateSessionCache?: boolean updateSessionCache?: boolean;
} };
export type DeleteDatabasesOptions = { export type DeleteDatabasesOptions = {
updateSessionCache?: boolean updateSessionCache?: boolean;
} };
export const useDatabaseAPI = (domain: string) => { export const useDatabaseAPI = (domain: string) => {
const { accessToken } = useAuthorizationCache(); const { accessToken } = useAuthorizationCache();
const cache = useSessionCache(); const cache = useSessionCache();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
function AddDatabase( function AddDatabase(request: AddDatabaseRequest, options: AddDatabaseOptions = {}): Promise<void> {
request: AddDatabaseRequest,
options: AddDatabaseOptions = {}
): Promise<void> {
const { setAsCurrent = true, updateDatabaseCache = false } = options; const { setAsCurrent = true, updateDatabaseCache = false } = options;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
fetch(`https://${domain}/user/database`, { fetch(`https://${domain}/user/database`, {
method: 'POST', method: 'POST',
credentials: 'same-origin', credentials: 'same-origin',
headers: new Headers({ headers: new Headers({
Authorization: Authorization: 'Bearer ' + accessToken,
'Bearer ' + accessToken,
}), }),
body: JSON.stringify(request), body: JSON.stringify(request),
}).then((response: Response) => { }).then((response: Response) => {
...@@ -57,10 +54,8 @@ export const useDatabaseAPI = (domain: string) => { ...@@ -57,10 +54,8 @@ export const useDatabaseAPI = (domain: string) => {
if (!response.ok) { if (!response.ok) {
reject(response.statusText); reject(response.statusText);
} }
if (setAsCurrent) if (setAsCurrent) dispatch(updateCurrentDatabase(request.name));
dispatch(updateCurrentDatabase(request.name)); if (updateDatabaseCache) GetAllDatabases({ updateSessionCache: true });
if (updateDatabaseCache)
GetAllDatabases({ updateSessionCache: true });
resolve(); resolve();
}); });
...@@ -74,8 +69,7 @@ export const useDatabaseAPI = (domain: string) => { ...@@ -74,8 +69,7 @@ export const useDatabaseAPI = (domain: string) => {
method: 'GET', method: 'GET',
credentials: 'same-origin', credentials: 'same-origin',
headers: new Headers({ headers: new Headers({
Authorization: Authorization: 'Bearer ' + accessToken,
'Bearer ' + accessToken,
}), }),
}); });
console.log(response); console.log(response);
...@@ -87,8 +81,7 @@ export const useDatabaseAPI = (domain: string) => { ...@@ -87,8 +81,7 @@ export const useDatabaseAPI = (domain: string) => {
// throw Error(response.statusText) // throw Error(response.statusText)
} }
const json = await response.json(); const json = await response.json();
if (updateDatabaseCache) if (updateDatabaseCache) dispatch(updateDatabaseList(json.databases));
dispatch(updateDatabaseList(json.databases));
return json.databases; return json.databases;
} }
...@@ -99,21 +92,19 @@ export const useDatabaseAPI = (domain: string) => { ...@@ -99,21 +92,19 @@ export const useDatabaseAPI = (domain: string) => {
method: 'DELETE', method: 'DELETE',
credentials: 'same-origin', credentials: 'same-origin',
headers: new Headers({ headers: new Headers({
Authorization: Authorization: 'Bearer ' + accessToken,
'Bearer ' + accessToken,
}), }),
}).then((response: Response) => { }).then((response: Response) => {
if (!response.ok) { if (!response.ok) {
reject(response.statusText); reject(response.statusText);
} }
if (updateDatabaseCache) if (updateDatabaseCache) GetAllDatabases({ updateSessionCache: true });
GetAllDatabases({ updateSessionCache: true });
resolve(); resolve();
}); });
}); });
} }
return { DatabaseType, AddDatabase, GetAllDatabases, DeleteDatabase } return { DatabaseType, AddDatabase, GetAllDatabases, DeleteDatabase };
}; };
export * from './database' export * from './database';
export * from './user' export * from './user';
export * from './schema' export * from './schema';
export * from './query' export * from './query';
\ No newline at end of file
// All database related API calls // All database related API calls
import { BackendQueryFormat } from "../../querybuilder/model/BackendQueryFormat"; import { BackendQueryFormat } from '../../querybuilder/model/BackendQueryFormat';
import { useAuthorizationCache, useSessionCache } from "../store"; import { useAuthorizationCache, useSessionCache } from '../store';
export const useQueryAPI = (domain: string) => { export const useQueryAPI = (domain: string) => {
const cache = useSessionCache(); const cache = useSessionCache();
const { accessToken } = useAuthorizationCache(); const { accessToken } = useAuthorizationCache();
async function execute(query: BackendQueryFormat) { async function execute(query: BackendQueryFormat) {
const response = await fetch(`https://${domain}/query/execute/`, {
const response = await fetch(`https://${domain}/query/execute/`, { method: 'POST',
method: 'POST', credentials: 'same-origin',
credentials: 'same-origin', headers: new Headers({
headers: new Headers({ Authorization: 'Bearer ' + accessToken,
Authorization: }),
'Bearer ' + accessToken, body: JSON.stringify(query),
}), });
body: JSON.stringify(query)
}); if (!response?.ok) {
const ret = await response.text();
if (!response?.ok) { console.error(response, ret);
const ret = await response.text(); return;
console.error(response, ret);
}
const ret = await response.json();
console.log('Sent Query EXECUTION', ret);
}
async function retrieveCachedQuery(queryID: string) {
// TODO: check if this method is needed!
// const response = await fetch(`https://${domain}/query/retrieve-cached/`, {
// method: 'POST',
// credentials: 'same-origin',
// headers: new Headers({
// Authorization:
// 'Bearer ' + accessToken,
// }),
// body: JSON.stringify({ queryID })
// });
// if (!response?.ok) {
// const ret = await response.text();
// console.error(response, ret);
// }
// // const ret = await response.json();
// console.log(response);
} }
const ret = await response.json();
return { execute, retrieveCachedQuery }; console.log('Sent Query EXECUTION', ret);
}
async function retrieveCachedQuery(queryID: string) {
// TODO: check if this method is needed!
// const response = await fetch(`https://${domain}/query/retrieve-cached/`, {
// method: 'POST',
// credentials: 'same-origin',
// headers: new Headers({
// Authorization:
// 'Bearer ' + accessToken,
// }),
// body: JSON.stringify({ queryID })
// });
// if (!response?.ok) {
// const ret = await response.text();
// console.error(response, ret);
// }
// // const ret = await response.json();
// console.log(response);
}
return { execute, retrieveCachedQuery };
}; };
// All database related API calls // All database related API calls
import { useAuthorizationCache, useSessionCache } from "../store"; import { useAuthorizationCache, useSessionCache } from '../store';
export const useSchemaAPI = (domain: string) => { export const useSchemaAPI = (domain: string) => {
const cache = useSessionCache(); const cache = useSessionCache();
const { accessToken } = useAuthorizationCache(); const { accessToken } = useAuthorizationCache();
async function RequestSchema(databaseName?: string) {
if (!databaseName) databaseName = cache.currentDatabase;
if (!databaseName) {
throw Error('Must call with a database name');
}
async function RequestSchema(databaseName?: string) { const request = {
if (!databaseName) databaseName = cache.currentDatabase; databaseName,
if (!databaseName) { cached: true,
throw Error('Must call with a database name'); };
}
const response = await fetch(`https://${domain}/schema/`, {
const request = { method: 'POST',
databaseName, credentials: 'same-origin',
cached: true, headers: new Headers({
}; Authorization: 'Bearer ' + accessToken,
}),
const response = await fetch(`https://${domain}/schema/`, { body: JSON.stringify(request),
method: 'POST', });
credentials: 'same-origin',
headers: new Headers({ if (!response?.ok) {
Authorization: const ret = await response.text();
'Bearer ' + accessToken, console.error(response, ret);
}),
body: JSON.stringify(request)
});
if (!response?.ok) {
const ret = await response.text();
console.error(response, ret);
}
// const ret = await response.json();
console.log(response);
} }
// const ret = await response.json();
console.log(response);
}
return { RequestSchema }; return { RequestSchema };
}; };
// All user related API calls // All user related API calls
import { useAuthorizationCache } from "../store"; import { useAuthorizationCache } from '../store';
export type User = { export type User = {
Name: string; Name: string;
...@@ -37,6 +37,5 @@ export const useUserAPI = (domain: string) => { ...@@ -37,6 +37,5 @@ export const useUserAPI = (domain: string) => {
}); });
} }
return { GetUserInfo }; return { GetUserInfo };
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment