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

Fix: lambda python functions not rendering correctly on flowchart #851

Merged
merged 24 commits into from
May 20, 2022

Conversation

tynandebold
Copy link
Member

@tynandebold tynandebold commented May 16, 2022

Description

Fixes #817.

Development notes

I'm no longer using _strip_tags in the backend, so the <> come through to the frontend. I've create a replaceMatches() utility function and added that to the node-list-row.js file to ensure both <lambda> and <partial> will render via dangerouslySetInnerHTML.

QA notes

I've added a lambda node so this can be tested. Open the Gitpod URL and expand the Ingestion modular pipeline. You'll see the lambda function there.

Checklist

  • Read the contributing guidelines
  • Opened this PR as a 'Draft Pull Request' if it is work-in-progress
  • Updated the documentation to reflect the code changes
  • Added new entries to the RELEASE.md file
  • Added tests to cover my changes

Signed-off-by: Tynan DeBold <[email protected]>
Signed-off-by: Tynan DeBold <[email protected]>
Signed-off-by: Tynan DeBold <[email protected]>
@tynandebold tynandebold removed the request for review from yetudada May 16, 2022 11:16
Copy link
Contributor

@studioswong studioswong left a comment

Choose a reason for hiding this comment

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

It looks like this PR contains the work for this PR that is not merged in main yet - would be great if you could remove those changes in this PR to avoid confusion. Thank you!

…x/lambda-python-functions-on-flowchart

Signed-off-by: Tynan DeBold <[email protected]>
@tynandebold tynandebold requested a review from studioswong May 16, 2022 14:15
@tynandebold
Copy link
Member Author

It looks like this PR contains the work for this PR that is not merged in main yet - would be great if you could remove those changes in this PR to avoid confusion. Thank you!

Done now.

@tynandebold tynandebold marked this pull request as draft May 16, 2022 14:39
Signed-off-by: Tynan DeBold <[email protected]>
@tynandebold tynandebold marked this pull request as ready for review May 16, 2022 14:46
@antonymilne
Copy link
Contributor

This looks right on the tree view and metadata side panel to me but looks kind of funky when I search for it...
image

Outside the scope of this PR, but related: did we ever get a ticket created to change these partial names to something more descriptive? As per the discussion in #692.

RELEASE.md Outdated
@@ -6,6 +6,10 @@ Please follow the established format:
- Include the ID number for the related PR (or PRs) in parentheses
-->

## Bug fixes and other changes

