Skip to content

Commit 9708d43

Browse files
committed
Add pagination to ProjectHistoryPage
1 parent 3f9847e commit 9708d43

File tree

5 files changed

+90
-59
lines changed

5 files changed

+90
-59
lines changed

src/UnisonShare/Link.elm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ projectOverview projectRef_ =
251251
toClick (Route.projectOverview projectRef_)
252252

253253

254+
projectHistory : ProjectRef -> Maybe BranchRef -> PageCursorParam -> Click msg
255+
projectHistory projectRef_ branchRef_ cursor =
256+
toClick (Route.projectHistory projectRef_ branchRef_ cursor)
257+
258+
254259
projectBranches : ProjectRef -> PageCursorParam -> Click msg
255260
projectBranches projectRef_ cursor =
256261
toClick (Route.projectBranches projectRef_ cursor)

src/UnisonShare/Page/ProjectHistoryPage.elm

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,26 @@ import UI.PageLayout as PageLayout exposing (PageLayout)
1717
import UI.PageTitle as PageTitle
1818
import UI.Placeholder as Placeholder
1919
import UI.ProfileSnippet as ProfileSnippet
20-
import UnisonShare.Api as ShareApi
2120
import UnisonShare.AppContext exposing (AppContext)
21+
import UnisonShare.Link as Link
2222
import UnisonShare.Page.ErrorPage as ErrorPage
2323
import UnisonShare.PageFooter as PageFooter
24+
import UnisonShare.Paginated as Paginated exposing (Paginated(..))
2425
import UnisonShare.Project as Project exposing (ProjectDetails)
25-
import UnisonShare.Project.BranchHistory as BranchHistory exposing (BranchHistory, HistoryEntry)
26+
import UnisonShare.Project.BranchHistory as BranchHistory exposing (HistoryEntry)
2627
import UnisonShare.Project.ProjectRef exposing (ProjectRef)
2728

2829

2930

3031
-- MODEL
3132

3233

34+
type alias PaginatedBranchHistory =
35+
Paginated.Paginated HistoryEntry
36+
37+
3338
type alias Model =
34-
{ history : WebData BranchHistory
39+
{ history : WebData PaginatedBranchHistory
3540
}
3641

3742

@@ -41,15 +46,15 @@ preInit =
4146
}
4247

4348

44-
init : AppContext -> ProjectDetails -> Maybe BranchRef -> ( Model, Cmd Msg )
45-
init appContext project branchRef =
49+
init : AppContext -> ProjectDetails -> Maybe BranchRef -> Paginated.PageCursorParam -> ( Model, Cmd Msg )
50+
init appContext project branchRef cursor =
4651
let
4752
branchRef_ : BranchRef
4853
branchRef_ =
4954
Maybe.withDefault (Project.defaultBrowsingBranch project) branchRef
5055
in
5156
( { history = Loading }
52-
, fetchProjectBranchHistory appContext project.ref branchRef_
57+
, fetchProjectBranchHistory appContext project.ref branchRef_ cursor
5358
)
5459

5560

@@ -58,28 +63,36 @@ init appContext project branchRef =
5863

5964

6065
type Msg
61-
= FetchProjectBranchHistoryFinished BranchRef (WebData BranchHistory)
66+
= FetchProjectBranchHistoryFinished BranchRef (WebData PaginatedBranchHistory)
6267

6368

6469
update : AppContext -> ProjectDetails -> Maybe BranchRef -> Msg -> Model -> ( Model, Cmd Msg )
65-
update appContext project branchRef msg model =
70+
update _ _ _ msg model =
6671
case msg of
67-
FetchProjectBranchHistoryFinished branchRef_ history ->
72+
FetchProjectBranchHistoryFinished _ history ->
6873
( { model | history = history }, Cmd.none )
6974

7075

7176

7277
-- EFFECTS
7378

7479

75-
fetchProjectBranchHistory : AppContext -> ProjectRef -> BranchRef -> Cmd Msg
76-
fetchProjectBranchHistory appContext projectRef branchRef =
80+
fetchProjectBranchHistory : AppContext -> ProjectRef -> BranchRef -> Paginated.PageCursorParam -> Cmd Msg
81+
fetchProjectBranchHistory _ _ branchRef cursor =
7782
let
83+
params =
84+
{ limit = 64
85+
, cursor = cursor
86+
}
87+
88+
mkPaginated prev next items =
89+
Paginated.Paginated { prev = prev, next = next, items = items }
90+
7891
mock =
7992
RemoteData.Success
80-
{ projectRef = projectRef
81-
, branchRef = branchRef
82-
, history =
93+
(mkPaginated
94+
Nothing
95+
(Just (Paginated.PageCursor "asdf-1234"))
8396
[ BranchHistory.Comment
8497
{ createdAt = DateTime.unsafeFromISO8601 "2025-11-03T13:35:33-05:00"
8598
, afterCausalHash = Hash.unsafeFromString "commenthash1"
@@ -110,7 +123,7 @@ fetchProjectBranchHistory appContext projectRef branchRef =
110123
, body = "And it was really cool"
111124
}
112125
]
113-
}
126+
)
114127
in
115128
Util.delayMsg 500 (FetchProjectBranchHistoryFinished branchRef mock)
116129

@@ -243,22 +256,40 @@ viewHistoryEntry appContext entry =
243256
[ viewCardContent changeset ]
244257

245258

246-
viewPageContent : AppContext -> ProjectDetails -> Maybe BranchRef -> BranchHistory -> PageContent Msg
247-
viewPageContent appContext _ _ history =
259+
viewPaginationControls : ProjectRef -> Maybe BranchRef -> { a | prev : Maybe Paginated.PageCursor, next : Maybe Paginated.PageCursor } -> Html msg
260+
viewPaginationControls projectRef branchRef cursors =
261+
let
262+
toLink cursor =
263+
Link.projectHistory projectRef branchRef cursor
264+
in
265+
Paginated.view toLink cursors
266+
267+
268+
viewPageContent : AppContext -> ProjectDetails -> Maybe BranchRef -> PaginatedBranchHistory -> PageContent Msg
269+
viewPageContent appContext project branchRef (Paginated history) =
248270
let
249271
entries =
250-
if List.isEmpty history.history then
272+
if List.isEmpty history.items then
251273
[ div [] [ text "No entries" ] ]
252274

253275
else
254-
List.map (viewHistoryEntry appContext) history.history
276+
List.map (viewHistoryEntry appContext) history.items
255277
in
256-
PageContent.oneColumn [ div [ class "history-entries" ] entries ]
278+
PageContent.oneColumn
279+
[ div [ class "history-entries" ] entries
280+
, viewPaginationControls project.ref branchRef history
281+
]
257282
|> PageContent.withPageTitle (PageTitle.title "History")
258283

259284

260-
view : AppContext -> ProjectDetails -> Maybe BranchRef -> Model -> ( PageLayout Msg, Maybe (Html Msg) )
261-
view appContext project branchRef model =
285+
view :
286+
AppContext
287+
-> ProjectDetails
288+
-> Maybe BranchRef
289+
-> Paginated.PageCursorParam
290+
-> Model
291+
-> ( PageLayout Msg, Maybe (Html Msg) )
292+
view appContext project branchRef _ model =
262293
case model.history of
263294
NotAsked ->
264295
( viewLoadingPage, Nothing )

src/UnisonShare/Page/ProjectPage.elm

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import UnisonShare.Page.ProjectSettingsPage as ProjectSettingsPage
4848
import UnisonShare.Page.ProjectTicketPage as ProjectTicketPage
4949
import UnisonShare.Page.ProjectTicketsPage as ProjectTicketsPage
5050
import UnisonShare.PageFooter as PageFooter
51+
import UnisonShare.Paginated as Paginated
5152
import UnisonShare.Project as Project exposing (ProjectDetails)
5253
import UnisonShare.Project.ProjectRef as ProjectRef exposing (ProjectRef)
5354
import UnisonShare.Route as Route exposing (CodeRoute, ProjectRoute(..))
@@ -72,7 +73,7 @@ type SubPage
7273
| Contributions ProjectContributionsPage.Model
7374
| Ticket TicketRef ProjectTicketPage.Model
7475
| Tickets ProjectTicketsPage.Model
75-
| History (Maybe BranchRef) ProjectHistoryPage.Model
76+
| History (Maybe BranchRef) Paginated.PageCursorParam ProjectHistoryPage.Model
7677
| Settings ProjectSettingsPage.Model
7778

7879

