Skip to content

Commit 7812607

Browse files
committed
Add the query as a query parameter in UI.
1 parent 77a60e0 commit 7812607

File tree

5 files changed

+177
-21
lines changed

5 files changed

+177
-21
lines changed

web/package-lock.json

Lines changed: 145 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@
2020
"@types/react": "^17.0.0",
2121
"@types/react-dom": "^17.0.0",
2222
"@types/react-measure": "^2.0.6",
23+
"@types/react-router-dom": "^5.1.6",
2324
"@welldone-software/why-did-you-render": "^6.0.3",
2425
"axios": "^0.21.0",
2526
"classnames": "^2.2.6",
2627
"d3": "^6.3.0",
2728
"material-table": "^1.69.2",
29+
"query-string": "^6.13.7",
2830
"react": "^17.0.1",
2931
"react-dom": "^17.0.1",
3032
"react-measure": "^2.5.2",
33+
"react-router-dom": "^5.2.0",
3134
"react-scripts": "4.0.1",
32-
"typescript": "~4.1.2"
35+
"typescript": "~4.1.2",
36+
"use-query-params": "^1.1.9"
3337
},
3438
"scripts": {
3539
"start": "react-scripts start",

web/src/App.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react';
22
import { createMuiTheme, ThemeProvider } from '@material-ui/core';
33
import ExplorerView from './views/ExplorerView';
4+
import { BrowserRouter as Router, Route } from 'react-router-dom';
5+
import { QueryParamProvider } from 'use-query-params';
46

57
if (process.env.NODE_ENV !== 'production') {
68
const whyDidYouRender = require('@welldone-software/why-did-you-render');
@@ -16,7 +18,11 @@ const App: React.FC = () => {
1618

1719
return (
1820
<ThemeProvider theme={darkTheme}>
19-
<ExplorerView />
21+
<Router>
22+
<QueryParamProvider ReactRouterRoute={Route}>
23+
<ExplorerView />
24+
</QueryParamProvider>
25+
</Router>
2026
</ThemeProvider >
2127
);
2228
}

web/src/components/D3Graph.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ const D3Graph = <Node extends NodeLike, Edge extends EdgeLike>(props: Props<Node
252252
onNodeMouseOutCallback(d.data);
253253
}
254254
})
255-
.on("dblclick", function (d) {
255+
.on("dblclick", function (ev, d) {
256256
onNodeDoubleClickCallback(d.data);
257257
});
258258

web/src/views/ExplorerView.tsx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import DatabaseDialog from '../components/DatabaseDialog';
1414
import { DatabaseDetails } from '../models/DatabaseDetails';
1515
import SearchField from '../components/SearchField';
1616
import MuiAlert from '@material-ui/lab/Alert';
17+
import { useQueryParam, StringParam, withDefault } from 'use-query-params';
1718

1819
function Alert(props: any) {
1920
return <MuiAlert elevation={6} variant="filled" {...props} />;
@@ -26,6 +27,7 @@ const ExplorerView = () => {
2627
const styles = useStyles();
2728
const [sources, setSources] = useState(undefined as string[] | undefined);
2829
const [query, setQuery] = useState(QUERY);
30+
const [submittedQuery, setSubmittedQuery] = useQueryParam("q", withDefault(StringParam, QUERY));
2931
const [queryResult, setQueryResult] = useState(undefined as QueryResultSet | undefined);
3032
const [isQueryLoading, setIsQueryLoading] = useState(false);
3133
const [error, setError] = useState(undefined as undefined | Error);
@@ -36,16 +38,23 @@ const ExplorerView = () => {
3638
const [searchFocus, setSearchFocus] = useState(false);
3739

3840
const handleQuerySubmit = useCallback(async (q: string) => {
39-
setIsQueryLoading(true);
40-
try {
41-
const res = await postQuery(q);
42-
setQueryResult(res);
43-
} catch (err) {
44-
console.error(err);
45-
setError(err);
46-
}
47-
setIsQueryLoading(false);
48-
}, [setIsQueryLoading, setQueryResult]);
41+
setSubmittedQuery(q);
42+
}, [setSubmittedQuery]);
43+
44+
useEffect(() => {
45+
(async function() {
46+
setIsQueryLoading(true);
47+
try {
48+
const res = await postQuery(submittedQuery);
49+
setQueryResult(res);
50+
} catch (err) {
51+
console.error(err);
52+
setError(err);
53+
}
54+
setIsQueryLoading(false);
55+
})();
56+
setQuery(submittedQuery);
57+
}, [submittedQuery]);
4958

5059
const getSourcesCallback = useCallback(async () => {
5160
try {

0 commit comments

Comments
 (0)