Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ describe("&query URL param", () => {
cy.visit(`${baseUrl}?query=${query}&executeQuery=true`);
cy.getGridRow(0).should("contain", "2").snapshot();
});

it("should not append query if it already exists in editor", () => {
cy.visit(baseUrl);
const query = "select x\nfrom long_sequence(1);\n\n-- a\n-- b\n-- c";
cy.runQuery(query);
cy.visit(`${baseUrl}?query=${encodeURIComponent(query)}&executeQuery=true`);
cy.getEditor().should("have.value", query);
});
});

describe("autocomplete", () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/web-console/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `Fixed` for any bug fixes.
* `Security` in case of vulnerabilities.

## Next

### Fixed

- fix duplication issue when loading web console with `?query=some sql&executeQuery=true` multiple time [#33](https://github.com/questdb/ui/pull/33)

## 0.0.6 - 2022-09-26

### Added
Expand Down
11 changes: 10 additions & 1 deletion packages/web-console/src/scenes/Editor/Monaco/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,18 @@ const MonacoEditor = () => {

// Insert query, if one is found in the URL
const params = new URLSearchParams(window.location.search)
// Support multi-line queries (URL encoded)
const query = params.get("query")
const model = editor.getModel()
if (query) {
appendQuery(editor, query, { appendAt: "end" })
// Find if the query is already in the editor
const matches = model?.findMatches(query, true, false, true, null, true)
if (matches && matches.length > 0) {
editor.setSelection(matches[0].range)
// otherwise, append the query
} else {
appendQuery(editor, query, { appendAt: "end" })
}
}

const executeQuery = params.get("executeQuery")
Expand Down