[PR #128] [MERGED] Custom JSON formatter that works with template syntax #63

Closed
opened 2025-12-29 07:19:08 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mountain-loop/yaak/pull/128
Author: @gschier
Created: 10/22/2024
Status: Merged
Merged: 10/22/2024
Merged by: @gschier

Base: masterHead: custom-json-formatter


📝 Commits (1)

  • 9b40d1e Custom JSON formatter that works with template syntax

📊 Changes

17 files changed (+414 additions, -117 deletions)

View changed files

📝 package-lock.json (+44 -44)
📝 package.json (+1 -1)
📝 src-tauri/Cargo.lock (+66 -33)
📝 src-tauri/Cargo.toml (+5 -5)
📝 src-tauri/gen/schemas/desktop-schema.json (+1 -1)
📝 src-tauri/gen/schemas/macOS-schema.json (+1 -1)
📝 src-tauri/src/lib.rs (+11 -4)
src-tauri/yaak_templates/src/format.rs (+230 -0)
📝 src-tauri/yaak_templates/src/lib.rs (+1 -0)
📝 src-web/components/core/Editor/Editor.tsx (+3 -3)
📝 src-web/components/responseViewers/EventStreamViewer.tsx (+9 -6)
📝 src-web/components/responseViewers/HTMLOrTextViewer.tsx (+1 -1)
📝 src-web/components/responseViewers/TextViewer.tsx (+7 -8)
src-web/hooks/useFormatText.ts (+28 -0)
📝 src-web/hooks/useSyncWorkspaceChildModels.ts (+1 -0)
📝 src-web/lib/formatters.ts (+4 -10)
📝 src-web/lib/tauri.ts (+1 -0)

📄 Description

Before, the JSON formatter would simply do JSON.stringify(JSON.parse(text, null, 2)). However, that meant it could only parse valid JSON, and would do things like round floats when they contained trailing zeros like 1.000.

This new formatter is implemented in Rust and is implemented as a simple string iterator. This means:

  • It works on invalid/incomplete JSON
  • It can do custom things like ignore Template Tags ${[ ...]}
  • It preserves original content like 1.000 instead of rounding to 1

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new command for formatting JSON strings asynchronously.
    • Added a new FormattedEditor component for improved text formatting in event streams.
    • Implemented a custom hook, useFormatText, for handling text formatting based on language.
  • Improvements

    • Updated the Editor component to support asynchronous formatting operations.
    • Enhanced error handling and loading states in various components.
  • Bug Fixes

    • Corrected references and improved logic for handling paste events in the editor.
  • Chores

    • Updated dependency versions for improved performance and stability.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/mountain-loop/yaak/pull/128 **Author:** [@gschier](https://github.com/gschier) **Created:** 10/22/2024 **Status:** ✅ Merged **Merged:** 10/22/2024 **Merged by:** [@gschier](https://github.com/gschier) **Base:** `master` ← **Head:** `custom-json-formatter` --- ### 📝 Commits (1) - [`9b40d1e`](https://github.com/mountain-loop/yaak/commit/9b40d1eb2d9f84e44a66223f00171ca718b77bb4) Custom JSON formatter that works with template syntax ### 📊 Changes **17 files changed** (+414 additions, -117 deletions) <details> <summary>View changed files</summary> 📝 `package-lock.json` (+44 -44) 📝 `package.json` (+1 -1) 📝 `src-tauri/Cargo.lock` (+66 -33) 📝 `src-tauri/Cargo.toml` (+5 -5) 📝 `src-tauri/gen/schemas/desktop-schema.json` (+1 -1) 📝 `src-tauri/gen/schemas/macOS-schema.json` (+1 -1) 📝 `src-tauri/src/lib.rs` (+11 -4) ➕ `src-tauri/yaak_templates/src/format.rs` (+230 -0) 📝 `src-tauri/yaak_templates/src/lib.rs` (+1 -0) 📝 `src-web/components/core/Editor/Editor.tsx` (+3 -3) 📝 `src-web/components/responseViewers/EventStreamViewer.tsx` (+9 -6) 📝 `src-web/components/responseViewers/HTMLOrTextViewer.tsx` (+1 -1) 📝 `src-web/components/responseViewers/TextViewer.tsx` (+7 -8) ➕ `src-web/hooks/useFormatText.ts` (+28 -0) 📝 `src-web/hooks/useSyncWorkspaceChildModels.ts` (+1 -0) 📝 `src-web/lib/formatters.ts` (+4 -10) 📝 `src-web/lib/tauri.ts` (+1 -0) </details> ### 📄 Description Before, the JSON formatter would simply do `JSON.stringify(JSON.parse(text, null, 2))`. However, that meant it could only parse valid JSON, and would do things like round floats when they contained trailing zeros like `1.000`. This new formatter is implemented in Rust and is implemented as a simple string iterator. This means: - It works on invalid/incomplete JSON - It can do custom things like ignore Template Tags `${[ ...]}` - It preserves original content like `1.000` instead of rounding to `1` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Introduced a new command for formatting JSON strings asynchronously. - Added a new `FormattedEditor` component for improved text formatting in event streams. - Implemented a custom hook, `useFormatText`, for handling text formatting based on language. - **Improvements** - Updated the `Editor` component to support asynchronous formatting operations. - Enhanced error handling and loading states in various components. - **Bug Fixes** - Corrected references and improved logic for handling paste events in the editor. - **Chores** - Updated dependency versions for improved performance and stability. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 07:19:08 +01:00
adam closed this issue 2025-12-29 07:19:08 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/yaak#63