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

Add AlertComponent for displaying alerts in the GUI #1975

Open
wants to merge 33 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a4c1f02
Add AlertComponent for displaying alerts in the GUI
Rishi-0007 Oct 8, 2024
31f9bc2
Merge branch 'develop' into feature/#693-AddAlertVisualElement
Rishi-0007 Oct 8, 2024
7b3d3d7
Add AlertComponent in index.ts
Rishi-0007 Oct 9, 2024
965deb7
Refactor AlertComponent to handle dynamic message and update dependen…
Rishi-0007 Oct 9, 2024
97bbda4
Renamed AlertComponent to Notification and updated dependencies
Rishi-0007 Oct 9, 2024
5d7b543
Merge branch 'develop' into feature/#693-AddAlertVisualElement
Rishi-0007 Oct 9, 2024
1654d62
updated dependencies
Rishi-0007 Oct 9, 2024
af84cfb
updated viselements.json
Rishi-0007 Oct 9, 2024
3b6fd8a
Refactor Notification component to handle dynamic message and add def…
Rishi-0007 Oct 10, 2024
2ed97c0
Merge branch 'develop' into feature/#693-AddAlertVisualElement
Rishi-0007 Oct 10, 2024
1cff75e
Apply suggestions from code review
Rishi-0007 Oct 11, 2024
c50e8ca
Refactor Notification component and add dynamic message handling
Rishi-0007 Oct 11, 2024
55ace5a
Renamed Notification component to Alert and vice versa and updated de…
Rishi-0007 Oct 12, 2024
e3023e1
Refactor Alert component and update dependencies
Rishi-0007 Oct 12, 2024
80d3621
Merge branch 'develop' into feature/#693-AddAlertVisualElement
Rishi-0007 Oct 13, 2024
67ed55d
Merge branch 'develop' into feature/#693-AddAlertVisualElement
Rishi-0007 Oct 14, 2024
c69b596
Refactor Alert component to add dynamic rendering capability
Rishi-0007 Oct 14, 2024
23bb22b
feat: Enhance TaipyAlert with dynamic classNames and dispatch actions
Rishi-0007 Oct 14, 2024
ce58645
Merge branch 'develop' into feature/#693-AddAlertVisualElement
Rishi-0007 Oct 14, 2024
73aabd8
Merge branch 'develop' into feature/#693-AddAlertVisualElement
Rishi-0007 Oct 15, 2024
f053daa
Merge branch 'develop' into feature/#693-AddAlertVisualElement
Rishi-0007 Oct 19, 2024
d4fec0e
Add Alert.py example with dynamic properties and button to update alert
Rishi-0007 Oct 19, 2024
e69a0ec
Refactor Alert.py example and add package.json
Rishi-0007 Oct 19, 2024
5346893
refactor package.json to match it with develop branch
Rishi-0007 Oct 19, 2024
5f6e40f
Merge branch 'develop' into feature/#693-AddAlertVisualElement
Rishi-0007 Oct 21, 2024
9ead544
Merge branch 'develop' into feature/#693-AddAlertVisualElement
FredLL-Avaiga Oct 22, 2024
7582bbb
Add license headers to Alert components
Rishi-0007 Oct 22, 2024
2633fd3
Merge branch 'develop' into feature/#693-AddAlertVisualElement
Rishi-0007 Oct 22, 2024
474cddf
Merge branch 'develop' into feature/#693-AddAlertVisualElement
Rishi-0007 Oct 22, 2024
0bf9b5c
Fixed linter issue using ruff
Rishi-0007 Oct 22, 2024
9becf2f
Merge branch 'develop' into feature/#693-AddAlertVisualElement
Rishi-0007 Oct 23, 2024
1346fe7
Refactor Notification component and fix merge issue
Rishi-0007 Oct 23, 2024
0119c35
Refactor Notification component and fix issue due to other PR
Rishi-0007 Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions frontend/taipy-gui/src/components/Taipy/Notification.tsx
FredLL-Avaiga marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react";
import Alert from "@mui/material/Alert";
import { TaipyBaseProps } from "./utils";

interface NotificationProps extends TaipyBaseProps {
severity?: "error" | "warning" | "info" | "success";
message: string | (() => string); // Dynamic string handling
Rishi-0007 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

should be declared as message?: string;

variant?: "filled" | "outlined" | "standard";
}

const Notification = (props: NotificationProps) => {
const { severity = "info", message, variant = "filled" } = props;

// Handle dynamic string by checking if `message` is a function and calling it
const displayMessage = typeof message === "function" ? message() : message;
Rishi-0007 marked this conversation as resolved.
Show resolved Hide resolved

return (
<Alert severity={severity} variant={variant} id={props.id} className={props.className}>
{displayMessage}
</Alert>
);
};

export default Notification;
2 changes: 2 additions & 0 deletions frontend/taipy-gui/src/components/Taipy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import StatusList from "./StatusList";
import Table from "./Table";
import Toggle from "./Toggle";
import TreeView from "./TreeView";
import Notification from "./Notification";
Copy link
Member

Choose a reason for hiding this comment

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

In the nearest possible future, we will have to rename 'Notification' to 'Alert' for homogeneity (although programmers don't really care).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @FabienLelaquais thanks for your review, but Alert.tsx already exists.


const registeredComponents: Record<string, ComponentType> = {};

Expand All @@ -66,6 +67,7 @@ export const getRegisteredComponents = () => {
MenuCtl: MenuCtl,
Metric: Metric,
NavBar: NavBar,
Notification: Notification,
PageContent: PageContent,
Pane: Pane,
Part: Part,
Expand Down
13 changes: 13 additions & 0 deletions taipy/gui/_renderers/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class _Factory:
__TAIPY_NAME_SPACE = "taipy."

__CONTROL_DEFAULT_PROP_NAME = {
"alert": "message",
"button": "label",
"chat": "messages",
"chart": "data",
Expand Down Expand Up @@ -618,6 +619,18 @@ class _Factory:
]
)
._set_propagate(),
"alert": lambda gui, control_type, attrs: _Builder(
gui=gui,
control_type=control_type,
element_name="Notification",
attributes=attrs,
)
.set_value_and_default(var_type=PropertyType.dynamic_string)
.set_attributes(
[
("severity", PropertyType.string), # severity is a simple string property
]
Rishi-0007 marked this conversation as resolved.
Show resolved Hide resolved
),
}

# TODO: process \" in property value
Expand Down
31 changes: 30 additions & 1 deletion taipy/gui/viselements.json
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,36 @@
}
]
}
]
],
[
"alert",
{
"inherits": ["shared"],
"properties": [
{
"name": "severity",
"default_property": false,
Rishi-0007 marked this conversation as resolved.
Show resolved Hide resolved
"type": "dynamic(str)",
"default_value": "\"info\"",
"doc": "Defines the severity level of the notification. Valid values: \"error\", \"warning\", \"info\", \"success\"."
Rishi-0007 marked this conversation as resolved.
Show resolved Hide resolved
},
{
"name": "message",
"default_property": true,
"type": "dynamic(str)",
"default_value": "\"\"",
"doc": "The message displayed in the notification. Can be a dynamic string."
},
{
"name": "variant",
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure we need this 'variant' property, although it simplifies styling.
I mean no other element has that kind of styling=-dedicated property.
We will discuss that.

"default_property": false,
"type": "str",
"default_value": "\"filled\"",
"doc": "Defines the variant of the notification. Valid values: \"filled\", \"outlined\", \"standard\"."
Rishi-0007 marked this conversation as resolved.
Show resolved Hide resolved
}
]
}
]
],
"blocks": [
[
Expand Down