Skip to content

Allow sharing query parameters at route branches#989

Open
alexfmpe wants to merge 3 commits intoobsidiansystems:developfrom
alexfmpe:path-component-ignoring
Open

Allow sharing query parameters at route branches#989
alexfmpe wants to merge 3 commits intoobsidiansystems:developfrom
alexfmpe:path-component-ignoring

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)

, 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

@alexfmpe alexfmpe force-pushed the path-component-ignoring branch from f86920b to e674ce5 Compare September 26, 2022 03:44
@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 alexfmpe force-pushed the path-component-ignoring branch from c883dae to 2a21612 Compare May 15, 2024 17:12
@alexfmpe
Copy link
Contributor Author

Rebased on top of #1079

@alexfmpe alexfmpe force-pushed the path-component-ignoring branch from 2a21612 to 7fb80c0 Compare November 14, 2024 23:55
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