Skip to content

Commit 2fa0f38

Browse files
authored
Merge pull request #128 from unisoncomputing/diff-hover
Add definition summary hovers on diffs
2 parents 6050a6c + f3f8a22 commit 2fa0f38

File tree

3 files changed

+86
-21
lines changed

3 files changed

+86
-21
lines changed

elm-git.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"git-dependencies": {
33
"direct": {
4-
"https://github.com/unisonweb/ui-core": "9518fe75925e2a2d3828a4a5c2415ed0eac5d661"
4+
"https://github.com/unisonweb/ui-core": "58d63fe0de338b9355a37262ccc8ed9fb486b806"
55
},
66
"indirect": {}
77
}

src/UnisonShare/DefinitionDiffCard.elm

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module UnisonShare.DefinitionDiffCard exposing (..)
22

33
import Code.Hash as Hash
4-
import Code.Syntax.SyntaxConfig exposing (SyntaxConfig)
4+
import Code.Syntax.SyntaxConfig as SyntaxConfig exposing (SyntaxConfig)
55
import Code.Syntax.SyntaxSegment as SyntaxSegment
66
import Html exposing (Html, code, div, header, pre, span, text)
77
import Html.Attributes exposing (class, style)
@@ -36,7 +36,7 @@ viewDiffSegment : SyntaxConfig msg -> DiffSegment -> List (Html msg)
3636
viewDiffSegment syntaxConfig segment =
3737
let
3838
viewSegment =
39-
SyntaxSegment.view syntaxConfig
39+
SyntaxSegment.view (SyntaxConfig.withoutDependencyTooltip syntaxConfig)
4040

4141
viewSegments_ className =
4242
viewSegments syntaxConfig className
@@ -61,7 +61,10 @@ viewDiffSegment syntaxConfig segment =
6161
]
6262
)
6363
|> Tooltip.view
64-
(span [ class "diff-segment annotation-change" ] [ viewSegment change.segment ])
64+
(span [ class "diff-segment annotation-change" ]
65+
[ viewSegment change.segment
66+
]
67+
)
6568
]
6669

6770
SegmentChange { from, to } ->
@@ -72,7 +75,9 @@ viewDiffSegment syntaxConfig segment =
7275
]
7376
)
7477
|> Tooltip.view
75-
(span [ class "diff-segment segment-change" ] [ viewSegment to ])
78+
(span [ class "diff-segment segment-change" ]
79+
[ viewSegment to ]
80+
)
7681
]
7782

7883

src/UnisonShare/Page/ProjectContributionChangesPage.elm

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ port module UnisonShare.Page.ProjectContributionChangesPage exposing (..)
22

33
import Code.BranchRef as BranchRef
44
import Code.Definition.Reference exposing (Reference)
5+
import Code.DefinitionSummaryTooltip as DefinitionSummaryTooltip
56
import Code.FullyQualifiedName as FQN
67
import Code.Hash as Hash
78
import Code.Perspective as Perspective
@@ -30,14 +31,15 @@ import UI.TabList as TabList
3031
import UI.Tooltip as Tooltip
3132
import UnisonShare.Account as Account
3233
import UnisonShare.Api as ShareApi
33-
import UnisonShare.AppContext exposing (AppContext)
34+
import UnisonShare.AppContext as AppContext exposing (AppContext)
3435
import UnisonShare.BranchDiff as BranchDiff exposing (BranchDiff)
3536
import UnisonShare.BranchDiff.ChangeLine as ChangeLine exposing (ChangeLine)
3637
import UnisonShare.BranchDiff.ChangeLineId as ChangeLineId exposing (ChangeLineId)
3738
import UnisonShare.BranchDiff.DefinitionType as DefinitionType exposing (DefinitionType)
3839
import UnisonShare.BranchDiff.LibDep as LibDep exposing (LibDep)
3940
import UnisonShare.BranchDiff.ToggledChangeLines as ToggledChangeLines exposing (ToggledChangeLines)
4041
import UnisonShare.BranchDiffState as BranchDiffState exposing (BranchDiffState)
42+
import UnisonShare.CodeBrowsingContext as CodeBrowsingContext
4143
import UnisonShare.Contribution exposing (ContributionDetails)
4244
import UnisonShare.Contribution.ContributionRef exposing (ContributionRef)
4345
import UnisonShare.DefinitionDiff as DefinitionDiff
@@ -57,6 +59,8 @@ type alias Model =
5759
{ branchDiff : BranchDiffState
5860
, toggledChangeLines : ToggledChangeLines
5961
, urlFocusedChangeLineId : Maybe ChangeLineId
62+
, oldDefinitionSummaryTooltip : DefinitionSummaryTooltip.Model
63+
, newDefinitionSummaryTooltip : DefinitionSummaryTooltip.Model
6064
}
6165

