Skip to content

Commit 2164ecb

Browse files
committed
Add definition permalink
1 parent 27768a4 commit 2164ecb

File tree

5 files changed

+68
-8
lines changed

5 files changed

+68
-8
lines changed

src/Code2/Workspace/WorkspaceDefinitionItemCard.elm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type alias WorkspaceDefinitionItemCardConfig msg =
5555
, syntaxConfig : SyntaxConfig.SyntaxConfig msg
5656
, showDependents : msg
5757
, showDependencies : msg
58+
, toPermalink : Maybe msg
5859
, namespaceDropdown : Maybe (NamespaceDropdown msg)
5960
}
6061

@@ -336,6 +337,16 @@ titlebarRight cfg =
336337
else
337338
UI.nothing
338339

340+
permalinkButton =
341+
case cfg.toPermalink of
342+
Just toPermalink ->
343+
titlebarButton toPermalink Icon.chain
344+
|> TitlebarButton.withLeftOfTooltip (text "View as permalink")
345+
|> TitlebarButton.view
346+
347+
_ ->
348+
UI.nothing
349+
339350
otherNames_ =
340351
DefinitionItem.otherNames cfg.item
341352

@@ -365,6 +376,7 @@ titlebarRight cfg =
365376
UI.nothing
366377
in
367378
[ defHash
379+
, permalinkButton
368380
, otherNames
369381
, dependenciesButton
370382
, dependentsButton

src/Code2/Workspace/WorkspacePane.elm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ type Msg
9797
| ToggleFold WorkspaceItemRef
9898
| Keydown KeyboardEvent.KeyboardEvent
9999
| SetFocusedItem WorkspaceItemRef
100+
| ToPermalink Reference
100101
| DefinitionSummaryTooltipMsg DefinitionSummaryTooltip.Msg
101102
| KeyboardShortcutMsg KeyboardShortcut.Msg
102103

@@ -107,6 +108,7 @@ type OutMsg
107108
| FocusOn WorkspaceItemRef
108109
| RequestFindInNamespace FQN
109110
| RequestChangePerspective Reference FQN
111+
| RequestPermalink Reference
110112
| Emptied
111113

112114

@@ -368,6 +370,12 @@ update config paneId msg model =
368370
, FocusOn wsRef
369371
)
370372

373+
ToPermalink ref ->
374+
( model
375+
, Cmd.none
376+
, RequestPermalink ref
377+
)
378+
371379
FindWithinNamespace wsRef fqn ->
372380
let
373381
workspaceItems_ =
@@ -804,6 +812,7 @@ type alias PaneConfig =
804812
, withFocusedPaneIndicator : Bool
805813
, withNamespaceDropdown : Bool
806814
, withMinimap : Bool
815+
, withPermalink : Bool
807816
}
808817

809818

@@ -857,6 +866,13 @@ viewItem cfg collapsedItems definitionSummaryTooltip item isFocused =
857866
else
858867
Nothing
859868

869+
toPermalink =
870+
if cfg.withPermalink then
871+
Just (ToPermalink definitionRef)
872+
873+
else
874+
Nothing
875+
860876
config =
861877
{ wsRef = wsRef
862878
, definitionRef = definitionRef
@@ -874,6 +890,7 @@ viewItem cfg collapsedItems definitionSummaryTooltip item isFocused =
874890
, toggleFold = ToggleFold wsRef
875891
, showDependents = ShowDependentsOf wsRef
876892
, showDependencies = ShowDependenciesOf wsRef
893+
, toPermalink = toPermalink
877894
, namespaceDropdown = namespaceDropdown
878895
}
879896
in

src/Code2/Workspace/WorkspacePanes.elm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type OutMsg
6969
| Emptied
7070
| ChangePerspectiveToSubNamespace Reference FQN
7171
| ShowFinderRequest FQN
72+
| RequestPermalink Reference
7273

7374

7475
update : Config -> Msg -> Model -> ( Model, Cmd Msg, OutMsg )
@@ -101,6 +102,9 @@ update config msg model =
101102
WorkspacePane.RequestChangePerspective ref fqn ->
102103
( model, ChangePerspectiveToSubNamespace ref fqn )
103104

105+
WorkspacePane.RequestPermalink ref ->
106+
( model, RequestPermalink ref )
107+
104108
_ ->
105109
( model, NoOut )
106110
in
@@ -133,6 +137,9 @@ update config msg model =
133137
WorkspacePane.Emptied ->
134138
( model, Emptied )
135139

140+
WorkspacePane.RequestPermalink ref ->
141+
( model, RequestPermalink ref )
142+
136143
_ ->
137144
( model, NoOut )
138145
in
@@ -298,6 +305,7 @@ type alias PanesConfig =
298305
, withFocusedPaneIndicator : Bool
299306
, withNamespaceDropdown : Bool
300307
, withMinimap : Bool
308+
, withPermalink : Bool
301309
}
302310

303311

@@ -311,6 +319,7 @@ view cfg model =
311319
, withFocusedPaneIndicator = cfg.withFocusedPaneIndicator
312320
, withNamespaceDropdown = cfg.withNamespaceDropdown
313321
, withMinimap = cfg.withMinimap
322+
, withPermalink = cfg.withPermalink
314323
}
315324

316325
left isFocused =

src/UnisonShare/Page/CodePage.elm

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Code.Finder as Finder
77
import Code.Finder.SearchOptions as SearchOptions
88
import Code.FullyQualifiedName as FQN exposing (FQN)
99
import Code.FullyQualifiedNameSet as FQNSet
10-
import Code.Namespace exposing (NamespaceDetails)
10+
import Code.Namespace as Namespace exposing (NamespaceDetails)
1111
import Code.Perspective as Perspective exposing (Perspective)
1212
import Code.ReadmeCard as ReadmeCard
1313
import Code2.Workspace.WorkspaceItemRef as WorkspaceItemRef
@@ -385,6 +385,23 @@ update appContext context codeRoute msg model =
385385
in
386386
( { model | modal = FinderModal fm }, Cmd.map FinderMsg fCmd )
387387

388+
WorkspacePanes.RequestPermalink ref ->
389+
let
390+
perspective =
391+
case model.config.perspective of
392+
Perspective.Root { details } ->
393+
case details of
394+
RemoteData.Success (Namespace.Namespace _ hash _) ->
395+
Perspective.absoluteRootPerspective hash
396+
397+
_ ->
398+
model.config.perspective
399+
400+
_ ->
401+
model.config.perspective
402+
in
403+
( model, navigateToCode appContext context (Route.replacePerspective (Just ref) perspective) )
404+
388405
_ ->
389406
( model, Cmd.none )
390407
in
@@ -645,6 +662,11 @@ viewContent appContext perspective content =
645662
, withNamespaceDropdown = True
646663
, withFocusedPaneIndicator = False
647664
, withMinimap = True
665+
666+
-- Can't find the root hash without the root perspective
667+
-- and as such we can't create a permalink
668+
, withPermalink =
669+
Perspective.isRootPerspective perspective
648670
}
649671
in
650672
PageContent.oneColumn [ Html.map WorkspacePanesMsg (WorkspacePanes.view cfg workspace) ]

src/css/code2/workspace/workspace-card.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@
6969
color: var(--u-color_text_subdued);
7070
}
7171

72-
& .workspace-card_titlebar_left {
72+
.workspace-card_titlebar_left {
7373
display: flex;
7474
flex-direction: row;
7575
gap: 0.5rem;
7676
align-items: center;
7777

78-
& .copy-on-click {
78+
.copy-on-click {
7979
display: flex;
8080
flex-direction: row;
8181
align-items: center;
8282
gap: 0.25rem;
8383

84-
& .copy-on-click_success {
84+
.copy-on-click_success {
8585
position: absolute;
8686
background: var(--u-color_positive_element_subdued);
8787
width: 1.5rem;
@@ -92,26 +92,26 @@
9292
align-items: center;
9393
justify-content: center;
9494

95-
& .icon {
95+
.icon {
9696
color: var(--u-color_positive_icon-on-element_subdued);
9797
font-size: var(--font-size-base);
9898
}
9999
}
100100
}
101101

102-
& .tooltip {
102+
.tooltip {
103103
margin-top: 0.5rem;
104104
margin-left: -0.5rem;
105105

106-
& .tooltip-bubble {
106+
.tooltip-bubble {
107107
height: 2.25rem;
108108
display: flex;
109109
align-items: center;
110110
}
111111
}
112112
}
113113

114-
& .workspace-card_titlebar_right {
114+
.workspace-card_titlebar_right {
115115
position: absolute;
116116
right: 0.325rem;
117117
display: flex;

0 commit comments

Comments
 (0)