-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProjectContributionChangesPage.elm
More file actions
1057 lines (897 loc) · 38.9 KB
/
Copy pathProjectContributionChangesPage.elm
File metadata and controls
1057 lines (897 loc) · 38.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
port module UnisonShare.Page.ProjectContributionChangesPage exposing (..)
import Code.BranchRef as BranchRef
import Code.Definition.Reference exposing (Reference)
import Code.DefinitionSummaryTooltip as DefinitionSummaryTooltip
import Code.FullyQualifiedName as FQN
import Code.Hash as Hash
import Code.Perspective as Perspective
import Code.ProjectDependency as ProjectDependency
import Code.Syntax as Syntax
import Code.Syntax.SyntaxConfig as SyntaxConfig
import Code.Version as Version
import Html exposing (Html, br, code, div, h2, label, p, pre, span, strong, text)
import Html.Attributes exposing (class, id, style)
import Http
import Lib.HttpApi as HttpApi exposing (HttpResult)
import Lib.ScrollTo as ScrollTo
import Lib.Util as Util
import List.Nonempty as NEL
import String.Extra exposing (pluralize)
import UI
import UI.Button as Button
import UI.Card as Card
import UI.Click as Click
import UI.Icon as Icon exposing (Icon)
import UI.PageContent as PageContent exposing (PageContent)
import UI.Placeholder as Placeholder
import UI.StatusBanner as StatusBanner
import UI.StatusIndicator as StatusIndicator
import UI.TabList as TabList
import UI.Tooltip as Tooltip
import UnisonShare.Account as Account
import UnisonShare.Api as ShareApi
import UnisonShare.AppContext as AppContext exposing (AppContext)
import UnisonShare.BranchDiff as BranchDiff exposing (BranchDiff)
import UnisonShare.BranchDiff.ChangeLine as ChangeLine exposing (ChangeLine)
import UnisonShare.BranchDiff.ChangeLineId as ChangeLineId exposing (ChangeLineId)
import UnisonShare.BranchDiff.DefinitionType as DefinitionType exposing (DefinitionType)
import UnisonShare.BranchDiff.LibDep as LibDep exposing (LibDep)
import UnisonShare.BranchDiff.ToggledChangeLines as ToggledChangeLines exposing (ToggledChangeLines)
import UnisonShare.BranchDiffState as BranchDiffState exposing (BranchDiffState)
import UnisonShare.Contribution exposing (ContributionDetails)
import UnisonShare.Contribution.ContributionRef exposing (ContributionRef)
import UnisonShare.DefinitionDiff as DefinitionDiff
import UnisonShare.DefinitionDiffCard as DefinitionDiffCard
import UnisonShare.Link as Link
import UnisonShare.Project.ProjectRef exposing (ProjectRef)
import UnisonShare.Route as Route
import UnisonShare.Session as Session
import Url
-- MODEL
type alias Model =
{ branchDiff : BranchDiffState
, toggledChangeLines : ToggledChangeLines
, urlFocusedChangeLineId : Maybe ChangeLineId
, oldDefinitionSummaryTooltip : DefinitionSummaryTooltip.Model
, newDefinitionSummaryTooltip : DefinitionSummaryTooltip.Model
}
type alias DiffBranches =
{ oldBranch : BranchDiff.DiffBranchRef
, newBranch : BranchDiff.DiffBranchRef
}
init : AppContext -> ProjectRef -> ContributionRef -> Maybe ChangeLineId -> ( Model, Cmd Msg )
init appContext projectRef contribRef changeLineId =
( { branchDiff = BranchDiffState.Loading
, toggledChangeLines = ToggledChangeLines.empty
, urlFocusedChangeLineId = changeLineId
, oldDefinitionSummaryTooltip = DefinitionSummaryTooltip.init
, newDefinitionSummaryTooltip = DefinitionSummaryTooltip.init
}
, fetchBranchDiff appContext projectRef contribRef 1
)
-- UPDATE
type Msg
= FetchBranchDiffFinished (HttpResult BranchDiffState)
| RetryBranchDiffFetch Int
| ToggleChangeDetails ChangeLine
| CopyChangeLinePermalink ChangeLineId
| SetChangeLinePermalink ChangeLineId
| ScrollTo ChangeLineId
| ExpandCollapsedDiffSection ChangeLineId { index : Int }
| OldDefinitionSummaryTooltipMsg DefinitionSummaryTooltip.Msg
| NewDefinitionSummaryTooltipMsg DefinitionSummaryTooltip.Msg
| NoOp
update : AppContext -> ProjectRef -> ContributionRef -> Msg -> Model -> ( Model, Cmd Msg )
update appContext projectRef contribRef msg model =
case msg of
FetchBranchDiffFinished branchDiffState ->
let
( model_, cmd ) =
case branchDiffState of
Ok (BranchDiffState.Computed bd) ->
let
toggledChangeLines =
model.urlFocusedChangeLineId
|> Maybe.andThen (\changeLineId -> BranchDiff.changeLineById changeLineId bd)
|> Maybe.map
(\changeLine ->
ToggledChangeLines.expand model.toggledChangeLines changeLine
)
|> Maybe.withDefault model.toggledChangeLines
cmd_ =
model.urlFocusedChangeLineId
|> Maybe.map (ScrollTo >> Util.delayMsg 10)
|> Maybe.withDefault Cmd.none
in
( { model
| branchDiff =
BranchDiffState.Computed
{ bd
| lines =
bd.lines
|> BranchDiff.condense
|> BranchDiff.sortWithDocs
}
, toggledChangeLines = toggledChangeLines
}
, cmd_
)
Ok ((BranchDiffState.Computing { numTries }) as bds) ->
if numTries >= 3 then
( { model | branchDiff = bds }, Cmd.none )
else
( { model | branchDiff = BranchDiffState.Reloading { numTries = numTries + 1 } }
, Util.delayMsg 1000 (RetryBranchDiffFetch (numTries + 1))
)
Ok bds ->
( { model | branchDiff = bds }, Cmd.none )
Err e ->
( { model | branchDiff = BranchDiffState.Failure e }, Cmd.none )
in
( model_, cmd )
RetryBranchDiffFetch numTries ->
( model
, fetchBranchDiff appContext projectRef contribRef numTries
)
ScrollTo changeLineId ->
( model, scrollTo changeLineId )
ToggleChangeDetails changeLine ->
case model.branchDiff of
BranchDiffState.Computed _ ->
let
toggled =
if ToggledChangeLines.isExpanded model.toggledChangeLines changeLine then
ToggledChangeLines.collapse model.toggledChangeLines changeLine
else
ToggledChangeLines.expand model.toggledChangeLines changeLine
in
( { model | toggledChangeLines = toggled }, Cmd.none )
_ ->
( model, Cmd.none )
SetChangeLinePermalink changeLineId ->
let
route =
Route.projectContributionChange
projectRef
contribRef
changeLineId
in
( model
, Cmd.batch
[ Route.navigate appContext.navKey route
, scrollTo changeLineId
]
)
CopyChangeLinePermalink changeLineId ->
let
route =
Route.projectContributionChange
projectRef
contribRef
changeLineId
url =
route
|> Route.toUrl appContext
|> Url.toString
in
( model
, Cmd.batch
[ copyToClipboard url
, Route.navigate appContext.navKey route
, scrollTo changeLineId
]
)
ExpandCollapsedDiffSection changeLineId { index } ->
let
expandCollapsedDiffSection changeLine =
case changeLine of
ChangeLine.Updated type_ details ->
ChangeLine.Updated
type_
{ details | diff = DefinitionDiff.expandCollapsedDiffSection index details.diff }
_ ->
changeLine
branchDiff =
BranchDiffState.updateChangeLineById
expandCollapsedDiffSection
changeLineId
model.branchDiff
in
( { model | branchDiff = branchDiff }, Cmd.none )
OldDefinitionSummaryTooltipMsg tMsg ->
case model.branchDiff of
BranchDiffState.Computed bd ->
let
config =
AppContext.toCodeConfig
appContext
{ projectRef = projectRef, branchRef = bd.oldBranch.ref }
(Perspective.absoluteRootPerspective bd.oldBranch.hash)
( definitionSummaryTooltip, tCmd ) =
DefinitionSummaryTooltip.update config tMsg model.oldDefinitionSummaryTooltip
in
( { model | oldDefinitionSummaryTooltip = definitionSummaryTooltip }
, Cmd.map OldDefinitionSummaryTooltipMsg tCmd
)
_ ->
( model, Cmd.none )
NewDefinitionSummaryTooltipMsg tMsg ->
case model.branchDiff of
BranchDiffState.Computed bd ->
let
config =
AppContext.toCodeConfig
appContext
{ projectRef = projectRef, branchRef = bd.newBranch.ref }
(Perspective.absoluteRootPerspective bd.newBranch.hash)
( definitionSummaryTooltip, tCmd ) =
DefinitionSummaryTooltip.update config tMsg model.newDefinitionSummaryTooltip
in
( { model | newDefinitionSummaryTooltip = definitionSummaryTooltip }
, Cmd.map NewDefinitionSummaryTooltipMsg tCmd
)
_ ->
( model, Cmd.none )
NoOp ->
( model, Cmd.none )
port copyToClipboard : String -> Cmd msg
-- EFFECTS
scrollTo : ChangeLineId -> Cmd Msg
scrollTo changeLineId =
ScrollTo.scrollTo_ NoOp "page-content" (ChangeLineId.toDomId changeLineId) 16
fetchBranchDiff : AppContext -> ProjectRef -> ContributionRef -> Int -> Cmd Msg
fetchBranchDiff appContext projectRef contributionRef numTries =
ShareApi.projectContributionDiff projectRef contributionRef
|> HttpApi.toRequest (BranchDiffState.decode numTries) FetchBranchDiffFinished
|> HttpApi.perform appContext.api
-- VIEW
branchLink_ : ProjectRef -> BranchDiff.DiffBranchRef -> Reference -> Click.Click Msg
branchLink_ projectRef diffBranchRef ref =
Link.projectBranchDefinition_
projectRef
diffBranchRef.ref
(Perspective.absoluteRootPerspective diffBranchRef.hash)
ref
branchLink : ProjectRef -> BranchDiff.DiffBranchRef -> Reference -> Html Msg -> Html Msg
branchLink projectRef diffBranchRef ref label =
branchLink_ projectRef diffBranchRef ref
|> Link.view_ label
changeIcon : ChangeLine -> Icon msg
changeIcon changeLine =
case changeLine of
ChangeLine.Added _ _ ->
Icon.largePlus
ChangeLine.Removed _ _ ->
Icon.dash
ChangeLine.Updated _ _ ->
Icon.refreshSmallBold
ChangeLine.RenamedFrom _ _ ->
Icon.tag
ChangeLine.Aliased _ _ ->
Icon.tags
_ ->
Icon.largeDot
viewChangeIcon : ChangeLine -> Html Msg
viewChangeIcon item =
let
type_ =
ChangeLine.toString item
in
Tooltip.text type_
|> Tooltip.tooltip
|> Tooltip.withArrow Tooltip.Start
|> Tooltip.view
(span
[ class "change-icon"
, class (String.toLower type_)
]
[ Icon.view (changeIcon item) ]
)
viewChangeBadge : Int -> ChangeLine -> Html msg
viewChangeBadge maxBadgeLength changeLine =
let
type_ =
ChangeLine.toString changeLine
in
viewChangeBadge_ maxBadgeLength (changeIcon changeLine) type_
viewChangeBadge_ : Int -> Icon msg -> String -> Html msg
viewChangeBadge_ maxBadgeLength icon label_ =
let
width =
String.fromInt maxBadgeLength
in
span [ class "change-badge_wrapper", style "width" (width ++ "ch") ]
[ span
[ class "change-badge"
, class (String.toLower label_)
]
[ Icon.view icon
, label [] [ text label_ ]
]
]
viewDefinitionIcon : DefinitionType -> Html msg
viewDefinitionIcon definitionType =
let
( description, icon ) =
case definitionType of
DefinitionType.Term ->
( "Term", Icon.term )
DefinitionType.Type ->
( "Type", Icon.type_ )
DefinitionType.Doc ->
( "Doc", Icon.doc )
DefinitionType.Ability ->
( "Ability", Icon.ability )
DefinitionType.AbilityConstructor ->
( "Ability Constructor", Icon.abilityConstructor )
DefinitionType.DataConstructor ->
( "Data Constructor", Icon.dataConstructor )
DefinitionType.Test ->
( "Test", Icon.test )
in
div [ class "def-icon-anchor" ]
[ Tooltip.text description
|> Tooltip.tooltip
|> Tooltip.withArrow Tooltip.Start
|> Tooltip.view (span [ class "def-icon" ] [ Icon.view icon ])
]
viewDiffTreeNode : ProjectRef -> ToggledChangeLines -> ChangeLine -> Html Msg
viewDiffTreeNode projectRef toggledChangeLines changeLine =
let
viewTitle fqn =
case ChangeLine.toChangeLineId changeLine of
Just changeLineId ->
Click.onClick (SetChangeLinePermalink changeLineId)
|> Click.view [ class "change-title" ] [ FQN.view fqn ]
Nothing ->
div [ class "change-title" ] [ FQN.view fqn ]
view_ type_ content =
div [ class "change-line" ]
[ viewChangeIcon changeLine
, viewDefinitionIcon type_
, content
]
in
case changeLine of
ChangeLine.Added type_ { shortName } ->
view_ type_ (viewTitle shortName)
ChangeLine.Removed type_ { shortName } ->
view_ type_ (viewTitle shortName)
ChangeLine.Updated type_ { shortName } ->
view_ type_ (viewTitle shortName)
ChangeLine.Propagated _ _ ->
UI.nothing
ChangeLine.RenamedFrom type_ { newShortName } ->
view_ type_ (viewTitle newShortName)
ChangeLine.Aliased type_ { aliasShortName } ->
view_ type_ (viewTitle aliasShortName)
ChangeLine.Namespace ns ->
viewNamespaceLine projectRef toggledChangeLines ns
viewContributionChangesGroup : ProjectRef -> ToggledChangeLines -> List ChangeLine -> Html Msg
viewContributionChangesGroup projectRef toggledChangeLines lines =
div [ class "contribution-changes-group" ] (List.map (viewDiffTreeNode projectRef toggledChangeLines) lines)
viewNamespaceLine : ProjectRef -> ToggledChangeLines -> ChangeLine.NamespaceLineItem -> Html Msg
viewNamespaceLine projectRef toggledChangeLines { name, lines } =
let
isDeeplyPropagated cl =
case cl of
ChangeLine.Propagated _ _ ->
True
ChangeLine.Namespace ns ->
List.all isDeeplyPropagated ns.lines
_ ->
False
in
if List.all isDeeplyPropagated lines then
UI.nothing
else
div [ class "change-line namespace" ]
[ div [ class "namespace-info" ] [ Icon.view Icon.folder, FQN.view name ]
, viewContributionChangesGroup projectRef toggledChangeLines lines
]
viewChangedDefinitionCard : ProjectRef -> Model -> BranchDiff -> Int -> ChangeLine -> DefinitionType -> Html Msg -> Html Msg
viewChangedDefinitionCard projectRef model branchDiff maxBadgeLength changeLine type_ content =
let
toTooltipConfig isNew =
if isNew then
DefinitionSummaryTooltip.tooltipConfig NewDefinitionSummaryTooltipMsg model.newDefinitionSummaryTooltip
else
DefinitionSummaryTooltip.tooltipConfig OldDefinitionSummaryTooltipMsg model.oldDefinitionSummaryTooltip
toSyntaxConfig isNew =
let
diffBranchRef =
if isNew then
branchDiff.newBranch
else
branchDiff.oldBranch
tooltipConfig =
toTooltipConfig isNew
in
SyntaxConfig.empty
|> SyntaxConfig.withToClick
(Link.projectBranchDefinition_
projectRef
diffBranchRef.ref
(Perspective.absoluteRootPerspective diffBranchRef.hash)
)
|> SyntaxConfig.withDependencyTooltip tooltipConfig
( expanded, toggleIcon ) =
if ToggledChangeLines.isCollapsed model.toggledChangeLines changeLine then
( Nothing, Icon.expandDown )
else
case changeLine of
ChangeLine.Updated _ { diff } ->
case ChangeLine.toChangeLineId changeLine of
Just id ->
let
viewConfig =
{ toSyntaxConfig = toSyntaxConfig
, toExpandCollapsedDiffSectionMsg = ExpandCollapsedDiffSection id
}
in
( Just (DefinitionDiffCard.view viewConfig diff), Icon.collapseUp )
Nothing ->
( Nothing, Icon.dash )
_ ->
case ChangeLine.source changeLine of
Just source ->
let
( branchRef, gutterIndicator, isNew ) =
case changeLine of
ChangeLine.Removed _ _ ->
( branchDiff.oldBranch.ref, "-", False )
ChangeLine.Added _ _ ->
( branchDiff.newBranch.ref, "+", True )
_ ->
( branchDiff.newBranch.ref, "", True )
linked =
SyntaxConfig.empty
|> SyntaxConfig.withToClick
(Link.projectBranchDefinition projectRef branchRef)
|> SyntaxConfig.withDependencyTooltip (toTooltipConfig isNew)
gutter =
let
lns =
List.range 1 (Syntax.numLines source)
viewLn ln =
div [ class "gutter" ]
[ span [ class "line-number" ] [ ln |> String.fromInt |> text ]
, text " "
, span [ class "change-indicator" ] [ text gutterIndicator ]
, text " "
]
in
div [ class "gutter-lines" ] (List.map viewLn lns)
expandedContent =
div [ class "definition-source", class (String.toLower (ChangeLine.toString changeLine)) ]
[ gutter
, pre [ class "definition-syntax monochrome" ]
[ code [] [ Syntax.view linked source ] ]
]
in
( Just expandedContent
, Icon.collapseUp
)
Nothing ->
( Nothing, Icon.expandDown )
domId =
changeLine
|> ChangeLine.toChangeLineId
|> Maybe.map ChangeLineId.toDomId
copyPermalink =
changeLine
|> ChangeLine.toChangeLineId
|> Maybe.map
(\cid ->
Button.icon (CopyChangeLinePermalink cid) Icon.chain
|> Button.subdued
|> Button.small
|> Button.view
)
|> Maybe.map
(\bt ->
Tooltip.text "Copy permanent link"
|> Tooltip.tooltip
|> Tooltip.withPosition Tooltip.LeftOf
|> Tooltip.view bt
)
in
Card.card
[ div [ class "definition-change-header" ]
[ div [ class "change-line" ]
[ viewChangeBadge maxBadgeLength changeLine
, viewDefinitionIcon type_
, content
]
, div [ class "definition-change-actions" ]
[ Maybe.withDefault UI.nothing copyPermalink
, Button.icon (ToggleChangeDetails changeLine) toggleIcon
|> Button.subdued
|> Button.small
|> Button.view
]
]
, expanded
|> Maybe.map
(\details ->
div [ class "definition-change-details" ] [ details ]
)
|> Maybe.withDefault UI.nothing
]
|> Card.withClassName
("definition-change "
++ String.toLower
(ChangeLine.toString changeLine)
)
|> Util.pipeMaybe Card.withDomId domId
|> Card.asContained
|> Card.view
viewChangedDefinitionsCards : ProjectRef -> Model -> Int -> BranchDiff -> List (Html Msg)
viewChangedDefinitionsCards projectRef model maxBadgeLength branchDiff =
let
view_ =
viewChangedDefinitionCard
projectRef
model
branchDiff
maxBadgeLength
f changeLine acc =
let
viewTitle fqn =
Click.onClick (ToggleChangeDetails changeLine)
|> Click.view [ class "change-title" ] [ FQN.view fqn ]
clickableHash diffBranchRef ref hash =
branchLink projectRef diffBranchRef ref (Hash.view hash)
viewInfo contents =
div [ class "change-info" ] contents
in
case changeLine of
ChangeLine.Added type_ i ->
view_ changeLine
type_
(viewInfo
[ viewTitle i.fullName
, clickableHash branchDiff.newBranch i.ref i.hash
]
)
:: acc
ChangeLine.Removed type_ i ->
view_ changeLine
type_
(viewInfo
[ viewTitle i.fullName
, clickableHash branchDiff.oldBranch i.ref i.hash
]
)
:: acc
ChangeLine.Updated type_ i ->
view_ changeLine
type_
(viewInfo
[ viewTitle i.fullName
, clickableHash branchDiff.oldBranch i.ref i.oldHash
, Icon.view Icon.arrowRight
, clickableHash branchDiff.newBranch i.ref i.newHash
]
)
:: acc
ChangeLine.Propagated _ _ ->
acc
ChangeLine.RenamedFrom type_ i ->
view_ changeLine
type_
(viewInfo
[ viewTitle i.newFullName
, clickableHash branchDiff.oldBranch i.newRef i.hash
, span [ class "small-label" ]
[ text "(was "
, branchLink projectRef
branchDiff.oldBranch
-- TODO: should be oldRefs, plural...
i.oldRef
(i.oldNames
|> NEL.map FQN.toString
|> NEL.toList
|> String.join ", "
|> text
)
, text ")"
]
]
)
:: acc
ChangeLine.Aliased type_ i ->
view_ changeLine
type_
(viewInfo
[ viewTitle i.aliasFullName
, clickableHash branchDiff.newBranch i.ref i.hash
, span [ class "small-label" ]
[ text "(AKA "
, i.otherNames
|> NEL.map FQN.toString
|> NEL.toList
|> String.join ", "
|> text
, text ")"
]
]
)
:: acc
ChangeLine.Namespace ns ->
go ns.lines ++ acc
go lines =
List.foldr f [] lines
in
go branchDiff.lines
viewLibDep : Int -> LibDep -> Html msg
viewLibDep maxBadgeLength libDep =
let
viewCard content =
Card.card
[ div [ class "definition-change-header" ]
[ div [ class "change-line" ] content ]
]
|> Card.withClassName "definition-change lib-dep"
|> Card.asContained
|> Card.view
badge icon type_ =
viewChangeBadge_ maxBadgeLength icon type_
viewDepInfoBadge dep =
div [ class "dep-info change-info" ]
[ div [ class "change-title" ]
[ ProjectDependency.viewLibraryBadge_ { withVersion = True, withTooltip = False } dep.dep
, span [ class "lib-namespace-info" ] [ text "(", FQN.view dep.name, text ")" ]
]
]
in
case libDep of
LibDep.Added dep ->
viewCard
[ badge Icon.largePlus "Added"
, viewDepInfoBadge dep
]
LibDep.Removed dep ->
viewCard
[ badge Icon.dash "Removed"
, viewDepInfoBadge dep
]
LibDep.Updated { before, after } ->
let
toFrom =
case ( before.dep.version, after.dep.version ) of
( Just beforeV, Just afterV ) ->
[ ProjectDependency.viewLibraryBadge_
{ withVersion = False
, withTooltip = False
}
before.dep
, Version.view beforeV
, Icon.view Icon.arrowRight
, Version.view afterV
, span [ class "lib-namespace-info" ]
[ text "("
, FQN.view before.name
, Icon.view Icon.arrowRight
, FQN.view after.name
, text ")"
]
]
_ ->
[ ProjectDependency.viewLibraryBadge before.dep
, Icon.view Icon.arrowRight
, ProjectDependency.viewLibraryBadge after.dep
, span [ class "lib-namespace-info" ]
[ text "("
, FQN.view before.name
, Icon.view Icon.arrowRight
, FQN.view after.name
, text ")"
]
]
in
viewCard
[ badge Icon.refreshSmallBold "Updated"
, div [ class "dep-info change-info" ]
[ div [ class "change-title" ] toFrom
]
]
viewLibDeps : Int -> List LibDep -> List (Html msg)
viewLibDeps maxBadgeLength deps =
deps
|> LibDep.mergeUpdated
|> List.map (viewLibDep maxBadgeLength)
viewBranchDiff : ProjectRef -> Model -> BranchDiff -> Html Msg
viewBranchDiff projectRef model diff =
let
summary =
BranchDiff.summary diff
maxBadgeLength =
diff.lines
|> List.map (ChangeLine.toString >> String.length)
|> List.maximum
|> Maybe.withDefault 0
-- There's no reason to show a tree with a single element...
tree =
if BranchDiff.size diff > 1 then
Card.card
[ viewContributionChangesGroup projectRef model.toggledChangeLines diff.lines
]
|> Card.withClassName "change-tree"
|> Card.asContained
|> Card.view
else
UI.nothing
in
div [ class "branch-diff-content" ]
[ strong []
[ text (pluralize "change" "changes" summary.numChanges)
]
, div [ class "branch-diff-content-cards" ]
[ tree
, div [ id "definition-changes", class "definition-changes" ]
(viewLibDeps maxBadgeLength diff.libDeps
++ viewChangedDefinitionsCards projectRef model maxBadgeLength diff
)
]
]
viewLoadingPage : Html Msg -> PageContent Msg
viewLoadingPage tabs =
let
shape length =
Placeholder.text
|> Placeholder.withLength length
|> Placeholder.subdued
|> Placeholder.tiny
|> Placeholder.view
in
PageContent.oneColumn
[ div [ class "project-contribution-changes-page" ]
[ tabs
, Card.card
[ shape Placeholder.Large
, shape Placeholder.Small
, shape Placeholder.Medium
]
|> Card.asContained
|> Card.view
]
]
viewErrorPage : AppContext -> ContributionRef -> Html Msg -> Http.Error -> PageContent Msg
viewErrorPage appContext _ tabs err =
let
errorDetails =
case appContext.session of
Session.SignedIn account ->
if Account.isUnisonMember account then
pre [] [ text (Util.httpErrorToString err) ]
else
UI.nothing
_ ->
UI.nothing
in
PageContent.oneColumn
[ tabs
, div [ class "project-contribution-changes-page" ]
[ StatusBanner.bad
"Something broke on our end and we couldn't show the contribution changes. Please try again."
, errorDetails
]
]
viewCulprit : ContributionDetails -> BranchDiffState.DiffErrorCulprit -> Html msg
viewCulprit contribution culprit =
case culprit of
BranchDiffState.TargetBranch ->
strong [] [ text (BranchRef.toString contribution.targetBranchRef) ]
BranchDiffState.SourceBranch ->
strong [] [ text (BranchRef.toString contribution.sourceBranchRef) ]
view : AppContext -> ProjectRef -> ContributionDetails -> Model -> PageContent Msg
view appContext projectRef contribution model =
let
tabs =
TabList.tabList
[ TabList.tab "Overview" (Link.projectContribution projectRef contribution.ref)
]
(TabList.tab "Changes" (Link.projectContributionChanges projectRef contribution.ref))
[]
|> TabList.view
in
case model.branchDiff of
BranchDiffState.Loading ->
viewLoadingPage tabs
BranchDiffState.Computing _ ->
PageContent.oneColumn
[ tabs
, div [ class "project-contribution-changes-page" ]
[ Card.card
[ StatusBanner.working "The contribution diff is still being computed..."
, p [ class "refresh-message" ]
[ text "Unison Share will never show a stale diff, and sometimes it takes a minute or two to compute."
, br [] []
, text "You can try refreshing this page."
]
]
|> Card.withClassName "contribution-diff_computing"
|> Card.asContainedWithFade
|> Card.view
]
]
BranchDiffState.Reloading _ ->
viewLoadingPage tabs
BranchDiffState.Computed diff ->
PageContent.oneColumn
[ tabs
, div
[ class "project-contribution-changes-page" ]
[ viewBranchDiff projectRef model diff ]
]
BranchDiffState.Uncomputable error ->
let
errorDetails =
case error of
BranchDiffState.ConstructorAlias { culprit, typeName, constructorName1, constructorName2 } ->
Just
[ text "The type "
, FQN.view typeName
, text " has a constructor alias: "
, FQN.view constructorName1
, text " and "
, FQN.view constructorName2
, text " on the "
, viewCulprit contribution culprit
, text " branch."
]
BranchDiffState.MissingConstructorName { culprit, typeName } ->
Just