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

Let the application know that a notification was closed #2471

Open
1 of 7 tasks
FabienLelaquais opened this issue Mar 3, 2025 · 9 comments · May be fixed by #2519
Open
1 of 7 tasks

Let the application know that a notification was closed #2471

FabienLelaquais opened this issue Mar 3, 2025 · 9 comments · May be fixed by #2519
Assignees
Labels
🖰 GUI Related to GUI 🆘 Help wanted Open to participation from the community 📈 Improvement Improvement of a feature. ✨New feature 🟩 Priority: Low Low priority and doesn't need to be rushed

Comments

@FabienLelaquais
Copy link
Member

FabienLelaquais commented Mar 3, 2025

Description

We have no way to control whether a notification was closed or not.
It could make sense for the app to know about this, in order to potentially show other notifications that would be unreadable should too many notifications be visible yet.

Solution Proposed

Improve the notify() API with a callback:
notify(..., on_close=notification_closed)
and
def notification_closed(state, notification_id, reason
reason being "forced" or "timeout". I don't think we need to know whether the 'force' was manual or not.

Acceptance Criteria

  • If applicable, a new demo code is provided to show the new feature in action.
  • Integration tests exhibiting how the functionality works are added.
  • Any new code is covered by a unit tested.
  • Check code coverage is at least 90%.
  • Related issue(s) in taipy-doc are created for documentation and Release Notes are updated.

Code of Conduct

  • I have checked the existing issues.
  • I am willing to work on this issue (optional)
@FabienLelaquais FabienLelaquais added ✨New feature 📈 Improvement Improvement of a feature. 🖰 GUI Related to GUI 🟩 Priority: Low Low priority and doesn't need to be rushed labels Mar 3, 2025
@Andre-Pestana0
Copy link

Hi there, I would like to help with this issue if possible!

@FlorianJacta
Copy link
Member

This is currently not in the product backlog. Can this be assigned? @FabienLelaquais

@FabienLelaquais
Copy link
Member Author

This is currently not in the product backlog. Can this be assigned? @FabienLelaquais

@FlorianJacta Certainly, yes.
I let you set the priority my friend.

@jrobinAV jrobinAV added the 🆘 Help wanted Open to participation from the community label Mar 21, 2025
@Andre-Pestana0
Copy link

Could i help with this issue?

@FlorianJacta
Copy link
Member

Sure @Andre-Pestana0, I am assigning it to you

@Andre-Pestana0
Copy link

Hello there, I have some doubts that I would like to share.

First and foremost this is my work until now:

  • I have added a callback to notify "on_close" and inside of it Im expecting a user to send the state, notification_id and reason for closing the notification.
def notify(
    state: State,
    notification_type: str = "info",
    message: str = "",
    system_notification: t.Optional[bool] = None,
    duration: t.Optional[int] = None,
    id: str = "",
    on_close: t.Optional[t.Callable[[State, str, str], None]] = None,
) -> t.Optional[str]:

....


    def _notify(
        self,
        notification_type: str = "I",
        message: str = "",
        system_notification: t.Optional[bool] = None,
        duration: t.Optional[int] = None,
        notification_id: t.Optional[str] = None,
        on_close: t.Optional[t.Callable[[State, str, str], None]] = None,
    ):
        if notification_id and on_close:
            self._notification_callbacks[notification_id] = on_close  # A dictonary was created in order to store the callback

  • I have added the reason to on_close:
def close_notification(state: State, id: str, reason:str) -> None:
...



    def _close_notification(
        self,
        notification_id: str,
        reason: str = "forced", 
    ):
        if notification_id:
            self.__send_ws_notification(
                type="",  # Empty string indicates closing
                message="",  # No need for a message when closing
                system_notification=False,  # System notification not needed for closing
                duration=0,  # No duration since it's an immediate close
                notification_id=notification_id,
            )

            if notification_id in self._notification_callbacks:
                callback = self._notification_callbacks.pop(notification_id)  
                callback(self, notification_id, reason)

The final result can be seen by the following code and prints:

from taipy.gui import Gui, notify, close_notification

#Callback function
def on_close(state, notification_id, reason):
    print(f"Notification {notification_id} closed due to {reason}")

# Function to trigger a notification
def send_notification(state):
    notify(state, "info", "This is a test notification!", None, None, "3", on_close)

# Function to close the notification
def close_test_notification(state):
    close_notification(state, "3", "forced")

if __name__ == "__main__":
    page = """
# Notification Demo

Click the button to trigger a notification:

<|button|text=Send Notification|on_action=send_notification|>

Click the button to close the notification:

<|button|text=Close Notification|on_action=close_test_notification|>
"""
Gui(page).run()

Image

Image

My question

I don't understand if the changes requested are these or if the reasons"forced" and "timout" should be something that the user never has to actually state

@FlorianJacta
Copy link
Member

Can you create a PR to explain what you have done like this message? Then, the R&D can discuss on it @Andre-Pestana0

@Andre-Pestana0 Andre-Pestana0 linked a pull request Mar 31, 2025 that will close this issue
11 tasks
@Andre-Pestana0
Copy link

Hello there @FlorianJacta, I have created the PR and put my doubt there as a comment

@FlorianJacta
Copy link
Member

Great, I have put as reviewers the R&D! @Andre-Pestana0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🖰 GUI Related to GUI 🆘 Help wanted Open to participation from the community 📈 Improvement Improvement of a feature. ✨New feature 🟩 Priority: Low Low priority and doesn't need to be rushed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants