Skip to content

feat: Add 'Code Snippets' to the Playground's Query bar (4007) - #57

Open
adwait-bruno wants to merge 2 commits into
usebruno:mainfrom
adwait-bruno:feat/codesnippet-desktopparity
Open

feat: Add 'Code Snippets' to the Playground's Query bar (4007)#57
adwait-bruno wants to merge 2 commits into
usebruno:mainfrom
adwait-bruno:feat/codesnippet-desktopparity

Conversation

@adwait-bruno

@adwait-bruno adwait-bruno commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

REF:BRU-4007
Adds a Generate Code button to the playground's URL bar, so you can grab a cURL / JavaScript / Python snippet for the request you're working on without leaving the playground. This matches Bruno desktop, where the same control sits
next to the URL.

image image

@adwait-bruno
adwait-bruno force-pushed the feat/codesnippet-desktopparity branch from 79eb05a to ef0edde Compare August 25, 2026 07:59

@vasharma05-bruno vasharma05-bruno left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small changes, otherwise looks good to me. Please work on the changes suggested.

setPlaygroundResponse,
selectPlaygroundResponse,
applyScriptVariableChanges
} from '@/store/slices/playground';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} from '@/store/slices/playground';
} from '@slices/playground';

Refer:

"@slices/*": ["src/store/slices/*"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to revert this as lint was failing under the rule:

'no-restricted-imports': ['error', {
patterns: [{
group: ['**/store/slices/', '!@/store/slices/', '@slices/'],
message: 'Import slices through the @/store/slices/
alias.'
}]
}],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove the @slices/ from tsconfig and vite configs @arpit-bruno.

Comment on lines +54 to +73
const effectiveAuth = useMemo<Auth | undefined>(() => {
const ownAuth = getRequestAuth(editableItem) as Auth | undefined;
return ownAuth === 'inherit' ? resolveInheritedAuth(collection, ancestry, editableItem).auth : ownAuth;
}, [collection, ancestry, editableItem]);

// Applies same rules as runner so that the code snippet shows the same effective headers as the runner.
const effectiveHeaders = useMemo<HttpRequestHeader[]>(() => {
const auth = effectiveAuth && effectiveAuth !== 'inherit' ? effectiveAuth : undefined;
const authWritesAuthorization = Boolean(
(auth?.type === 'bearer' && auth.token) || (auth?.type === 'basic' && auth.username && auth.password)
);
const keep = (header: { name?: string }) =>
!authWritesAuthorization || (header.name || '').toLowerCase() !== 'authorization';
const ownRows = getRequestHeaders(editableItem).filter(keep);
const inheritedRows = getInheritedHeaders(collection, ancestry, editableItem)
.filter(keep)
.map((header) => ({ name: header.name, value: header.value ?? '', disabled: header.disabled }));
return [...ownRows, ...inheritedRows];
}, [collection, ancestry, editableItem, effectiveAuth]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sundram-bruno, I see this block been written multiple times in the whole application. Since you have worked on Auth, can we have a new reusable hook which does this, and update the implementation at other places accordingly.

Thanks!

Image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly it's in GrpcRequest, and now in the PlaygroundView. We have the useRequestPageData hook, but that's more than what is needed for this implementation.

Maybe, we can use the said hook inside the useRequestPageData,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vasharma05-bruno , ok will look into it and see what can be done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we let this change go ahead in this PR, or make the change in this PR itself?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let this change go. Currently I dont have the bandwidth to do the change and no need to hold this pr for something where we can change it across the whole repo. I feel we can let it be a separate task for it.

Comment on lines +71 to +77
it('labels the icon trigger for screen readers and marks it as opening a dialog', () => {
const root = useRenderToDom(<SnippetTabs snippets={snippets} variant="icon" testId="query-bar-code-snippet" />);

const trigger = getByTestId(root, 'query-bar-code-snippet-trigger');
expect(trigger.attributes['aria-label']).toBe('Generate Code');
expect(trigger.attributes['aria-haspopup']).toBe('dialog');
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add a test for clicking on the trigger button, and then check the modal renders with content inside it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have covered this in the e2e(query-bar-code-snippet.spec.ts) ,clicking cannot be simulated in rendertoStaticMarkup.

Comment on lines 105 to 128

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
) : (
<button
ref={triggerRef}
type="button"
className={variant == icon ? "snippet-icon-trigger" : "snippet-trigger"}
aria-haspopup="dialog"
aria-label="Generate Code"
data-testid={`${testId}-trigger`}
onClick={openModal}
>
<IconCode size={16} stroke={1.5} />
{variant === 'inline' && "Code Snippet"}
</button>
)

@vasharma05-bruno

vasharma05-bruno commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Please update the PR title: feat: Add 'Code Snippets' to the Playground's Query bar (Ticket number)

@adwait-bruno adwait-bruno changed the title Feat:CodeSnippet in the URL feat: Add 'Code Snippets' to the Playground's Query bar (4007) Aug 25, 2026
@adwait-bruno
adwait-bruno force-pushed the feat/codesnippet-desktopparity branch from 83f6c9e to be6916d Compare August 25, 2026 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants