Skip to content

Commit 16921f7

Browse files
committed
Add SwitchBranch picker to ProjectHistoryPage
1 parent 9708d43 commit 16921f7

File tree

3 files changed

+67
-14
lines changed

3 files changed

+67
-14
lines changed

src/UnisonShare/Page/ProjectHistoryPage.elm

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Lib.Util as Util
99
import RemoteData exposing (RemoteData(..), WebData)
1010
import String.Extra exposing (pluralize)
1111
import UI
12+
import UI.AnchoredOverlay as AnchoredOverlay exposing (AnchoredOverlay)
1213
import UI.Card as Card
1314
import UI.DateTime as DateTime
1415
import UI.Icon as Icon exposing (Icon)
@@ -25,6 +26,8 @@ import UnisonShare.Paginated as Paginated exposing (Paginated(..))
2526
import UnisonShare.Project as Project exposing (ProjectDetails)
2627
import UnisonShare.Project.BranchHistory as BranchHistory exposing (HistoryEntry)
2728
import UnisonShare.Project.ProjectRef exposing (ProjectRef)
29+
import UnisonShare.Route as Route
30+
import UnisonShare.SwitchBranch as SwitchBranch
2831

2932

3033

@@ -37,23 +40,26 @@ type alias PaginatedBranchHistory =
3740

3841
type alias Model =
3942
{ history : WebData PaginatedBranchHistory
43+
, switchBranch : SwitchBranch.Model
4044
}
4145

4246

4347
preInit : Model
4448
preInit =
4549
{ history = NotAsked
50+
, switchBranch = SwitchBranch.init
4651
}
4752

4853

