Skip to content

Commit 98686ee

Browse files
committed
Contribution: Add branch copy buttons and vied local instructions
1 parent a4c739c commit 98686ee

File tree

4 files changed

+132
-16
lines changed

4 files changed

+132
-16
lines changed

src/UnisonShare/Page/ProjectContributionOverviewPage.elm

Lines changed: 86 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module 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)
45
import Html.Attributes exposing (class)
56
import Http
67
import Json.Decode as Decode
@@ -10,8 +11,11 @@ import UI
1011
import UI.Button as Button
1112
import UI.ByAt as ByAt
1213
import UI.Card as Card
14+
import UI.CopyField as CopyField
1315
import UI.DateTime as DateTime
16+
import UI.Divider as Divider
1417
import UI.Icon as Icon
18+
import UI.Modal as Modal
1519
import UI.PageContent as PageContent exposing (PageContent)
1620
import UI.StatusBanner as StatusBanner
1721
import UI.TabList as TabList
@@ -28,7 +32,7 @@ import UnisonShare.ContributionTimeline as ContributionTimeline
2832
import UnisonShare.DateTimeContext exposing (DateTimeContext)
2933
import UnisonShare.Link as Link
3034
import UnisonShare.Markdown as Markdown
31-
import UnisonShare.Project.ProjectRef exposing (ProjectRef)
35+
import UnisonShare.Project.ProjectRef as ProjectRef exposing (ProjectRef)
3236
import UnisonShare.Session as Session exposing (Session)
3337
import UnisonShare.Timeline.TimelineEvent as TimelineEvent
3438

@@ -46,7 +50,7 @@ type UpdateStatus
4650

4751
type ContributionOverviewModal
4852
= NoModal
49-
| UpdateBranchInstructionsModal
53+
| ViewLocallyInstructionsModal
5054

5155

5256
type 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+
502571
view : AppContext -> ProjectRef -> ContributionDetails -> Model -> ( PageContent Msg, Maybe (Html Msg) )
503572
view 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
)

src/UnisonShare/Page/ProjectContributionPage.elm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import UI
1010
import UI.Button as Button
1111
import UI.ByAt as ByAt
1212
import UI.Card as Card
13+
import UI.CopyOnClick as CopyOnClick
1314
import UI.DateTime as DateTime exposing (DateTime)
1415
import UI.Icon as Icon
1516
import UI.PageContent as PageContent
@@ -343,11 +344,13 @@ detailedPageTitle appContext contribution =
343344
|> Tag.withClick (Link.projectBranchRoot contribution.projectRef contribution.sourceBranchRef)
344345
|> Tag.large
345346
|> Tag.view
347+
, CopyOnClick.copyButton (BranchRef.toString contribution.sourceBranchRef)
346348
, text "to"
347349
, BranchRef.toTag contribution.targetBranchRef
348350
|> Tag.withClick (Link.projectBranchRoot contribution.projectRef contribution.targetBranchRef)
349351
|> Tag.large
350352
|> Tag.view
353+
, CopyOnClick.copyButton (BranchRef.toString contribution.targetBranchRef)
351354
]
352355
]
353356
]

src/css/unison-share/page/project-contribution-overview-page.css

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,27 @@
107107
}
108108
}
109109

110-
#project-contribution-how-to-review-modal .instructions {
111-
display: flex;
112-
flex-direction: column;
113-
gap: 0.5rem;
110+
#project-contribution-view-locally-instructions-modal {
111+
& h3 {
112+
margin-bottom: 0.5rem;
113+
font-size: var(--font-size-base);
114+
}
114115

115-
& .copy-field {
116-
margin-bottom: 1rem;
116+
& .divider {
117+
background-color: var(--u-color_border);
117118
}
118119

119-
& p {
120-
margin-bottom: 0;
120+
& .instructions {
121+
display: flex;
122+
flex-direction: column;
123+
gap: 0.5rem;
124+
125+
& .copy-field:not(:last-child) {
126+
margin-bottom: 1rem;
127+
}
128+
129+
& p {
130+
margin-bottom: 0;
131+
}
121132
}
122133
}

src/css/unison-share/page/project-contribution-page.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,30 @@
7575
border-color: var(--u-color_border_hovered);
7676
background: var(--u-color_container_hovered);
7777
}
78+
79+
& .copy-on-click {
80+
display: flex;
81+
flex-direction: row;
82+
align-items: center;
83+
width: 1.5rem;
84+
85+
& .button {
86+
height: 1.5rem;
87+
width: 1.5rem;
88+
flex-grow: 0;
89+
}
90+
91+
& .copy-on-click_success {
92+
position: absolute;
93+
width: 1.5rem;
94+
height: 1.5rem;
95+
display: flex;
96+
justify-content: center;
97+
align-items: center;
98+
border-radius: var(--border-radius-base);
99+
background: var(--u-color_action);
100+
}
101+
}
78102
}
79103
}
80104
}

0 commit comments

Comments
 (0)