Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.

Commit 591d6ba

Browse files
committed
Remove Api and Env dependencies from CodebaseTree
1 parent 42bd8ca commit 591d6ba

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

src/Code/CodebaseTree.elm

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
module Code.CodebaseTree exposing (Model, Msg, OutMsg(..), init, update, view)
22

3-
import Api exposing (ApiRequest)
3+
import Code.CodebaseApi as CodebaseApi
44
import Code.CodebaseTree.NamespaceListing as NamespaceListing
55
exposing
66
( DefinitionListing(..)
77
, NamespaceListing(..)
88
, NamespaceListingChild(..)
99
, NamespaceListingContent
1010
)
11+
import Code.Config exposing (Config)
1112
import Code.Definition.Category as Category
1213
import Code.Definition.Reference exposing (Reference(..))
14+
import Code.EntityId as EntityId
1315
import Code.FullyQualifiedName as FQN exposing (FQN, unqualifiedName)
1416
import Code.FullyQualifiedNameSet as FQNSet exposing (FQNSet)
1517
import Code.HashQualified exposing (HashQualified(..))
16-
import Code.Perspective as Perspective exposing (Perspective)
18+
import Code.Perspective as Perspective
1719
import Env exposing (Env)
1820
import Html exposing (Html, a, div, label, span, text)
1921
import Html.Attributes exposing (class, title)
2022
import Html.Events exposing (onClick)
2123
import Http
24+
import Lib.Api as Api exposing (ApiRequest)
2225
import Lib.Util as Util
2326
import RemoteData exposing (RemoteData(..), WebData)
2427
import UI
@@ -37,13 +40,13 @@ type alias Model =
3740
}
3841

3942

40-
init : Env -> ( Model, Cmd Msg )
41-
init env =
43+
init : Config -> ( Model, Cmd Msg )
44+
init config =
4245
let
4346
model =
4447
{ rootNamespaceListing = Loading, expandedNamespaceListings = FQNSet.empty }
4548
in
46-
( model, Api.perform env.apiBasePath (fetchRootNamespaceListing env.perspective) )
49+
( model, Api.perform config.apiBasePath (fetchRootNamespaceListing config) )
4750

4851

4952

@@ -63,8 +66,8 @@ type OutMsg
6366
| ChangePerspectiveToNamespace FQN
6467

6568

66-
update : Env -> Msg -> Model -> ( Model, Cmd Msg, OutMsg )
67-
update env msg model =
69+
update : Config -> Msg -> Model -> ( Model, Cmd Msg, OutMsg )
70+
update config msg model =
6871
case msg of
6972
ToggleExpandedNamespaceListing fqn ->
7073
let
@@ -98,7 +101,7 @@ update env msg model =
98101

99102
cmd =
100103
if shouldExpand && not namespaceContentFetched then
101-
Api.perform env.apiBasePath (fetchSubNamespaceListing env.perspective fqn)
104+
Api.perform config.apiBasePath (fetchSubNamespaceListing config fqn)
102105

103106
else
104107
Cmd.none
@@ -147,7 +150,7 @@ update env msg model =
147150
ChangePerspectiveToNamespace name ->
148151
let
149152
newPerspectiveFqn =
150-
case env.perspective of
153+
case config.perspective of
151154
Perspective.Namespace { fqn } ->
152155
FQN.append fqn name
153156

@@ -164,19 +167,20 @@ update env msg model =
164167
-- EFFECTS
165168

166169

167-
fetchRootNamespaceListing : Perspective -> ApiRequest NamespaceListing Msg
168-
fetchRootNamespaceListing perspective =
169-
fetchNamespaceListing perspective Nothing FetchRootNamespaceListingFinished
170+
fetchRootNamespaceListing : Config -> ApiRequest NamespaceListing Msg
171+
fetchRootNamespaceListing config =
172+
fetchNamespaceListing config Nothing FetchRootNamespaceListingFinished
170173

171174