6266

@@ -71,6 +75,8 @@ init appContext projectRef contribRef changeLineId =
7175
( { branchDiff = BranchDiffState.Loading
7276
, toggledChangeLines = ToggledChangeLines.empty
7377
, urlFocusedChangeLineId = changeLineId
78+
, oldDefinitionSummaryTooltip = DefinitionSummaryTooltip.init
79+
, newDefinitionSummaryTooltip = DefinitionSummaryTooltip.init
7480
}
7581
, fetchBranchDiff appContext projectRef contribRef 1
7682
)
@@ -88,6 +94,8 @@ type Msg
8894
| SetChangeLinePermalink ChangeLineId
8995
| ScrollTo ChangeLineId
9096
| ExpandCollapsedDiffSection ChangeLineId { index : Int }
97+
| OldDefinitionSummaryTooltipMsg DefinitionSummaryTooltip.Msg
98+
| NewDefinitionSummaryTooltipMsg DefinitionSummaryTooltip.Msg
9199
| NoOp
92100

93101

@@ -220,6 +228,46 @@ update appContext projectRef contribRef msg model =
220228
in
221229
( { model | branchDiff = branchDiff }, Cmd.none )
222230

231+
OldDefinitionSummaryTooltipMsg tMsg ->
232+
case model.branchDiff of
233+
BranchDiffState.Computed bd ->
234+
let
235+
config =
236+
AppContext.toCodeConfig
237+
appContext
238+
(CodeBrowsingContext.ProjectBranch projectRef bd.oldBranch.ref)
239+
(Perspective.absoluteRootPerspective bd.oldBranch.hash)
240+
241+
( definitionSummaryTooltip, tCmd ) =
242+
DefinitionSummaryTooltip.update config tMsg model.oldDefinitionSummaryTooltip
243+
in
244+
( { model | oldDefinitionSummaryTooltip = definitionSummaryTooltip }
245+
, Cmd.map OldDefinitionSummaryTooltipMsg tCmd
246+
)
247+
248+
_ ->
249+
( model, Cmd.none )
250+
251+
NewDefinitionSummaryTooltipMsg tMsg ->
252+
case model.branchDiff of
253+
BranchDiffState.Computed bd ->
254+
let
255+
config =
256+
AppContext.toCodeConfig
257+
appContext
258+
(CodeBrowsingContext.ProjectBranch projectRef bd.newBranch.ref)
259+
(Perspective.absoluteRootPerspective bd.newBranch.hash)
260+
261+
( definitionSummaryTooltip, tCmd ) =
262+
DefinitionSummaryTooltip.update config tMsg model.newDefinitionSummaryTooltip
263+
in
264+
( { model | newDefinitionSummaryTooltip = definitionSummaryTooltip }
265+
, Cmd.map NewDefinitionSummaryTooltipMsg tCmd
266+
)
267+
268+
_ ->
269+
( model, Cmd.none )
270+
223271
NoOp ->
224272
( model, Cmd.none )
225273

@@ -433,9 +481,16 @@ viewNamespaceLine projectRef toggledChangeLines { name, lines } =
433481
]
434482

435483

436-
viewChangedDefinitionCard : ProjectRef -> ToggledChangeLines -> BranchDiff -> Int -> ChangeLine -> DefinitionType -> Html Msg -> Html Msg
437-
viewChangedDefinitionCard projectRef toggledChangeLines branchDiff maxBadgeLength changeLine type_ content =
484+
viewChangedDefinitionCard : ProjectRef -> Model -> BranchDiff -> Int -> ChangeLine -> DefinitionType -> Html Msg -> Html Msg
485+
viewChangedDefinitionCard projectRef model branchDiff maxBadgeLength changeLine type_ content =
438486
let
487+
toTooltipConfig isNew =
488+
if isNew then
489+
DefinitionSummaryTooltip.tooltipConfig NewDefinitionSummaryTooltipMsg model.newDefinitionSummaryTooltip
490+
491+
else
492+
DefinitionSummaryTooltip.tooltipConfig OldDefinitionSummaryTooltipMsg model.oldDefinitionSummaryTooltip
493+
439494
toSyntaxConfig isNew =
440495
let
441496
diffBranchRef =
@@ -444,6 +499,9 @@ viewChangedDefinitionCard projectRef toggledChangeLines branchDiff maxBadgeLengt
444499

