-
Notifications
You must be signed in to change notification settings - Fork 0
feat: store sets of runs as shareable reports #90
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
Open
Copilot
wants to merge
6
commits into
main
Choose a base branch
from
copilot/fix-84
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.
+417
−15
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
99cdbc8
Initial plan
Copilot 8ff9bce
Initial analysis and planning for report permalinks feature
Copilot f58420b
Implement report permalinks feature for sharing sets of runs
Copilot 100eec6
Fix linting issues and add documentation for report permalinks feature
Copilot db70c78
Merge branch 'main' into copilot/fix-84
serhalp b38cbb7
Address PR feedback: delete files, fix types, improve error handling,…
Copilot 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 |
|---|---|---|
|
|
@@ -6,7 +6,24 @@ defineProps<{ | |
| error: string | null | ||
| loading: boolean | ||
| onClear: () => void | ||
| currentReportId?: string | null | ||
| }>() | ||
|
|
||
| const generateReportPermalink = (reportId: string) => { | ||
| const baseUrl = typeof window !== 'undefined' ? window.location.origin : '' | ||
| return `${baseUrl}/report/${reportId}` | ||
| } | ||
|
|
||
| const copyToClipboard = async (text: string) => { | ||
| if (typeof navigator !== 'undefined' && navigator.clipboard) { | ||
| try { | ||
| await navigator.clipboard.writeText(text) | ||
| } | ||
| catch (err) { | ||
| console.error('Failed to copy to clipboard:', err) | ||
| } | ||
| } | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
|
|
@@ -35,6 +52,27 @@ defineProps<{ | |
| </div> | ||
|
|
||
| <div class="reset-container"> | ||
| <div | ||
| v-if="currentReportId && runs.length > 0" | ||
| class="report-permalink" | ||
| > | ||
| <label>Share this report:</label> | ||
| <div class="permalink-container"> | ||
| <input | ||
| :value="generateReportPermalink(currentReportId)" | ||
| readonly | ||
| class="permalink-input" | ||
| /> | ||
| <button | ||
| class="copy-button" | ||
| title="Copy to clipboard" | ||
| @click="copyToClipboard(generateReportPermalink(currentReportId))" | ||
| > | ||
| 📋 | ||
| </button> | ||
|
Comment on lines
+66
to
+72
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in b38cbb7:
|
||
| </div> | ||
| </div> | ||
|
|
||
| <button | ||
| v-if="runs.length > 0" | ||
| @click="onClear()" | ||
|
|
@@ -70,4 +108,54 @@ defineProps<{ | |
| text-align: center; | ||
| background-color: inherit; | ||
| } | ||
|
|
||
| .report-permalink { | ||
| margin-bottom: 1em; | ||
| padding: 1em; | ||
| background-color: var(--bg-200, #f8fafc); | ||
| border-radius: 0.5em; | ||
| border: 1px solid var(--border-200, #e2e8f0); | ||
| } | ||
|
|
||
| .report-permalink label { | ||
| display: block; | ||
| font-weight: 500; | ||
| margin-bottom: 0.5em; | ||
| color: var(--text-700, #374151); | ||
| } | ||
|
|
||
| .permalink-container { | ||
| display: flex; | ||
| gap: 0.5em; | ||
| align-items: stretch; | ||
| max-width: 100%; | ||
| margin: 0 auto; | ||
| } | ||
|
|
||
| .permalink-input { | ||
| flex: 1; | ||
| padding: 0.5em; | ||
| border: 1px solid var(--border-300, #d1d5db); | ||
| border-radius: 0.25em; | ||
| background-color: white; | ||
| font-family: monospace; | ||
| font-size: 0.875em; | ||
| } | ||
|
|
||
| .copy-button { | ||
| padding: 0.5em 1em; | ||
| background-color: white; | ||
| color: var(--blue-600, #2563eb); | ||
| border: 2px solid var(--blue-600, #2563eb); | ||
| border-radius: 0.25em; | ||
| cursor: pointer; | ||
| font-size: 0.875em; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| .copy-button:hover { | ||
| background-color: var(--blue-50, #eff6ff); | ||
| } | ||
| </style> | ||
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,125 @@ | ||
| /** | ||
| * @vitest-environment jsdom | ||
| */ | ||
| import { describe, it, expect, vi, beforeEach } from 'vitest' | ||
| import { useRunManager } from './useRunManager' | ||
| import type { ApiRun } from '~/types/run' | ||
|
|
||
| // Mock the getCacheHeaders function | ||
| vi.mock('~/utils/getCacheHeaders', () => ({ | ||
| default: vi.fn((headers: Record<string, string>) => headers), | ||
| })) | ||
|
|
||
| // Mock navigateTo composable | ||
| vi.mock('#app/composables/router', () => ({ | ||
| navigateTo: vi.fn(async () => {}), | ||
| })) | ||
|
|
||
| // Mock fetch and $fetch | ||
| global.fetch = vi.fn() | ||
| vi.stubGlobal('$fetch', vi.fn()) | ||
|
|
||
| describe('useRunManager - Report Functionality', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| it('tracks currentReportId state', () => { | ||
| const { currentReportId, setCurrentReportId } = useRunManager() | ||
|
|
||
| expect(currentReportId.value).toBe(null) | ||
|
|
||
| setCurrentReportId('test-report-123') | ||
| expect(currentReportId.value).toBe('test-report-123') | ||
|
|
||
| setCurrentReportId(null) | ||
| expect(currentReportId.value).toBe(null) | ||
| }) | ||
|
|
||
| it('sends currentReportId in API requests when set', async () => { | ||
| const mockApiRun: ApiRun = { | ||
| runId: 'test-run', | ||
| url: 'https://example.com', | ||
| status: 200, | ||
| durationInMs: 100, | ||
| headers: { 'cache-control': 'max-age=3600' }, | ||
| reportId: 'new-report-456', | ||
| } | ||
|
|
||
| const mockFetch = $fetch as unknown as ReturnType<typeof vi.fn> | ||
| mockFetch.mockResolvedValueOnce(mockApiRun) | ||
|
|
||
| const { handleRequestFormSubmit, setCurrentReportId, currentReportId } = useRunManager() | ||
|
|
||
| setCurrentReportId('existing-report-123') | ||
|
|
||
| await handleRequestFormSubmit({ url: 'https://example.com' }) | ||
|
|
||
| expect(mockFetch).toHaveBeenCalledWith('/api/inspect-url', { | ||
| method: 'POST', | ||
| body: { | ||
| url: 'https://example.com', | ||
| currentReportId: 'existing-report-123', | ||
| }, | ||
| }) | ||
|
|
||
| // Should update to the new report ID returned from API | ||
| expect(currentReportId.value).toBe('new-report-456') | ||
| }) | ||
|
|
||
| it('updates currentReportId when API returns new reportId', async () => { | ||
| const mockApiRun: ApiRun = { | ||
| runId: 'test-run', | ||
| url: 'https://example.com', | ||
| status: 200, | ||
| durationInMs: 100, | ||
| headers: { 'cache-control': 'max-age=3600' }, | ||
| reportId: 'new-report-789', | ||
| } | ||
|
|
||
| const mockFetch = $fetch as unknown as ReturnType<typeof vi.fn> | ||
| mockFetch.mockResolvedValueOnce(mockApiRun) | ||
|
|
||
| const { handleRequestFormSubmit, currentReportId } = useRunManager() | ||
|
|
||
| expect(currentReportId.value).toBe(null) | ||
|
|
||
| await handleRequestFormSubmit({ url: 'https://example.com' }) | ||
|
|
||
| expect(currentReportId.value).toBe('new-report-789') | ||
| }) | ||
|
|
||
| it('clears currentReportId when clearing runs', async () => { | ||
| const { handleClickClear, setCurrentReportId, currentReportId } = useRunManager() | ||
|
|
||
| setCurrentReportId('test-report-123') | ||
| expect(currentReportId.value).toBe('test-report-123') | ||
|
|
||
| await handleClickClear() | ||
|
|
||
| expect(currentReportId.value).toBe(null) | ||
| }) | ||
|
|
||
| it('handles API response without reportId', async () => { | ||
| const mockApiRun: ApiRun = { | ||
| runId: 'test-run', | ||
| url: 'https://example.com', | ||
| status: 200, | ||
| durationInMs: 100, | ||
| headers: { 'cache-control': 'max-age=3600' }, | ||
| // No reportId in response | ||
| } | ||
|
|
||
| const mockFetch = $fetch as unknown as ReturnType<typeof vi.fn> | ||
| mockFetch.mockResolvedValueOnce(mockApiRun) | ||
|
|
||
| const { handleRequestFormSubmit, currentReportId, setCurrentReportId } = useRunManager() | ||
|
|
||
| setCurrentReportId('existing-report') | ||
|
|
||
| await handleRequestFormSubmit({ url: 'https://example.com' }) | ||
|
|
||
| // Should keep existing reportId if API doesn't return one | ||
| expect(currentReportId.value).toBe('existing-report') | ||
| }) | ||
| }) |
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
serhalp marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
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.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be much wider as it often contains quite long URLs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in b38cbb7 - changed
max-widthfrom600pxto100%so the input can expand to show longer URLs.