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 redirectTo returned by useEditController #8243

Merged
merged 2 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/ra-core/src/controller/edit/useEditController.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,31 @@ describe('useEditController', () => {
});
});

it('should return the `redirect` provided through props or the default', async () => {
const getOne = jest
.fn()
.mockImplementationOnce(() =>
Promise.resolve({ data: { id: 12, title: 'hello' } })
);
const dataProvider = ({ getOne } as unknown) as DataProvider;
const Component = ({ redirect = undefined }) => (
<CoreAdminContext dataProvider={dataProvider}>
<EditController {...defaultProps} redirect={redirect}>
{({ redirect }) => <div>{redirect}</div>}
</EditController>
</CoreAdminContext>
);
const { rerender } = render(<Component />);
await waitFor(() => {
expect(screen.queryAllByText('list')).toHaveLength(1);
});

rerender(<Component redirect="show" />);
await waitFor(() => {
expect(screen.queryAllByText('show')).toHaveLength(1);
});
});

describe('queryOptions', () => {
it('should accept custom client query options', async () => {
const mock = jest
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/controller/edit/useEditController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export const useEditController = <
isLoading,
mutationMode,
record,
redirect: DefaultRedirect,
redirect: redirectTo,
Copy link
Member

Choose a reason for hiding this comment

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

This context variable isn't used anywhere in our code - I think it's a leftover from v3. I'll validate the PR, but I think we should ultimately mark it as deprecated.

refetch,
registerMutationMiddleware,
resource,
Expand Down