@@ -182,8 +183,8 @@ init appContext projectRef route =
182183
in
183184
( Releases releases_, Cmd.map ProjectReleasesPageMsg releasesCmd )
184185

185-
ProjectHistory branchRef ->
186-
( History branchRef ProjectHistoryPage.preInit, Cmd.none )
186+
ProjectHistory branchRef cursor ->
187+
( History branchRef cursor ProjectHistoryPage.preInit, Cmd.none )
187188

188189
ProjectSettings ->
189190
let
@@ -309,12 +310,12 @@ update appContext projectRef route msg model =
309310
]
310311
)
311312

312-
( History branchRef _, Success project_ ) ->
313+
( History branchRef cursor _, Success project_ ) ->
313314
let
314315
( history, cmd ) =
315-
ProjectHistoryPage.init appContext project_ branchRef
316+
ProjectHistoryPage.init appContext project_ branchRef cursor
316317
in
317-
( { modelWithProject | subPage = History branchRef history }
318+
( { modelWithProject | subPage = History branchRef cursor history }
318319
, Cmd.batch
319320
[ Cmd.map ProjectHistoryPageMsg cmd
320321
]
@@ -720,14 +721,14 @@ update appContext projectRef route msg model =
720721
_ ->
721722
( model, Cmd.none )
722723

723-
( History _ history, ProjectHistoryPageMsg historyPageMsg ) ->
724+
( History _ _ history, ProjectHistoryPageMsg historyPageMsg ) ->
724725
case ( model.project, route ) of
725-
( Success project, Route.ProjectHistory branchRef_ ) ->
726+
( Success project, Route.ProjectHistory branchRef_ cursor ) ->
726727
let
727728
( history_, historyCmd ) =
728729
ProjectHistoryPage.update appContext project branchRef_ historyPageMsg history
729730
in
730-
( { model | subPage = History branchRef_ history_ }
731+
( { model | subPage = History branchRef_ cursor history_ }
731732
, Cmd.map ProjectHistoryPageMsg historyCmd
732733
)
733734

@@ -939,19 +940,19 @@ updateSubPage appContext projectRef model route =
939940
in
940941
( { model | subPage = Release version releasePage_ }, Cmd.map ProjectReleasePageMsg releasePageCmd )
941942

942-
ProjectHistory branchRef ->
943+
ProjectHistory branchRef cursor ->
943944
case model.subPage of
944-
History _ _ ->
945+
History _ _ _ ->
945946
( model, Cmd.none )
946947

947948
_ ->
948949
case model.project of
949950
Success project ->
950951
let
951952
( history, cmd ) =
952-
ProjectHistoryPage.init appContext project branchRef
953+
ProjectHistoryPage.init appContext project branchRef cursor
953954
in
954-
( { model | subPage = History branchRef history }, Cmd.map ProjectHistoryPageMsg cmd )
955+
( { model | subPage = History branchRef cursor history }, Cmd.map ProjectHistoryPageMsg cmd )
955956

956957
_ ->
957958
( model, Cmd.none )
@@ -1367,7 +1368,7 @@ viewErrorPage appContext subPage projectRef error =
13671368
PageFooter.pageFooter
13681369
|> PageLayout.withSubduedBackground
13691370

1370-
History _ _ ->
1371+
History _ _ _ ->
13711372
PageLayout.centeredNarrowLayout
13721373
(PageContent.oneColumn [ errorCard ])
13731374
PageFooter.pageFooter
@@ -1453,7 +1454,7 @@ viewLoadingPage appContext subPage projectRef =
14531454
, "project-releases-page"
14541455
)
14551456

1456-
History _ _ ->
1457+
History _ _ _ ->
14571458
( ProjectHistoryPage.viewLoadingPage, "project-history-page" )
14581459

14591460
Settings _ ->
@@ -1770,10 +1771,10 @@ view appContext projectRef model =
17701771
, modal = modal (Maybe.map (Html.map ProjectTicketsPageMsg) modal_)
17711772
}
17721773

1773-
History branchRef history ->
1774+
History branchRef cursor history ->
17741775
let
17751776
( history_, modal_ ) =
1776-
ProjectHistoryPage.view appContext project branchRef history
1777+
ProjectHistoryPage.view appContext project branchRef cursor history
17771778
in
17781779
{ pageId = "project-page project-history-page"
17791780
, title = title

src/UnisonShare/Project/BranchHistory.elm

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ type alias ChangesetDetails =
4747

4848

4949
type alias BranchHistory =
50-
{ projectRef : ProjectRef
51-
, branchRef : BranchRef
52-
, history : List HistoryEntry
53-
}
50+
List HistoryEntry
5451

5552

5653

@@ -122,7 +119,4 @@ decodeHistoryEntry =
122119

123120
decode : Decode.Decoder BranchHistory
124121
decode =
125-
Decode.succeed BranchHistory
126-
|> required "projectRef" ProjectRef.decode
127-
|> required "branchRef" BranchRef.decode
128-
|> required "history" (Decode.list decodeHistoryEntry)
122+
Decode.field "history" (Decode.list decodeHistoryEntry)

src/UnisonShare/Route.elm

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ type ProjectRoute
144144
| ProjectContribution ContributionRef ProjectContributionRoute
145145
| ProjectContributions ProjectContributionsRoute
146146
| ProjectSettings
147-
| ProjectHistory (Maybe BranchRef)
147+
| ProjectHistory (Maybe BranchRef) PageCursorParam
148148

149149

150150
type NotificationsRoute
@@ -325,9 +325,9 @@ projectTickets projectRef_ =
325325
Project projectRef_ ProjectTickets
326326

327327

328-
projectHistory : ProjectRef -> Maybe BranchRef -> Route
329-
projectHistory projectRef_ branchRef_ =
330-
Project projectRef_ (ProjectHistory branchRef_)
328+
projectHistory : ProjectRef -> Maybe BranchRef -> PageCursorParam -> Route
329+
projectHistory projectRef_ branchRef_ cursor =
330+
Project projectRef_ (ProjectHistory branchRef_ cursor)
331331

332332

333333
projectSettings : ProjectRef -> Route
@@ -777,14 +777,14 @@ projectParser queryString =
777777
ps =
778778
ProjectRef.projectRef handle slug
779779
in
780-
Project ps (ProjectHistory (Just branchRef))
780+
Project ps (ProjectHistory (Just branchRef) paginationCursor)
781781

782782
projectHistoryDefault_ handle slug =
783783
let
784784
ps =
785785
ProjectRef.projectRef handle slug
786786
in
787-
Project ps (ProjectHistory Nothing)
787+
Project ps (ProjectHistory Nothing paginationCursor)
788788
in
789789
oneOf
790790
[ b (succeed projectOverview_ |. slash |= userHandle |. slash |= projectSlug |. end)
@@ -1028,10 +1028,10 @@ toUrlPattern r =
10281028
Project _ ProjectTickets ->
10291029
":handle/:project-slug/tickets"
10301030

1031-
Project _ (ProjectHistory Nothing) ->
1031+
Project _ (ProjectHistory Nothing _) ->
10321032
":handle/:project-slug/history"
10331033

1034-
Project _ (ProjectHistory (Just _)) ->
1034+
Project _ (ProjectHistory (Just _) _) ->
10351035
":handle/:project-slug/history/:branch-ref"
10361036

10371037
Project _ ProjectSettings ->
@@ -1219,11 +1219,11 @@ toUrlString route =
12191219
Project projectRef_ ProjectTickets ->
12201220
( ProjectRef.toUrlPath projectRef_ ++ [ "tickets" ], [] )
12211221

1222-
Project projectRef_ (ProjectHistory (Just branchRef_)) ->
1223-
( ProjectRef.toUrlPath projectRef_ ++ "history" :: BranchRef.toUrlPath branchRef_, [] )
1222+
Project projectRef_ (ProjectHistory (Just branchRef_) cursor) ->
1223+
( ProjectRef.toUrlPath projectRef_ ++ "history" :: BranchRef.toUrlPath branchRef_, paginationCursorToQueryParams cursor )
12241224

1225-
Project projectRef_ (ProjectHistory Nothing) ->
1226-
( ProjectRef.toUrlPath projectRef_ ++ [ "history" ], [] )
1225+
Project projectRef_ (ProjectHistory Nothing cursor) ->
1226+
( ProjectRef.toUrlPath projectRef_ ++ [ "history" ], paginationCursorToQueryParams cursor )
12271227

12281228
Project projectRef_ ProjectSettings ->
12291229
( ProjectRef.toUrlPath projectRef_ ++ [ "settings" ], [] )

0 commit comments

Comments
 (0)