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

404 support for non existing paths #162

Merged

Conversation

parostatkiem-zz
Copy link
Contributor

@parostatkiem-zz parostatkiem-zz commented Oct 25, 2018

Description

Changes proposed in this pull request:

  • create a helper function to detect unexpected segments in the URL
  • display an alert (taken from FundamentalUI) when when needed
  • test the helper function
  • move existing test files to separate folders (according the code hierarchy)

Related issue(s)

Refeers #58

@dariadomagala-sap dariadomagala-sap self-assigned this Oct 25, 2018
Copy link
Contributor

@dariadomagala-sap dariadomagala-sap left a comment

Choose a reason for hiding this comment

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

Read the comments and add an example to our angular app together with a UI test.

<Backdrop>
<div class="fd-page iframeContainer" use:init="context" />


Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm picky, but please remove unnecessary spaces ;)

@@ -226,6 +240,20 @@
console.error('goBack() not possible, no preserved views found.');
}
}

if ('luigi.displayAlert' === e.data.msg) {
if (e.data.detail) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be better to add one additional check to prevent from those undefined errors.
if(e.data && e.data.detail){}

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I would vote for changing from 'detail' to 'errorMessage' or something more straight forward. Could be discussed :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

errorMessage looks good to me. message would be even better but it'd collide with the postMessage name which is the same.

this.set({ alertMessage: e.data.detail });
} else {
console.error(
'Error alert has been triggered but no message was provided in "detail" property'
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change this message. I think it would be sufficient to just let the user know that there was an error, without telling him that the event message has not been sent properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So what error should it be?
I thought we may use the alert somewhere else in the future and the developer may forget about the message in an event so this error would tell him directly what the problem is.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't show to the user an error saying that developers misconfigured something. That wouldn't tell the user anything, but could cause a confusion. In my opinion it would be sufficient that this information is visible in the console and in the UI there is a more generic message.
We can discuss it with the team.


it("should return false when pathSegments numbers don't match", async () => {
const tooShortSourceUrl = 'one/two';
const tooLongSourceUrl = 'lets/change/Sinon/to/Jest/someday';
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change this part.

core/test/utilities/helpers.spec.js Show resolved Hide resolved
return false; //we can already tell segments will not match so no loop is needed
}

mandatorySegments.forEach((segment, index) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be good to add an if statement before forEach loop, because if mandatorySegments will be undefined, there will be an error.
It might not be the case for our example, but I'm rather cautious with forEach loops and things like that, they can be tricky 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

Same with this mandatorySegments.length above etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'll improve it

@dariadomagala-sap
Copy link
Contributor

Code looks better, but please also add an example and UI test as I requested previously.

…04-support-for-non-existing-paths

# Conflicts:
#	core/examples/luigi-sample-angular/src/app/project/project.component.html
#	core/src/App.html
#	core/src/services/routing.js
@jesusreal jesusreal self-assigned this Nov 13, 2018
Copy link
Contributor

@jesusreal jesusreal left a comment

Choose a reason for hiding this comment

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

  • If I enter a url like http://localhost:4200/#/projects-does-not-exist the route is not changed. Tested for both hash and path routing. In this case we should probably redirect to localhost:4200.
  • The notification still does not show the route the user wanted to navigate to .

@parostatkiem-zz parostatkiem-zz force-pushed the 404-support-for-non-existing-paths branch from 86165ab to d35f53c Compare November 13, 2018 12:54
@jesusreal
Copy link
Contributor

jesusreal commented Nov 15, 2018

The implementation is not working for a url with query parameters like http://localhost:4200/#/projects/pr2/settings?~foo=bar&

Additionally, there are some refactorings that I would apply. I generated the following patch file you can apply it with this command: git apply patch-404-support-for-non-existing-paths.

Copy link
Contributor

@jesusreal jesusreal left a comment

Choose a reason for hiding this comment

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

Please see my comment

@@ -86,6 +86,36 @@ export const prependOrigin = path => {
return window.location.origin;
};

export const containsAllSegments = (sourceUrl, targetPathSegments) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is still a bug when the user introduces a url with a trailing slash like '/projects/pr2/' (sourceUrl param in function)
Furthermore the implementation could be simpler. My proposal is the following (unit tests are still green after refactoring)

@kwiatekus kwiatekus merged commit 6eb2406 into SAP:master Nov 20, 2018
@parostatkiem-zz parostatkiem-zz deleted the 404-support-for-non-existing-paths branch November 28, 2018 08:28
stanleychh pushed a commit to stanleychh/luigi that referenced this pull request Dec 30, 2021
Handle 404 when route is absolutely not found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants