Skip to content

fix(VE-5555): add instance button loading state#406

Merged
faraazb merged 3 commits intodevelop_v3from
VE-5555-add-reference-instance-multiple-modals
Mar 24, 2025
Merged

fix(VE-5555): add instance button loading state#406
faraazb merged 3 commits intodevelop_v3from
VE-5555-add-reference-instance-multiple-modals

Conversation

@faraazb
Copy link
Copy Markdown
Contributor

@faraazb faraazb commented Mar 20, 2025

Adding a reference instance is an async operation on visual builder side. Use a loading state to disable the button, so that the add instance message cannot be sent when it is already sent and a response is being awaited.

Adding a reference instance is an async operation on visual builder
side. Use a loading state to disable the button, so that the add
instance message cannot be sent when it is already sent and a response
is being awaited
@faraazb faraazb requested a review from a team as a code owner March 20, 2025 10:56
@faraazb faraazb requested review from Copilot and removed request for a team March 20, 2025 10:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a loading state to the instance-adding button in the visual builder, preventing duplicate messages during asynchronous operations. Key changes include:

  • Updating AddInstanceButtonComponent to manage a loading signal and disable the button during async operations.
  • Modifying generateAddInstanceButton to pass required props (loading, index, fieldMetadata) to the component.
  • Adding visual feedback for the loading state via new CSS classes.
  • Introducing a shared loading signal for multiple add buttons in multipleElementAddButton.ts.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/visualBuilder/components/addInstanceButton.tsx Updated to include async handling with a loading state and revised disabled logic.
src/visualBuilder/generators/generateAddInstanceButtons.tsx Adjusted to forward additional props (loading, fieldMetadata, index) to the button component.
src/visualBuilder/visualBuilder.style.ts Added CSS for a loading state to provide user feedback.
src/visualBuilder/utils/multipleElementAddButton.ts Implemented a shared loading signal for coordinating multiple add buttons.
Comments suppressed due to low confidence (1)

src/visualBuilder/components/addInstanceButton.tsx:29

  • [nitpick] Consider renaming the inner onClick function (e.g., handleButtonClick) to clearly differentiate it from the props.onClick callback.
const onClick = async (event: MouseEvent) => {

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 20, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 81.44% 6806 / 8357
🔵 Statements 81.44% 6806 / 8357
🔵 Functions 75.23% 243 / 323
🔵 Branches 85.57% 854 / 998
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/visualBuilder/visualBuilder.style.ts 100% 100% 100% 100%
src/visualBuilder/components/addInstanceButton.tsx 93.67% 50% 100% 93.67% 40-41, 62, 64, 76
src/visualBuilder/generators/generateAddInstanceButtons.tsx 100% 100% 100% 100%
src/visualBuilder/utils/multipleElementAddButton.ts 87.97% 87.5% 100% 87.97% 83-84, 92, 95, 208-209, 247-273
Generated in workflow #341 for commit e98a8e3 by the Vitest Coverage Report Action

@faraazb faraazb requested a review from Copilot March 20, 2025 12:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a loading state for the add instance button to prevent multiple async submissions while waiting for a response. Key changes include:

  • Updating the add instance button component to disable the button during async operations.
  • Adjusting tests across generators, components, and utilities to handle the new loading prop.
  • Adding new loading-specific styling to visually indicate the button’s state.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/visualBuilder/generators/test/generateAddInstanceButtons.test.tsx Updated tests to include fieldMetadata and loading props for add instance button generation.
src/visualBuilder/components/addInstanceButton.tsx Refactored the component to set a loading state during async postMessage sending and adjusted the disabled logic.
src/visualBuilder/generators/generateAddInstanceButtons.tsx Modified the props order and added loading and fieldMetadata to the component invocation.
src/visualBuilder/visualBuilder.style.ts Added styles for the loading state of the add instance button.
src/visualBuilder/utils/test/multipleElementAddButton.test.ts Updated tests to include loading state handling with signals.
src/visualBuilder/utils/multipleElementAddButton.ts Introduced a shared loading signal for managing add instance button states.
src/visualBuilder/components/test/addInstanceButton.test.tsx Enhanced tests to verify that the component sends the add-instance message and calls the onClick callback.
Comments suppressed due to low confidence (2)

src/visualBuilder/components/addInstanceButton.tsx:29

  • [nitpick] The internal function 'onClick' shadows the prop 'onClick'. Consider renaming it to 'handleClick' to improve clarity.
const onClick = async (event: MouseEvent) => {

src/visualBuilder/components/test/addInstanceButton.test.tsx:58

  • [nitpick] Consider extending this test to verify that the loading state is set to true before the async operation and reset to false afterward.
test("sends add-instance message when clicked", async () => {

@faraazb
Copy link
Copy Markdown
Contributor Author

faraazb commented Mar 20, 2025

We can ignore the failing tests, they are being removed in another PR.

Copy link
Copy Markdown
Contributor

@hiteshshetty-dev hiteshshetty-dev left a comment

Choose a reason for hiding this comment

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

Chanf

Copy link
Copy Markdown
Contributor

@hiteshshetty-dev hiteshshetty-dev left a comment

Choose a reason for hiding this comment

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

Changes looks good to me!! Let's test it once on DotNET project as signal might have some impact here.

@faraazb faraazb merged commit 645b7f7 into develop_v3 Mar 24, 2025
7 checks passed
@faraazb faraazb deleted the VE-5555-add-reference-instance-multiple-modals branch March 24, 2025 07:31
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.

4 participants