4954
init : AppContext -> ProjectDetails -> Maybe BranchRef -> Paginated.PageCursorParam -> ( Model, Cmd Msg )
5055
init appContext project branchRef cursor =
5156
let
52-
branchRef_ : BranchRef
5357
branchRef_ =
5458
Maybe.withDefault (Project.defaultBrowsingBranch project) branchRef
5559
in
56-
( { history = Loading }
60+
( { history = Loading
61+
, switchBranch = SwitchBranch.init
62+
}
5763
, fetchProjectBranchHistory appContext project.ref branchRef_ cursor
5864
)
5965

@@ -64,14 +70,41 @@ init appContext project branchRef cursor =
6470

6571
type Msg
6672
= FetchProjectBranchHistoryFinished BranchRef (WebData PaginatedBranchHistory)
73+
| SwitchBranchMsg SwitchBranch.Msg
6774

6875

6976
update : AppContext -> ProjectDetails -> Maybe BranchRef -> Msg -> Model -> ( Model, Cmd Msg )
70-
update _ _ _ msg model =
77+
update appContext project _ msg model =
7178
case msg of
7279
FetchProjectBranchHistoryFinished _ history ->
7380
( { model | history = history }, Cmd.none )
7481

82+
SwitchBranchMsg sbMsg ->
83+
let
84+
( switchBranch, switchBranchCmd, out ) =
85+
SwitchBranch.update appContext project.ref sbMsg model.switchBranch
86+
87+
navCmd =
88+
case out of
89+
SwitchBranch.SwitchToBranchRequest branchRef ->
90+
Route.navigate
91+
appContext.navKey
92+
(Route.projectHistory
93+
project.ref
94+
(Just branchRef)
95+
Paginated.NoPageCursor
96+
)
97+
98+
_ ->
99+
Cmd.none
100+
in
101+
( { model | switchBranch = switchBranch }
102+
, Cmd.batch
103+
[ Cmd.map SwitchBranchMsg switchBranchCmd
104+
, navCmd
105+
]
106+
)
107+
75108

76109

77110
-- EFFECTS
@@ -265,9 +298,12 @@ viewPaginationControls projectRef branchRef cursors =
265298
Paginated.view toLink cursors
266299

267300

268-
viewPageContent : AppContext -> ProjectDetails -> Maybe BranchRef -> PaginatedBranchHistory -> PageContent Msg
269-
viewPageContent appContext project branchRef (Paginated history) =
301+
viewPageContent : AppContext -> ProjectDetails -> Maybe BranchRef -> SwitchBranch.Model -> PaginatedBranchHistory -> PageContent Msg
302+
viewPageContent appContext project branchRef switchBranch (Paginated history) =
270303
let
304+
branchRef_ =
305+
Maybe.withDefault (Project.defaultBrowsingBranch project) branchRef
306+
271307
entries =
272308
if List.isEmpty history.items then
273309
[ div [] [ text "No entries" ] ]
@@ -279,7 +315,17 @@ viewPageContent appContext project branchRef (Paginated history) =
279315
[ div [ class "history-entries" ] entries
280316
, viewPaginationControls project.ref branchRef history
281317
]
282-
|> PageContent.withPageTitle (PageTitle.title "History")
318+
|> PageContent.withPageTitle
319+
(PageTitle.title "History"
320+
|> PageTitle.withRightSide
321+
[ SwitchBranch.toAnchoredOverlay project.ref
322+
branchRef_
323+
False
324+
switchBranch
325+
|> AnchoredOverlay.map SwitchBranchMsg
326+
|> AnchoredOverlay.view
327+
]
328+
)
283329

284330

285331
view :
@@ -299,7 +345,7 @@ view appContext project branchRef _ model =
299345

300346
Success history ->
301347
( PageLayout.centeredNarrowLayout
302-
(viewPageContent appContext project branchRef history)
348+
(viewPageContent appContext project branchRef model.switchBranch history)
303349
PageFooter.pageFooter
304350
|> PageLayout.withSubduedBackground
305351
, Nothing

src/UnisonShare/Page/ProjectPage.elm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ view appContext projectRef model =
15341534
, switchBranch =
15351535
AnchoredOverlay.map
15361536
SwitchBranchMsg
1537-
(SwitchBranch.toAnchoredOverlay projectRef branchRef model.switchBranch)
1537+
(SwitchBranch.toAnchoredOverlay projectRef branchRef True model.switchBranch)
15381538
, contextClick = Click.onClick (ChangeRouteTo (Route.projectOverview projectRef))
15391539
}
15401540
project

src/UnisonShare/SwitchBranch.elm

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ viewSuggestions data =
201201
MaybeE.values [ ownContributorBranches, projectBranches ]
202202

203203

204-
viewSheet : ProjectRef -> Sheet -> Html Msg
205-
viewSheet projectRef sheet =
204+
viewSheet : ProjectRef -> Bool -> Sheet -> Html Msg
205+
viewSheet projectRef withViewAllBranches sheet =
206206
let
207207
recentBranches =
208208
RemoteData.map2
@@ -222,18 +222,25 @@ viewSheet projectRef sheet =
222222
{ data = recentBranches
223223
, view = viewSuggestions
224224
}
225+
226+
viewAll =
227+
if withViewAllBranches then
228+
Just (Link.view "View all branches" (Link.projectBranches projectRef Paginated.NoPageCursor))
229+
230+
else
231+
Nothing
225232
in
226233
Html.map SearchBranchSheetMsg
227234
(SearchBranchSheet.view
228235
"Switch Branch"
229236
suggestions
230-
(Just (Link.view "View all branches" (Link.projectBranches projectRef Paginated.NoPageCursor)))
237+
viewAll
231238
sheet.sheet
232239
)
233240

234241

235-
toAnchoredOverlay : ProjectRef -> BranchRef -> Model -> AnchoredOverlay Msg
236-
toAnchoredOverlay projectRef branchRef model =
242+
toAnchoredOverlay : ProjectRef -> BranchRef -> Bool -> Model -> AnchoredOverlay Msg
243+
toAnchoredOverlay projectRef branchRef withViewAllBranches model =
237244
let
238245
button caret =
239246
Button.iconThenLabel ToggleSheet Icon.branch (BranchRef.toString branchRef)
@@ -252,4 +259,4 @@ toAnchoredOverlay projectRef branchRef model =
252259
Open sheet ->
253260
ao_ (button Icon.caretUp)
254261
|> AnchoredOverlay.withSheetPosition AnchoredOverlay.BottomLeft
255-
|> AnchoredOverlay.withSheet (AnchoredOverlay.sheet (viewSheet projectRef sheet))
262+
|> AnchoredOverlay.withSheet (AnchoredOverlay.sheet (viewSheet projectRef withViewAllBranches sheet))

0 commit comments

Comments
 (0)