- Fix lambda Python functions not rendering correctly on flowchart. (#851)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Fix lambda Python functions not rendering correctly on flowchart. (#851)
- Fix lambda and partial Python functions not rendering correctly on flowchart. (#851)

The same fix here will work for both cases :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice one. Updated!

};

export const replaceMatches = (str) => {
if (str && str.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious: what is this conditional for here? I sort of understand the zero-length string case but not the case where bool(str) would evaluate to False - when does that occur?

Copy link
Member Author

Choose a reason for hiding this comment

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

If you don't have that check you'd get this error: TypeError: Cannot read property 'length' of undefined. I've changed it now to this str?.length > 0 which does the same thing: first checks if there's a string, and if so, proceed to find the length.

Signed-off-by: Tynan DeBold <[email protected]>
Signed-off-by: Tynan DeBold <[email protected]>
Signed-off-by: Tynan DeBold <[email protected]>
@tynandebold
Copy link
Member Author

This looks right on the tree view and metadata side panel to me but looks kind of funky when I search for it... image

Outside the scope of this PR, but related: did we ever get a ticket created to change these partial names to something more descriptive? As per the discussion in #692.

Good catch on the search. I need to update it, but it's a bit tricky since we're putting these partial and lambda names between < > symbols, which really conflicts with HTML, since that will render an HTML element.

Can we use something else instead of these to make it easier for ourselves, like a ~ or something? Or is < > convention?

…x/lambda-python-functions-on-flowchart

Signed-off-by: Tynan DeBold <[email protected]>
@antonymilne
Copy link
Contributor

antonymilne commented May 16, 2022

Good catch on the search. I need to update it, but it's a bit tricky since we're putting these partial and lambda names between < > symbols, which really conflicts with HTML, since that will render an HTML element.

Can we use something else instead of these to make it easier for ourselves, like a ~ or something? Or is < > convention?

I'm afraid <> is quite a strong convention since this is how Python names anonymous functions:
image

If <> is too awkward then I would just not have any special character there at all, i.e. lambda. This would be fine I think.

Copy link
Contributor

@studioswong studioswong left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this.

I haven't reviewed the code yet, but on checking out the branch and poking around it seems that this breaks the search functionality in general:
image

This is due to having taken out the dangerouslySetInnerHTML which is needed to implement the bold highlighting during search.

Signed-off-by: Tynan DeBold <[email protected]>
@tynandebold tynandebold requested review from studioswong and antonymilne and removed request for studioswong May 17, 2022 11:50
Comment on lines -46 to -47
def _strip_tags(name: str) -> str:
return name.replace("<", "&lt;").replace(">", "&gt;")
Copy link
Member Author

Choose a reason for hiding this comment

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

I think the solve for this is to leave the <> in place in the backend and then change it to use the HTML entities only where we need it in the frontend.

@@ -124,7 +131,9 @@ const NodeListRow = memo(
'pipeline-nodelist__row__label--disabled': disabled,
}
)}
dangerouslySetInnerHTML={{ __html: label }}
dangerouslySetInnerHTML={{
__html: replaceMatches(label, stringsToReplace),
Copy link
Member Author

Choose a reason for hiding this comment

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

Replace the <> here so we can still use dangerouslySetInnerHTML without a problem, specifically when searching.

Signed-off-by: Tynan DeBold <[email protected]>
width: 20px;
height: 20px;
z-index: 1;
Copy link
Member Author

Choose a reason for hiding this comment

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

You couldn't click the X icon to clear the search. This fixes that.

README.md Outdated
@@ -35,6 +35,7 @@ Kedro-Viz is an interactive development tool for building data science pipelines
- 🔎 Highly interactive, filterable and searchable
- 🔬 Focus mode for modular pipeline visualisation
- 📊 Rich metadata side panel to display parameters, plots, etc.
- 📊 Supports [plotly](https://plotly.com/javascript/) charts.
Copy link
Member Author

Choose a reason for hiding this comment

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

@rashidakanchwala curious why this made it in here?

Signed-off-by: Tynan DeBold <[email protected]>
…x/lambda-python-functions-on-flowchart

Signed-off-by: Tynan DeBold <[email protected]>
@tynandebold
Copy link
Member Author

tynandebold commented May 18, 2022

On the main branch, searching for something with < doesn't work. See here:

image

I tried to fix that in this ticket but it turned into a bigger issue. I'll create a separate bug report for that and leave this one here.

Update: related ticket here: #854

…x/lambda-python-functions-on-flowchart

Signed-off-by: Tynan DeBold <[email protected]>
Copy link
Contributor

@rashidakanchwala rashidakanchwala left a comment

Choose a reason for hiding this comment

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

thanks @tynandebold . approving it since we will look at the <> bug in another ticket :)

@tynandebold tynandebold mentioned this pull request May 20, 2022
5 tasks
Copy link
Contributor

@studioswong studioswong left a comment

Choose a reason for hiding this comment

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

The PR is definitely in a much better shape now!

one small thing I noticed ( sorry to be a pain) - when searching for the lambda function with a <, the search results displayed gets weird ( some characters gets wiped out):
image

I think this could potentially be tied to having replaced <lambda with &lt;partial&gt; ? ( though I am not sure at all - this might require a bit of further poke around to find a workaround for that.)

@tynandebold
Copy link
Member Author

The PR is definitely in a much better shape now!

one small thing I noticed ( sorry to be a pain) - when searching for the lambda function with a <, the search results displayed gets weird ( some characters gets wiped out): image

I think this could potentially be tied to having replaced <lambda with &lt;partial&gt; ? ( though I am not sure at all - this might require a bit of further poke around to find a workaround for that.)

Good eye. I think that's to be expected at this point, which will be solved by the solution for this bug ticket.

In the current version, if you have a <lambda> function and search for <lam, nothing actually shows up. In this case, if you do the same, at least you get a search result, even though the highlighting isn't exactly correct. I would say returning the result you're showing in your screenshot is better than not returning anything at all.

If you're comfortable with that, would be great if we can approve this now and iterate on the fix in the linked ticket above.

Copy link
Contributor

@studioswong studioswong left a comment

Choose a reason for hiding this comment

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

Just saw the ticket you mentioned above, all good 👍

May I suggest to add in an end-2-end test in the upcoming PR for #854 to ensure we capture any errors with the search case for Lambda functions ( since this seems to be a use case that could be easily prone to errors)? 😆

Given that we are looking into releasing soon, it might be worth to release first before merging this in so this can be released alongside the fix for the search (#854 ) as one complete fix? ( totally up to the team)

Copy link
Contributor

@antonymilne antonymilne left a comment

Choose a reason for hiding this comment

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

Definitely good to get this merged, thanks for doing all the iteration on it!

If it turns out the search thing is hard to fix then honestly I think it's fine if we just drop the <> altogether and call it plain lambda or partial everywhere. Also the number of people who will be searching for a lambda function in the is very small. So would be good to fix but not a biggy at all I think.

@tynandebold
Copy link
Member Author

Definitely good to get this merged, thanks for doing all the iteration on it!

If it turns out the search thing is hard to fix then honestly I think it's fine if we just drop the <> altogether and call it plain lambda or partial everywhere. Also the number of people who will be searching for a lambda function in the is very small. So would be good to fix but not a biggy at all I think.

Good to know. I'll add this comment to the context of the other ticket I created. I do think it'll be a pain to solve and we'd be wise to just drop <> all together, especially as it's probably a very small slice of users searching for it, as you said.

@tynandebold tynandebold merged commit 3760c8a into main May 20, 2022
@tynandebold tynandebold deleted the fix/lambda-python-functions-on-flowchart branch May 20, 2022 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lambda python functions don't render nicely on the flowchart
4 participants