445500
else
446501
branchDiff.oldBranch
502+
503+
tooltipConfig =
504+
toTooltipConfig isNew
447505
in
448506
SyntaxConfig.empty
449507
|> SyntaxConfig.withToClick
@@ -452,9 +510,10 @@ viewChangedDefinitionCard projectRef toggledChangeLines branchDiff maxBadgeLengt
452510
diffBranchRef.ref
453511
(Perspective.absoluteRootPerspective diffBranchRef.hash)
454512
)
513+
|> SyntaxConfig.withDependencyTooltip tooltipConfig
455514

456515
( expanded, toggleIcon ) =
457-
if ToggledChangeLines.isCollapsed toggledChangeLines changeLine then
516+
if ToggledChangeLines.isCollapsed model.toggledChangeLines changeLine then
458517
( Nothing, Icon.expandDown )
459518

460519
else
@@ -477,21 +536,22 @@ viewChangedDefinitionCard projectRef toggledChangeLines branchDiff maxBadgeLengt
477536
case ChangeLine.source changeLine of
478537
Just source ->
479538
let
480-
( branchRef, gutterIndicator ) =
539+
( branchRef, gutterIndicator, isNew ) =
481540
case changeLine of
482541
ChangeLine.Removed _ _ ->
483-
( branchDiff.oldBranch.ref, "-" )
542+
( branchDiff.oldBranch.ref, "-", False )
484543

485544
ChangeLine.Added _ _ ->
486-
( branchDiff.newBranch.ref, "+" )
545+
( branchDiff.newBranch.ref, "+", True )
487546

488547
_ ->
489-
( branchDiff.newBranch.ref, "" )
548+
( branchDiff.newBranch.ref, "", True )
490549

491550
linked =
492551
SyntaxConfig.empty
493552
|> SyntaxConfig.withToClick
494553
(Link.projectBranchDefinition projectRef branchRef)
554+
|> SyntaxConfig.withDependencyTooltip (toTooltipConfig isNew)
495555

496556
gutter =
497557
let
@@ -577,13 +637,13 @@ viewChangedDefinitionCard projectRef toggledChangeLines branchDiff maxBadgeLengt
577637
|> Card.view
578638

579639

580-
viewChangedDefinitionsCards : ProjectRef -> ToggledChangeLines -> Int -> BranchDiff -> List (Html Msg)
581-
viewChangedDefinitionsCards projectRef toggledChangeLines maxBadgeLength branchDiff =
640+
viewChangedDefinitionsCards : ProjectRef -> Model -> Int -> BranchDiff -> List (Html Msg)
641+
viewChangedDefinitionsCards projectRef model maxBadgeLength branchDiff =
582642
let
583643
view_ =
584644
viewChangedDefinitionCard
585645
projectRef
586-
toggledChangeLines
646+
model
587647
branchDiff
588648
maxBadgeLength
589649

@@ -773,8 +833,8 @@ viewLibDeps maxBadgeLength deps =
773833
|> List.map (viewLibDep maxBadgeLength)
774834

775835

776-
viewBranchDiff : ProjectRef -> ToggledChangeLines -> BranchDiff -> Html Msg
777-
viewBranchDiff projectRef toggledChangeLines diff =
836+
viewBranchDiff : ProjectRef -> Model -> BranchDiff -> Html Msg
837+
viewBranchDiff projectRef model diff =
778838
let
779839
summary =
780840
BranchDiff.summary diff
@@ -789,7 +849,7 @@ viewBranchDiff projectRef toggledChangeLines diff =
789849
tree =
790850
if BranchDiff.size diff > 1 then
791851
Card.card
792-
[ viewContributionChangesGroup projectRef toggledChangeLines diff.lines
852+
[ viewContributionChangesGroup projectRef model.toggledChangeLines diff.lines
793853
]
794854
|> Card.withClassName "change-tree"
795855
|> Card.asContained
@@ -806,7 +866,7 @@ viewBranchDiff projectRef toggledChangeLines diff =
806866
[ tree
807867
, div [ id "definition-changes", class "definition-changes" ]
808868
(viewLibDeps maxBadgeLength diff.libDeps
809-
++ viewChangedDefinitionsCards projectRef toggledChangeLines maxBadgeLength diff
869+
++ viewChangedDefinitionsCards projectRef model maxBadgeLength diff
810870
)
811871
]
812872
]
@@ -912,7 +972,7 @@ view appContext projectRef contribution model =
912972
[ tabs
913973
, div
914974
[ class "project-contribution-changes-page" ]
915-
[ viewBranchDiff projectRef model.toggledChangeLines diff ]
975+
[ viewBranchDiff projectRef model diff ]
916976
]
917977

918978
BranchDiffState.Uncomputable error ->

0 commit comments

Comments
 (0)