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

Improve preview feedback in fetch query #1153

Merged
merged 6 commits into from
Oct 14, 2022
Merged

Conversation

bytasv
Copy link
Contributor

@bytasv bytasv commented Oct 13, 2022

Added logic for:

  • Checking if we have any data returned but potentially not mapped correctly with transform function
  • If preview is invoked and user is looking at different tab, transform tab will become active
  • If request completes but returns empty response - show appropriate message

image

image

@bytasv bytasv added the feature: Queries Making new API requests label Oct 13, 2022
@bytasv bytasv requested a review from a team October 13, 2022 14:30
@bytasv bytasv self-assigned this Oct 13, 2022
@render
Copy link

render bot commented Oct 13, 2022

@oliviertassinari oliviertassinari requested a deployment to improve-fetch-preview - toolpad-db PR #1153 October 13, 2022 14:30 — with Render Abandoned
@Janpot
Copy link
Member

Janpot commented Oct 14, 2022

  • If preview is invoked and user is looking at different tab, transform tab will become active

I don't feel like this is the right approach. We should leave the user in control of navigating the UI. Perhaps we can make the word "transform" in the warning clickable to open the tab?

@bytasv
Copy link
Contributor Author

bytasv commented Oct 14, 2022

I don't feel like this is the right approach

I personally feel differently about this. Can you provide an example where you wouldn't want to check how transform is defined after getting this message?
We could also do a link, but IMO this is a better UX (at least from my perspective)

-edit: I'd consider it a very similar pattern to when you get error in a long form and browser scrolls to the actual error so you are not left hanging wondering what's wrong

bytasv and others added 4 commits October 14, 2022 12:20
Co-authored-by: Bharat Kashyap <bharatkashyap@outlook.com>
Signed-off-by: Vytautas Butkus <vytautas.butkus@gmail.com>
Co-authored-by: Bharat Kashyap <bharatkashyap@outlook.com>
Signed-off-by: Vytautas Butkus <vytautas.butkus@gmail.com>
Co-authored-by: Bharat Kashyap <bharatkashyap@outlook.com>
Signed-off-by: Vytautas Butkus <vytautas.butkus@gmail.com>
@Janpot
Copy link
Member

Janpot commented Oct 14, 2022

Can you provide an example where you wouldn't want to check how transform is defined after getting this message?

It's not about interested in it or not. It's about not disrupting the UI without user interaction. Maybe the backend takes 7 seconds to respond and in those 7 seconds I may have started to look in one of the other tabs. Suddenly out of nothing the tab changes and I'm pulled out of my context. Instead, in the preview message give a button to open the relevant tab so that I can correct it in a time that makes more sense for me as a user (e.g. when I'm inspecting the message in the preview window). Another option is to mark the tab with a badge to tell the user there is some important action to be taken there.

edit:

there's an important difference with scrolling to a validation error. it's that in that case the scroll happens when the user clicks the button. In the case of the query preview it happens async, potentially a long while after clicking the button

@bytasv
Copy link
Contributor Author

bytasv commented Oct 14, 2022

there's an important difference with scrolling to a validation error. it's that in that case the scroll happens when the user clicks the button. In the case of the query preview it happens async, potentially a long while after clicking the button

Not necessarily, it can also happen same way as you described with preview - you submit, data is validated async on API, API is slow, you get response after same 7 seconds.
IMO situation about pressing preview and immediately starting to edit something is more hypothetical, than actually waiting to see what's the result.
Anyways, lets see what others think and I will change it if needed

@Janpot
Copy link
Member

Janpot commented Oct 14, 2022

Not necessarily, it can also happen same way as you described with preview - you submit, data is validated async on API, API is slow, you get response after same 7 seconds.

I'd consider that a flawed UX. I think a user should stay in control of the scroll position. If the validation comes back async I'd consider showing a notification "x validation errors" that scrolls to the relevant field on click.

One of the main tenets of user interface design, is that the user needs to feel in control, and mostly, that they are in control of their time. if we're not going to block the whole UI while preview is loading, then we shouldn't manipulate it without user action.

IMO situation about pressing preview and immediately starting to edit something is more hypothetical

Nothing hypothetical about that, I do it all the time. e.g. I often realize right when I click the button that I forgot something. It's also not only editing, I may just be reading through the other tabs to see which options are available.

@bytasv
Copy link
Contributor Author

bytasv commented Oct 14, 2022

cc @gerdadesign for your input about above ☝️

@Janpot
Copy link
Member

Janpot commented Oct 14, 2022

Just to note that the specific feature in question is not strictly necessary to close the ticket. Another option could be to merge without it and take our time to define the right UX. (e.g. in a follow-up issue, or RFC,...)

@bytasv bytasv enabled auto-merge (squash) October 14, 2022 14:05
@bytasv bytasv merged commit 9bf96d9 into master Oct 14, 2022
@bytasv bytasv deleted the improve-fetch-preview branch October 14, 2022 14:18
@Janpot
Copy link
Member

Janpot commented Oct 14, 2022

Another option could be to merge without it

@bytasv I might have not expressed myself very well, so the idea was be to merge this PR without the automatic tab switching. Or perhaps this was merged accidentally?

return true;
}

return !isEmpty(data);
Copy link
Member

@Janpot Janpot Oct 14, 2022

Choose a reason for hiding this comment

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

I don't think the logic is sound here. It should be perfectly valid to return empty arrays or empty objects from the transform function. Similarly, untransformedData can perfectly return an empty array while the transformed data returns undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry it's not really clear what you are proposing or what's exactly the issue?

Similarly, untransformedData can perfectly return an empty array while the transformed data returns undefined.

Can you provide an example?

Copy link
Member

Choose a reason for hiding this comment

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

Can you provide an example?

Sure thing, here's a transform function that legitimately returns an empty array:

use url: https://httpbin.org/json
use transform: return data.slideshow.slides.filter(slide => slide.title.includes('foo'));

I believe this should not show the warning.

I also think we should accept null as a legitimate value and only show a warning when the transform is returning undefined.
We should probably also make the JsonView show undefined instead of nothing when the input is undefined

Lastly, I believe we should also consider preventing the overuse of basic lodash methods through no-restricted-imports and only whitelist a few like pick, throttle, get and set. Methods like isEmpty cover a too broad range of values and result in bugs like these. Also, the word "empty" doesn't have a well defined meaning in programming, making the code less intuitive. Better to use native constructs to express the intent clearer to other maintainers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, that's great feedback, I've addressed it in a follow up PR: #1165

@bytasv
Copy link
Contributor Author

bytasv commented Oct 14, 2022

@bytasv I might have not expressed myself very well, so the idea was be to merge this PR without the automatic tab switching. Or perhaps this was merged accidentally?

No, I did set this to merge as that's how I understood your comment. As for feature itself, I disagree with you, I think tab switching is a good UX in this case, just as I explained in previous comment, so I will not revert this change for now. If there is more feedback from others adding that it should not behave like that we can change it.

@bytasv bytasv mentioned this pull request Oct 17, 2022
@apedroferreira
Copy link
Member

About switching tabs automatically, I also don't like that type of pattern as it can be disruptive or annoying to users.
In my opinion we should leave it up to the user, I think there are more cons than pros to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: Queries Making new API requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show undefined results in fetch preview window
5 participants