Skip to content

Commit 092464f

Browse files
authored
Merge pull request #2899 from leeagustin/deprecate-LogoutButton
Deprecate LogoutButton
2 parents 376599e + 6bd822e commit 092464f

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from dash.exceptions import PreventUpdate
22
from dash import Dash, Input, Output, dcc, html
33
import flask
4+
import pytest
45
import time
56

67

7-
def test_llgo001_location_logout(dash_dcc):
8+
@pytest.mark.parametrize("add_initial_logout_button", [False, True])
9+
def test_llgo001_location_logout(dash_dcc, add_initial_logout_button):
810
app = Dash(__name__)
911

1012
@app.server.route("/_logout", methods=["POST"])
@@ -13,9 +15,14 @@ def on_logout():
1315
rep.set_cookie("logout-cookie", "", 0)
1416
return rep
1517

16-
app.layout = html.Div(
17-
[html.H2("Logout test"), dcc.Location(id="location"), html.Div(id="content")]
18-
)
18+
layout_children = [
19+
html.H2("Logout test"),
20+
dcc.Location(id="location"),
21+
html.Div(id="content"),
22+
]
23+
if add_initial_logout_button:
24+
layout_children.append(dcc.LogoutButton())
25+
app.layout = html.Div(layout_children)
1926

2027
@app.callback(Output("content", "children"), [Input("location", "pathname")])
2128
def on_location(location_path):
@@ -33,15 +40,19 @@ def _insert_cookie(rep):
3340

3441
return dcc.LogoutButton(id="logout-btn", logout_url="/_logout")
3542

36-
dash_dcc.start_server(app)
37-
time.sleep(1)
38-
dash_dcc.percy_snapshot("Core Logout button")
43+
with pytest.warns(
44+
DeprecationWarning,
45+
match="The Logout Button is no longer used with Dash Enterprise and can be replaced with a html.Button or html.A.",
46+
):
47+
dash_dcc.start_server(app)
48+
time.sleep(1)
49+
dash_dcc.percy_snapshot("Core Logout button")
3950

40-
assert dash_dcc.driver.get_cookie("logout-cookie")["value"] == "logged-in"
51+
assert dash_dcc.driver.get_cookie("logout-cookie")["value"] == "logged-in"
4152

42-
dash_dcc.wait_for_element("#logout-btn").click()
43-
dash_dcc.wait_for_text_to_equal("#content", "Logged out")
53+
dash_dcc.wait_for_element("#logout-btn").click()
54+
dash_dcc.wait_for_text_to_equal("#content", "Logged out")
4455

45-
assert not dash_dcc.driver.get_cookie("logout-cookie")
56+
assert not dash_dcc.driver.get_cookie("logout-cookie")
4657

47-
assert dash_dcc.get_logs() == []
58+
assert dash_dcc.get_logs() == []

Diff for: dash/_validate.py

+19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import sys
2+
from collections import defaultdict
23
from collections.abc import MutableSequence
34
import re
5+
import warnings
46
from textwrap import dedent
57
from keyword import iskeyword
68
import flask
@@ -422,6 +424,21 @@ def validate_layout(layout, layout_value):
422424
component_ids = set()
423425

424426
def _validate(value):
427+
def _validate_type(comp):
428+
deprecated_components = defaultdict(lambda: defaultdict(dict))
429+
deprecated_components["dash_core_components"][
430+
"LogoutButton"
431+
] = """
432+
The Logout Button is no longer used with Dash Enterprise and can be replaced with a html.Button or html.A.
433+
eg: html.A(href=os.getenv('DASH_LOGOUT_URL'))
434+
"""
435+
436+
_type = getattr(comp, "_type", "")
437+
_ns = getattr(comp, "_namespace", "")
438+
deprecation_message = deprecated_components[_ns][_type]
439+
if deprecation_message:
440+
warnings.warn(dedent(deprecation_message), DeprecationWarning)
441+
425442
def _validate_id(comp):
426443
component_id = stringify_id(getattr(comp, "id", None))
427444
if component_id and component_id in component_ids:
@@ -432,9 +449,11 @@ def _validate_id(comp):
432449
)
433450
component_ids.add(component_id)
434451

452+
_validate_type(value)
435453
_validate_id(value)
436454

437455
for component in value._traverse(): # pylint: disable=protected-access
456+
_validate_type(component)
438457
_validate_id(component)
439458

440459
if isinstance(layout_value, (list, tuple)):

0 commit comments

Comments
 (0)