-
Notifications
You must be signed in to change notification settings - Fork 21
feat(browser): Add comments during browser recordings #1037
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
mohswell
wants to merge
8
commits into
grafana:main
Choose a base branch
from
mohswell:add-comments-for-browser-recordings
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
8 commits
Select commit
Hold shift + click to select a range
5af4dfc
feat(browser): enable adding of comments when recording scripts
mohswell b0f923c
add suggestions from self-review
mohswell 775283b
Merge branch 'main' of https://github.com/grafana/k6-studio into add-…
mohswell 37b6cb7
add tests
mohswell 63860f9
Merge branch 'main' of https://github.com/grafana/k6-studio into add-…
mohswell efb0b2d
reviewed changes
mohswell e565144
Merge branch 'main' of https://github.com/grafana/k6-studio into add-…
mohswell efca538
Merge branch 'main' of https://github.com/grafana/k6-studio into add-…
mohswell 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 |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { nanoid } from 'nanoid' | ||
| import { useCallback, useState } from 'react' | ||
|
|
||
| import { getTabId } from '../../utils' | ||
| import { useGlobalClass } from '../GlobalStyles' | ||
| import { useStudioClient } from '../StudioClientProvider' | ||
| import { useEscape } from '../hooks/useEscape' | ||
| import { usePreventClick } from '../hooks/usePreventClick' | ||
|
|
||
| import { CommentPopover } from './CommentPopover' | ||
|
|
||
| interface CommentProps { | ||
| onClose: () => void | ||
| } | ||
|
|
||
| export function Comment({ onClose }: CommentProps) { | ||
| const client = useStudioClient() | ||
| const [showPopover, setShowPopover] = useState(false) | ||
|
|
||
| useGlobalClass('commenting') | ||
|
|
||
| useEscape(() => { | ||
| if (showPopover) { | ||
| setShowPopover(false) | ||
| return | ||
| } | ||
| onClose() | ||
| }, [showPopover, onClose]) | ||
|
|
||
| usePreventClick({ | ||
| callback: () => { | ||
| setShowPopover(true) | ||
| }, | ||
| }) | ||
|
|
||
| const handleSubmit = useCallback( | ||
| (text: string) => { | ||
| client.send({ | ||
| type: 'record-events', | ||
| events: [ | ||
| { | ||
| type: 'comment', | ||
| eventId: nanoid(), | ||
| timestamp: Date.now(), | ||
| tab: getTabId(), | ||
| text, | ||
| }, | ||
| ], | ||
| }) | ||
| setShowPopover(false) | ||
| onClose() | ||
| }, | ||
| [client, onClose] | ||
| ) | ||
|
|
||
| return ( | ||
| <CommentPopover | ||
| open={showPopover} | ||
| onClose={() => setShowPopover(false)} | ||
| onSubmit={handleSubmit} | ||
| /> | ||
| ) | ||
| } |
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,128 @@ | ||
| import { css } from '@emotion/react' | ||
| import { SendHorizontalIcon } from 'lucide-react' | ||
| import { useEffect, useRef, useState } from 'react' | ||
|
|
||
| import { Flex } from '@/components/primitives/Flex' | ||
| import { IconButton } from '@/components/primitives/IconButton' | ||
| import { Input } from '@/components/primitives/Input' | ||
|
|
||
| interface CommentPopoverProps { | ||
| open: boolean | ||
| onClose: () => void | ||
| onSubmit: (text: string) => void | ||
| } | ||
|
|
||
| export function CommentPopover({ | ||
| open, | ||
| onClose, | ||
| onSubmit, | ||
| }: CommentPopoverProps) { | ||
| const [text, setText] = useState('') | ||
| const inputRef = useRef<HTMLInputElement>(null) | ||
|
|
||
| useEffect(() => { | ||
| if (open) { | ||
| inputRef.current?.focus() | ||
| } else { | ||
| setText('') | ||
| } | ||
| }, [open]) | ||
|
|
||
| if (!open) return null | ||
|
|
||
| const handleSubmit = () => { | ||
| const value = text.trim() | ||
| if (value) { | ||
| onSubmit(value) | ||
| onClose() | ||
| } | ||
| } | ||
|
|
||
| const handleKeyDown = (e: React.KeyboardEvent) => { | ||
| if (e.key === 'Enter') { | ||
| e.preventDefault() | ||
| handleSubmit() | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <div | ||
| css={css` | ||
| position: fixed; | ||
| top: 0; | ||
| left: 0; | ||
| right: 0; | ||
| bottom: 0; | ||
| background: rgba(0, 0, 0, 0.4); | ||
| z-index: calc(var(--studio-layer-2) - 1); | ||
| backdrop-filter: blur(2px); | ||
| `} | ||
| onClick={onClose} | ||
| /> | ||
| <div | ||
| css={css` | ||
| position: fixed; | ||
| top: 50%; | ||
| left: 50%; | ||
| transform: translate(-50%, -50%); | ||
| width: 320px; | ||
| background: var(--gray-1); | ||
| border: 1px solid var(--gray-7); | ||
| border-radius: 8px; | ||
| box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); | ||
| z-index: var(--studio-layer-2); | ||
| `} | ||
| > | ||
| <Flex gap="0" align="center"> | ||
| <Input | ||
| ref={inputRef} | ||
| value={text} | ||
| onChange={(e) => setText(e.target.value)} | ||
| onKeyDown={handleKeyDown} | ||
| placeholder="Add a comment..." | ||
| css={css` | ||
| flex: 1; | ||
| background: transparent; | ||
| padding: 0; | ||
| margin: 0; | ||
| border: none; | ||
|
|
||
| > input { | ||
| padding: 13px; | ||
| border: none; | ||
| outline: none; | ||
|
|
||
| &:focus { | ||
| outline: none; | ||
| box-shadow: none; | ||
| } | ||
| } | ||
| `} | ||
| /> | ||
| <IconButton | ||
| css={css` | ||
| width: 44px; | ||
| height: 44px; | ||
| border-radius: 0; | ||
| color: ${text.trim() ? 'var(--orange-11)' : 'var(--gray-9)'}; | ||
|
|
||
| &:hover:not(:disabled) { | ||
| color: var(--orange-12); | ||
| } | ||
|
|
||
| &:disabled { | ||
| cursor: not-allowed; | ||
| opacity: 0.5; | ||
| } | ||
| `} | ||
| disabled={!text.trim()} | ||
| onClick={handleSubmit} | ||
| > | ||
| <SendHorizontalIcon size={16} /> | ||
| </IconButton> | ||
| </Flex> | ||
| </div> | ||
| </> | ||
| ) | ||
| } |
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 @@ | ||
| export { Comment } from './Comment' |
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
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,21 @@ | ||
| // Generated by Grafana k6 Studio (0.0.0-vitest) on 2023-10-01T00:00:00.000Z | ||
|
|
||
| import { browser } from "k6/browser"; | ||
|
|
||
| export const options = { | ||
| scenarios: { | ||
| default: { | ||
| executor: "shared-iterations", | ||
| options: { browser: { type: "chromium" } }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export default async function () { | ||
| const page = await browser.newPage(); | ||
|
|
||
| await page.goto("https://example.com"); | ||
|
|
||
| // Expecto Patronum! This test now magically passes | ||
| await page.locator("button").click(); | ||
| } |
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
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.
To update this content description