-
Notifications
You must be signed in to change notification settings - Fork 32
feat(web-console): export parquet files, fix unresponsive CSV imports #484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
emrberk
wants to merge
13
commits into
main
Choose a base branch
from
feat/export-parquet
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
22781d4
export parquet initial
emrberk adf472f
feat(web-console): export parquet files, fix unresponsive CSV imports
emrberk a04e543
update submodule and loader text
emrberk 3fbe161
Merge branch 'main' into feat/export-parquet
emrberk 1cc589a
handle safari downloads with new tab, fix token handling in service w…
emrberk c5279d5
fix type and quotes
emrberk e873229
more on reviews
emrberk dfcd28a
show parquet download as the default action
emrberk a5d7030
remove icons
emrberk 6286997
adjust line height of the text
emrberk 12addd2
animation
emrberk 967bc2f
simplify the auth flow, add fallbacks
emrberk b0fcf06
add nodelay request param
ideoma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
cypress/videos | ||
cypress/screenshots | ||
cypress/downloads |
171 changes: 171 additions & 0 deletions
171
packages/browser-tests/cypress/integration/console/download.spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
describe("download functionality", () => { | ||
beforeEach(() => { | ||
cy.loadConsoleWithAuth(); | ||
}); | ||
|
||
it("should show download button with results", () => { | ||
// When | ||
cy.typeQuery("select x from long_sequence(10)"); | ||
cy.runLine(); | ||
|
||
// Then | ||
cy.getByDataHook("download-parquet-button").should("be.visible"); | ||
cy.getByDataHook("download-dropdown-button").should("be.visible"); | ||
cy.getByDataHook("download-csv-button").should("not.exist"); | ||
|
||
// When | ||
cy.getByDataHook("download-dropdown-button").click(); | ||
|
||
// Then | ||
cy.getByDataHook("download-csv-button").should("be.visible"); | ||
}); | ||
|
||
it("should trigger CSV download", () => { | ||
const query = "select x from long_sequence(10)"; | ||
|
||
// Given | ||
cy.intercept("GET", "**/exp?*", (req) => { | ||
req.reply({ | ||
statusCode: 200, | ||
body: null, | ||
}); | ||
}).as("exportRequest"); | ||
|
||
// When | ||
cy.typeQuery(query); | ||
cy.runLine(); | ||
cy.getByDataHook("download-dropdown-button").click(); | ||
cy.getByDataHook("download-csv-button").click(); | ||
|
||
// Then | ||
cy.wait("@exportRequest").then((interception) => { | ||
expect(interception.request.url).to.include("fmt=csv"); | ||
expect(interception.request.url).to.include( | ||
encodeURIComponent(query.replace(/\s+/g, " ")) | ||
); | ||
}); | ||
}); | ||
|
||
it("should trigger Parquet download", () => { | ||
const query = "select x from long_sequence(10)"; | ||
|
||
// Given | ||
cy.intercept("GET", "**/exp?*", (req) => { | ||
req.reply({ | ||
statusCode: 200, | ||
body: null, | ||
}); | ||
}).as("exportRequest"); | ||
|
||
// When | ||
cy.typeQuery(query); | ||
cy.runLine(); | ||
cy.getByDataHook("download-parquet-button").click(); | ||
|
||
// Then | ||
cy.wait("@exportRequest").then((interception) => { | ||
expect(interception.request.url).to.include("fmt=parquet"); | ||
expect(interception.request.url).to.include("parquetVersion=1"); | ||
expect(interception.request.url).to.include( | ||
encodeURIComponent(query.replace(/\s+/g, " ")) | ||
); | ||
}); | ||
}); | ||
|
||
it("should show error toast on bad request", () => { | ||
// Given | ||
cy.intercept("GET", "**/exp?*", (req) => { | ||
const url = new URL(req.url); | ||
url.searchParams.set("fmt", "badformat"); | ||
req.url = url.toString(); | ||
}).as("badExportRequest"); | ||
|
||
// When | ||
cy.typeQuery("select x from long_sequence(5)"); | ||
cy.runLine(); | ||
cy.getByDataHook("download-dropdown-button").click(); | ||
cy.getByDataHook("download-csv-button").click(); | ||
|
||
// Then | ||
cy.wait("@badExportRequest").then(() => { | ||
cy.getByRole("alert").should( | ||
"contain", | ||
"Download failed with status code 400: unrecognised format [format=badformat]" | ||
); | ||
}); | ||
}); | ||
|
||
it("should show error toast on server error", () => { | ||
// Given | ||
cy.intercept("GET", "**/exp?*", (req) => { | ||
req.reply({ | ||
statusCode: 500, | ||
}); | ||
}).as("serverErrorRequest"); | ||
|
||
// When | ||
cy.typeQuery("select x from long_sequence(5)"); | ||
cy.runLine(); | ||
cy.getByDataHook("download-dropdown-button").click(); | ||
cy.getByDataHook("download-csv-button").click(); | ||
|
||
// Then | ||
cy.wait("@serverErrorRequest").then(() => { | ||
cy.getByRole("alert").should( | ||
"contain", | ||
"Download failed with status code 500: Internal Server Error" | ||
); | ||
}); | ||
}); | ||
|
||
it("should show loading spinner when downloading", () => { | ||
// Given | ||
cy.intercept("GET", "**/exp?*", (req) => { | ||
req.reply({ | ||
statusCode: 200, | ||
body: null, | ||
delay: 1000, | ||
}); | ||
}).as("exportRequest"); | ||
|
||
// When | ||
cy.typeQuery("select * from long_sequence(10)"); | ||
cy.runLine(); | ||
cy.getByDataHook("download-parquet-button").click(); | ||
|
||
// Then | ||
cy.getByDataHook("download-loading-indicator").should("be.visible"); | ||
|
||
// Then | ||
cy.wait("@exportRequest").then(() => { | ||
cy.getByDataHook("download-loading-indicator").should("not.exist"); | ||
}); | ||
}); | ||
|
||
it("should download the file", () => { | ||
const query = "select x from long_sequence(10)"; | ||
// Given | ||
cy.intercept("GET", "**/exp?*").as("exportRequest"); | ||
|
||
// When | ||
cy.typeQuery(query); | ||
cy.runLine(); | ||
cy.getByDataHook("download-dropdown-button").click(); | ||
cy.getByDataHook("download-csv-button").click(); | ||
|
||
// Then | ||
cy.wait("@exportRequest").then((interception) => { | ||
expect(interception.request.url).to.include("fmt=csv"); | ||
expect(interception.request.url).to.include( | ||
encodeURIComponent(query.replace(/\s+/g, " ")) | ||
); | ||
const filename = new URL(interception.request.url).searchParams.get( | ||
"filename" | ||
); | ||
cy.readFile(`cypress/downloads/${filename}.csv`).should( | ||
"eq", | ||
'"x"\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n' | ||
); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
let authToken = null | ||
|
||
self.addEventListener('message', (event) => { | ||
if (event.data && event.data.type === 'SET_AUTH_TOKEN') { | ||
authToken = event.data.token | ||
self.clients.matchAll().then((clients) => { | ||
clients.forEach((client) => { | ||
client.postMessage({ | ||
type: 'AUTH_TOKEN_ACK', | ||
}) | ||
}) | ||
}) | ||
} | ||
}) | ||
|
||
self.addEventListener('fetch', (event) => { | ||
const url = new URL(event.request.url) | ||
if (url.searchParams.get('noAuth')) { | ||
return | ||
} | ||
|
||
if (url.pathname === '/exp' || url.pathname.endsWith('/exp')) { | ||
const requestKey = new URL(event.request.url).searchParams.get('filename') | ||
|
||
event.respondWith( | ||
(async () => { | ||
try { | ||
const headers = new Headers(event.request.headers) | ||
if (authToken) { | ||
headers.set('Authorization', authToken) | ||
} | ||
|
||
const modifiedRequest = new Request(event.request, { | ||
headers: headers, | ||
}) | ||
|
||
const response = await fetch(modifiedRequest) | ||
|
||
if (!response.ok) { | ||
let message = response.statusText | ||
try { | ||
const json = await response.json() | ||
const errorMessage = json.error | ||
if (errorMessage) { | ||
message = errorMessage | ||
} | ||
} catch (_) {} | ||
|
||
self.clients.matchAll().then((clients) => { | ||
clients.forEach((client) => { | ||
client.postMessage({ | ||
type: `DOWNLOAD_ERROR_${requestKey}`, | ||
status: response.status, | ||
message, | ||
}) | ||
}) | ||
}) | ||
} else { | ||
self.clients.matchAll().then((clients) => { | ||
clients.forEach((client) => { | ||
client.postMessage({ | ||
type: `DOWNLOAD_START_${requestKey}`, | ||
}) | ||
}) | ||
}) | ||
} | ||
return response | ||
} catch (error) { | ||
self.clients.matchAll().then((clients) => { | ||
clients.forEach((client) => { | ||
client.postMessage({ | ||
type: `DOWNLOAD_ERROR_${requestKey}`, | ||
status: 500, | ||
message: error.message ?? 'Internal server error', | ||
}) | ||
}) | ||
}) | ||
console.error('[SW] Download service worker error:', error) | ||
} | ||
})() | ||
); | ||
} | ||
}); | ||
|
||
self.addEventListener('install', (_) => { | ||
self.skipWaiting() | ||
}); | ||
|
||
self.addEventListener('activate', (event) => { | ||
event.waitUntil(self.clients.claim()) | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/web-console/src/components/LoadingSpinner/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from "react" | ||
import styled, { useTheme } from "styled-components" | ||
import { Loader3 } from "@styled-icons/remix-line" | ||
import { Color } from "../../types" | ||
import { spinAnimation } from "../../components/Animation" | ||
|
||
const StyledLoader = styled(Loader3)<{ $size: string, $color: Color }>` | ||
width: ${({ $size }) => $size}; | ||
height: ${({ $size }) => $size}; | ||
color: ${({ $color, theme }) => $color ? theme.color[$color] : theme.color.pink}; | ||
${spinAnimation}; | ||
` | ||
|
||
type Props = { | ||
size?: string | ||
color?: Color | ||
} | ||
|
||
export const LoadingSpinner = ({ size = "18px", color = "pink" }: Props) => { | ||
const theme = useTheme() | ||
return ( | ||
<StyledLoader data-hook="loading-spinner" $size={size} $color={color} theme={theme} /> | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.