11module UnisonShare.Page.ProjectContributionOverviewPage exposing (..)
22
3- import Html exposing (Html , div , em , header , text )
3+ import Code.BranchRef as BranchRef
4+ import Html exposing (Html , div , em , h3 , header , p , text )
45import Html.Attributes exposing (class )
56import Http
67import Json.Decode as Decode
@@ -10,8 +11,11 @@ import UI
1011import UI.Button as Button
1112import UI.ByAt as ByAt
1213import UI.Card as Card
14+ import UI.CopyField as CopyField
1315import UI.DateTime as DateTime
16+ import UI.Divider as Divider
1417import UI.Icon as Icon
18+ import UI.Modal as Modal
1519import UI.PageContent as PageContent exposing (PageContent )
1620import UI.StatusBanner as StatusBanner
1721import UI.TabList as TabList
@@ -28,7 +32,7 @@ import UnisonShare.ContributionTimeline as ContributionTimeline
2832import UnisonShare.DateTimeContext exposing (DateTimeContext )
2933import UnisonShare.Link as Link
3034import UnisonShare.Markdown as Markdown
31- import UnisonShare.Project.ProjectRef exposing (ProjectRef )
35+ import UnisonShare.Project.ProjectRef as ProjectRef exposing (ProjectRef )
3236import UnisonShare.Session as Session exposing (Session )
3337import UnisonShare.Timeline.TimelineEvent as TimelineEvent
3438
@@ -46,7 +50,7 @@ type UpdateStatus
4650
4751type ContributionOverviewModal
4852 = NoModal
49- | UpdateBranchInstructionsModal
53+ | ViewLocallyInstructionsModal
5054
5155
5256type MergeStatus
@@ -92,7 +96,7 @@ type Msg
9296 = NoOp
9397 | UpdateStatus ContributionStatus
9498 | UpdateStatusFinished ContributionStatus ( HttpResult () )
95- | ShowUpdateBranchInstructionsModal
99+ | ShowViewLocallyInstructionsModal
96100 | CloseModal
97101 | FetchMergeabilityFinished ( HttpResult ContributionMergeability )
98102 | Merge
@@ -196,8 +200,8 @@ update appContext projectRef contributionRef contribution msg model =
196200 Session . Anonymous ->
197201 ( model, Cmd . none, NoOut )
198202
199- ShowUpdateBranchInstructionsModal ->
200- ( { model | modal = UpdateBranchInstructionsModal }, Cmd . none, NoOut )
203+ ShowViewLocallyInstructionsModal ->
204+ ( { model | modal = ViewLocallyInstructionsModal }, Cmd . none, NoOut )
201205
202206 CloseModal ->
203207 ( { model | modal = NoModal }, Cmd . none, NoOut )
@@ -283,6 +287,10 @@ viewContribution session projectRef updateStatus contribution mergeStatus =
283287 " Browse Code"
284288 |> Button . view
285289
290+ viewLocallyInstructionsButton =
291+ Button . iconThenLabel ShowViewLocallyInstructionsModal Icon . download " View locally"
292+ |> Button . view
293+
286294 archiveButton =
287295 if ( hasProjectAccess || isContributor) && updateStatus /= TimelineNotReady then
288296 Button . iconThenLabel ( UpdateStatus ContributionStatus . Archived ) Icon . archive " Archive"
@@ -365,6 +373,7 @@ viewContribution session projectRef updateStatus contribution mergeStatus =
365373 case contribution. status of
366374 ContributionStatus . Draft ->
367375 [ browseButton
376+ , viewLocallyInstructionsButton
368377 , div [ class " right-actions" ]
369378 [ Button . iconThenLabel ( UpdateStatus ContributionStatus . InReview ) Icon . conversation " Submit for review"
370379 |> Button . emphasized
@@ -373,17 +382,22 @@ viewContribution session projectRef updateStatus contribution mergeStatus =
373382 ]
374383
375384 ContributionStatus . InReview ->
376- [ div [ class " left-actions" ] [ browseButton ]
385+ [ div [ class " left-actions" ]
386+ [ browseButton
387+ , viewLocallyInstructionsButton
388+ ]
377389 , div [ class " right-actions" ] [ archiveButton, mergeButton ]
378390 ]
379391
380392 ContributionStatus . Merged ->
381393 [ browseButton
394+ , viewLocallyInstructionsButton
382395 , div [ class " right-actions" ] [ StatusBanner . good " Merged" ]
383396 ]
384397
385398 ContributionStatus . Archived ->
386399 [ browseButton
400+ , viewLocallyInstructionsButton
387401 , div [ class " right-actions" ] [ reopenButton ]
388402 ]
389403
@@ -499,14 +513,78 @@ viewPageContent appContext projectRef updateStatus contribution mergeStatus time
499513 ]
500514
501515
516+ viewViewLocallyInstructionsModal : ContributionDetails -> Html Msg
517+ viewViewLocallyInstructionsModal contribution =
518+ let
519+ projectRef =
520+ ProjectRef . toString contribution. projectRef
521+
522+ source =
523+ " /" ++ BranchRef . toString contribution. sourceBranchRef
524+
525+ target =
526+ " /" ++ BranchRef . toString contribution. targetBranchRef
527+
528+ content =
529+ div []
530+ [ h3 [] [ text " View the contribution locally:" ]
531+ , div [ class " instructions" ]
532+ [ p [] [ text " Clone the contribution branch:" ]
533+ , CopyField . copyField ( always NoOp ) ( " clone " ++ source)
534+ |> CopyField . withPrefix ( projectRef ++ " /main>" )
535+ |> CopyField . view
536+ ]
537+ , Divider . divider |> Divider . small |> Divider . view
538+ , h3 [] [ text " Merge (and resolve conflicts) locally:" ]
539+ , div [ class " instructions" ]
540+ [ p [] [ text " Clone the contribution branch:" ]
541+ , CopyField . copyField ( always NoOp ) ( " clone " ++ source)
542+ |> CopyField . withPrefix ( projectRef ++ " /main>" )
543+ |> CopyField . view
544+ , p [] [ text " Next, switch to the target branch (usually /main):" ]
545+ , CopyField . copyField ( always NoOp ) ( " switch " ++ target)
546+ |> CopyField . withPrefix ( projectRef ++ source ++ " >" )
547+ |> CopyField . view
548+ , p [] [ text " Make sure the target branch is up to date:" ]
549+ , CopyField . copyField ( always NoOp ) " pull"
550+ |> CopyField . withPrefix ( projectRef ++ " /main>" )
551+ |> CopyField . view
552+ , p [] [ text " Merge the changes:" ]
553+ , CopyField . copyField ( always NoOp ) ( " merge " ++ source)
554+ |> CopyField . withPrefix ( projectRef ++ target ++ " >" )
555+ |> CopyField . view
556+ , p [] [ text " Finally, push the project to share and mark the contribution as merged." ]
557+ ]
558+ ]
559+ in
560+ content
561+ |> Modal . content
562+ |> Modal . modal " project-contribution-view-locally-instructions-modal" CloseModal
563+ |> Modal . withActions
564+ [ Button . button CloseModal " Got it"
565+ |> Button . medium
566+ |> Button . emphasized
567+ ]
568+ |> Modal . view
569+
570+
502571view : AppContext -> ProjectRef -> ContributionDetails -> Model -> ( PageContent Msg , Maybe (Html Msg ) )
503572view appContext projectRef contribution model =
573+ let
574+ modal =
575+ case model. modal of
576+ NoModal ->
577+ Nothing
578+
579+ ViewLocallyInstructionsModal ->
580+ Just ( viewViewLocallyInstructionsModal contribution)
581+ in
504582 ( viewPageContent
505583 appContext
506584 projectRef
507585 model. updateStatus
508586 contribution
509587 model. mergeStatus
510588 model. timeline
511- , Nothing
589+ , modal
512590 )
0 commit comments