Skip to content

Conversation

anders-kiaer
Copy link
Contributor

Closes #1625 (except the dash-docs part - but I can take that after review and if accepted).

Contributor Checklist

  • I have broken down my PR scope into the following TODO tasks
    • Expose stringify_id at top level.
    • Add css_escape function.
  • I have run the tests locally and they passed. (refer to testing section in contributing)
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR

optionals

  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follows
    • this GitHub #PR number updates the dash docs
    • here is the show and tell thread in Plotly Dash community

@anders-kiaer anders-kiaer changed the title Expose at top level and add optional parameter Expose stringify_id at top level and add optional parameter escape_css May 9, 2021
@anders-kiaer anders-kiaer force-pushed the stringify_id_and_css_escape branch from b7d8305 to 0c621fc Compare May 9, 2021 11:14
@anders-kiaer anders-kiaer marked this pull request as ready for review May 9, 2021 11:16
@anders-kiaer anders-kiaer force-pushed the stringify_id_and_css_escape branch from 0c621fc to e4df8ce Compare May 9, 2021 18:57

dash_duo.start_server(app)

assert dash_duo.wait_for_element_by_id(dash.stringify_id(id, escape_css=True))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is an easy possibility of extending

def wait_for_element_by_id(self, element_id, timeout=None):
"""Explicit wait until the element is present, timeout if not set,
equals to the fixture's `wait_timeout` shortcut to `WebDriverWait` with
`EC.presence_of_element_located`."""
return self._wait_for(
EC.presence_of_element_located,
((By.ID, element_id),),
timeout,
"timeout {}s => waiting for element id {}".format(
timeout if timeout else self._wait_timeout, element_id
),
)

to check if input element_id is dict, and then do dash.stringify_id(element_id, escape_css=True) for the user in the wait_for_element_by_id function.

The user's test line here

assert dash_duo.wait_for_element_by_id(dash.stringify_id(id, escape_css=True))

then becomes

assert dash_duo.wait_for_element_by_id(id)

both in the case with string IDs, and dictionary IDs (when you use pattern-matching callbacks).

Not sure if that is too magical 🔮 or a nice and easy to understand convenience.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea with extending the testing utilities, I think that is where most cases would be for escaping.

@gvwilson
Copy link
Contributor

hi @T4rk1n - is this one still relevant or has it gone stale?

Copy link
Contributor

@T4rk1n T4rk1n left a comment

Choose a reason for hiding this comment

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

Sorry this PR fell under the cracks, I think this is still good, just need to update with dev branch which include new code for stringify_id

if isinstance(id_, dict):
return json.dumps(id_, sort_keys=True, separators=(",", ":"))
return id_
def css_escape(stringified_id):
Copy link
Contributor

Choose a reason for hiding this comment

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

I would maybe rename to escape_css_id.

@@ -3,6 +3,7 @@
# must come before any other imports.
__plotly_dash = True
from .dash import Dash, no_update # noqa: F401,E402
from ._utils import stringify_id # noqa: F401,E402
Copy link
Contributor

Choose a reason for hiding this comment

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

Could also expose css_escape


dash_duo.start_server(app)

assert dash_duo.wait_for_element_by_id(dash.stringify_id(id, escape_css=True))
Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea with extending the testing utilities, I think that is where most cases would be for escaping.

@gvwilson
Copy link
Contributor

thanks @T4rk1n - I'll add it to the pile for the next cycle (no need to work on it right now). Cheers - @gvwilson

@gvwilson gvwilson added feature something new P2 considered for next cycle labels Aug 13, 2024
@gvwilson gvwilson added the community community contribution label Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community community contribution feature something new P2 considered for next cycle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

provide Python function returning stringified dict component IDs
3 participants