1
1
module Code.CodebaseTree exposing (Model , Msg , OutMsg (..) , init , update , view )
2
2
3
- import Api exposing ( ApiRequest )
3
+ import Code.CodebaseApi as CodebaseApi
4
4
import Code.CodebaseTree.NamespaceListing as NamespaceListing
5
5
exposing
6
6
( DefinitionListing (..)
7
7
, NamespaceListing (..)
8
8
, NamespaceListingChild (..)
9
9
, NamespaceListingContent
10
10
)
11
+ import Code.Config exposing (Config )
11
12
import Code.Definition.Category as Category
12
13
import Code.Definition.Reference exposing (Reference (..) )
14
+ import Code.EntityId as EntityId
13
15
import Code.FullyQualifiedName as FQN exposing (FQN , unqualifiedName )
14
16
import Code.FullyQualifiedNameSet as FQNSet exposing (FQNSet )
15
17
import Code.HashQualified exposing (HashQualified (..) )
16
- import Code.Perspective as Perspective exposing ( Perspective )
18
+ import Code.Perspective as Perspective
17
19
import Env exposing (Env )
18
20
import Html exposing (Html , a , div , label , span , text )
19
21
import Html.Attributes exposing (class , title )
20
22
import Html.Events exposing (onClick )
21
23
import Http
24
+ import Lib.Api as Api exposing (ApiRequest )
22
25
import Lib.Util as Util
23
26
import RemoteData exposing (RemoteData (..) , WebData )
24
27
import UI
@@ -37,13 +40,13 @@ type alias Model =
37
40
}
38
41
39
42
40
- init : Env -> ( Model , Cmd Msg )
41
- init env =
43
+ init : Config -> ( Model , Cmd Msg )
44
+ init config =
42
45
let
43
46
model =
44
47
{ rootNamespaceListing = Loading , expandedNamespaceListings = FQNSet . empty }
45
48
in
46
- ( model, Api . perform env . apiBasePath ( fetchRootNamespaceListing env . perspective ) )
49
+ ( model, Api . perform config . apiBasePath ( fetchRootNamespaceListing config ) )
47
50
48
51
49
52
@@ -63,8 +66,8 @@ type OutMsg
63
66
| ChangePerspectiveToNamespace FQN
64
67
65
68
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 =
68
71
case msg of
69
72
ToggleExpandedNamespaceListing fqn ->
70
73
let
@@ -98,7 +101,7 @@ update env msg model =
98
101
99
102
cmd =
100
103
if shouldExpand && not namespaceContentFetched then
101
- Api . perform env . apiBasePath ( fetchSubNamespaceListing env . perspective fqn)
104
+ Api . perform config . apiBasePath ( fetchSubNamespaceListing config fqn)
102
105
103
106
else
104
107
Cmd . none
@@ -147,7 +150,7 @@ update env msg model =
147
150
ChangePerspectiveToNamespace name ->
148
151
let
149
152
newPerspectiveFqn =
150
- case env . perspective of
153
+ case config . perspective of
151
154
Perspective . Namespace { fqn } ->
152
155
FQN . append fqn name
153
156
@@ -164,19 +167,20 @@ update env msg model =
164
167
-- EFFECTS
165
168
166
169
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
170
173
171
174
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)
175
178
176
179
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
180
184
|> Api . toRequest ( NamespaceListing . decode fqn) toMsg
181
185
182
186
0 commit comments