Skip to content

Commit

Permalink
query cleanup fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
rrmerugu committed May 28, 2021
1 parent 09e6cdd commit 57f15b4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/utils/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
// }
// }

export function cleanQuery(queryString) {
return queryString
.replace(/(^"|"$)/g, '')
// .replace(/\\"/g, "\"")
.replace(/\\n/g, "\n")
.replace(/\\r/g, "\r")
// .replace(/\n|\r/g, "")
.trim().trim();
}

export function convertMapKeysToArray(mapData) {
let data = [];
Expand Down
10 changes: 3 additions & 7 deletions src/web/viewlets/canvas/query-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
removeHistoryFromStorageById,
} from "../../../utils/localStorage";
import {HISTORY_SETTINGS} from "../../../settings/history";
import {cleanQuery} from "../../../utils/core";

export default class RequestHistoryView extends React.Component {

Expand Down Expand Up @@ -39,11 +40,7 @@ export default class RequestHistoryView extends React.Component {

extractRawQuery(graphQLQuery) {
try {
const _ = graphQLQuery.query.split("rawQuery(gremlin:")[1].split("){id,type,label,")[0]
.replace(/(^"|"$)/g, '')
.replace(/\\"/g, "\"")
.replace(/\n|\r/g, "")
.trim();
const _ = cleanQuery(graphQLQuery.query.split("rawQuery(gremlin:")[1].split("){id,type,label,")[0]);
console.log("extractRawQuery History", typeof _, _);
return _;
} catch (e) {
Expand Down Expand Up @@ -90,8 +87,7 @@ export default class RequestHistoryView extends React.Component {
<li className={"list-group-item border-0 p-0"}
key={i}>
<pre className={" ml-2 mr-2 mt-2 p-3 mt-0 mb-0"}
style={{"backgroundColor": "#efefef"}}>
{this.extractRawQuery(existingHistoryItem.query)}
style={{"backgroundColor": "#efefef"}}>{this.extractRawQuery(existingHistoryItem.query)}
</pre>
{/*<pre className={"mb-0"}>{JSON.stringify(existingHistoryItem.query, null, 2)}</pre>*/}

Expand Down
3 changes: 2 additions & 1 deletion src/web/viewlets/welcome/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import {getDataFromLocalStorage} from "../../../utils/localStorage";
import {HISTORY_SETTINGS} from "../../../settings/history";
import DefaultRemoteComponent from "../../layouts/default-remote";
import {STUDIO_SETTINGS} from "../../../settings";
import {cleanQuery} from "../../../utils/core";

export default class Welcome extends DefaultRemoteComponent {


extractRawQuery(graphQLQuery) {
try {
return graphQLQuery.query.split("rawQuery(gremlin:")[1].split("){id,type,label,")[0].replace(/(^"|"$)/g, '').replace(/\\"/g, "\"").replace(/\n|\r/g, "");
return cleanQuery(graphQLQuery.query.split("rawQuery(gremlin:")[1].split("){id,type,label,")[0]);
} catch (e) {
return graphQLQuery.query;
}
Expand Down

0 comments on commit 57f15b4

Please sign in to comment.