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

isActiveAction should take query string into account #1725

Merged
merged 12 commits into from
Jul 24, 2023

Conversation

amitaibu
Copy link
Collaborator

No description provided.

@amitaibu amitaibu marked this pull request as ready for review June 25, 2023 12:12

isActivePath #{param}: #{isActivePath $ "/test/TestWithParam?param=" <> param}
isActivePath bar: #{isActivePath ("/test/TestWithParam?param=bar" :: Text)}
|]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@mpscholten added tests so we have more confidence over the change! 🍻

When I try to add

isActiveController TestController: #{isActiveController @TestController}

I get:

image

Copy link
Member

Choose a reason for hiding this comment

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

The function can only be called from a view. To fix the test you can add a view data structure and render it to HSX

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The function can only be called from a view

What indicates it? Is it the use of fromFrozenContext?

Copy link
Member

Choose a reason for hiding this comment

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

Yep exactly. The renderHtml does call Context.freeze before rendering the html https://github.com/digitallyinduced/ihp/blob/master/IHP/Controller/Render.hs#L60

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, forgot to comment here, pushed a fix to https://github.com/amitaibu/ihp/pull/4/files Once merged the tests should be green 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks. @mpscholten can you give a short explanation on how you knew what this fix is?

Copy link
Member

Choose a reason for hiding this comment

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

I dumped the response body of the the 500 Internal Server Error response. It showed that the error was happening here https://github.com/digitallyinduced/ihp/blob/master/IHP/Controller/Session.hs#L162 That error should never happen. I was first confused why the session was even used, because no code in the tests is doing anything with the session. I placed many error calls in my local IHP codebase to trace it back. Turns out that renderHtml calls initFlashMessages which then accesses the session.

Then I looked thorugh the test code and checked what could be wrong with the session setup. I figured out that we never called the session middleware. After that it was an easy fix, just wiring up the middleware so that the session is available 👍

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 dumped the response body of the the 500 Internal Server Error response

How did you do it?

Copy link
Member

Choose a reason for hiding this comment

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

Changed the

assertTextExists body response = do
    response.simpleStatus `shouldBe` status200

function to this:

assertTextExists body response = do
    error (show response)
    response.simpleStatus `shouldBe` status200

@amitaibu
Copy link
Collaborator Author

@mpscholten tests are passing, but it shows the build as failing.

@amitaibu amitaibu requested a review from mpscholten July 23, 2023 19:52
Copy link
Member

@mpscholten mpscholten left a comment

Choose a reason for hiding this comment

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

Thanks, looks good 👍

@mpscholten mpscholten merged commit c5422cd into digitallyinduced:master Jul 24, 2023
3 of 8 checks passed
@s0kil
Copy link
Collaborator

s0kil commented Jul 27, 2023

I use this function often, and I expect isActiveAction to not take query string into account.

We should have isActiveAction as generic, and isActiveActionPath Or isActiveActionParams as strict param checking.

@amitaibu amitaibu deleted the isActiveAction-alias branch July 27, 2023 15:53
@amitaibu
Copy link
Collaborator Author

I use this function often, and I expect isActiveAction to not take query string into account.

How do you use it? How would it work on ShowPostAction (Id Post) if you don't pass the Post Id?

@s0kil
Copy link
Collaborator

s0kil commented Jul 27, 2023

With the example shown, the path would be /ShowPostAction?postId=UUID, But we can still match on /ShowPostAction.

@amitaibu
Copy link
Collaborator Author

I think for that we'd need an isActiveActionByBasePath (or some better but still explicit name).

@s0kil
Copy link
Collaborator

s0kil commented Jul 27, 2023

In a current project, I have a helper:

-- TODO: File An Issue In IHP, The Provided Func Is Broken
isActivePathOrSub :: _ => controller -> Bool
isActivePathOrSub route =
    let
        currentPath = Wai.rawPathInfo theRequest
    in
        currentPath `ByteString.isPrefixOf` cs (pathTo route)

That seems to work as well.

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