added editor value cleaning

This commit is contained in:
TzeYiing authored and Joshen Lim committed 2022-02-15 17:56:20 +08:00
1 parent f4c622d65e
commit 8e7e8d4cce
2 files changed
+11 -7

No files matched your search

@@ -180,8 +180,8 @@ export const LogPage: NextPage = () => {
setEditorValue(template.searchString)
setParams((prev) => ({
...prev,
where: isSelectQuery ? '' : template.searchString,
sql: isSelectQuery ? template.searchString : '',
where: isSelectQuery ? '' : cleanEditorValue(template.searchString),
sql: isSelectQuery ? cleanEditorValue(template.searchString) : '',
search_query: '',
timestamp_end: '',
}))
@@ -191,8 +191,8 @@ export const LogPage: NextPage = () => {
const handleEditorSubmit = () => {
setParams((prev) => ({
...prev,
where: isSelectQuery ? '' : editorValue,
sql: isSelectQuery ? editorValue : '',
where: isSelectQuery ? '' : cleanEditorValue(editorValue),
sql: isSelectQuery ? cleanEditorValue(editorValue) : '',
search_query: '',
}))
if (!logsQueryParamsSyncing) return
@@ -200,7 +200,7 @@ export const LogPage: NextPage = () => {
pathname: router.pathname,
query: {
...router.query,
q: editorValue,
q: cleanEditorValue(editorValue),
s: undefined,
te: undefined,
},
@@ -227,7 +227,10 @@ export const LogPage: NextPage = () => {
})
setEditorValue('')
}
const cleanEditorValue = (value: string) => {
if (typeof value !== "string") return value
return value.replace(/\n/g, ' ')
}
return (
<SettingsLayout title={title}>
<div className="h-full flex flex-col flex-grow">
+2 -1
View File
@@ -297,7 +297,7 @@ test('custom sql querying', async () => {
expect(editor).toBeTruthy()
})
editor = container.querySelector('.monaco-editor')
userEvent.type(editor, 'select count(*) as my_count from edge_logs')
userEvent.type(editor, 'select \ncount(*) as my_count \nfrom edge_logs')
// should show sandbox warning alert
await waitFor(() => screen.getByText(/restricted to a 7 day querying window/))
@@ -305,6 +305,7 @@ test('custom sql querying', async () => {
userEvent.click(screen.getByText('Run'))
await waitFor(
() => {
expect(get).not.toHaveBeenCalledWith(expect.stringContaining(encodeURI('\n')))
expect(get).toHaveBeenCalledWith(expect.stringContaining('sql='))
expect(get).toHaveBeenCalledWith(expect.stringContaining('select'))
expect(get).toHaveBeenCalledWith(expect.stringContaining('edge_logs'))