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

Add FeedbackButton to DeleteDialog of CrudContextMenu #2237

Closed
wants to merge 8 commits into from

Conversation

jomunker
Copy link
Contributor

@jomunker jomunker commented Jul 1, 2024


This was done to give the user feedback if something is loading and/ or goes wrong. Additionally, the FeedbackButton was reworked to use Promises for state updates, which simplifies the usage. This was done after a discussion with @johnnyomair.

PR Checklist

  • Verify if the change requires a changeset. See CONTRIBUTING.md
  • Link to the respective task if one exists: COM-754
  • Provide screenshots/screencasts if the change contains visual changes
Screenshots/screencasts
Screen.Recording.2024-07-01.at.17.03.09.mov

@jomunker jomunker requested a review from johnnyomair July 1, 2024 15:07
@jomunker jomunker self-assigned this Jul 1, 2024
loading?: boolean;
hasErrors?: boolean;
Omit<LoadingButtonProps, "loading"> {
onClick: () => Promise<void>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

@nsams @thomasdax98 what do you think about using the promise states (pending, resolved, rejected) to handle the display states of the button instead of loading, hasErrors etc. props? I think this is easier to understand and less error-prone as the state transitions are pretty clear. Could there be use cases where I wouldn't want to have this?

@jomunker jomunker requested a review from jamesricky July 31, 2024 13:09
@jomunker jomunker requested a review from johnnyomair July 31, 2024 14:05
@jomunker
Copy link
Contributor Author

I added a flag called feedbackStateControl to differentiate between the manual handling via props and the automatic handling via a returned promise in the onClick function. This seemed like the most descriptive way of doing it. I discussed this with @jamesricky

Copy link
Collaborator

@johnnyomair johnnyomair left a comment

Choose a reason for hiding this comment

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

It should be possible to make this a non-breaking change targeting main. Also, should we move the Promise detection into a separate PR and discussion?

}

export interface FeedbackButtonPropsPromise extends FeedbackButtonPropsBase {
feedbackStateControl: "onClickPromise";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Couldn't this be inferred based on the passed onClick handler? Is it possible to detect if a function is async or not?

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 are ways but it's not straightforward and probably also not reliable. Additionally, it is way more descriptive with the flag. So users will actually understand whats going on.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@nsams @thomasdax98 what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer a solution that doesn't need this feedbackStateControl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. The other two options I can think of are:

  1. Somehow infer from function if it is async or not
  2. Add a second onClickAsync prop for the promise-based usage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's too late unfortunately. I could infer that a user wants to rely on outside state if loading and/or hasError is not undefined 🤷🏻‍♂️

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's too late unfortunately. I could infer that a user wants to rely on outside state if loading and/or hasError is not undefined 🤷🏻‍♂️

I like this idea! Could you please try this? Also, I'd still recommend adding the promise detection in a separate PR: #2237 (review)

Copy link
Contributor Author

@jomunker jomunker Aug 14, 2024

Choose a reason for hiding this comment

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

Added a new PR for the changes to CrudContextMenu: #2423
Was easier to do it like this since the current PR targets next. I'll add another one for the addition of the promise feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here to following PR: #2425

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will close this one

Comment on lines 59 to 60
hasErrors?: undefined;
loading?: undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
hasErrors?: undefined;
loading?: undefined;
hasErrors?: never;
loading?: never;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

loading?: boolean;
hasErrors?: boolean;
Omit<LoadingButtonProps, "loading"> {
feedbackStateControl: FeedbackStateControl;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would need to be optional to not be a breaking change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jomunker jomunker requested a review from johnnyomair August 1, 2024 07:26
@jomunker jomunker closed this Aug 14, 2024
@jomunker
Copy link
Contributor Author

Closed because it was split in PRs #2423 and #2425

@jomunker jomunker deleted the COM-754-feedback-button-delete-dialog branch August 14, 2024 09:42
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.

3 participants