172-
fetchSubNamespaceListing : Perspective -> FQN -> ApiRequest NamespaceListing Msg
173-
fetchSubNamespaceListing perspective fqn =
174-
fetchNamespaceListing perspective (Just fqn) (FetchSubNamespaceListingFinished fqn)
175+
fetchSubNamespaceListing : Config -> FQN -> ApiRequest NamespaceListing Msg
176+
fetchSubNamespaceListing config fqn =
177+
fetchNamespaceListing config (Just fqn) (FetchSubNamespaceListingFinished fqn)
175178

176179

177-
fetchNamespaceListing : Perspective -> Maybe FQN -> (Result Http.Error NamespaceListing -> msg) -> ApiRequest NamespaceListing msg
178-
fetchNamespaceListing perspective fqn toMsg =
179-
Api.list perspective (Maybe.map FQN.toString fqn)
180+
fetchNamespaceListing : Config -> Maybe FQN -> (Result Http.Error NamespaceListing -> msg) -> ApiRequest NamespaceListing msg
181+
fetchNamespaceListing config fqn toMsg =
182+
CodebaseApi.Browse { perspective = config.perspective, namespaceId = Maybe.map EntityId.NameId fqn }
183+
|> config.toApiEndpointUrl
180184
|> Api.toRequest (NamespaceListing.decode fqn) toMsg
181185

182186

src/UnisonLocal/App.elm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ init env route =
8080
Workspace.init codebaseConfig Nothing
8181

8282
( codebaseTree, codebaseTreeCmd ) =
83-
CodebaseTree.init env
83+
CodebaseTree.init codebaseConfig
8484

8585
fetchNamespaceDetailsCmd =
8686
env.perspective
@@ -250,7 +250,7 @@ update msg ({ env } as model) =
250250
CodebaseTreeMsg cMsg ->
251251
let
252252
( codebaseTree, cCmd, outMsg ) =
253-
CodebaseTree.update env cMsg model.codebaseTree
253+
CodebaseTree.update codebaseConfig cMsg model.codebaseTree
254254

255255
model2 =
256256
{ model | codebaseTree = codebaseTree }
@@ -337,8 +337,11 @@ navigateToPerspective model perspective =
337337
fetchPerspectiveAndCodebaseTree : Perspective -> Model -> ( Model, Cmd Msg )
338338
fetchPerspectiveAndCodebaseTree oldPerspective ({ env } as model) =
339339
let
340+
codebaseConfig =
341+
Env.toCodeConfig Api.codebaseApiEndpointToEndpointUrl model.env
342+
340343
( codebaseTree, codebaseTreeCmd ) =
341-
CodebaseTree.init env
344+
CodebaseTree.init codebaseConfig
342345

343346
fetchNamespaceDetailsCmd =
344347
env.perspective

src/UnisonShare/App.elm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ init env route =
7575
Workspace.init codebaseConfig Nothing
7676

7777
( codebaseTree, codebaseTreeCmd ) =
78-
CodebaseTree.init env
78+
CodebaseTree.init codebaseConfig
7979

8080
fetchNamespaceDetailsCmd =
8181
env.perspective
@@ -310,7 +310,7 @@ update msg ({ env } as model) =
310310
( Route.Project _ _, CodebaseTreeMsg cMsg ) ->
311311
let
312312
( codebaseTree, cCmd, outMsg ) =
313-
CodebaseTree.update env cMsg model.codebaseTree
313+
CodebaseTree.update codebaseConfig cMsg model.codebaseTree
314314

315315
model2 =
316316
{ model | codebaseTree = codebaseTree }
@@ -380,8 +380,11 @@ navigateToPerspective model perspective =
380380
fetchPerspectiveAndCodebaseTree : Perspective -> Model -> ( Model, Cmd Msg )
381381
fetchPerspectiveAndCodebaseTree oldPerspective ({ env } as model) =
382382
let
383+
codebaseConfig =
384+
Env.toCodeConfig Api.codebaseApiEndpointToEndpointUrl model.env
385+
383386
( codebaseTree, codebaseTreeCmd ) =
384-
CodebaseTree.init env
387+
CodebaseTree.init codebaseConfig
385388

386389
fetchNamespaceDetailsCmd =
387390
env.perspective

0 commit comments

Comments
 (0)