Repository navigation
feat(logging): bulk download selected log entries as CSV #865
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fe5341a
feat(logging): add bulk CSV download for selected log entries
josephfusco ef6c222
fix(logging): harden CSV log downloads against formula injection
josephfusco 0c3314e
test(logging): cover bulk download wiring, formula escaping and ID ed…
josephfusco 2c799ac
docs(logging): document bulk log downloads and skip unneeded list tab…
josephfusco ac44359
Potential fix for pull request finding 'Stop output-buffer cleanup wh…
josephfusco cca6d4e
Merge remote-tracking branch 'origin/main' into feat/logging-bulk-dow…
Copilot dd2a70e
fix(logging): drop impossible false check on ob_get_status() result
josephfusco 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
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
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
75 changes: 75 additions & 0 deletions
75
plugins/wpgraphql-logging/tests/e2e/specs/bulk-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,75 @@ | ||
| import { expect, test } from "@wordpress/e2e-test-utils-playwright"; | ||
| import { | ||
| goToLoggingSettingsPage, | ||
| goToLogsListPage, | ||
| configureLogging, | ||
| executeGraphQLQuery, | ||
| resetPluginSettings, | ||
| } from "../utils"; | ||
| import { GET_POSTS_QUERY } from "../constants"; | ||
|
|
||
| test.describe("Bulk Log Download", () => { | ||
| test.beforeEach(async ({ admin, page }) => { | ||
| await resetPluginSettings(admin); | ||
|
|
||
| await goToLoggingSettingsPage(admin); | ||
| await expect(page.locator("h1")).toHaveText("WPGraphQL Logging Settings"); | ||
| }); | ||
|
|
||
| test("downloads selected logs as a single CSV", async ({ | ||
| page, | ||
| admin, | ||
| request, | ||
| }) => { | ||
| await configureLogging(page, { | ||
| enabled: true, | ||
| dataSampling: "100", | ||
| eventLogSelection: ["graphql_request_results"], | ||
| }); | ||
|
|
||
| // Create at least two log entries. | ||
| for (let i = 0; i < 2; i++) { | ||
| const response = await executeGraphQLQuery(request, GET_POSTS_QUERY); | ||
| expect(response.ok()).toBeTruthy(); | ||
| } | ||
|
|
||
| await goToLogsListPage(admin); | ||
| await expect(page.locator("h1")).toContainText("WPGraphQL Logs"); | ||
|
|
||
| const logRows = page | ||
| .locator("#the-list tr") | ||
| .filter({ hasText: "GetPosts" }); | ||
| await expect(logRows.nth(1)).toBeVisible({ timeout: 10000 }); | ||
|
|
||
| const selectedIds = []; | ||
| for (let i = 0; i < 2; i++) { | ||
| const checkbox = logRows.nth(i).locator('input[name="log[]"]'); | ||
| await checkbox.check(); | ||
| selectedIds.push(await checkbox.inputValue()); | ||
| } | ||
|
|
||
| await page | ||
| .locator("#bulk-action-selector-top") | ||
| .selectOption("bulk_download"); | ||
|
|
||
| const downloadPromise = page.waitForEvent("download"); | ||
| await page.locator("#doaction").click(); | ||
| const download = await downloadPromise; | ||
|
|
||
| expect(download.suggestedFilename()).toMatch( | ||
| /^graphql_logs_\d{4}-\d{2}-\d{2}_\d{6}\.csv$/ | ||
| ); | ||
|
|
||
| const fs = require("fs"); | ||
| const content = fs.readFileSync(await download.path(), "utf8"); | ||
| const lines = content.trim().split("\n"); | ||
|
|
||
| // One header row, then one row per selected log. | ||
| expect(lines[0]).toContain("ID"); | ||
| expect(lines[0]).toContain("Message"); | ||
| for (const id of selectedIds) { | ||
| expect(content).toMatch(new RegExp(`^${id},`, "m")); | ||
| } | ||
| expect(content).toContain("GetPosts"); | ||
| }); | ||
| }); |
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.