Skip to content

Validate mock response body#499

Open
snappdevelopment wants to merge 2 commits intoopenflocon:mainfrom
snappdevelopment:validate-mock-response-body
Open

Validate mock response body#499
snappdevelopment wants to merge 2 commits intoopenflocon:mainfrom
snappdevelopment:validate-mock-response-body

Conversation

@snappdevelopment
Copy link
Contributor

This adds two tabs "Edit" and "Validate" to the mock edit screen. "Edit" shows the regular TextField like before, while "Validate" uses JsonTree to validate the input and display it pretty printed.

  • Increased the minLines value of the TextField to 10, to allow easier editing
  • Increased the window size to 800.dp to show the full TextField when the window opens
  • Added two tabs to switch between edit and validation mode
  • If the json is not valid, the validation tab shows the error message of the throwable, which tells the user where the error is inside the json string

Let me know what you think :)

The feature request also asks to pretty print the editable string. This should already work if a json is pasted into the TextField and then saved.

Closes #496

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @snappdevelopment, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the user experience for editing and validating mock response bodies by integrating a tabbed interface. Users can now seamlessly switch between a standard text editor and a dedicated JSON validation and pretty-printing view, which also provides immediate feedback on malformed JSON. These changes aim to streamline the process of creating and maintaining accurate mock data.

Highlights

  • Enhanced Mock Body Editing: Introduced two tabs, 'Edit' and 'Validate', to the mock edit screen for managing the response body. The 'Edit' tab provides a standard text field, while the 'Validate' tab offers JSON validation and pretty-printing.
  • Improved Text Field Usability: Increased the minimum lines for the body TextField to 10, allowing for easier and more comprehensive editing of larger content.
  • Adjusted Window Size: The default window size for the mock editing screen has been increased to 900.dp x 800.dp to better accommodate the expanded TextField and new UI elements.
  • Real-time JSON Validation Feedback: The 'Validate' tab now displays error messages with localized details if the input JSON is invalid, guiding users to correct issues within the JSON string.
Changelog
  • FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/features/network/mock/edition/view/NetworkEditionWindow.kt
    • Added necessary imports for layout components like 'height', JSON tree components ('TreeState', 'FloconJsonTree'), and design system components ('DefaultLabel').
    • Increased the initial window size from 700.dp to 800.dp in height.
    • Replaced the single 'FloconTextField' for the mock body with a tabbed interface.
    • Implemented 'Edit' and 'Validate' tabs, allowing users to switch between raw text editing and structured JSON viewing/validation.
    • Configured the 'Edit' tab's 'FloconTextField' to have a minimum of 10 lines.
    • Integrated 'FloconJsonTree' into the 'Validate' tab to display pretty-printed JSON and handle validation errors.
    • Added logic to display localized error messages when JSON validation fails in the 'Validate' tab.
Activity
  • The author, snappdevelopment, has implemented the requested features to validate mock response bodies and is seeking feedback on the changes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a valuable feature by adding a validation tab for the mock response body, which will certainly improve the user experience. The implementation is solid, adding tabs to switch between editing and validating the JSON content. My review focuses on a few areas related to UI consistency and theming. I've identified some hardcoded colors that could lead to readability issues in different themes and have provided suggestions to address them.

Comment on lines +402 to +411
Box(
modifier = Modifier
.fillMaxWidth()
.height(400.dp)
.background(
color = FloconTheme.colorPalette.primary,
shape = FloconTheme.shapes.medium,
)
.padding(vertical = 4.dp, horizontal = 8.dp),
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The FloconJsonTree component uses defaultDarkColors, which are hardcoded and not theme-aware. Placing it inside a Box with a primary background can lead to color clashes and poor readability, especially in a light theme. The ideal solution is to make FloconJsonTree theme-aware. As a workaround, you could remove the background from this Box, but be aware this may create a visual inconsistency between the 'Edit' and 'Validate' tabs.

Comment on lines 377 to 386
Tab(
text = "Edit",
isSelected = isEditSelected,
onSelected = { isEditSelected = true }
)
Tab(
text = "Validate",
isSelected = !isEditSelected,
onSelected = { isEditSelected = false }
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The Tab component's implementation uses hardcoded colors (Color.White) for its background, which prevents it from adapting to different application themes (e.g., light vs. dark). It is recommended to refactor the Tab component to use theme-based colors from FloconTheme to ensure visual consistency across the application.

} else {
Text(
text = throwable.localizedMessage,
style = FloconTheme.typography.bodySmall
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The parent Box has a primary background color. For correct color contrast and adherence to the theme, the text color should be explicitly set to onPrimary. Since the Text composable is inside this box, its color should be set accordingly.

Suggested change
style = FloconTheme.typography.bodySmall
style = FloconTheme.typography.bodySmall.copy(color = FloconTheme.colorPalette.onPrimary)
References
  1. When a component's background color is primary, its content color should be onPrimary for semantic correctness and to ensure robustness against future theme changes.

var isEditSelected by remember { mutableStateOf(true) }

Row(modifier = Modifier.fillMaxWidth()) {
Tab(
Copy link
Contributor

Choose a reason for hiding this comment

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

could we use a FloconTab ? If does not exist, can we create it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! It didn't exist yet, but was defined in the same file at the bottom. I moved it to the components and styled the rounded corners a bit differently to get more of a single-choice style.

(Btw feel free to merge my PRs when you approve them. I can't do it myself, because only maintainers have the rights for that)

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.

[Feature]: Pretty-printed, nested JSON and validation support for Mock Response Body

2 participants