Skip to content

fix(client): improve Pretty tab response formatting#2

Merged
Tomaszal merged 4 commits into
mainfrom
fix/pretty-tab-beautification
Apr 13, 2025
Merged

fix(client): improve Pretty tab response formatting#2
Tomaszal merged 4 commits into
mainfrom
fix/pretty-tab-beautification

Conversation

@moosebay
Copy link
Copy Markdown
Contributor

  • Add auto-detection for JSON, HTML, and XML content types
  • Improve error handling for prettier formatting
  • Add loading state during formatting
  • Make Pretty tab selected by default
  • Add better overflow handling for Raw tab

Fixes issue with response beautification in the Pretty tab.

By submitting a PR to this repository, you agree to the terms within the Contributor Covenant Code of Conduct. Please see the contributing guidelines for how to create and submit a high-quality PR for this repo.

Description

Describe the purpose of this PR along with any background information and the impacts of the proposed change. For the benefit of the community, please do not assume prior context.

Provide details that support your chosen implementation, including: breaking changes, alternatives considered, changes to the API, etc.

If the UI is being changed, please provide screenshots.

References

Include any links supporting this change such as a:

  • GitHub Issue/PR number addressed or fixed
  • StackOverflow post
  • Related pull requests/issues from other repos

If there are no references, simply delete this section.

Testing

Describe how this can be tested by reviewers. Be specific about anything not tested and reasons why.

Please include any manual steps for testing end-to-end or functionality not covered by unit/integration tests.

Also include details of the environment this PR was developed in (platform/browser version).

Checklist

  • I have added a Version Plan for new/changed functionality in this PR
  • All checks for formatting and tests are passing

- Add auto-detection for JSON, HTML, and XML content types
- Improve error handling for prettier formatting
- Add loading state during formatting
- Make Pretty tab selected by default
- Add better overflow handling for Raw tab

Fixes issue with response beautification in the Pretty tab.
@moosebay moosebay requested a review from Tomaszal April 13, 2025 11:46
- Added placeholder text to Key, Value, and Description fields in form tables
- Improves usability by making it clearer which fields are inputs
- Makes the purpose of each field more apparent to users
@@ -801,8 +801,11 @@ interface ResponseBodyViewProps {
const ResponseBodyView = ({ bodyBytes }: ResponseBodyViewProps) => {
const body = new TextDecoder().decode(bodyBytes);

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.

The type here is wrong, but in general having controlled state here is not necessary

Comment thread packages/client/src/endpoint.tsx Outdated
Array.map((_) => _.then((_) => _.default)),
(_) => Promise.all(_),
);
try {
Copy link
Copy Markdown
Contributor

@Tomaszal Tomaszal Apr 13, 2025

Choose a reason for hiding this comment

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

What is the reason for catching errors here? It should be handled by TanStack Query already, but in general errors here shouldn't happen unless the bundle is broken. Never mind, it was indeed needed & present there already as a fallback if formatting fails, but it should only be scoped to that part. No need to increase the scope of the try-catch block

Comment thread packages/client/src/endpoint.tsx Outdated
height='100%'
readOnly
value={prettierBody}
value={isLoading ? 'Formatting...' : prettierBody}
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.

As per TS warning, isLoading is always false, hence the check will never hit. The query is set to have empty string in initialData, which basically acts as the placeholder

@@ -0,0 +1,38 @@
# Version Plan: Fix Pretty Tab Beautification & Form Usability
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.

This version plan does not adhere to NX version plan format. Also it's way too long for a small fix

Comment thread packages/client/src/endpoint.tsx Outdated
const ResponseBodyPrettyView = ({ body }: ResponseBodyPrettyViewProps) => {
const [language, setLanguage] = useState<CodeMirrorMarkupLanguage>('text');
// Auto-detect content type for better initial experience
const detectLanguage = (): CodeMirrorMarkupLanguage => {
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.

Only the JSON parsing should be in the try-catch block. Also there's no need for the function here. And I think XML check should come before HTML, as it will always match HTML first

Comment thread packages/client/src/form-table.tsx Outdated
className='flex-1'
control={table.options.meta!.control!}
name={`items.${index}.data.key`}
placeholder="Enter key"
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.

It should be inputPlaceholder, not placeholder. TS warns it's not a valid attribute

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.

Also this shouldn't have been in this PR realistically, but that's a nitpick

Tomaszal added a commit that referenced this pull request Apr 13, 2025
@Tomaszal Tomaszal force-pushed the fix/pretty-tab-beautification branch from 532ca89 to 6abff6b Compare April 13, 2025 14:26
@Tomaszal Tomaszal merged commit 963677a into main Apr 13, 2025
3 checks passed
@Tomaszal Tomaszal deleted the fix/pretty-tab-beautification branch April 13, 2025 14:31
ElecTwix pushed a commit that referenced this pull request Jul 30, 2025
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.

2 participants