grafana / grafana-aws-sdk-react

Apache License 2.0
3 stars 1 forks source link

Add an option for deleting fields that contain empty string values in jsonData #56

Closed katebrenner closed 1 year ago

katebrenner commented 1 year ago

When jsonData.endpoint is an empty string, we were experiencing bugs outlined in this Twinmaker issue. The bug could also be fixed in Twinmaker itself but I wonder if there are other places in which having an empty string endpoint would cause unexpected behaviors.

To reproduce, follow the steps here and you should no longer see the error.

CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.

idastambuk commented 1 year ago

I see some places in Twinmaker that we check for the endpoint string, but can you point me to the piece code this bug is caused by? I wonder if we're just not checking for truthy values properly there, since I would normally expect if something is an empty string, that it doesn't get evaluated at all.

katebrenner commented 1 year ago

I see some places in Twinmaker that we check for the endpoint string, but can you point me to the piece code this bug is caused by? I wonder if we're just not checking for truthy values properly there, since I would normally expect if something is an empty string, that it doesn't get evaluated at all.

It actual looks like the error is somewhere deep in a dependency of the scene viewer panel, where new URL('') is being called and resulting in Uncaught TypeError: Failed to construct 'URL': Invalid URL.

To clarify, when I mentioned that we could fix this in Twinmaker itself, I was thinking more along the lines of adding a useEffect in ConfigEditor.tsx to check if the value was an empty string, but didn't actually see a place in which we're not checking truthy values in the Twinmaker code, but that's a good point, maybe this can be fixed in SceneViewer.tsx, I'll take a look :). Regardless, I do wish we weren't passing along empty strings as values in the jsonData when the field is empty

idastambuk commented 1 year ago

I see some places in Twinmaker that we check for the endpoint string, but can you point me to the piece code this bug is caused by? I wonder if we're just not checking for truthy values properly there, since I would normally expect if something is an empty string, that it doesn't get evaluated at all.

It actual looks like the error is somewhere deep in a dependency of the scene viewer panel, where new URL('') is being called and resulting in Uncaught TypeError: Failed to construct 'URL': Invalid URL.

To clarify, when I mentioned that we could fix this in Twinmaker itself, I was thinking more along the lines of adding a useEffect in ConfigEditor.tsx to check if the value was an empty string, but didn't actually see a place in which we're not checking truthy values in the Twinmaker code, but that's a good point, maybe this can be fixed in SceneViewer.tsx, I'll take a look :). Regardless, I do wish we weren't passing along empty strings as values in the jsonData when the field is empty

I see your point in not passing empty strings if something isn't actually defined. But I also feel like doing it isn't non-standard practice, at least as far as I've seen?🤔 Also, it would make sense to me that wherever something that might not be defined is used, like the endpoint, to have a condition for falsy anyway? Meaning, I'd rather see it fixed in SceneViewer if it's not too complicated, but I'm ok with this solution!

katebrenner commented 1 year ago

will likely close this pr in favor of https://github.com/grafana/grafana-iot-twinmaker-app/pull/208