Skip to content

Commit

Permalink
Feature/query editor (#25)
Browse files Browse the repository at this point in the history
* Add Query Editor

* Add Query Editor
  • Loading branch information
akageun committed Jul 4, 2024
1 parent f40580c commit 1eac848
Show file tree
Hide file tree
Showing 5 changed files with 322 additions and 126 deletions.
70 changes: 70 additions & 0 deletions cadio-web/src/main/webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cadio-web/src/main/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"react-dom": "^18.3.1",
"react-router-dom": "^6.11.0",
"react-scripts": "5.0.1",
"react-ace": "^12.0.0",
"ace-builds": "^1.35.2",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,81 @@
import QueryEditor from "./query/query-editor";
import axios from "axios";
import {useEffect, useState} from "react";
import {useParams} from "react-router-dom";
import QueryResult from "./query/query-result";

const QueryHome = () => {
const routeParams = useParams();

const [queryParam, setQueryParam] = useState(
{
query: "",
nextCursor: "",
}
);

const initQueryResult = {
wasApplied: null,
rows: [],
columnNames: [],
};

const [queryResult, setQueryResult] = useState(initQueryResult)

const queryExecute = (query, cursor, setLoading) => {
if (!query) {
alert("쿼리를 입력해 주세요.")
return;
}

if (cursor === null) {
setQueryResult({
wasApplied: null,
rows: [],
columnNames: [],
})
}

setLoading(true);

axios({
method: "POST",
url: `/api/cassandra/cluster/${routeParams.clusterId}/query`,
data: {
query: query,
pageSize: 2,
timeoutSeconds: 3,
cursor: cursor,
},
}).then((response) => {
console.log("response query execute ", response.data.result.nextCursor)
setQueryParam({
query: query,
nextCursor: response.data.result.nextCursor
})

setQueryResult({
wasApplied: response.data.result.wasApplied,
rows: [...queryResult.rows, ...response.data.result.rows],
columnNames: response.data.result.columnNames,
})
}).catch((error) => {

}).finally(() => {
setLoading(false);
})
}

useEffect(() => {
//show component
setQueryResult(initQueryResult);

return () => {
//hide component

};
}, []);


return (
<>
Expand All @@ -19,8 +94,15 @@ const QueryHome = () => {
</div>
</div>

<QueryEditor/>

<QueryEditor
queryExecute={queryExecute}
/>
<QueryResult
queryExecute={queryExecute}
result={queryResult}
query={queryParam.query}
nextCursor={queryParam.nextCursor}
/>
</>
)
}
Expand Down
Loading

0 comments on commit 1eac848

Please sign in to comment.