Skip to content
This repository was archived by the owner on Sep 30, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

None

## [v1.1.2.2](https://github.com/pbrisbin/yesod-paginator/compare/v1.1.2.1...v1.1.2.2)
Comment thread
eahlberg marked this conversation as resolved.

- Fix (issue with filtering out query
parameters)[https://github.com/pbrisbin/yesod-paginator/issues/40]
Comment thread
eahlberg marked this conversation as resolved.
Outdated

## [v1.1.2.1](https://github.com/pbrisbin/yesod-paginator/compare/v1.1.2.0...v1.1.2.1)

- Support GHCs 9.0 and 9.2
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: yesod-paginator
version: 1.1.2.1
version: 1.1.2.2
synopsis: A pagination approach for yesod
description: Paginate a list showing a per-item widget and links to other pages
category: Web, Yesod
Expand Down
13 changes: 9 additions & 4 deletions src/Yesod/Paginator/Widgets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module Yesod.Paginator.Widgets
, simpleWith
, ellipsed
, ellipsedWith

-- * Exported for testing
, filterParams
Comment thread
eahlberg marked this conversation as resolved.
Outdated
) where

import Yesod.Paginator.Prelude
Expand Down Expand Up @@ -178,12 +181,14 @@ getUpdateGetParams
getUpdateGetParams pageParamName = do
params <- handlerToWidget $ reqGetParams <$> getRequest
pure
$ \number ->
nubOn fst
$ [(unPageParamName pageParamName, tshow number)]
<> params
$ \number -> filterParams pageParamName number params

renderGetParams :: [(Text, Text)] -> Text
renderGetParams [] = ""
renderGetParams ps = "?" <> T.intercalate "&" (map renderGetParam ps)
where renderGetParam (k, v) = encodeText k <> "=" <> encodeText v

filterParams :: Show a => PageParamName -> a -> [(Text, Text)] -> [(Text, Text)]
filterParams pageParamName number params =
let name = unPageParamName pageParamName
in [(name, tshow number)] <> filter ((/=) name . fst) params
1 change: 1 addition & 0 deletions test/SpecHelper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Test.Hspec as X
import Yesod.Core
import Yesod.Paginator as X
import Yesod.Paginator.Prelude as X
import Yesod.Paginator.Widgets as X
import Yesod.Test as X

data App = App
Expand Down
21 changes: 19 additions & 2 deletions test/Yesod/Paginator/WidgetsSpec.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{-# LANGUAGE OverloadedStrings #-}
module Yesod.Paginator.WidgetsSpec
( spec
)
where
) where

import SpecHelper

Expand Down Expand Up @@ -189,3 +188,21 @@ spec = withApp $ do
, "<li class=\"next disabled\"><a>»</a></li>"
, "</ul>"
]

describe "filterParams" $ it "works" $ do
Comment thread
eahlberg marked this conversation as resolved.
Outdated
let pageParamName = PageParamName "p"
pageNumber :: Int
pageNumber = 3
params :: [(Text, Text)]
params =
[ ("p", "2")
, ("p", "3")
, ("foo", "bar")
, ("ids[]", "1")
, ("ids[]", "2")
]

assertEq
"filters page params not equal to the page number but keeps query params with the same name"
(filterParams pageParamName pageNumber params)
[("p", "3"), ("foo", "bar"), ("ids[]", "1"), ("ids[]", "2")]
Comment thread
eahlberg marked this conversation as resolved.
Outdated
4 changes: 2 additions & 2 deletions yesod-paginator.cabal
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.34.4.
-- This file has been generated from package.yaml by hpack version 0.34.5.
Comment thread
eahlberg marked this conversation as resolved.
--
-- see: https://github.com/sol/hpack

name: yesod-paginator
version: 1.1.2.1
version: 1.1.2.2
synopsis: A pagination approach for yesod
description: Paginate a list showing a per-item widget and links to other pages
category: Web, Yesod
Expand Down