Add copy response headers action#41884
Conversation
Walkthrough
ChangesCopy Headers Toolbar
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
app/client/src/PluginActionEditor/components/PluginActionResponse/components/ApiResponseHeaders.tsx (2)
82-82: ⚡ Quick winUse i18n pattern for toast message.
The toast message is hardcoded, but the file already imports
createMessage()fromee/constants/messages(line 7). For consistency with the codebase's internationalization pattern, consider adding message constants.♻️ Use createMessage pattern
Add to
ee/constants/messages:COPY_HEADERS_SUCCESS: () => "Response headers copied to clipboard", COPY_HEADERS_ERROR: () => "Failed to copy headers to clipboard",Then update the callback:
-toast.show("Response headers copied to clipboard", { +toast.show(createMessage(COPY_HEADERS_SUCCESS), { kind: "success", });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/client/src/PluginActionEditor/components/PluginActionResponse/components/ApiResponseHeaders.tsx` at line 82, Replace the hardcoded toast text in the ApiResponseHeaders component with i18n message constants: add COPY_HEADERS_SUCCESS and COPY_HEADERS_ERROR factory entries to ee/constants/messages, import them into PluginActionResponse/components/ApiResponseHeaders.tsx (you already import createMessage), and call toast.show(createMessage(COPY_HEADERS_SUCCESS())) on successful clipboard copy and toast.show(createMessage(COPY_HEADERS_ERROR())) in the catch/failure branch so both success and error toasts use the project i18n pattern.
124-124: ⚡ Quick winApply i18n pattern to button text.
The button text "Copy headers" is hardcoded. For consistency with the i18n pattern used elsewhere in the codebase, consider using
createMessage().🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/client/src/PluginActionEditor/components/PluginActionResponse/components/ApiResponseHeaders.tsx` at line 124, In ApiResponseHeaders component replace the hardcoded button label "Copy headers" with the i18n helper (e.g., createMessage(Messages.COPY_HEADERS)); import createMessage and the appropriate Messages key if missing, and use createMessage(Messages.COPY_HEADERS) wherever the literal "Copy headers" is used (button text, aria-labels or tooltips) so the component follows the project's i18n pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@app/client/src/PluginActionEditor/components/PluginActionResponse/components/ApiResponseHeaders.tsx`:
- Around line 80-85: The copyResponseHeaders handler always shows a success
toast even if copy(headersInput.value) fails; change it to capture the boolean
return (e.g., const success = copy(headersInput.value)) and only call toast.show
with the success message when success is true, otherwise call toast.show with an
error/failure message; update the copyResponseHeaders useCallback to use
headersInput.value and the copy result to decide which toast to display.
---
Nitpick comments:
In
`@app/client/src/PluginActionEditor/components/PluginActionResponse/components/ApiResponseHeaders.tsx`:
- Line 82: Replace the hardcoded toast text in the ApiResponseHeaders component
with i18n message constants: add COPY_HEADERS_SUCCESS and COPY_HEADERS_ERROR
factory entries to ee/constants/messages, import them into
PluginActionResponse/components/ApiResponseHeaders.tsx (you already import
createMessage), and call toast.show(createMessage(COPY_HEADERS_SUCCESS())) on
successful clipboard copy and toast.show(createMessage(COPY_HEADERS_ERROR())) in
the catch/failure branch so both success and error toasts use the project i18n
pattern.
- Line 124: In ApiResponseHeaders component replace the hardcoded button label
"Copy headers" with the i18n helper (e.g.,
createMessage(Messages.COPY_HEADERS)); import createMessage and the appropriate
Messages key if missing, and use createMessage(Messages.COPY_HEADERS) wherever
the literal "Copy headers" is used (button text, aria-labels or tooltips) so the
component follows the project's i18n pattern.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e3a1a86b-9ebf-4666-a407-3e395c72bcd5
📒 Files selected for processing (1)
app/client/src/PluginActionEditor/components/PluginActionResponse/components/ApiResponseHeaders.tsx
| const copyResponseHeaders = useCallback(() => { | ||
| copy(headersInput.value); | ||
| toast.show("Response headers copied to clipboard", { | ||
| kind: "success", | ||
| }); | ||
| }, [headersInput.value]); |
There was a problem hiding this comment.
Handle copy operation failure.
The copy() function returns a boolean indicating success, but the code shows a success toast regardless of the result. If the copy fails (e.g., browser restrictions), users will see a misleading success message.
✅ Check copy success before showing toast
const copyResponseHeaders = useCallback(() => {
- copy(headersInput.value);
- toast.show("Response headers copied to clipboard", {
- kind: "success",
- });
+ const success = copy(headersInput.value);
+ if (success) {
+ toast.show("Response headers copied to clipboard", {
+ kind: "success",
+ });
+ } else {
+ toast.show("Failed to copy headers to clipboard", {
+ kind: "error",
+ });
+ }
}, [headersInput.value]);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const copyResponseHeaders = useCallback(() => { | |
| copy(headersInput.value); | |
| toast.show("Response headers copied to clipboard", { | |
| kind: "success", | |
| }); | |
| }, [headersInput.value]); | |
| const copyResponseHeaders = useCallback(() => { | |
| const success = copy(headersInput.value); | |
| if (success) { | |
| toast.show("Response headers copied to clipboard", { | |
| kind: "success", | |
| }); | |
| } else { | |
| toast.show("Failed to copy headers to clipboard", { | |
| kind: "error", | |
| }); | |
| } | |
| }, [headersInput.value]); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@app/client/src/PluginActionEditor/components/PluginActionResponse/components/ApiResponseHeaders.tsx`
around lines 80 - 85, The copyResponseHeaders handler always shows a success
toast even if copy(headersInput.value) fails; change it to capture the boolean
return (e.g., const success = copy(headersInput.value)) and only call toast.show
with the success message when success is true, otherwise call toast.show with an
error/failure message; update the copyResponseHeaders useCallback to use
headersInput.value and the copy result to decide which toast to display.
|
This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected. |
Description
Tip
Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team).
Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR.
Fixes #
Issue Numberor
Fixes
Issue URLWarning
If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.
Automation
/ok-to-test tags=""
🔍 Cypress test results
Caution
If you modify the content in this section, you are likely to disrupt the CI result for your PR.
Communication
Should the DevRel and Marketing teams inform users about this change?
Summary by CodeRabbit