Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Alert shows twice for select widget #26696

Closed
1 task done
ghost opened this issue Aug 28, 2023 · 5 comments
Closed
1 task done

[Bug]: Alert shows twice for select widget #26696

ghost opened this issue Aug 28, 2023 · 5 comments
Assignees
Labels
Bug Something isn't working Low An issue that is neither critical nor breaks a user flow Needs Triaging Needs attention from maintainers to triage Production Select Widget Select or dropdown widget Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets

Comments

@ghost
Copy link

ghost commented Aug 28, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Description

Attached screen shot :
image

Steps To Reproduce

  • Drag and drop select widget
  • For an event "onDropdownClosed" > Set an action of show alert = Drop down closed
  • Now open the drop down of select widget and collapse the drop down and observe alerts shows 2 times

Public Sample App

No response

Environment

Production

Issue video log

No response

Version

Appsmith v1.9.35-SNAPSHOT

@ghost ghost added Bug Something isn't working Select Widget Select or dropdown widget Low An issue that is neither critical nor breaks a user flow Production Needs Triaging Needs attention from maintainers to triage labels Aug 28, 2023
@github-actions github-actions bot added the Widgets Product This label groups issues related to widgets label Aug 28, 2023
@Nikhil-Nandagopal
Copy link
Contributor

This no longer occurs

@SunnyTitus
Copy link

Generated the possible solution through ChatGPT:

Technical Solution (ChatGPT)

Frontend (React)

Ensure that the event listener for "onDropdownClosed" is correctly debounced or throttled to prevent multiple triggers.import React, { useState } from 'react';import Select from 'react-select'; // Assuming use of react-select library

const CustomSelect = () => { const [isDropdownOpen, setDropdownOpen] = useState(false);

const handleDropdownClose = () => { if (isDropdownOpen) { alert('Drop down closed'); setDropdownOpen(false); } };

return ( <Select options={[{ value: '1', label: 'Option 1' }, { value: '2', label: 'Option 2' }]} onMenuOpen={() => setDropdownOpen(true)} onMenuClose={handleDropdownClose} /> );};

export default CustomSelect;

Backend (Spring Boot)

Ensure the backend processes any event related to dropdown closing only once, if applicable.

This might not be needed specifically for the dropdown closing event, but ensure idempotency in API calls if any backend actions are triggered by UI events.

Solution Summary
To fix the issue where the alert shows twice for the select widget when the dropdown is closed, the "onDropdownClosed" event should be handled in such a way that it only triggers once. This can be achieved by implementing a flag to check if the dropdown is open and setting it appropriately. The provided React code snippet demonstrates how to achieve this using state management to ensure the alert is shown only once.

@prasad-madine
Copy link
Contributor

Hi @Nikhil-Nandagopal , I'm picking this issue.

@kamakshibhat-appsmith
Copy link

This issue occurs if we click on the widget again to close the dropdown . loom

@Nikhil-Nandagopal Nikhil-Nandagopal added the Widgets & Accelerators Pod Issues related to widgets & Accelerators label Aug 6, 2024
yatinappsmith pushed a commit that referenced this issue Oct 4, 2024
…elect widget (#34812)

## Description: 
> When using the select widget, setting the "onDropdownClosed" event to
show an alert results in the alert being shown twice instead of once.
> I have raised this PR to ensure that `show alert is called only once
in the select widget on calling onCloseDropdown`.
## [Issue Link](#26696)

## Cypress video:


https://github.com/appsmithorg/appsmith/assets/136346053/b602fd18-a7ed-4a0b-8546-cf29d90ba0f9


## Screenshots:
### Before resolving bug:
![Screenshot from 2024-07-05
09-46-03](https://github.com/appsmithorg/appsmith/assets/136346053/451ca605-5c04-4473-8bc7-f1dfcf81890c)


### After resolving bug :
![Screenshot from 2024-07-08
08-55-14](https://github.com/appsmithorg/appsmith/assets/136346053/f2b113c4-9a07-479f-a6bf-607652e88ea2)



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Tests**
- Introduced new tests for the Select widget to validate
`onDropdownClose`, `onDropdownOpen`, and `onOptionChange` events,
ensuring alerts display correctly during interactions.
- Added a test suite for the `SelectComponent` to verify that dropdown
callbacks are triggered correctly.

- **New Features**
- Enhanced the visibility toggle logic for the Select widget's popover,
improving user experience by preventing redundant actions when toggling
via button clicks.
- Added a specific method to handle button click events for toggling the
popover visibility.
- Improved responsiveness of the Select widget by ensuring active item
updates only occur when the selected item changes.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@rahulbarwal
Copy link
Contributor

Fixed via: #34812

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Low An issue that is neither critical nor breaks a user flow Needs Triaging Needs attention from maintainers to triage Production Select Widget Select or dropdown widget Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets
Projects
None yet
Development

No branches or pull requests

8 participants