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

override useShowController onFailure behavior and return error object #6625

Closed
wants to merge 2 commits into from
Closed

Conversation

panfiva
Copy link

@panfiva panfiva commented Sep 28, 2021

See #5197

… also added "error" to data returned object
Copy link
Collaborator

@djhi djhi left a comment

Choose a reason for hiding this comment

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

Hi and thanks for taking the time to open a PR!

Although adding the onFailure is ok, it's a new feature so your PR should target the next branch. However, please revert the addition of the error returned by useGetOne and useShowController. Indeed, overriding the onFailure should be enough as it will called with the error as its first argument even though we don't use it in our default handler.

Finally, can you please revert unrelated changes in the documentation?

Thanks!

@panfiva
Copy link
Author

panfiva commented Oct 1, 2021

@djhi ,

The reason i added "error" property is to be able to support the following usecase:

const showController = useShowController<T>({
    resource,  basePath, id,     
    onFailure: () => {}, // prevent redirect to list and user notification on errors
  })

const { loaded, record, error } = showController

if (error) return <Error error={error} />
else if (loaded) return <Render record={record} />
else return <Loading />

This way, I do not have to create custom onFailure function that uses useState to render <Error> component

@djhi djhi deleted the branch marmelab:master October 4, 2021 09:03
@djhi djhi closed this Oct 4, 2021
@djhi djhi reopened this Oct 4, 2021
@panfiva
Copy link
Author

panfiva commented Oct 8, 2021

@djhi ,

can we commit with error, since it is a very useful feature to have?

@djhi djhi changed the base branch from next to master October 12, 2021 08:30
@djhi
Copy link
Collaborator

djhi commented Oct 12, 2021

@panfiva We discussed it and we agree it is a good idea so thank you for bringing that up! However, there are two other places where this would make sense as well: useEditController for the getOne operation and useListController for its getList. Would you mind adding support for error in those as well? Thanks!

@djhi djhi added this to the 3.19 milestone Oct 12, 2021
@panfiva
Copy link
Author

panfiva commented Oct 12, 2021

I can add support there as well. Would you like me to update the current pull request, or create a separate pull request?

@djhi
Copy link
Collaborator

djhi commented Oct 12, 2021

Thanks! You can do that in the same PR if you want.

@djhi
Copy link
Collaborator

djhi commented Oct 14, 2021

Thanks for starting the work on this! I finished it in another PR as we want to release 3.19

@djhi djhi closed this Oct 14, 2021
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.

2 participants