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

Allow sharing query parameters at route branches #989

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

alexfmpe
Copy link
Contributor

@alexfmpe alexfmpe commented Sep 26, 2022

Edit: Rebased on top of #1079

Allows turning

data ParentRoute :: * -> * where
  ParentRoute_ChildA :: ParentRoute ()
  ParentRoute_ChildB :: ParentRoute ()
  ParentRoute_ChildC :: ParentRoute ()

  FrontendRoute_Parent -> PathSegment "parent" $ pathComponentEncoder $ \case
    ParentRoute_ChildA -> PathEnd $ unitEncoderLenient mempty
    ParentRoute_ChildB -> PathSegment "b" $ pathOnlyEncoderIgnoringQuery . unitEncoder mempty
    ParentRoute_ChildC -> PathSegment "c" $ pathOnlyEncoderIgnoringQuery . unitEncoder mempty

into

  FrontendRoute_Parent -> PathSegment "parent" $ pathComponentEncoderIgnoringQuery $ \case
    ParentRoute_ChildA -> PathEnd id
    ParentRoute_ChildB -> PathSegment "b" $ unitEncoder mempty
    ParentRoute_ChildC -> PathSegment "c" $ unitEncoder mempty

and

  FrontendRoute_Parent :: FrontendRoute (R ParentRoute)

data ParentRoute :: * -> * where
  ParentRoute_ChildA :: ParentRoute (Map Text (Maybe Text))
  ParentRoute_ChildB :: ParentRoute (Map Text (Maybe Text))
  ParentRoute_ChildC :: ParentRoute (Map Text (Maybe Text))

  FrontendRoute_Parent -> PathSegment "parent" $ pathComponentEncoder $ \case
    ParentRoute_ChildA -> PathEnd id
    ParentRoute_ChildB -> PathSegment "b" queryOnlyEncoder
    ParentRoute_ChildC -> PathSegment "c" queryOnlyEncoder

into

  FrontendRoute_Parent :: FrontendRoute (R ParentRoute, Map Text (Maybe Text))

  FrontendRoute_Parent -> PathSegment "parent" $ pathComponentEncoderSharingQuery id $ \case
    ParentRoute_ChildA -> PathEnd id
    ParentRoute_ChildB -> PathSegment "b" $ unitEncoder mempty
    ParentRoute_ChildC -> PathSegment "c" $ unitEncoder mempty

Motivation

  • for the former comes from a project frequently linked to from social media, which has a habit of injecting tracking parameters and breaking all the links, which forces fooIgnoringQuery to be added all over the leaf routes
  • for the later comes from a project where several sub-routes shared the same query parameters which made it necessary to add the same encoder (yielding something more structured than `queryOnlyEncoder) to all the children

I have:

  • Based work on latest develop branch
  • Followed the contribution guide
  • Looked for lint in my changes with hlint . (lint found code you did not write can be left alone)
  • Run the test suite: $(nix-build -A selftest --no-out-link)
  • Updated the changelog
  • (Optional) Run CI tests locally: nix-build release.nix -A build.x86_64-linux --no-out-link (or x86_64-darwin on macOS)

@@ -119,6 +121,7 @@ module Obelisk.Route
, queryParametersTextEncoder
, integralEncoder
, pathSegmentEncoder
, pathOnlyEncoderIgnoringQuery
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably should be exported - I end up inlining this in every project

lib/route/src/Obelisk/Route.hs Outdated Show resolved Hide resolved
@alexfmpe alexfmpe changed the title Allow ignoring query parameters at route branches Allow sharing query parameters at route branches Sep 26, 2022
@alexfmpe alexfmpe mentioned this pull request May 15, 2024
6 tasks
@alexfmpe
Copy link
Contributor Author

Rebased on top of #1079

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.

1 participant