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

PWA-875: Implement dynamic redirects #244

Merged
merged 12 commits into from
Sep 10, 2018

Conversation

fkloes
Copy link
Collaborator

@fkloes fkloes commented Sep 5, 2018

  • updated the router subscriptions to enable processing of dynamic redirects
  • removed some outdated webckeckout related code
  • fixed a product selector bug that caused endless loading state for descriptions
  • extended tests

- it doesn't return NULL anymore, if the description is an empty string
- introduced the "historyReplace" action to handle redirect situations
- replaced existing logic with the new action
- when protector routes are about to be replaced by legacy or in-app-browser routes, they are now popped from the history stack
- added router subscriptions coverage for redirect handlers
- added tests for the historyRedirect action
- added redirect data to the listener within the user subscriptions
- removed logic from the web checkout since it duplicated the logic from the user subscriptions
- subscribers now receive the expected parameters
…o PWA-875-implement-dynamic-redirects

# Conflicts:
#	themes/gmd
*/
export function historyRedirect(params = {}) {
return (dispatch) => {
const { location, state = {} } = params;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't make the state an empty object. The history... actions will pass it through. This means if state is not set, it will be treated as undefined. Thas the way to go.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

return (dispatch) => {
const { location, state = {} } = params;

if (location) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rewrite this to be a guard clause:

if (!location) {
  dispatch(historyPop());
  return;
}

...

This is more readable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -3,6 +3,8 @@ export * from './historyPop';
export * from './historyReplace';
export * from './historyReset';

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove unnecessary empty lines.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

parsed.query.sgcloud_callback_data = JSON.stringify({ redirectTo });

// Explicitly check if we are about to be redirected to the checkout.
if (redirect && redirect.startsWith(CHECKOUT_PATH)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The first check doesn't make sense here. If the redirect param is maybe not set, it falls back to an empty string. Please don't give it a default, if you check it either way. Or don't check it again. One of both is redundant.

Copy link
Collaborator Author

@fkloes fkloes Sep 7, 2018

Choose a reason for hiding this comment

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

i removed the check but kept the default value.

@@ -0,0 +1,32 @@
import queryString from 'query-string';
import {
CHECKOUT_PATH,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please make this single lined. Its only two variables. Makes it a bit cleaner.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done


if (redirect) {
// Check if a redirect handler was assigned and execute it.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is not needed. It is obvious what's happening.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

dispatch(unsetViewLoading(pathname));

if (!redirect) {
// Stop processing when no redirect was created.
Copy link
Contributor

Choose a reason for hiding this comment

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

Also obvious. The code speaks for itself.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

testExpectedCall(conductor.push, {
...params,
pathname: params.pathname.slice(0, -1),
});
});

it('should redirect to a protector route when the user is not logged in', () => {
it('should redirect to a protector route when the user is not logged in', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

protected route

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

protector is correct since the pushed route is protected. so the navigate$ subscription redirects the user the the protector route e.g. login.

@@ -198,7 +215,7 @@ describe('Router subscriptions', () => {
}));
});

it('should not redirect to a protector route when the user is logged in', () => {
it('should not redirect to a protector route when the user is logged in', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

protected

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same like above. it's about a redirect to the route which protects a protected route. this is called protector.

/**
* @return {Promise}
*/
const redirectHandler = () => Promise.reject(error);
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to store this into a variable. Please put that inline. (reduces the amount of code)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i did it because it makes the test more readable from my point of view. a function which returns a rejected promise as the 2nd argument of the set method would be hard to understand if someone would have to understand or extend this test.
so i'd be happy to keep it like it is.

@devbucket devbucket added the bug Something isn't working label Sep 5, 2018
@devbucket devbucket merged commit 713b3d7 into PWA-327-Exchange-Router Sep 10, 2018
@devbucket devbucket deleted the PWA-875-implement-dynamic-redirects branch September 10, 2018 09:10
SG-Noxoreos pushed a commit that referenced this pull request Oct 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants